Skip to content

Commit 63be37d

Browse files
committed
Improve test infrastructure
* Add a launch configuration to run tests that match a given regexp
1 parent 12aa351 commit 63be37d

File tree

6 files changed

+83
-43
lines changed

6 files changed

+83
-43
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ end_of_line = lf
88
trim_trailing_whitespace = true
99
insert_final_newline = true
1010

11+
[*.tokens]
12+
insert_final_newline = false
13+
1114
[*.py]
1215
indent_size = 4
1316

.vscode/launch.json

Lines changed: 68 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@
2525
// debug instance on the same workspace as the development instance.
2626
// So you can checkout a second copy of the ALS repository under
2727
// ../als-rt and use it with the following line.
28-
"${workspaceFolder}/../als-rt"
28+
// "${workspaceFolder}/../als-rt"
29+
"${workspaceFolder}/integration/vscode/ada/test/TestWorkspace"
2930
],
30-
"preLaunchTask": "npm: compile"
31+
"preLaunchTask": "npm: compile",
32+
"env": {
33+
// This is necessary to make the "child" vscode inherit the PATH
34+
// variable set in the workspace settings. Without it in some setups
35+
// (e.g. vscode remote) the child vscode does not get visibility
36+
// over the Ada toolchain available in the parent vscode
37+
// environment.
38+
"PATH": "${env:PATH}"
39+
}
3140
},
3241
{
3342
"name": "Extension Tests",
@@ -43,30 +52,21 @@
4352
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/index",
4453
"${workspaceFolder}/integration/vscode/ada/test/TestWorkspace"
4554
],
55+
// Below we make the executables of node modules visible to the tests.
56+
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
57+
// tests.
4658
"env": {
59+
// This is necessary to make the "child" vscode inherit the PATH
60+
// variable set in the workspace settings. Without it in some setups
61+
// (e.g. vscode remote) the child vscode does not get visibility
62+
// over the Ada toolchain available in the parent vscode
63+
// environment.
64+
"PATH": "${env:PATH}",
4765
// This is custom env var that we use in
4866
// integration/vscode/ada/test/suite/index.ts to prevent timeouts in
4967
// tests when debugging
5068
"MOCHA_TIMEOUT": "0"
5169
},
52-
// Below we make the executables of node modules visible to the tests.
53-
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
54-
// tests.
55-
"windows": {
56-
"env": {
57-
"PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin;${env:PATH}"
58-
}
59-
},
60-
"osx": {
61-
"env": {
62-
"PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin:${env:PATH}"
63-
}
64-
},
65-
"linux": {
66-
"env": {
67-
"PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin:${env:PATH}"
68-
}
69-
},
7070
"preLaunchTask": "npm: pretest"
7171
},
7272
{
@@ -83,7 +83,16 @@
8383
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/index",
8484
"${workspaceFolder}/integration/vscode/ada/test/TestWorkspace"
8585
],
86+
// Below we make the executables of node modules visible to the tests.
87+
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
88+
// tests.
8689
"env": {
90+
// This is necessary to make the "child" vscode inherit the PATH
91+
// variable set in the workspace settings. Without it in some setups
92+
// (e.g. vscode remote) the child vscode does not get visibility
93+
// over the Ada toolchain available in the parent vscode
94+
// environment.
95+
"PATH": "${env:PATH}",
8796
// This is custom env var that we use in
8897
// integration/vscode/ada/test/suite/index.ts to prevent timeouts in
8998
// tests when debugging
@@ -94,24 +103,6 @@
94103
// integration/vscode/ada/test/suite/highlighting.test.ts
95104
"MOCHA_ALS_UPDATE": "1"
96105
},
97-
// Below we make the executables of node modules visible to the tests.
98-
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
99-
// tests.
100-
"windows": {
101-
"env": {
102-
"PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin;${env:PATH}"
103-
}
104-
},
105-
"osx": {
106-
"env": {
107-
"PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin:${env:PATH}"
108-
}
109-
},
110-
"linux": {
111-
"env": {
112-
"PATH": "${workspaceFolder}/integration/vscode/ada/node_modules/.bin:${env:PATH}"
113-
}
114-
},
115106
"preLaunchTask": "npm: pretest"
116107
},
117108
{
@@ -121,6 +112,45 @@
121112
"target": ".obj/server/ada_language_server",
122113
"cwd": "${workspaceRoot}",
123114
"valuesFormatting": "parseText"
115+
},
116+
{
117+
"name": "Extension Tests (Test Name Regexp)",
118+
"type": "extensionHost",
119+
"request": "launch",
120+
"runtimeExecutable": "${execPath}",
121+
"outFiles": [
122+
"${workspaceFolder}/integration/vscode/ada/out/**/*.js",
123+
"!**/node_modules/**"
124+
],
125+
"args": [
126+
"--extensionDevelopmentPath=${workspaceFolder}/integration/vscode/ada",
127+
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/index",
128+
"${workspaceFolder}/integration/vscode/ada/test/TestWorkspace"
129+
],
130+
// Below we make the executables of node modules visible to the tests.
131+
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
132+
// tests.
133+
"env": {
134+
"MOCHA_GREP": "${input:testPattern}",
135+
// This is necessary to make the "child" vscode inherit the PATH
136+
// variable set in the workspace settings. Without it in some setups
137+
// (e.g. vscode remote) the child vscode does not get visibility
138+
// over the Ada toolchain available in the parent vscode
139+
// environment.
140+
"PATH": "${env:PATH}",
141+
// This is custom env var that we use in
142+
// integration/vscode/ada/test/suite/index.ts to prevent timeouts in
143+
// tests when debugging
144+
"MOCHA_TIMEOUT": "0"
145+
},
146+
"preLaunchTask": "npm: pretest"
147+
}
148+
],
149+
"inputs": [
150+
{
151+
"id": "testPattern",
152+
"description": "A regexp of tests to run",
153+
"type": "promptString"
124154
}
125155
]
126156
}

