Skip to content

Commit ac5e73e

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 42aa322 + a37a7f7 commit ac5e73e

File tree

15 files changed

+148
-56
lines changed

15 files changed

+148
-56
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ endif
152152

153153
vscode-test:
154154
# Run the VS Code integration testsuite.
155-
MOCHA_ALS_UPDATE=$(MOCHA_ALS_UPDATE) cd integration/vscode/ada; LD_LIBRARY_PATH= npm run test
155+
cd integration/vscode/ada; MOCHA_ALS_UPDATE=$(MOCHA_ALS_UPDATE) LD_LIBRARY_PATH= python vscode-test-win-workaround.py npm run test
156156

157157
vscode-package:
158158
cd integration/vscode/ada; LD_LIBRARY_PATH= $(VSCE) package

integration/vscode/ada/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/*.vsix
33
/out/
44
/.vscode-test/
5-
**/obj/
65

76
# Locations of ALS executable in VS Code extension. VS Code is supported on arm,
87
# arm64 and x64 so we only consider those architectures.

integration/vscode/ada/.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ tsconfig.json
1515
**/*.ts
1616
**/*.ts.map
1717
xfail.yaml
18+
vscode-test-win-workaround.py

integration/vscode/ada/src/gnattest.ts

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
77
import { TestItem } from 'vscode';
88
import { CancellationToken } from 'vscode-languageclient';
99
import { adaExtState } from './extension';
10-
import { exe, getObjectDir } from './helpers';
10+
import { escapeRegExp, exe, getObjectDir } from './helpers';
1111

1212
export let controller: vscode.TestController;
1313
export let testRunProfile: vscode.TestRunProfile;
@@ -524,17 +524,20 @@ async function handleRunRequestedTests(request: vscode.TestRunRequest, token?: C
524524
return !excludedLeafTests?.includes(t);
525525
});
526526

527-
await buildTestDriver(run);
527+
/**
528+
* Mark tests as queued
529+
*/
530+
testsToRun.forEach((t) => run.enqueued(t));
531+
532+
/**
533+
* Build the test driver
534+
*/
535+
await buildTestDriverAndReportErrors(run, testsToRun);
528536

529537
if (token?.isCancellationRequested) {
530538
throw new vscode.CancellationError();
531539
}
532540

533-
/**
534-
* Mark tests as queued for execution
535-
*/
536-
testsToRun.forEach((t) => run.enqueued(t));
537-
538541
/**
539542
* Invoke the test driver for each test
540543
*/
@@ -563,6 +566,30 @@ async function handleRunRequestedTests(request: vscode.TestRunRequest, token?: C
563566
}
564567
}
565568

569+
/**
570+
* Build the test driver and report build failure as errors on the tests
571+
* requested for execution.
572+
*
573+
* @param run - the TestRun hosting the execution
574+
* @param testsToRun - the tests requested for execution - build failure will be
575+
* reported on those tests.
576+
*/
577+
async function buildTestDriverAndReportErrors(run: vscode.TestRun, testsToRun: vscode.TestItem[]) {
578+
try {
579+
await buildTestDriver(run);
580+
} catch (error) {
581+
/**
582+
* In case of failure, report all tests as errored.
583+
*/
584+
const md = getBuildErrorMessage();
585+
for (const test of testsToRun) {
586+
run.errored(test, new vscode.TestMessage(md));
587+
}
588+
run.end();
589+
throw error;
590+
}
591+
}
592+
566593
/**
567594
* VS Code terminals expect `\r\n` as a line separator, so this function is
568595
* a wrapper to prepare the given output to use that line separator and
@@ -584,9 +611,19 @@ async function handleRunAll(request: vscode.TestRunRequest, token?: Cancellation
584611
const run = controller.createTestRun(request, undefined, false);
585612
try {
586613
/**
587-
* First we need to build the test driver project.
614+
* Collect all tests, i.e. all leafs of the TestItem tree.
588615
*/
589-
await buildTestDriver(run);
616+
const allTests: TestItem[] = collectLeafsFromCollection(controller.items, token);
617+
618+
/**
619+
* Mark tests as queued
620+
*/
621+
allTests.forEach((t) => run.enqueued(t));
622+
623+
/**
624+
* Build the test driver
625+
*/
626+
await buildTestDriverAndReportErrors(run, allTests);
590627

