Skip to content

Commit

Permalink
loadOnStartup documenttion
Browse files Browse the repository at this point in the history
  • Loading branch information
matepek committed Aug 5, 2022
1 parent 9296d60 commit 398802d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.) |
Expand Down
2 changes: 1 addition & 1 deletion documents/configuration/debug.configTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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[] |
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -1453,7 +1459,7 @@
"${envObjArray}",
"${sourceFileMapObj}",
"${label}",
"${suiteLabel}"
"${parentLabel}"
]
},
{
Expand Down
7 changes: 6 additions & 1 deletion src/Configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type Config =
| 'test.randomGeneratorSeed'
| 'test.runtimeLimit'
| 'test.parallelExecutionLimit'
| 'discovery.loadOnStartup'
| 'discovery.gracePeriodForMissing'
| 'discovery.runtimeLimit'
| 'discovery.testListCaching'
Expand Down Expand Up @@ -101,7 +102,7 @@ export class Configurations {
);

const template: vscode.DebugConfiguration = {
name: '${label} (${suiteLabel})',
name: '${label} (${parentLabel})',
request: 'launch',
type: 'cppdbg',
};
Expand Down Expand Up @@ -339,6 +340,10 @@ export class Configurations {
}
}

getLoadAtStartup(): boolean {
return this._getD<boolean>('discovery.loadOnStartup', false);
}

getDebugBreakOnFailure(): boolean {
return this._getD<boolean>('debug.breakOnFailure', true);
}
Expand Down
25 changes: 19 additions & 6 deletions src/WorkspaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -205,7 +207,7 @@ export class WorkspaceManager implements vscode.Disposable {
'discovery.strictPattern',
)
) {
this.load();
this.init(true);
}
} catch (e) {
this._shared.log.exceptionS(e);
Expand All @@ -224,12 +226,19 @@ export class WorkspaceManager implements vscode.Disposable {
this._disposables.forEach(d => d.dispose());
}

async load(): Promise<void> {
private initP: Thenable<void> | boolean;

async init(forceReload: boolean): Promise<void> {
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 }>,
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 },
Expand Down
18 changes: 11 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
}
};

const commandReloadTests = async () => {
return Promise.allSettled([...workspace2manager.values()].map(manager => manager.load())).then<void>();
};
const initWorkspaceManagers = (forceReload: boolean) =>
Promise.allSettled([...workspace2manager.values()].map(manager => manager.init(forceReload))).then<void>();

const commandReloadWorkspaces = async () => {
const commandReloadWorkspaces = () => {
for (const ws of workspace2manager.keys()) {
removeWorkspaceManager(ws);
}
Expand All @@ -52,7 +51,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
controller.items.replace([]);

addOpenedWorkspaces();
return Promise.allSettled([...workspace2manager.values()].map(manager => manager.load())).then<void>();

return initWorkspaceManagers(false);
};

///
Expand All @@ -68,7 +68,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
return Promise.resolve();
}
} else {
return Promise.allSettled([...workspace2manager.values()].map(manager => manager.load())).then();
return initWorkspaceManagers(false);
}
};

Expand Down Expand Up @@ -229,7 +229,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
},
});

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),
Expand All @@ -238,4 +240,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
addOpenedWorkspaces();

log.info('Activation finished');

[...workspace2manager.values()].forEach(manager => manager.initAtStartupIfRequestes());
}
4 changes: 2 additions & 2 deletions test/disabled_TODO/toRefactor/Catch2FrameworkLoad.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
Expand Down Expand Up @@ -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' });
});
Expand Down

0 comments on commit 398802d

Please sign in to comment.