1
1
import assert from 'assert' ;
2
2
import * as vscode from 'vscode' ;
3
3
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' ;
6
6
import { SemanticTokensParams , SemanticTokensRequest , integer } from 'vscode-languageclient' ;
7
7
import { adaExtState } from '../../../src/extension' ;
8
8
import { assertEqualToFileContent , update , activate } from '../utils' ;
9
9
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' ) ;
11
13
12
14
suite ( 'Highlighting' , function ( ) {
13
15
this . beforeAll ( async function ( ) {
14
16
await activate ( ) ;
15
17
} ) ;
16
18
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 ( / \. a d [ b s ] $ / ) ) {
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 ) ;
41
38
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 ( ) {
47
39
this . afterAll ( async function ( ) {
48
40
await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
49
41
} ) ;
@@ -57,10 +49,22 @@ suite('Highlighting', function () {
57
49
} ) ;
58
50
59
51
test ( 'semantic' , async function ( ) {
52
+ const absFileUri = vscode . Uri . file ( absPath ) ;
60
53
await testSemanticHighlighting ( absFileUri ) ;
61
54
} ) ;
62
55
} ) ;
63
56
}
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
+ }
64
68
} ) ;
65
69
66
70
/**
@@ -186,8 +190,6 @@ function getDocUri(p: string): vscode.Uri {
186
190
}
187
191
}
188
192
189
- const extensionRootPath = path . resolve ( __dirname , '../../../../' ) ;
190
-
191
193
/**
192
194
* A type representing the two TextMate grammars available in the repository.
193
195
* The values match directory names in the extension source directory. The
@@ -234,58 +236,63 @@ function testSyntaxHighlighting(absFilePath: string, syntax: Syntaxes) {
234
236
) ;
235
237
}
236
238
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' ) ;
285
240
} finally {
286
241
if ( existsSync ( workSnapPath ) ) {
287
242
// Rename .snap --> .snap.<syntax>
288
243
renameSync ( workSnapPath , refSnapPath ) ;
289
244
}
290
245
}
291
246
}
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