Skip to content

Commit 2edab84

Browse files
committed
Set up the environment outside the testsuite itself
It feels like a better practice. Also provided comments in some places that needed them.
1 parent 3384e2c commit 2edab84

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed

.vscode/launch.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@
4949
// tests when debugging
5050
"MOCHA_TIMEOUT": "0"
5151
},
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+
},
5270
"preLaunchTask": "npm: pretest"
5371
},
5472
{
@@ -76,6 +94,24 @@
7694
// integration/vscode/ada/test/suite/highlighting.test.ts
7795
"MOCHA_ALS_UPDATE": "1"
7896
},
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+
},
79115
"preLaunchTask": "npm: pretest"
80116
},
81117
{

integration/vscode/ada/src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ export class ContextClients {
109109
}
110110

111111
export async function activate(context: vscode.ExtensionContext): Promise<void> {
112+
// Create an output channel for the extension. There are dedicated channels
113+
// for the Ada and Gpr language servers, and this one is a general channel
114+
// for non-LSP features of the extension.
112115
mainLogChannel = vscode.window.createOutputChannel('Ada Extension');
116+
113117
context.subscriptions.push(
114118
vscode.commands.registerCommand('ada.showExtensionOutput', () => mainLogChannel.show())
115119
);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ async function testSemanticHighlighting(docUri: vscode.Uri) {
168168
assertEqualToFileContent(actual, expectedUri);
169169
}
170170

171+
/**
172+
* This function queries the VS Code API for the Ada extension and waits until
173+
* it is activated.
174+
*/
171175
async function activate(): Promise<void> {
172176
const ext = vscode.extensions.getExtension('AdaCore.ada');
173177
if (ext !== undefined) {
@@ -177,13 +181,26 @@ async function activate(): Promise<void> {
177181
}
178182
}
179183

184+
/**
185+
*
186+
* @param path - path of a file or directory relative to the TestWorkspace
187+
* workspace.
188+
* @returns a Uri representing the full path to the given relative workspace
189+
* path
190+
*/
180191
function getDocUri(path: string): vscode.Uri {
181192
assert(vscode.workspace.workspaceFolders !== undefined);
182193
return vscode.Uri.joinPath(vscode.workspace.workspaceFolders[0].uri, path);
183194
}
184195

185196
const extensionRootPath = path.resolve(__dirname, '../../../');
186197

198+
/**
199+
* A type representing the two TextMate grammars available in the repository.
200+
* The values match directory names in the extension source directory. The
201+
* 'syntaxes' grammar is the one currently in use in the package.json, while the
202+
* 'advanced' one is an experimental alternative that is not used in production.
203+
*/
187204
type Syntaxes = 'syntaxes' | 'advanced';
188205

189206
/**

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import path, { resolve } from 'path';
44
import { env } from 'process';
55

66
export function run(): Promise<void> {
7-
// Make package executables visible
8-
const extensionRootPath = path.resolve(__dirname, '../../../');
9-
const nodeModulesBin = path.join(extensionRootPath, 'node_modules', '.bin');
10-
process.env.PATH = `${nodeModulesBin}${path.delimiter}${process.env.PATH as string}`;
11-
127
const mochaOptions: MochaOptions = {
138
ui: 'tdd',
149
color: true,
@@ -30,6 +25,9 @@ export function run(): Promise<void> {
3025
mocha.addFile(resolve(testsRoot, file));
3126
}
3227
try {
28+
// This variable is set in the launch configuration (launch.json) of
29+
// the VS Code workspace to allow debugging without triggering test
30+
// timeouts.
3331
if (env['MOCHA_TIMEOUT']) {
3432
mocha.timeout(env['MOCHA_TIMEOUT']);
3533
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export function assertEqualToFileContent(actual: string, expectedUri: vscode.Uri
2828
/**
2929
*
3030
* @returns true if the testsuite is running in update mode, i.e. the
31-
* environment variable MOCHA_ALS_UPDATE is set
31+
* environment variable MOCHA_ALS_UPDATE is set. For example, the VS Code
32+
* workspace of this repository provides a launch configuration with that
33+
* environment variable set to allow quickly updating test references.
3234
*/
3335
export function update(): boolean {
3436
return process.env.MOCHA_ALS_UPDATE ? true : false;

0 commit comments

Comments
 (0)