Skip to content

Commit

Permalink
Merge remote branch 'origin/master' into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
automatic-merge committed Mar 23, 2024
2 parents 4b3f236 + 92f0f3d commit a166984
Show file tree
Hide file tree
Showing 27 changed files with 940 additions and 93 deletions.
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"esbenp.prettier-vscode",
"gruntfuggly.triggertaskonsave",
"davidanson.vscode-markdownlint",
"adacore.ada"
"adacore.ada",
"ms-vscode.extension-test-runner"
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,10 @@
"**/node_modules/*/**": true,
"**/.hg/store/**": true,
".obj/": true
},
"extension-test-runner.extractSettings": {
"suite": ["describe", "suite"],
"test": ["it", "test"],
"extractWith": "syntax"
}
}
7 changes: 3 additions & 4 deletions doc/HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,9 @@ To write a functional test for Ada Language Server:
Run `make vscode-test` to run the VS Code testsuite.
If you open the ALS repository in VS Code, it is also possible to run VS Code
integration tests using the provided launch configurations:
- `(vscode) Run testsuite 'general'`
- `(vscode) Run testsuite 'gnattest'`
integration tests using the Testing view.
The `integration/vscode/ada/.vscode-test.mjs` contains a configuration allowing to load the tests in the Testing view.
The UI offers ways to run all or a subset of the tests.
### Other tests
Expand Down
86 changes: 86 additions & 0 deletions integration/vscode/ada/.vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { defineConfig } from '@vscode/test-cli';
import { mkdtempSync } from 'fs';
import * as os from 'os';
import { join } from 'path';

let baseMochaOptions = {
ui: 'tdd',
color: true,
};

if (process.env.MOCHA_REPORTER) {
// If a reporter was specified externally, use it. For example, the CI
// environment could set this to 'mocha-junit-reporter' to produce JUnit
// results.
baseMochaOptions.reporter = process.env.MOCHA_REPORTER;
}

if (!baseMochaOptions.reporterOptions) {
baseMochaOptions.reporterOptions = {
maxDiffSize: 0,
};
}

if (process.env['MOCHA_TIMEOUT']) {
baseMochaOptions.timeout = process.env['MOCHA_TIMEOUT'];
} else {
/**
* Some tests involve calling gprbuild which takes time. So we disable test
* timeouts altogether.
*/
baseMochaOptions.timeout = '0';
}

if (process.env['MOCHA_GREP']) {
baseMochaOptions.grep = process.env['MOCHA_GREP'];
}

const testsuites = ['general', 'gnattest', 'workspace_missing_dirs'];

