Skip to content

Commit 86e5bfc

Browse files
committed
Refactor the VS Code highlighting testsuite and add GPR tests
1 parent 6f0cde8 commit 86e5bfc

File tree

5 files changed

+1135
-83
lines changed

5 files changed

+1135
-83
lines changed

integration/vscode/ada/.vscode-test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default defineConfig(
7676
// This may prevent running locally on Linux and having the test
7777
// windows visible, but we consider this a minor use case for
7878
// now. A workaround is to remove this line.
79-
DISPLAY: ':99',
79+
DISPLAY: process.env.DISPLAY ?? ':99',
8080
},
8181
launchArgs: [
8282
// It's important to use the --user-data-dir=<path> form. The

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

Lines changed: 89 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,41 @@
11
import assert from 'assert';
22
import * as vscode from 'vscode';
33
import { spawnSync } from 'child_process';
4-
import { existsSync, opendirSync, renameSync } from 'fs';
5-
import path, { basename, dirname } from 'path';
4+
import fs, { existsSync, lstatSync, opendirSync, readdirSync, renameSync } from 'fs';
5+
import path from 'path';
66
import { SemanticTokensParams, SemanticTokensRequest, integer } from 'vscode-languageclient';
77
import { adaExtState } from '../../../src/extension';
88
import { assertEqualToFileContent, update, activate } from '../utils';
99

10-
let adaFilePaths: string[] = [];
10+
const extensionRootPath = path.join(__dirname, '..', '..', '..', '..');
11+
const testWsPath = path.join(extensionRootPath, 'test', 'workspaces', 'general');
12+
const adaTestsPath = path.join(testWsPath, 'src', 'highlighting');
1113

1214
suite('Highlighting', function () {
1315
this.beforeAll(async function () {
1416
await activate();
1517
});
1618

17-
const highlightingTestRoot = getDocUri('src/highlighting').fsPath;
18-
adaFilePaths = [];
19-
20-
function walk(dir: string) {
21-
const openDir = opendirSync(dir);
22-
try {
23-
let child;
24-
while ((child = openDir.readSync()) != null) {
25-
const childPath = path.join(dir, child.name);
26-
if (child.isDirectory()) {
27-
walk(childPath);
28-
} else if (child.isFile()) {
29-
if (child.name.match(/\.ad[bs]$/)) {
30-
adaFilePaths.push(childPath);
31-
}
32-
}
33-
}
34-
} finally {
35-
openDir.closeSync();
36-
}
37-
}
38-
39-
walk(highlightingTestRoot);
40-
assert.notStrictEqual(adaFilePaths, []);
19+
const adaTestPaths = [
20+
'objects/objects.ads',
21+
'unknown_imports/pkg.ads',
22+
'hello/hello.adb',
23+
'nesting/main.adb',
24+
'invalid_ada/invalid.adb',
25+
'types/types.ads',
26+
'subprograms/subprograms.adb',
27+
'pkgs-and-specs/pkgbodynospec.adb',
28+
'pkgs-and-specs/pkgbodywithspec.ads',
29+
'pkgs-and-specs/pkgbodywithspec.adb',
30+
'lsp-ada_handlers/lsp-ada_handlers.adb',
31+
'lsp-ada_handlers/lsp.ads',
32+
'lsp-ada_handlers/lsp-ada_handlers.ads',
33+
];
34+
35+
for (const relPath of adaTestPaths) {
36+
suite(relPath, function () {
37+
const absPath = path.join(adaTestsPath, relPath);
4138

42-
for (const absPath of adaFilePaths) {
43-
const testName = `${basename(dirname(absPath))}/${basename(absPath)}`;
44-
const absFileUri = vscode.Uri.file(absPath);
45-
46-
suite(testName, function () {
4739
this.afterAll(async function () {
4840
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
4941
});
@@ -57,10 +49,22 @@ suite('Highlighting', function () {
5749
});
5850

5951
test('semantic', async function () {
52+
const absFileUri = vscode.Uri.file(absPath);
6053
await testSemanticHighlighting(absFileUri);
6154
});
6255
});
6356
}
57+
58+
const gprTests = ['prj.gpr', 'src/test.gpr'];
59+
60+
for (const relPath of gprTests) {
61+
const gprSyntaxPath = path.join(extensionRootPath, 'syntaxes', 'gpr.tmLanguage.json');
62+
63+
test(relPath, function () {
64+
const gprPath = path.join(testWsPath, relPath);
65+
testSyntax(gprSyntaxPath, gprPath, 'source.gpr');
66+
});
67+
}
6468
});
6569

6670
/**
@@ -186,8 +190,6 @@ function getDocUri(p: string): vscode.Uri {
186190
}
187191
}
188192

189-
const extensionRootPath = path.resolve(__dirname, '../../../../');
190-
191193
/**
192194
* A type representing the two TextMate grammars available in the repository.
193195
* The values match directory names in the extension source directory. The
@@ -234,58 +236,63 @@ function testSyntaxHighlighting(absFilePath: string, syntax: Syntaxes) {
234236
);
235237
}
236238

237-
const cmd = [
238-
// Use npx to avoid sensitivity to PATH env var. On Windows, the
239-
// Node installation provides a 'npx' executable file which is a
240-
// Bash script which doesn't work on Windows. Instead on Windows,
241-
// the 'npx.cmd' file should be used.
242-
process.platform == 'win32' ? 'npx.cmd' : 'npx',
243-
'vscode-tmgrammar-snap',
244-
// We pass a non-existing language configuration, otherwise the tool
245-
// picks up the package.json file and always loads the grammar in
246-
// use.
247-
'--config',
248-
'none',
249-
// Show diffs on separate lines because color coding isn't visible
250-
// in the VS Code debug console.
251-
'--expandDiff',
252-
'-g',
253-
syntaxPath,
254-
'-s',
255-
'source.ada',
256-
absFilePath,
257-
];
258-
259-
if (update()) {
260-
cmd.push('--updateSnapshot');
261-
}
262-
263-
const proc = spawnSync(cmd[0], cmd.slice(1), { cwd: workDirPath });
264-
265-
if (proc.error) {
266-
// proc.error is set if we fail to spawn the child process
267-
throw proc.error;
268-
}
269-
270-
if (proc.status === null) {
271-
const msg =
272-
`Null return code for command: ${cmd.join(' ')}\n` +
273-
String(proc.stdout) +
274-
String(proc.stderr);
275-
assert.fail(msg);
276-
} else if (proc.status != 0) {
277-
const msg =
278-
`Return code ${proc.status.toString()} for command: cd ${workDirPath}; ${cmd.join(
279-
' '
280-
)}\n` +
281-
String(proc.stdout) +
282-
String(proc.stderr);
283-
assert.fail(msg);
284-
}
239+
testSyntax(syntaxPath, absFilePath, 'source.ada');
285240
} finally {
286241
if (existsSync(workSnapPath)) {
287242
// Rename .snap --> .snap.<syntax>
288243
renameSync(workSnapPath, refSnapPath);
289244
}
290245
}
291246
}
247+
248+
function testSyntax(syntaxPath: string, absFilePath: string, languageId: string) {
249+
const workDirPath = path.dirname(syntaxPath);
250+
const cmd = [
251+
// Use npx to avoid sensitivity to PATH env var. On Windows, the
252+
// Node installation provides a 'npx' executable file which is a
253+
// Bash script which doesn't work on Windows. Instead on Windows,
254+
// the 'npx.cmd' file should be used.
255+
process.platform == 'win32' ? 'npx.cmd' : 'npx',
256+
'vscode-tmgrammar-snap',
257+
// We pass a non-existing language configuration, otherwise the tool
258+
// picks up the package.json file and always loads the grammar in
259+
// use.
260+
'--config',
261+
'none',
262+
// Show diffs on separate lines because color coding isn't visible
263+
// in the VS Code debug console.
264+
'--expandDiff',
265+
'-g',
266+
syntaxPath,
267+
'-s',
268+
languageId,
269+
absFilePath,
270+
];
271+
272+
if (update()) {
273+
cmd.push('--updateSnapshot');
274+
}
275+
276+
const proc = spawnSync(cmd[0], cmd.slice(1), { cwd: workDirPath });
277+
278+
if (proc.error) {
279+
// proc.error is set if we fail to spawn the child process
280+
throw proc.error;
281+
}
282+
283+
if (proc.status === null) {
284+
const msg =
285+
`Null return code for command: ${cmd.join(' ')}\n` +
286+
String(proc.stdout) +
287+
String(proc.stderr);
288+
assert.fail(msg);
289+
} else if (proc.status != 0) {
290+
const msg =
291+
`Return code ${proc.status.toString()} for command: cd ${workDirPath}; ${cmd.join(
292+
' '
293+
)}\n` +
294+
String(proc.stdout) +
295+
String(proc.stderr);
296+
assert.fail(msg);
297+
}
298+
}

0 commit comments

Comments
 (0)