Skip to content

Commit

Permalink
Merge remote branch 'origin/master' into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
automatic-merge committed Mar 26, 2024
2 parents a166984 + ce451f2 commit 8486b8b
Show file tree
Hide file tree
Showing 26 changed files with 873 additions and 143 deletions.
104 changes: 0 additions & 104 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,110 +38,6 @@
"PATH": "${env:PATH}"
}
},
{
"name": "(vscode) Run testsuite 'general'",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"outFiles": [
"${workspaceFolder}/integration/vscode/ada/out/**/*.js",
"!**/node_modules/**"
],
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/integration/vscode/ada",
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/general/index",
"${workspaceFolder}/integration/vscode/ada/test/workspaces/general"
],
// Below we make the executables of node modules visible to the tests.
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
// tests.
"env": {
"MOCHA_GREP": "${input:testPattern}",
// This is necessary to make the "child" vscode inherit the PATH
// variable set in the workspace settings. Without it in some setups
// (e.g. vscode remote) the child vscode does not get visibility
// over the Ada toolchain available in the parent vscode
// environment.
"PATH": "${env:PATH}",
// This is custom env var that we use in
// integration/vscode/ada/test/suite/index.ts to prevent timeouts in
// tests when debugging
"MOCHA_TIMEOUT": "0",
"MOCHA_ALS_UPDATE": "${input:updateTestRefs}"
},
"preLaunchTask": "npm: pretest - integration/vscode/ada",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "(vscode) Run testsuite 'gnattest'",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"outFiles": [
"${workspaceFolder}/integration/vscode/ada/out/**/*.js",
"!**/node_modules/**"
],
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/integration/vscode/ada",
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/gnattest/index",
"${workspaceFolder}/integration/vscode/ada/test/workspaces/gnattest"
],
// Below we make the executables of node modules visible to the tests.
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
// tests.
"env": {
"MOCHA_GREP": "${input:testPattern}",
// This is necessary to make the "child" vscode inherit the PATH
// variable set in the workspace settings. Without it in some setups
// (e.g. vscode remote) the child vscode does not get visibility
// over the Ada toolchain available in the parent vscode
// environment.
"PATH": "${env:PATH}",
// This is custom env var that we use in
// integration/vscode/ada/test/suite/index.ts to prevent timeouts in
// tests when debugging
"MOCHA_TIMEOUT": "0",
"MOCHA_ALS_UPDATE": "${input:updateTestRefs}"
},
"preLaunchTask": "npm: pretest - integration/vscode/ada",
// Switch to Debug Console to see test results
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "(vscode) Run testsuite 'workspace_missing_dirs'",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"outFiles": [
"${workspaceFolder}/integration/vscode/ada/out/**/*.js",
"!**/node_modules/**"
],
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/integration/vscode/ada",
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/workspace_missing_dirs/index",
"${workspaceFolder}/integration/vscode/ada/test/workspaces/workspace_missing_dirs"
],
// Below we make the executables of node modules visible to the tests.
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
// tests.
"env": {
"MOCHA_GREP": "${input:testPattern}",
// This is necessary to make the "child" vscode inherit the PATH
// variable set in the workspace settings. Without it in some setups
// (e.g. vscode remote) the child vscode does not get visibility
// over the Ada toolchain available in the parent vscode
// environment.
"PATH": "${env:PATH}",
// This is custom env var that we use in
// integration/vscode/ada/test/suite/index.ts to prevent timeouts in
// tests when debugging
"MOCHA_TIMEOUT": "0",
"MOCHA_ALS_UPDATE": "${input:updateTestRefs}"
},
"preLaunchTask": "npm: pretest - integration/vscode/ada",
// Switch to Debug Console to see test results
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "(npm) Launch all vscode tests with npm",
"type": "node",
Expand Down
7 changes: 7 additions & 0 deletions .vscode/settings.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,12 @@
"suite": ["describe", "suite"],
"test": ["it", "test"],
"extractWith": "syntax"
},
"extension-test-runner.debugOptions": {
"outFiles": [
"${workspaceFolder}/integration/vscode/ada/out/**/*.js",
"!**/node_modules/**"
],
"preLaunchTask": "npm: watch - integration/vscode/ada"
}
}
10 changes: 0 additions & 10 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@
"clear": true
}
},
{
"type": "npm",
"script": "watch",
"path": "integration/vscode/ada",
"group": "build",
"problemMatcher": ["$tsc-watch"],
"label": "npm: watch - integration/vscode/ada",
"detail": "node ./node_modules/typescript/bin/tsc -watch",
"isBackground": true
},
{
"type": "ada",
"configuration": {
Expand Down
2 changes: 1 addition & 1 deletion doc/HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Run `make vscode-test` to run the VS Code testsuite.
If you open the ALS repository in VS Code, it is also possible to run VS Code
integration tests using the Testing view.
The `integration/vscode/ada/.vscode-test.mjs` contains a configuration allowing to load the tests in the Testing view.
The UI offers ways to run all or a subset of the tests.
The UI offers ways to run or debug one test, a subset of tests or all tests.
### Other tests
Expand Down
7 changes: 6 additions & 1 deletion integration/vscode/ada/.vscode-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ export default defineConfig(
// now. A workaround is to remove this line.
DISPLAY: ':99',
},
launchArgs: ['--user-data-dir', tmpdir],
launchArgs: [
// It's important to use the --user-data-dir=<path> form. The
// --user-data-dir <path> form sometimes gets <path> considered
// as another workspace root directory.
`--user-data-dir=${tmpdir}`,
],
// Use external installation if provided in the VSCODE env variable
useInstallation: process.env.VSCODE ? { fromPath: process.env.VSCODE } : undefined,
};
Expand Down
4 changes: 2 additions & 2 deletions integration/vscode/ada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,8 @@
"compile": "node ./node_modules/typescript/bin/tsc",
"watch": "node ./node_modules/typescript/bin/tsc -watch",
"pretest": "npm run compile",
"lint": "eslint \"./src/**/*.{js,ts,tsx}\" --quiet --fix",
"cilint": "eslint \"./src/**/*.{js,ts,tsx}\"",
"lint": "eslint \"./src/**/*.{js,ts,tsx}\" \"./test/**/*.{js,ts,tsx}\" --quiet --fix",
"cilint": "eslint \"./src/**/*.{js,ts,tsx}\" \"./test/**/*.{js,ts,tsx}\"",
"test": "vscode-test",
"resolve-backtrace": "npx stacktracify",
"clean": "node -e \"fs.rmSync('out',{force:true,recursive:true})\""
Expand Down
8 changes: 8 additions & 0 deletions integration/vscode/ada/src/ExtensionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { initializeTesting } from './gnattest';
import { GprTaskProvider } from './gprTaskProvider';
import { TERMINAL_ENV_SETTING_NAME } from './helpers';
import { registerTaskProviders } from './taskProviders';
import { logger } from './extension';

/**
* This class encapsulates all state that should be maintained throughout the
Expand Down Expand Up @@ -125,10 +126,13 @@ export class ExtensionState {
// React to changes in configuration to recompute predefined tasks if the user
// changes scenario variables' values.
public configChanged = (e: vscode.ConfigurationChangeEvent) => {
logger.info('didChangeConfiguration event received');

if (
e.affectsConfiguration('ada.scenarioVariables') ||
e.affectsConfiguration('ada.projectFile')
) {
logger.info('project related settings have changed: clearing caches for tasks');
this.clearALSCache();
this.unregisterTaskProviders();
this.registerTaskProviders();
Expand All @@ -138,6 +142,10 @@ export class ExtensionState {
// a popup to reload the VS Code window and thus restart the
// Ada extension.
if (e.affectsConfiguration(TERMINAL_ENV_SETTING_NAME)) {
const new_value = vscode.workspace.getConfiguration().get(TERMINAL_ENV_SETTING_NAME);
logger.info(`${TERMINAL_ENV_SETTING_NAME} has changed: show reload popup`);
logger.info(`${TERMINAL_ENV_SETTING_NAME}: ${JSON.stringify(new_value, undefined, 2)}`);

void this.showReloadWindowPopup();
}
};
Expand Down
9 changes: 5 additions & 4 deletions integration/vscode/ada/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ async function activateExtension(context: vscode.ExtensionContext) {
adaExtState = new ExtensionState(context);
context.subscriptions.push(adaExtState);

// Subscribe to the didChangeConfiguration event
context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(adaExtState.configChanged)
);

const alsMiddleware: Middleware = {
executeCommand: alsCommandExecutor(adaExtState.adaClient),
};
Expand All @@ -148,10 +153,6 @@ async function activateExtension(context: vscode.ExtensionContext) {

await adaExtState.start();

context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(adaExtState.configChanged)
);

/**
* Register commands first so that commands such as displaying the extension
* Output become available even if the language servers fail to start.
Expand Down
20 changes: 10 additions & 10 deletions integration/vscode/ada/src/gnattest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function initializeTesting(context: vscode.ExtensionContext): vscode.Test
/**
* Reset and recreate the tree of TestItems based on the GNATtest XML.
*/
async function refreshTestItemTree() {
export async function refreshTestItemTree() {
controller.items.replace([]);
testData.clear();
await addTestsRootLevel();
Expand All @@ -142,7 +142,7 @@ async function getGnatTestXmlPath(): Promise<string> {
*
* @returns the full path to the GNATtest test driver GPR project.
*/
async function getGnatTestDriverProjectPath(): Promise<string> {
export async function getGnatTestDriverProjectPath(): Promise<string> {
const objDir = await getObjectDir();
const testDriverPath = path.join(objDir, 'gnattest', 'harness', 'test_driver.gpr');
return testDriverPath;
Expand All @@ -152,7 +152,7 @@ async function getGnatTestDriverProjectPath(): Promise<string> {
*
* @returns the full path to the GNATtest test driver executable.
*/
async function getGnatTestDriverExecPath(): Promise<string> {
export async function getGnatTestDriverExecPath(): Promise<string> {
const objDir = await getObjectDir();
const testDriverPath = path.join(objDir, 'gnattest', 'harness', 'test_runner' + exe);
return testDriverPath;
Expand Down Expand Up @@ -399,7 +399,7 @@ export function pathIsReadable(p: string): boolean {
* @param item - the TestItem whose children must be computed, or `undefined` if
* we should compute the root items of the tree.
*/
async function resolveHandler(
export async function resolveHandler(
item: TestItem | undefined,
recursive = false,
token?: CancellationToken
Expand Down Expand Up @@ -470,7 +470,7 @@ function configureTestExecution(controller: vscode.TestController) {
* @param request - the request based on the User selections
* @param token - a cancellation token
*/
async function runHandler(request: vscode.TestRunRequest, token: vscode.CancellationToken) {
export async function runHandler(request: vscode.TestRunRequest, token?: vscode.CancellationToken) {
if ((request.include?.length ?? 0) === 0 && (request.exclude?.length ?? 0) === 0) {
/**
* Run all tests. This ignores request.exclude which is why we only use
Expand All @@ -490,7 +490,7 @@ async function runHandler(request: vscode.TestRunRequest, token: vscode.Cancella
* controller.items) and request.exclude. It then runs the test driver for each
* test, using the --routines argument at each run to select a specific test.
*/
async function handleRunRequestedTests(request: vscode.TestRunRequest, token: CancellationToken) {
async function handleRunRequestedTests(request: vscode.TestRunRequest, token?: CancellationToken) {
const run = controller.createTestRun(request, undefined, false);
try {
const requestedRootTests = [];
Expand Down Expand Up @@ -580,7 +580,7 @@ function prepareAndAppendOutput(run: vscode.TestRun, out: string) {
* in {@link handleRunRequestedTests} fails because of GNATtest shortcomings, we
* still have this approach of running all tests as a backup.
*/
async function handleRunAll(request: vscode.TestRunRequest, token: CancellationToken) {
async function handleRunAll(request: vscode.TestRunRequest, token?: CancellationToken) {
const run = controller.createTestRun(request, undefined, false);
try {
/**
Expand Down Expand Up @@ -687,7 +687,7 @@ async function buildTestDriver(run: vscode.TestRun) {
* @param duration - the duration of execution of the test to be reported along
* with the outcome, if the information is available.
*/
function determineTestOutcome(
export function determineTestOutcome(
test: vscode.TestItem,
driverOutput: string,
run: vscode.TestRun,
Expand Down Expand Up @@ -763,7 +763,7 @@ function determineTestOutcome(
* @param token - a cancellation token to stop the traversal
* @returns the array of leaf TestItems reachable from the given collection.
*/
function collectLeafsFromCollection(
export function collectLeafsFromCollection(
items: vscode.TestItemCollection,
token?: CancellationToken
): vscode.TestItem[] {
Expand All @@ -783,7 +783,7 @@ function collectLeafsFromCollection(
* @param token - a cancellation token to stop the traversal
* @returns the array of leaf TestItems reachable from the given TestItem
*/
function collectLeafItems(item: TestItem, token?: CancellationToken): vscode.TestItem[] {
export function collectLeafItems(item: TestItem, token?: CancellationToken): vscode.TestItem[] {
if (item.children.size > 0) {
const res: vscode.TestItem[] = [];
item.children.forEach((i) => {
Expand Down
16 changes: 12 additions & 4 deletions integration/vscode/ada/src/taskProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import assert from 'assert';
import commandExists from 'command-exists';
import * as vscode from 'vscode';
import { adaExtState, logger } from './extension';
import { AdaMain, getAdaMains, getProjectFile, getSymbols } from './helpers';
import { SymbolKind } from 'vscode';
import { adaExtState } from './extension';
import { AdaMain, getAdaMains, getProjectFile, getSymbols } from './helpers';
import path from 'path';

export const ADA_TASK_TYPE = 'ada';

Expand Down Expand Up @@ -691,8 +692,15 @@ async function buildFullCommandLine(

if (taskDef.configuration.kind == 'runMain') {
if (adaMain) {
// Append the run of the main executable
cmd.push(adaMain.execRelPath());
// Append the main executable's relative path, prepending './'
// (or '.\\' on Windows) when needed, to make sure it's executable from
// a shell.
let execRelPath = adaMain.execRelPath();
if (!execRelPath.includes(path.sep)) {
execRelPath = '.' + path.sep + execRelPath;
}

cmd.push(execRelPath);
if (taskDef.configuration.mainArgs) {
cmd = cmd.concat(taskDef.configuration.mainArgs);
}
Expand Down
29 changes: 29 additions & 0 deletions integration/vscode/ada/test/suite/general/tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getSelectedRegion,
} from '../../../src/taskProviders';
import { activate } from '../utils';
import path from 'path';

suite('GPR Tasks Provider', function () {
let projectPath: string;
Expand Down Expand Up @@ -244,6 +245,34 @@ ada: Build and run main - src/test.adb - kind: buildAndRunMain`.trim();
assert.equal(execStatus, 0);
});

/**
* Check that the 'buildAndRunMain' task works fine with projects that
* do not explicitly define an object directory.
*/
test('buildAndRunMain task without object directory', async () => {
// Load a custom project that does not define any object dir by
// changing the 'ada.projectFile' setting.
const initialProjectFile = vscode.workspace.getConfiguration().get('ada.projectFile');
try {
await vscode.workspace
.getConfiguration()
.update(
'ada.projectFile',
'default_without_obj_dir' + path.sep + 'default_without_obj_dir.gpr'
);
const adaTasks = await vscode.tasks.fetchTasks({ type: 'ada' });
const task = adaTasks.find((v) => v.name == 'Build and run main - src/main1.adb');
assert(task);

// Check that the executable has been ran correctly
const execStatus: number | undefined = await runTaskAndGetResult(task);
assert.equal(execStatus, 0);
} finally {
// Reset the 'ada.projectFile' setting.
await vscode.workspace.getConfiguration().update('ada.projectFile', initialProjectFile);
}
});

/**
* Test that buildAndRunMain fails when configured with non-existing tasks
*/
Expand Down
Loading

0 comments on commit 8486b8b

Please sign in to comment.