export default defineConfig(
testsuites.map((suiteName) => {
// --user-data-dir is set to a unique directory under the OS
// default tmp directory for temporary files to avoid
// warnings related to longs paths in IPC sockets created by
// VSCode. The directory is made unique to avoid
// interference between successive runs.
//
// It also allows multiple testsuites to run concurrently with each VS
// Code instance using a different User data directory. This can happen
// when tests are launched from the VS Code UI.
const tmpdir = mkdtempSync(`${os.tmpdir()}/vsc-ada-test-`);

// Create a mocha options objects by copying the base one
let mochaOptions = { ...baseMochaOptions };

if (process.env.MOCHA_REPORTER) {
/**
* Produce results for each testsuite separately
*/
const mochaFile = process.env.MOCHA_RESULTS_DIR
? join(process.env.MOCHA_RESULTS_DIR, `${suiteName}.xml`)
: `${suiteName}.xml`;
mochaOptions.reporterOptions = { mochaFile: mochaFile };
}

return {
label: `Ada extension testsuite: ${suiteName}`,
files: `out/test/suite/${suiteName}/**/*.test.js`,
workspaceFolder: `./test/workspaces/${suiteName}`,
mocha: mochaOptions,
env: {
// When working remotely on Linux, it is necessary to have "Xvfb
// :99" running in the background, and this env variable set for
// the VS Code instances spawned for testing.
//
// This may prevent running locally on Linux and having the test
// windows visible, but we consider this a minor use case for
// now. A workaround is to remove this line.
DISPLAY: ':99',
},
launchArgs: ['--user-data-dir', tmpdir],
// Use external installation if provided in the VSCODE env variable
useInstallation: process.env.VSCODE ? { fromPath: process.env.VSCODE } : undefined,
};
})
);
1 change: 1 addition & 0 deletions integration/vscode/ada/.vscodeignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# This file contains patterns to exclude from the packaging into a .vsix
.vscode-test.mjs
.vscode-test/
advanced/
node_modules/
Expand Down
6 changes: 3 additions & 3 deletions integration/vscode/ada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,9 @@
"pretest": "npm run compile",
"lint": "eslint \"./src/**/*.{js,ts,tsx}\" --quiet --fix",
"cilint": "eslint \"./src/**/*.{js,ts,tsx}\"",
"test": "node ./out/test/runTest.js",
"vscode-test": "vscode-test",
"resolve-backtrace": "npx stacktracify"
"test": "vscode-test",
"resolve-backtrace": "npx stacktracify",
"clean": "node -e \"fs.rmSync('out',{force:true,recursive:true})\""
},
"dependencies": {
"@types/command-exists": "1.2.0",
Expand Down
1 change: 0 additions & 1 deletion integration/vscode/ada/test/suite/general/codelens.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import assert from 'assert';
import { suite, test } from 'mocha';
import { Uri, window, workspace } from 'vscode';
import { adaExtState } from '../../../src/extension';
import { activate } from '../utils';
Expand Down
1 change: 0 additions & 1 deletion integration/vscode/ada/test/suite/general/debug.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import assert from 'assert';
import { suite, test } from 'mocha';
import {
AdaConfig,
adaDynamicDebugConfigProvider,
Expand Down
1 change: 0 additions & 1 deletion integration/vscode/ada/test/suite/general/env.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import assert from 'assert';
import { suite, test } from 'mocha';
import { setTerminalEnvironment } from '../../../src/helpers';

suite('Environment init', () => {
Expand Down
13 changes: 11 additions & 2 deletions integration/vscode/ada/test/suite/general/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as assert from 'assert';
import { adaExtState } from '../../../src/extension';
import { suite, test } from 'mocha';
import { getProjectFile, getObjectDir } from '../../../src/helpers';
import { assertEqualToFileContent, activate } from '../utils';

import * as vscode from 'vscode';
import { readFileSync, writeFileSync } from 'fs';

suite('Extensions Test Suite', function () {
// Make sure the extension is activated
Expand Down Expand Up @@ -38,6 +38,7 @@ suite('Extensions Test Suite', function () {
];
const folder = vscode.workspace.workspaceFolders[0].uri;
const fileUri = vscode.Uri.joinPath(folder, 'src', 'test_subprogram_box.adb');
const contentBefore = readFileSync(fileUri.fsPath);
const expectedUri = vscode.Uri.joinPath(folder, 'src', 'test_subprogram_box.expected');

for (const cursorPos of cursorPositions) {
Expand All @@ -47,8 +48,16 @@ suite('Extensions Test Suite', function () {
await vscode.commands.executeCommand('ada.subprogramBox');
}
const editorText = vscode.window.activeTextEditor?.document.getText() ?? '';
vscode.window.activeTextEditor?.hide();

assertEqualToFileContent(editorText, expectedUri);
try {
assertEqualToFileContent(editorText, expectedUri);
} finally {
/**
* Restore the old file content
*/
writeFileSync(fileUri.fsPath, contentBefore);
}
} else {
throw new Error('No workspace folder found for the specified URI');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import assert from 'assert';
import * as vscode from 'vscode';
import { spawnSync } from 'child_process';
import { suite, test } from 'mocha';
import { existsSync, opendirSync, renameSync } from 'fs';
import path, { basename, dirname } from 'path';
import { SemanticTokensParams, SemanticTokensRequest, integer } from 'vscode-languageclient';
Expand Down
5 changes: 0 additions & 5 deletions integration/vscode/ada/test/suite/general/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion integration/vscode/ada/test/suite/general/syntax.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as assert from 'assert';
import { adaExtState } from '../../../src/extension';
import { AdaGrammarRule, AdaSyntaxCheckProvider } from '../../../src/alsProtocolExtensions';
import { suite, test } from 'mocha';
import { activate } from '../utils';

suite('Syntax Check Test Suite', function () {
Expand Down
1 change: 0 additions & 1 deletion integration/vscode/ada/test/suite/general/tasks.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assert from 'assert';
import { existsSync } from 'fs';
import { suite, test } from 'mocha';
import * as vscode from 'vscode';
import { exe, getProjectFile } from '../../../src/helpers';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { suite } from 'mocha';
import { activate } from '../utils';

suite('GNATtest Integration Tests', function () {
Expand Down
5 changes: 0 additions & 5 deletions integration/vscode/ada/test/suite/gnattest/index.ts

This file was deleted.

60 changes: 0 additions & 60 deletions integration/vscode/ada/test/suite/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,63 +60,3 @@ export async function activate(): Promise<void> {
}
}
}

export function runMochaTestsuite(suiteName: string, suiteDirectory: string) {
const mochaOptions: MochaOptions = {
ui: 'bdd',
color: true,
};

if (process.env.MOCHA_REPORTER) {
// If a reporter was specified externally, use it. For example, the CI
// environment could set this to 'mocha-junit-reporter' to produce JUnit
// results.
mochaOptions.reporter = process.env.MOCHA_REPORTER;
const mochaFile = process.env.MOCHA_RESULTS_DIR
? path.join(`${process.env.MOCHA_RESULTS_DIR}`, `${suiteName}.xml`)
: `${suiteName}.xml`;
mochaOptions.reporterOptions = {
mochaFile,
};
}

if (!mochaOptions.reporterOptions) {
mochaOptions.reporterOptions = {
maxDiffSize: 0,
};
}

// Create the mocha test
const mocha = new Mocha(mochaOptions);

return new Promise<void>((resolve, reject) => {
const globOptions: GlobOptionsWithFileTypesUnset = { cwd: suiteDirectory };
const glob = new Glob('**/*.test.js', globOptions);
for (const file of glob) {
mocha.addFile(path.resolve(suiteDirectory, file));
}
try {
// This variable is set in the launch configuration (launch.json) of
// the VS Code workspace to allow debugging without triggering test
// timeouts.
if (env['MOCHA_TIMEOUT']) {
mocha.timeout(env['MOCHA_TIMEOUT']);
}

if (env['MOCHA_GREP']) {
mocha.grep(env['MOCHA_GREP']);
}

// Run the mocha test
mocha.run((failures) => {
if (failures > 0) {
reject(new Error(`${failures} tests failed.`));
} else {
resolve();
}
});
} catch (err) {
reject(err);
}
});
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as assert from 'assert';
import { suite, test } from 'mocha';
import { activate } from '../utils';

import * as vscode from 'vscode';
Expand Down
9 changes: 9 additions & 0 deletions source/ada/lsp-ada_handlers-project_loading.adb
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ package body LSP.Ada_Handlers.Project_Loading is
Build_Path => Project_Environment.Build_Path,
Environment => Environment);

if Self.Project_Tree.Are_Sources_Loaded then
-- Update_Sources can't be called when the sources are already
-- loaded
Self.Project_Tree.Invalidate_Sources;
end if;
Self.Project_Tree.Update_Sources (With_Runtime => True);

exception
Expand Down Expand Up @@ -687,6 +692,10 @@ package body LSP.Ada_Handlers.Project_Loading is
Project => Project,
Context => GPR2.Context.Empty);

if Self.Project_Tree.Are_Sources_Loaded then
-- Update_Sources can't be called when the sources are already loaded
Self.Project_Tree.Invalidate_Sources;
end if;
Self.Project_Tree.Update_Sources (With_Runtime => True);

exception
Expand Down
12 changes: 12 additions & 0 deletions source/ada/lsp-ada_handlers.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,10 @@ package body LSP.Ada_Handlers is

-- New sources were created on this project, so recompute its view

if Self.Project_Tree.Are_Sources_Loaded then
-- Update_Sources can't be called when the sources are already loaded
Self.Project_Tree.Invalidate_Sources;
end if;
Self.Project_Tree.Update_Sources (With_Runtime => True);

-- For each created file of Value.files:
Expand Down Expand Up @@ -2346,6 +2350,10 @@ package body LSP.Ada_Handlers is

-- Some project sources were deleted, so recompute its view

if Self.Project_Tree.Are_Sources_Loaded then
-- Update_Sources can't be called when the sources are already loaded
Self.Project_Tree.Invalidate_Sources;
end if;
Self.Project_Tree.Update_Sources (With_Runtime => True);

-- For each delete file of Value.files:
Expand Down Expand Up @@ -2461,6 +2469,10 @@ package body LSP.Ada_Handlers is

-- Some project sources were renamed, so recompute its view

if Self.Project_Tree.Are_Sources_Loaded then
-- Update_Sources can't be called when the sources are already loaded
Self.Project_Tree.Invalidate_Sources;
end if;
Self.Project_Tree.Update_Sources (With_Runtime => True);

-- For each oldUri of Value.files:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package Foo.Bar1 is
procedure N is null;
end Foo.Bar1;
3 changes: 3 additions & 0 deletions testsuite/ada_lsp/Did_Rename_Files.context_corruption/foo.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package Foo is
procedure Do_Nothing is null;
end Foo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
with Foo.Bar1;

procedure Main is
begin
Foo.Bar1.N;
end Main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project Test is
for Main use ("main.adb");
end Test;
Loading

0 comments on commit a166984

Please sign in to comment.