.vscode/settings.json.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"ada.projectFile": "gnat/lsp_server.gpr",
33
"ada.scenarioVariables": {
44
// Use static linking in local development to enable running the
5-
// ada_language_server executable after relaction into the VS Code
5+
// ada_language_server executable after relocation into the VS Code
66
// extension.
77
"LIBRARY_TYPE": "static"
88
},

integration/vscode/ada/test/TestWorkspace/default.gpr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ project Default is
44
("gnatpp.adb",
55
"test.adb");
66

7-
for Source_Dirs use ("src");
7+
for Source_Dirs use ("src", "highlighing");
88
for Object_Dir use "obj";
99
for Main use Tools_Mains;
10-
10+
1111
package Builder is
1212
for Executable ("gnatpp.adb") use "gnatpp";
1313
for Executable ("test.adb") use "gnattest";

integration/vscode/ada/test/suite/highlighting.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ function testSyntaxHighlighting(absFilePath: string, syntax: Syntaxes) {
242242
}
243243

244244
const cmd = [
245+
// Use npx to avoid sensitivity to PATH env var
245246
'npx',
246247
'vscode-tmgrammar-snap',
247248
// We pass a non-existing language configuration, otherwise the tool
@@ -263,7 +264,7 @@ function testSyntaxHighlighting(absFilePath: string, syntax: Syntaxes) {
263264
cmd.push('--updateSnapshot');
264265
}
265266

266-
const proc = spawnSync(cmd[0], cmd.slice(1));
267+
const proc = spawnSync(cmd[0], cmd.slice(1), { cwd: workDirPath });
267268

268269
if (proc.error) {
269270
// proc.error is set if we fail to spawn the child process
@@ -278,7 +279,9 @@ function testSyntaxHighlighting(absFilePath: string, syntax: Syntaxes) {
278279
assert.fail(msg);
279280
} else if (proc.status != 0) {
280281
const msg =
281-
`Return code ${proc.status.toString()} for command: ${cmd.join(' ')}\n` +
282+
`Return code ${proc.status.toString()} for command: cd ${workDirPath}; ${cmd.join(
283+
' '
284+
)}\n` +
282285
String(proc.stdout) +
283286
String(proc.stderr);
284287
assert.fail(msg);

integration/vscode/ada/test/suite/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export function run(): Promise<void> {
3535
mocha.timeout(env['MOCHA_TIMEOUT']);
3636
}
3737

38+
if (env['MOCHA_GREP']) {
39+
mocha.grep(env['MOCHA_GREP']);
40+
}
41+
3842
// Run the mocha test
3943
mocha.run((failures) => {
4044
if (failures > 0) {

0 commit comments

Comments
 (0)