diff --git a/CHANGELOG.md b/CHANGELOG.md index d0077c02..8d06547d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +## [4.3.0] + +### Added + +- `testMate.cpp.discovery.loadOnStartup` + ## [4.2.5] - 2022-07-30 Fixed broken version. diff --git a/README.md b/README.md index 222b4e7f..2e56c4cc 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ Not good enough for you?!: Edit your `.vscode/`[settings.json] file according to | `test.runtimeLimit` | [seconds] Test executable is running in a process. In case of an infinite loop it will run forever unless this parameter is set. It applies instantly. (0 means infinite) | | `test.parallelExecutionLimit` | Maximizes the number of the parallel test executions. (It applies instantly.) Note: If your executables depend on the **same resource** exclusively then this **could cause a problem**. | | `test.parallelExecutionOfExecutableLimit` | Maximizes the number of the parallel execution of executables. To enable this just for specific executables use the `testMate.cpp.test.advancedExecutables` -> `parallelizationLimit`. The `testMate.cpp.test.parallelExecutionLimit` is a global limit and this is a local one. Note: If your **test cases** depend on the **same resource** exclusively then this **could cause a problem**. | +| `discovery.loadOnStartup` | If true, the extension will try to load all the tests after the startup. Otherwise the user has to click on the Test icon on the sidebar to trigger the process. | | `discovery.gracePeriodForMissing` | [seconds] Test executables are being watched (only inside the workspace directory). In case of one recompiles it will try to preserve the test states. If compilation reaches timeout it will drop the suite. | | `discovery.runtimeLimit` | [seconds] The timeout of the test-executable used to identify it (Calls the exec with `--help`). | | `discovery.testListCaching` | (Experimental) In case your executable took too much time to list the tests, one can set this. It will preserve the output of `--gtest_list_tests --gtest_output=xml:...`. (Beware: Older Google Test doesn't support xml test list format.) | diff --git a/documents/configuration/debug.configTemplate.md b/documents/configuration/debug.configTemplate.md index 77f47473..633bd807 100644 --- a/documents/configuration/debug.configTemplate.md +++ b/documents/configuration/debug.configTemplate.md @@ -73,7 +73,7 @@ For [`vadimcn.vscode-lldb`](https://github.com/vadimcn/vscode-lldb#quick-start) | Variable name | Value meaning | Type | | --------------------- | ------------------------------------------------------------------------- | ------------------------------- | | `${label}` | The name of the test. Same as in the Test Explorer. | string | -| `${suiteLabel}` | The name of parent suites of the test. Same as in the Test Explorer. | string | +| `${parentLabel}` | The name of parent suites of the test. Same as in the Test Explorer. | string | | `${exec}` | The path of the executable. | string | | `${argsArray}` | The arguments for the executable. | string[] | | `${argsArrayFlat}` | The arguments for the executable. | string[] | diff --git a/package.json b/package.json index cb2335ec..49eff890 100644 --- a/package.json +++ b/package.json @@ -1393,6 +1393,12 @@ "default": 1, "minimum": 1 }, + "testMate.cpp.discovery.loadOnStartup": { + "markdownDescription": "If true, the extension will try to load all the tests after the startup. Otherwise the user has to click on the Test icon on the sidebar to trigger the process.", + "scope": "window", + "type": "boolean", + "default": false + }, "testMate.cpp.discovery.gracePeriodForMissing": { "markdownDescription": "[seconds] Test executables are being watched (only inside the workspace directory). In case of one recompiles it will try to preserve the test states. If compilation reaches timeout it will drop the suite.", "scope": "resource", @@ -1453,7 +1459,7 @@ "${envObjArray}", "${sourceFileMapObj}", "${label}", - "${suiteLabel}" + "${parentLabel}" ] }, { diff --git a/src/Configurations.ts b/src/Configurations.ts index cb37605d..f3454a55 100644 --- a/src/Configurations.ts +++ b/src/Configurations.ts @@ -34,6 +34,7 @@ export type Config = | 'test.randomGeneratorSeed' | 'test.runtimeLimit' | 'test.parallelExecutionLimit' + | 'discovery.loadOnStartup' | 'discovery.gracePeriodForMissing' | 'discovery.runtimeLimit' | 'discovery.testListCaching' @@ -101,7 +102,7 @@ export class Configurations { ); const template: vscode.DebugConfiguration = { - name: '${label} (${suiteLabel})', + name: '${label} (${parentLabel})', request: 'launch', type: 'cppdbg', }; @@ -339,6 +340,10 @@ export class Configurations { } } + getLoadAtStartup(): boolean { + return this._getD('discovery.loadOnStartup', false); + } + getDebugBreakOnFailure(): boolean { return this._getD('debug.breakOnFailure', true); } diff --git a/src/WorkspaceManager.ts b/src/WorkspaceManager.ts index 7376cbba..01ccac8a 100644 --- a/src/WorkspaceManager.ts +++ b/src/WorkspaceManager.ts @@ -127,6 +127,8 @@ export class WorkspaceManager implements vscode.Disposable { const configuration = this._getConfiguration(log); + this.initP = configuration.getLoadAtStartup(); + this._shared = new WorkspaceShared( workspaceFolder, log, @@ -205,7 +207,7 @@ export class WorkspaceManager implements vscode.Disposable { 'discovery.strictPattern', ) ) { - this.load(); + this.init(true); } } catch (e) { this._shared.log.exceptionS(e); @@ -224,12 +226,19 @@ export class WorkspaceManager implements vscode.Disposable { this._disposables.forEach(d => d.dispose()); } - async load(): Promise { + private initP: Thenable | boolean; + + async init(forceReload: boolean): Promise { + if (typeof this.initP !== 'boolean') { + if (!forceReload) return this.initP; + else await this.initP; + } + this._executableConfig.forEach(c => c.dispose()); const sbm = vscode.window.setStatusBarMessage('TestMate C++: loading tests...'); - return vscode.window.withProgress( + this.initP = vscode.window.withProgress( { location: { viewId: 'workbench.view.extension.test' } }, async ( progress: vscode.Progress<{ message?: string; increment?: number }>, @@ -251,6 +260,12 @@ export class WorkspaceManager implements vscode.Disposable { sbm.dispose(); }, ); + + return this.initP; + } + + public initAtStartupIfRequestes(): void { + if (this.initP === true) this.init(false); } private _getConfiguration(log: LoggerWrapper): Configurations { @@ -382,8 +397,6 @@ export class WorkspaceManager implements vscode.Disposable { const configuration = this._getConfiguration(this._shared.log); - const label = `${test.label} (${test.exec.shared.path})`; - const argsArray = executable.getDebugParams([test], configuration.getDebugBreakOnFailure()); // if (test instanceof Catch2Test) { @@ -477,7 +490,7 @@ export class WorkspaceManager implements vscode.Disposable { const varToResolve: ResolveRuleAsync[] = [ ...executable.shared.varToValue, - { resolve: '${label}', rule: label }, + { resolve: '${label}', rule: test.label }, { resolve: '${exec}', rule: executable.shared.path }, { resolve: '${args}', rule: argsArrayFunc }, // deprecated { resolve: '${argsArray}', rule: argsArrayFunc }, diff --git a/src/main.ts b/src/main.ts index 96bbf1b0..282533d9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -39,11 +39,10 @@ export async function activate(context: vscode.ExtensionContext): Promise } }; - const commandReloadTests = async () => { - return Promise.allSettled([...workspace2manager.values()].map(manager => manager.load())).then(); - }; + const initWorkspaceManagers = (forceReload: boolean) => + Promise.allSettled([...workspace2manager.values()].map(manager => manager.init(forceReload))).then(); - const commandReloadWorkspaces = async () => { + const commandReloadWorkspaces = () => { for (const ws of workspace2manager.keys()) { removeWorkspaceManager(ws); } @@ -52,7 +51,8 @@ export async function activate(context: vscode.ExtensionContext): Promise controller.items.replace([]); addOpenedWorkspaces(); - return Promise.allSettled([...workspace2manager.values()].map(manager => manager.load())).then(); + + return initWorkspaceManagers(false); }; /// @@ -68,7 +68,7 @@ export async function activate(context: vscode.ExtensionContext): Promise return Promise.resolve(); } } else { - return Promise.allSettled([...workspace2manager.values()].map(manager => manager.load())).then(); + return initWorkspaceManagers(false); } }; @@ -229,7 +229,9 @@ export async function activate(context: vscode.ExtensionContext): Promise }, }); - context.subscriptions.push(vscode.commands.registerCommand('testMate.cmd.reload-tests', commandReloadTests)); + context.subscriptions.push( + vscode.commands.registerCommand('testMate.cmd.reload-tests', () => initWorkspaceManagers(true)), + ); context.subscriptions.push( vscode.commands.registerCommand('testMate.cmd.reload-workspaces', commandReloadWorkspaces), @@ -238,4 +240,6 @@ export async function activate(context: vscode.ExtensionContext): Promise addOpenedWorkspaces(); log.info('Activation finished'); + + [...workspace2manager.values()].forEach(manager => manager.initAtStartupIfRequestes()); } diff --git a/test/disabled_TODO/toRefactor/Catch2FrameworkLoad.test.ts b/test/disabled_TODO/toRefactor/Catch2FrameworkLoad.test.ts index 51f5fc65..4e9e396a 100644 --- a/test/disabled_TODO/toRefactor/Catch2FrameworkLoad.test.ts +++ b/test/disabled_TODO/toRefactor/Catch2FrameworkLoad.test.ts @@ -1378,7 +1378,7 @@ describe(path.basename(__filename), function () { await settings.updateConfig('debug.configTemplate', { label: '${label}', - suiteLabel: '${suiteLabel}', + parentLabel: '${parentLabel}', exec: '${exec}', args: '${argsArray}', argsArray: '${argsArray}', @@ -1412,7 +1412,7 @@ describe(path.basename(__filename), function () { assert.deepStrictEqual(debugConfig.label, 's1t1'); assert.deepStrictEqual(debugConfig.name, 's1t1 (XexecPath1)'); assert.deepStrictEqual(debugConfig.request, 'launch'); - assert.deepStrictEqual(debugConfig.suiteLabel, 'XexecPath1'); + assert.deepStrictEqual(debugConfig.parentLabel, 'XexecPath1'); assert.deepStrictEqual(debugConfig.envObj.C2TESTVAR, 'c2testval'); assert.deepStrictEqual(debugConfig.sourceFileMap, { '/cpp': '/cxx' }); });