591628
if (token?.isCancellationRequested) {
592629
throw new vscode.CancellationError();
@@ -603,11 +640,6 @@ async function handleRunAll(request: vscode.TestRunRequest, token?: Cancellation
603640
throw new vscode.CancellationError();
604641
}
605642

606-
/**
607-
* Now let's collect all tests, i.e. all leafs of the TestItem tree.
608-
*/
609-
const allTests: TestItem[] = collectLeafsFromCollection(controller.items, token);
610-
611643
/**
612644
* Mark all tests as started.
613645
*/
@@ -645,6 +677,21 @@ async function handleRunAll(request: vscode.TestRunRequest, token?: Cancellation
645677
}
646678
}
647679

680+
/**
681+
* Failures to build the test driver are reported as test errors to make them
682+
* clearly visible.
683+
*
684+
* @returns the message to be used as a test failure when the test driver fails
685+
* to build.
686+
*/
687+
function getBuildErrorMessage() {
688+
const md = new vscode.MarkdownString(
689+
'Failed to build the test driver, [view output](command:testing.showMostRecentOutput)'
690+
);
691+
md.isTrusted = true;
692+
return md;
693+
}
694+
648695
/**
649696
* Invoke gprbuild on the test driver project and pipe the output into the given
650697
* TestRun object.
@@ -658,21 +705,12 @@ async function buildTestDriver(run: vscode.TestRun) {
658705
*/
659706
const driverPrjPath = await getGnatTestDriverProjectPath();
660707
run.appendOutput(`Building the test harness project\r\n`);
661-
const gprbuild = logAndRun(run, ['gprbuild', '-P', driverPrjPath]);
708+
const gprbuild = logAndRun(run, ['gprbuild', '-P', driverPrjPath, '-cargs:ada', '-gnatef']);
662709

663710
prepareAndAppendOutput(run, gprbuild.stdout.toLocaleString());
664711
prepareAndAppendOutput(run, gprbuild.stderr.toLocaleString());
665712

666713
if (gprbuild.status !== 0) {
667-
/**
668-
* Failed to build the test driver. The output of gprbuild is
669-
* usually pretty explicit so no need to add an error message.
670-
*
671-
* No need to show an error tooltip because the exception raised below
672-
* already causes that.
673-
*/
674-
run.end();
675-
676714
throw Error('Error while building the test driver');
677715
}
678716
}
@@ -798,17 +836,6 @@ export function collectLeafItems(item: TestItem, token?: CancellationToken): vsc
798836
}
799837
}
800838

