Skip to content

Commit a166984

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 4b3f236 + 92f0f3d commit a166984

27 files changed

+940
-93
lines changed

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"esbenp.prettier-vscode",
99
"gruntfuggly.triggertaskonsave",
1010
"davidanson.vscode-markdownlint",
11-
"adacore.ada"
11+
"adacore.ada",
12+
"ms-vscode.extension-test-runner"
1213
]
1314
}

.vscode/settings.json.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,10 @@
8888
"**/node_modules/*/**": true,
8989
"**/.hg/store/**": true,
9090
".obj/": true
91+
},
92+
"extension-test-runner.extractSettings": {
93+
"suite": ["describe", "suite"],
94+
"test": ["it", "test"],
95+
"extractWith": "syntax"
9196
}
9297
}

doc/HACKING.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ To write a functional test for Ada Language Server:
142142
Run `make vscode-test` to run the VS Code testsuite.
143143
144144
If you open the ALS repository in VS Code, it is also possible to run VS Code
145-
integration tests using the provided launch configurations:
146-
147-
- `(vscode) Run testsuite 'general'`
148-
- `(vscode) Run testsuite 'gnattest'`
145+
integration tests using the Testing view.
146+
The `integration/vscode/ada/.vscode-test.mjs` contains a configuration allowing to load the tests in the Testing view.
147+
The UI offers ways to run all or a subset of the tests.
149148
150149
### Other tests
151150
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { defineConfig } from '@vscode/test-cli';
2+
import { mkdtempSync } from 'fs';
3+
import * as os from 'os';
4+
import { join } from 'path';
5+
6+
let baseMochaOptions = {
7+
ui: 'tdd',
8+
color: true,
9+
};
10+
11+
if (process.env.MOCHA_REPORTER) {
12+
// If a reporter was specified externally, use it. For example, the CI
13+
// environment could set this to 'mocha-junit-reporter' to produce JUnit
14+
// results.
15+
baseMochaOptions.reporter = process.env.MOCHA_REPORTER;
16+
}
17+
18+
if (!baseMochaOptions.reporterOptions) {
19+
baseMochaOptions.reporterOptions = {
20+
maxDiffSize: 0,
21+
};
22+
}
23+
24+
if (process.env['MOCHA_TIMEOUT']) {
25+
baseMochaOptions.timeout = process.env['MOCHA_TIMEOUT'];
26+
} else {
27+
/**
28+
* Some tests involve calling gprbuild which takes time. So we disable test
29+
* timeouts altogether.
30+
*/
31+
baseMochaOptions.timeout = '0';
32+
}
33+
34+
if (process.env['MOCHA_GREP']) {
35+
baseMochaOptions.grep = process.env['MOCHA_GREP'];
36+
}
37+
38+
const testsuites = ['general', 'gnattest', 'workspace_missing_dirs'];
39+
40+
export default defineConfig(
41+
testsuites.map((suiteName) => {
42+
// --user-data-dir is set to a unique directory under the OS
43+
// default tmp directory for temporary files to avoid
44+
// warnings related to longs paths in IPC sockets created by
45+
// VSCode. The directory is made unique to avoid
46+
// interference between successive runs.
47+
//
48+
// It also allows multiple testsuites to run concurrently with each VS
49+
// Code instance using a different User data directory. This can happen
50+
// when tests are launched from the VS Code UI.
51+
const tmpdir = mkdtempSync(`${os.tmpdir()}/vsc-ada-test-`);
52+
53+
// Create a mocha options objects by copying the base one
54+
let mochaOptions = { ...baseMochaOptions };
55+
56+
if (process.env.MOCHA_REPORTER) {
57+
/**
58+
* Produce results for each testsuite separately
59+
*/
60+
const mochaFile = process.env.MOCHA_RESULTS_DIR
61+
? join(process.env.MOCHA_RESULTS_DIR, `${suiteName}.xml`)
62+
: `${suiteName}.xml`;
63+
mochaOptions.reporterOptions = { mochaFile: mochaFile };
64+
}
65+
66+
return {
67+
label: `Ada extension testsuite: ${suiteName}`,
68+
files: `out/test/suite/${suiteName}/**/*.test.js`,
69+
workspaceFolder: `./test/workspaces/${suiteName}`,
70+
mocha: mochaOptions,
71+
env: {
72+
// When working remotely on Linux, it is necessary to have "Xvfb
73+
// :99" running in the background, and this env variable set for
74+
// the VS Code instances spawned for testing.
75+
//
76+
// This may prevent running locally on Linux and having the test
77+
// windows visible, but we consider this a minor use case for
78+
// now. A workaround is to remove this line.
79+
DISPLAY: ':99',
80+
},
81+
launchArgs: ['--user-data-dir', tmpdir],
82+
// Use external installation if provided in the VSCODE env variable
83+
useInstallation: process.env.VSCODE ? { fromPath: process.env.VSCODE } : undefined,
84+
};
85+
})
86+
);

integration/vscode/ada/.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# This file contains patterns to exclude from the packaging into a .vsix
2+
.vscode-test.mjs
23
.vscode-test/
34
advanced/
45
node_modules/

integration/vscode/ada/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,9 +883,9 @@
883883
"pretest": "npm run compile",
884884
"lint": "eslint \"./src/**/*.{js,ts,tsx}\" --quiet --fix",
885885
"cilint": "eslint \"./src/**/*.{js,ts,tsx}\"",
886-
"test": "node ./out/test/runTest.js",
887-
"vscode-test": "vscode-test",
888-
"resolve-backtrace": "npx stacktracify"
886+
"test": "vscode-test",
887+
"resolve-backtrace": "npx stacktracify",
888+
"clean": "node -e \"fs.rmSync('out',{force:true,recursive:true})\""
889889
},
890890
"dependencies": {
891891
"@types/command-exists": "1.2.0",

integration/vscode/ada/test/suite/general/codelens.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import assert from 'assert';
2-
import { suite, test } from 'mocha';
32
import { Uri, window, workspace } from 'vscode';
43
import { adaExtState } from '../../../src/extension';
54
import { activate } from '../utils';

integration/vscode/ada/test/suite/general/debug.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import assert from 'assert';
2-
import { suite, test } from 'mocha';
32
import {
43
AdaConfig,
54
adaDynamicDebugConfigProvider,

integration/vscode/ada/test/suite/general/env.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import assert from 'assert';
2-
import { suite, test } from 'mocha';
32
import { setTerminalEnvironment } from '../../../src/helpers';
43

54
suite('Environment init', () => {

integration/vscode/ada/test/suite/general/extension.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as assert from 'assert';
22
import { adaExtState } from '../../../src/extension';
3-
import { suite, test } from 'mocha';
43
import { getProjectFile, getObjectDir } from '../../../src/helpers';
54
import { assertEqualToFileContent, activate } from '../utils';
65

76
import * as vscode from 'vscode';
7+
import { readFileSync, writeFileSync } from 'fs';
88

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

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

51-
assertEqualToFileContent(editorText, expectedUri);
53+
try {
54+
assertEqualToFileContent(editorText, expectedUri);
55+
} finally {
56+
/**
57+
* Restore the old file content
58+
*/
59+
writeFileSync(fileUri.fsPath, contentBefore);
60+
}
5261
} else {
5362
throw new Error('No workspace folder found for the specified URI');
5463
}

0 commit comments

Comments
 (0)