Skip to content

Commit

Permalink
testGrouping by label
Browse files Browse the repository at this point in the history
  • Loading branch information
matepek committed Mar 29, 2024
1 parent c76de3f commit f99f81d
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@
"preLaunchTask": "preDebug",
"postDebugTask": "postDebug"
},
{
"type": "extensionHost",
"request": "launch",
"name": "tmp",
"runtimeExecutable": "${execPath}",
"args": [
"/Users/matepek/Downloads/testmate",
"--extensionDevelopmentPath=${workspaceFolder}",
"--disable-extensions"
],
"env": {
"TESTMATE_DEBUG": "true"
},
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "preDebug",
"postDebugTask": "postDebug"
},
{
"type": "extensionHost",
"request": "launch",
Expand Down
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.12.0]

### Added

- `testGrouping.groupByLabel`. ex.: `"testGrouping": { "groupByLabel": { "label": "Release", "groupByExecutable": {}}}`

## [4.11.0] - 2024-03-09

### Changed
Expand Down
1 change: 1 addition & 0 deletions documents/configuration/test.advancedExecutables.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ It is undocumented. Contact me by opening an issue or read the code a bit.

| Property | Description |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `groupByLabel` | Groups tests by the given label. [Detail](https://github.com/matepek/vscode-catch2-test-adapter/blob/master/documents/configuration/test.advancedExecutables.md#testgrouping) |
| `groupByExecutable` | Groups tests by the executable file. [Detail](https://github.com/matepek/vscode-catch2-test-adapter/blob/master/documents/configuration/test.advancedExecutables.md#testgrouping) |
| `groupBySource` | It sorts the tests by the related source file group. (`${sourceRelPath}`, `${sourceAbsPath}`). [Detail](https://github.com/matepek/vscode-catch2-test-adapter/blob/master/documents/configuration/test.advancedExecutables.md#testgrouping) |
| `groupByTags` | True to group by every exiting combination of the tags. (`{$tag}`) Or it can be an array of tags: `["[tag1]["tag2"]", "tag2", "tag3"]` [Detail](https://github.com/matepek/vscode-catch2-test-adapter/blob/master/documents/configuration/test.advancedExecutables.md#testgrouping) |
Expand Down
355 changes: 355 additions & 0 deletions package.json

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/ConfigOfExecGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ export class ConfigOfExecGroup implements vscode.Disposable {

filePaths = await execWatcher.watched();

// TODO: we could figure out that it is a symlink and add extra
// filePaths.forEach(f => {
// try {
// if (fs.readlinkSync(f)) {
// console.log(`sym ${f}`);
// }
// } catch (e) {
// console.log(`not sym ${f}`);
// }
// });

execWatcher.onError((err: Error) => {
// eslint-disable-next-line
if ((err as any).code == 'ENOENT') this._shared.log.info('watcher error', err);
Expand Down
3 changes: 1 addition & 2 deletions src/Configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,9 @@ export class Configurations {
obj?: FrameworkSpecificConfig,
): FrameworkSpecificConfig {
const r: FrameworkSpecificConfig = {};
r.testGrouping = defaultTestGrouping;
if (typeof obj === 'object') {
if (obj.testGrouping) r.testGrouping = obj.testGrouping;
else r.testGrouping = defaultTestGrouping;

if (typeof obj.helpRegex === 'string') r.helpRegex = obj['helpRegex'];

Expand All @@ -672,7 +672,6 @@ export class Configurations {

if (typeof obj.failIfExceedsLimitNs === 'number') r.failIfExceedsLimitNs = obj.failIfExceedsLimitNs;
}

return r;
}

Expand Down
19 changes: 17 additions & 2 deletions src/TestGroupingInterface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export interface GroupByLabel extends TestGroupingConfig {
label?: string;
description?: string;
}

export interface GroupByExecutable extends TestGroupingConfig {
label?: string;
description?: string;
Expand Down Expand Up @@ -34,13 +39,16 @@ export type GroupByRegex = GroupByTagRegex;
///

export type TestGroupingType =
| 'groupByLabel'
| 'groupByExecutable'
| 'groupBySource'
| 'groupByTags'
| 'groupByTagRegex'
| 'groupByRegex';

export interface TestGroupingConfig extends Partial<Record<TestGroupingType, TestGroupingConfig>> {
groupByLabel?: GroupByLabel;

groupByExecutable?: GroupByExecutable;

groupBySource?: GroupBySource;
Expand All @@ -58,7 +66,10 @@ export function* testGroupIterator(
testGrouping: TestGroupingConfig,
): IterableIterator<[TestGroupingType, TestGroupingConfig]> {
while (testGrouping) {
if (testGrouping.groupByExecutable) {
if (testGrouping.groupByLabel) {
testGrouping = testGrouping.groupByLabel;
yield ['groupByLabel', testGrouping];
} else if (testGrouping.groupByExecutable) {
testGrouping = testGrouping.groupByExecutable;
yield ['groupByExecutable', testGrouping];
} else if (testGrouping.groupBySource) {
Expand All @@ -82,6 +93,7 @@ export function* testGroupIterator(
export async function testGroupingForEach(
testGrouping: TestGroupingConfig,
callbacks: {
groupByLabel: (g: GroupByLabel) => Promise<void>;
groupByExecutable: (g: GroupByExecutable) => Promise<void>;
groupBySource: (g: GroupBySource) => Promise<void>;
groupByTags: (g: GroupByTags) => Promise<void>;
Expand All @@ -90,7 +102,10 @@ export async function testGroupingForEach(
},
): Promise<void> {
while (testGrouping) {
if (testGrouping.groupByExecutable) {
if (testGrouping.groupByLabel) {
testGrouping = testGrouping.groupByLabel;
await callbacks.groupByLabel(testGrouping);
} else if (testGrouping.groupByExecutable) {
testGrouping = testGrouping.groupByExecutable;
await callbacks.groupByExecutable(testGrouping);
} else if (testGrouping.groupBySource) {
Expand Down
15 changes: 15 additions & 0 deletions src/framework/AbstractExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
testGroupingForEach,
GroupBySource,
GroupByTags,
GroupByLabel,
} from '../TestGroupingInterface';
import { isSpawnBusyError } from '../util/FSWrapper';
import { TestResultBuilder } from '../TestResultBuilder';
Expand Down Expand Up @@ -286,6 +287,20 @@ export abstract class AbstractExecutable<TestT extends AbstractTest = AbstractTe
};

await testGroupingForEach(testGrouping, {
groupByLabel: async (g: GroupByLabel): Promise<void> => {
const label = g.label ?? '${filename}';
const id = label;
const description = g.description ?? '${relDirpath}${osPathSep}';
itemOfLevel = await this._resolveAndGetOrCreateChildGroup(
itemOfLevel,
id,
label,
description,
varsToResolve,
undefined,
undefined,
);
},
groupByExecutable: async (g: GroupByExecutable): Promise<void> => {
this._updateVarsWithTags(g, tags, tagsResolveRule);

Expand Down
20 changes: 19 additions & 1 deletion test/cpp/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,27 @@
"cmake.configureOnOpen": true,
"testMate.cpp.test.advancedExecutables": [
{
"pattern":"build/**/*{test,Test,TEST}*",
"pattern":"build/**/*gtest*",
"runTask": {
// "before": ["build_all"]
},
"testGrouping": {
"groupByLabel": {
"label": "alma",
"groupByExecutable": {}
},
}
},
{
"pattern":"build/**/*suite*",
"runTask": {
// "before": ["build_all"]
},
"testGrouping": {
"groupByLabel": {
"label": "korte",
"groupByExecutable": {}
},
}
}
],
Expand Down

0 comments on commit f99f81d

Please sign in to comment.