801-
/**
802-
*
803-
* @param text - a string possibly containing special RegExp characters.
804-
* @returns a string where all RegExp special characters have been escaped. This
805-
* can be useful when searching for an exact string which may contain special
806-
* characters.
807-
*/
808-
function escapeRegExp(text: string) {
809-
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
810-
}
811-
812839
/**
813840
*
814841
* Run a command line as a child process and pipe the output into the TestRun

integration/vscode/ada/src/helpers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,14 @@ export function getSymbols(
425425

426426
return allSymbols;
427427
}
428+
429+
/**
430+
*
431+
* @param text - a string possibly containing special RegExp characters.
432+
* @returns a string where all RegExp special characters have been escaped. This
433+
* can be useful when searching for an exact string which may contain special
434+
* characters.
435+
*/
436+
export function escapeRegExp(text: string) {
437+
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
438+
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,16 @@ ada: Build and run main - src/test.adb - kind: buildAndRunMain`.trim();
268268
const execStatus: number | undefined = await runTaskAndGetResult(task);
269269
assert.equal(execStatus, 0);
270270
} finally {
271-
// Reset the 'ada.projectFile' setting.
272-
await vscode.workspace.getConfiguration().update('ada.projectFile', initialProjectFile);
271+
// Reset the 'ada.projectFile' setting. If the previous value was
272+
// empty, update to 'undefined' so that the setting gets removed.
273+
// That's because the default value of that setting is the empty
274+
// string.
275+
await vscode.workspace
276+
.getConfiguration()
277+
.update(
278+
'ada.projectFile',
279+
initialProjectFile === '' ? undefined : initialProjectFile
280+
);
273281
}
274282
});
275283

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
runHandler,
2929
} from '../../../src/gnattest';
3030
import { activate } from '../utils';
31+
import { escapeRegExp } from '../../../src/helpers';
3132

3233
suite('GNATtest Integration Tests', function () {
3334
this.beforeAll(async () => {
@@ -329,8 +330,7 @@ bar
329330
*/
330331
const buildOutput = `
331332
Building the test harness project
332-
$ "gprbuild" "-P" "${await getGnatTestDriverProjectPath()}"
333-
`.trimStart();
333+
$ "gprbuild" "-P" "${await getGnatTestDriverProjectPath()}"`.trimStart();
334334
const runOutput = `
335335
Running the test driver
336336
$ "${await getGnatTestDriverExecPath()}" "--passed-tests=show"
@@ -340,19 +340,18 @@ speed2.ads:12:4: info: corresponding test PASSED
340340
speed2.ads:16:4: info: corresponding test PASSED
341341
speed1.ads:12:4: inherited at speed2.ads:20:4: info: corresponding test PASSED
342342
speed2.ads:10:4: error: corresponding test FAILED: Test not implemented. (speed2-auto_controller_test_data-auto_controller_tests.adb:46)
343-
6 tests run: 5 passed; 1 failed; 0 crashed.
344-
`.trimStart();
345-
assert.ok(outputs.includes(buildOutput));
346-
assert.ok(outputs.includes(runOutput));
343+
6 tests run: 5 passed; 1 failed; 0 crashed.`.trimStart();
344+
assert.match(outputs, RegExp(escapeRegExp(buildOutput)));
345+
assert.match(outputs, RegExp(escapeRegExp(runOutput)));
347346

348347
/**
349348
* Check that calling the run handler with an empty include array
350349
* also yields an execution of all tests.
351350
*/
352351
outputs = '';
353352
await runHandler({ include: [], exclude: undefined, profile: undefined }, undefined);
354-
assert.ok(outputs.includes(buildOutput));
355-
assert.ok(outputs.includes(runOutput));
353+
assert.match(outputs, RegExp(escapeRegExp(buildOutput)));
354+
assert.match(outputs, RegExp(escapeRegExp(runOutput)));
356355
} finally {
357356
/**
358357
* Reset the controller object on which we set a spy

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import assert from 'assert';
22
import { existsSync, readFileSync, writeFileSync } from 'fs';
3-
import { Glob, GlobOptionsWithFileTypesUnset } from 'glob';
4-
import Mocha, { MochaOptions } from 'mocha';
5-
import path from 'path';
6-
import { env } from 'process';
73
import * as vscode from 'vscode';
84

95
/**
@@ -54,9 +50,12 @@ export function update(): boolean {
5450
*/
5551
export async function activate(): Promise<void> {
5652
const ext = vscode.extensions.getExtension('AdaCore.ada');
57-
if (ext !== undefined) {
58-
if (!ext.isActive) {
59-
await ext.activate();
60-
}
61-
}
53+
assert(ext);
54+
/**
55+
* Previously this code returned when ext.isActive was true. This is not
56+
* enough because it doesn't indicate if any errors occured during
57+
* activation. Instead, always awaiting the result of the activate() method
58+
* does report activation errors as a promise rejection.
59+
*/
60+
await ext.activate();
6261
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Object dir of the project
2+
/obj/
3+
4+
# Generated when testing gnatsas tasks
5+
/report.sarif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

0 commit comments

Comments
 (0)