Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ No core module imports `vscode`, even for types, nor any adapter module. The cor
| `src/coverageRun.ts` | Pure | Run modes, and a coverage request's file work: resetting and clearing counters, and reading its Cobertura report |
| `src/buildReporting.ts` | Pure | A build's results, or why it gave none, reported to the Testing view |
| `src/testFileNodes.ts` | Pure | A project's test files as tree nodes, with their ids and pretty labels |
| `src/testFileHierarchy.ts` | Pure | Test files grouped by folder, for `ceedlingExplorer.testFileHierarchy` |
| `src/engineFileSystem.ts` | Pure | The filesystem the engine works through, and the read, list, and delete helpers that share the engine's one read limit |
| `src/ceedlingProcess.ts` | Pure | Running Ceedling, with per-run cancellation |
| `src/unityTestDiscovery.ts` | Pure | Test functions and cases in source, named as Unity names them |
Expand Down
7 changes: 7 additions & 0 deletions docs/mkdocs/manual/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ Default: `true`

Shortens each test file’s label by dropping its path, prefix, and extension. For example, `test/LEDs/test_BlinkTask.c` becomes `BlinkTask`. [Running Tests][labels] shows both forms.

### `ceedlingExplorer.testFileHierarchy`

Default: `false`

Nests each test file in the _Testing_ view under one node per folder of its path. For example, `test/LEDs/test_BlinkTask.c` shows as `test` › `LEDs` › `test_BlinkTask.c`, or as `test` › `LEDs` › `BlinkTask` with `ceedlingExplorer.prettyTestFileLabel` on. [Running Tests][folders] explains running a folder.

### `ceedlingExplorer.problemMatching`

Default: none. Its `mode` field defaults to `"disabled"`, and its `patterns` field to `[]`.
Expand Down Expand Up @@ -141,6 +147,7 @@ Bind a keyboard shortcut to either by its ID. Running, debugging, and refreshing
[runs-ceedling]: getting-started.md#how-the-extension-runs-ceedling
[run-tasks]: running-tests.md#how-a-run-calls-ceedling
[labels]: running-tests.md#test-labels
[folders]: running-tests.md#test-folders
[mixins]: #mixins
[coverage-args]: #ceedlingexplorercoveragecommandargs
[problem-matching]: problem-matching.md
Expand Down
9 changes: 8 additions & 1 deletion docs/mkdocs/manual/running-tests.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Running Tests

Tests run from VS Code’s _Testing_ view or from the editor, and their results appear in both. This page covers what each kind of run does in Ceedling, how results are shown, how tests are labeled, and the cleanup commands. Debugging has a page of its own, [Debugging][debugging].
Tests run from VS Code’s _Testing_ view or from the editor, and their results appear in both. This page covers what each kind of run does in Ceedling, how results are shown, how tests are labeled and grouped into folders, and the cleanup commands. Debugging has a page of its own, [Debugging][debugging].

## Where to run tests

Expand Down Expand Up @@ -63,6 +63,12 @@ A test file’s label drops its path, prefix, and extension. For example, `test/

The prefixes come from the project’s own configuration, `:test_runner` ↳ `:test_prefix` and `:project` ↳ `:test_file_prefix`.

## Test folders

The _Testing_ view lists a project’s test files side by side by default. With [`ceedlingExplorer.testFileHierarchy`][hierarchy] on, it nests each test file under one node per folder of its path instead, which keeps a project with many test folders readable. For example, `test/LEDs/test_BlinkTask.c` shows as `test` › `LEDs` › `test_BlinkTask.c`. A nested file’s label drops its path, since its folders show it.

Running a folder runs each test file beneath it, one file at a time.

## Clean and Clobber

The _Testing_ view’s toolbar has Clean and Clobber buttons. They run `ceedling clean` and `ceedling clobber` in every Ceedling project in the workspace. Each project’s command waits for any Ceedling build under way in that project to finish. [Configuration][commands] lists their command IDs, for keyboard shortcuts.
Expand All @@ -79,6 +85,7 @@ Ceedling 1.2.2 builds each test in a new place, and an earlier release’s build
[crashes]: debugging.md#crashing-tests
[pretty-test]: configuration.md#ceedlingexplorerprettytestlabel
[pretty-file]: configuration.md#ceedlingexplorerprettytestfilelabel
[hierarchy]: configuration.md#ceedlingexplorertestfilehierarchy
[commands]: configuration.md#commands
[known-issues]: https://github.com/ThrowTheSwitch/vscode-ceedling/blob/master/docs/KnownIssues.md

Expand Down
2 changes: 2 additions & 0 deletions docs/mkdocs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This page lists every setting and command the extension contributes, grouped by

- [`prettyTestFileLabel`][pretty-file] — Shorten each test file’s label
- [`prettyTestLabel`][pretty-test] — Shorten each test’s label
- [`testFileHierarchy`][hierarchy] — Nest each test file under its folders

## Code coverage

Expand Down Expand Up @@ -66,6 +67,7 @@ Each custom pattern in `problemMatching.patterns` is an object with these proper
[test-args]: manual/configuration.md#ceedlingexplorertestcommandargs
[pretty-file]: manual/configuration.md#ceedlingexplorerprettytestfilelabel
[pretty-test]: manual/configuration.md#ceedlingexplorerprettytestlabel
[hierarchy]: manual/configuration.md#ceedlingexplorertestfilehierarchy
[coverage-args]: manual/configuration.md#ceedlingexplorercoveragecommandargs
[resets]: manual/configuration.md#ceedlingexplorercoverageresetscounters
[problem-matching]: manual/configuration.md#ceedlingexplorerproblemmatching
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@
"default": true,
"scope": "resource"
},
"ceedlingExplorer.testFileHierarchy": {
"markdownDescription": "Test files are nested in the test explorer under one node per folder of their path. E.g. `test/LEDs/test_BlinkTask.c` shows as `test` › `LEDs` › `test_BlinkTask.c`, or as `test` › `LEDs` › `BlinkTask` with `#ceedlingExplorer.prettyTestFileLabel#` active",
"type": "boolean",
"default": false,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've chosen the default for this to be false in order to maintain backwards compatibility. If the next_version changes are bringing other major features/changes to the UI it might also be an option to set this to true.

Other test_views in VSCode atleast have this behaviour on by default.

"scope": "resource"
},
"ceedlingExplorer.testCommandArgs": {
"markdownDescription": "The command line arguments used to run Ceedling tests. `${TEST_ID}` becomes the test file: its project-relative path with Ceedling 1.2.0 and later, else its name alone.",
"type": "array",
Expand Down
10 changes: 5 additions & 5 deletions src/ceedlingEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { type MatchedProblem, matchProblems } from './problemMatching';
import { setting, SETTING_DEFAULTS, type SettingKey, type Settings, type SettingsSource } from './settings';
import { allIds, type CeedlingFileNode, type CeedlingProjectNode, type CeedlingTestFunction, functionIds, leafIds, type RunReporter } from './testModel';
import { type CppUnitReport, parseCppUnitReport, reportedNames } from './testResults';
import { testFileNodes } from './testFileNodes';
import { type FileLabels, testFileNodes } from './testFileNodes';

// A vendored Ceedling's own version, relative to the project directory.
const VENDORED_VERSION = `${VENDORED_CEEDLING}/lib/version.rb`;
Expand Down Expand Up @@ -233,7 +233,7 @@ export class CeedlingEngine {
if (!project || index < 0) {
return undefined;
}
const [node] = await testFileNodes(this.io, project, [fileId], this.prettyLabels(), source);
const [node] = await testFileNodes(this.io, project, [fileId], this.fileLabels(), source);
if (node) {
project.files[index] = node;
}
Expand Down Expand Up @@ -294,7 +294,7 @@ export class CeedlingEngine {
`Check that Ceedling runs in the configured shell (ceedlingExplorer.shellPath), and that the project's ` +
`:paths: ↳ :test: entries are valid. The Ceedling Explorer log has Ceedling's output.`, exception)).join('\n'));
}
const labels = this.prettyLabels();
const labels = this.fileLabels();
await Promise.all(projects.map(async (project, i) => {
const listing = listings[i];
project.files = await testFileNodes(this.io, project, listing !== undefined && 'found' in listing ? listing.found : [], labels);
Expand Down Expand Up @@ -407,8 +407,8 @@ export class CeedlingEngine {
);
}

private prettyLabels(): { tests: boolean, files: boolean } {
return { tests: this.setting('prettyTestLabel'), files: this.setting('prettyTestFileLabel') };
private fileLabels(): FileLabels {
return { prettyTests: this.setting('prettyTestLabel'), prettyFiles: this.setting('prettyTestFileLabel'), nested: this.setting('testFileHierarchy') };
}

private project(projectKey: string): LoadedProject {
Expand Down
4 changes: 3 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type Settings = {
ceedlingCommand: string,
prettyTestLabel: boolean,
prettyTestFileLabel: boolean,
testFileHierarchy: boolean,
testCommandArgs: readonly string[],
coverageCommandArgs: readonly string[],
coverageResetsCounters: boolean,
Expand All @@ -30,6 +31,7 @@ export const SETTING_DEFAULTS: { readonly [K in SettingKey]: Settings[K] } = {
ceedlingCommand: 'ceedling',
prettyTestLabel: true,
prettyTestFileLabel: true,
testFileHierarchy: false,
testCommandArgs: ['test:${TEST_ID}'],
coverageCommandArgs: ['${PLUGIN}:${TEST_ID}'],
coverageResetsCounters: true,
Expand All @@ -41,7 +43,7 @@ export const SETTING_DEFAULTS: { readonly [K in SettingKey]: Settings[K] } = {
// Settings whose change changes what discovery finds, including how it reads Ceedling's output.
// The rest apply on the next run.
export const DISCOVERY_SETTINGS: readonly SettingKey[] = [
'projects', 'mixins', 'shellPath', 'ceedlingCommand', 'prettyTestLabel', 'prettyTestFileLabel', 'ansiEscapeSequencesRemoved',
'projects', 'mixins', 'shellPath', 'ceedlingCommand', 'prettyTestLabel', 'prettyTestFileLabel', 'testFileHierarchy', 'ansiEscapeSequencesRemoved',
];

// What settings are read from: a vscode.WorkspaceConfiguration, or a test's stand-in.
Expand Down
31 changes: 26 additions & 5 deletions src/testController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ProblemMatcher } from './problemMatcher';
import { buildRunPlan, type PlanTarget, type RunPlanEntry } from './runPlan';
import { ActivityTracker } from './concurrency';
import { SingleFlight } from './singleFlight';
import { filesInFolder, groupByFolder, type TestFolder } from './testFileHierarchy';
import { type CeedlingFileNode, type CeedlingProjectNode, type CeedlingTestFunction, type CoverageOutcome, coverageProfileLabel, type RunReporter } from './testModel';
import { createRunReporter, type ReportMessage } from './testReporting';
import { Debouncer, settingsChangeEffects, type SourceEvent, sourceEventEffect, watcherChanges } from './watchPolicy';
Expand Down Expand Up @@ -48,7 +49,8 @@ export class CeedlingTestController {
private readonly sourceWatchers = new Map<string, vscode.Disposable>();
private readonly editReparses = new Debouncer(EDIT_REPARSE_DELAY_MS);

private readonly targets = new WeakMap<vscode.TestItem, PlanTarget>();
// A folder stands for each of its test files.
private readonly targets = new WeakMap<vscode.TestItem, PlanTarget | PlanTarget[]>();
// Item ids are unique only within a project, so lookups are scoped by project key.
private readonly items = new Map<string, Map<string, vscode.TestItem>>();
private projects: CeedlingProjectNode[] = [];
Expand Down Expand Up @@ -383,24 +385,43 @@ export class CeedlingTestController {
return;
}
const multiProject = this.projects.length > 1;
const hierarchy = this.engine.setting('testFileHierarchy');
const rootItems: vscode.TestItem[] = [];
for (const project of this.projects) {
const projectItems = new Map<string, vscode.TestItem>();
this.items.set(project.projectKey, projectItems);
const fileItems = project.files.map((file) => this.buildFileItem(controller, project.projectKey, file, projectItems));
const absPath = this.engine.getProjectAbsPath(project.projectKey);
const childItems = hierarchy
? this.buildFolderChildren(controller, project.projectKey, absPath, groupByFolder(project.files, (file) => path.relative(absPath, file.absPath)), projectItems)
: project.files.map((file) => this.buildFileItem(controller, project.projectKey, file, projectItems));
if (multiProject) {
const projectItem = controller.createTestItem(project.projectKey, project.label);
projectItem.children.replace(fileItems);
projectItem.children.replace(childItems);
this.targets.set(projectItem, { kind: 'project', projectKey: project.projectKey });
rootItems.push(projectItem);
} else {
rootItems.push(...fileItems);
rootItems.push(...childItems);
}
}
controller.items.replace(rootItems);
this.logger.debug(`rebuildTree: ${this.projects.length} project(s)`);
}

// A folder's subfolders, then its files. A folder's directory uri makes the Testing view's
// "Go to Test" reveal it in the Explorer.
private buildFolderChildren(
controller: vscode.TestController, projectKey: string, projectAbsPath: string, folder: TestFolder<CeedlingFileNode>,
projectItems: Map<string, vscode.TestItem>,
): vscode.TestItem[] {
const folderItems = folder.folders.map((child) => {
const item = controller.createTestItem(child.id, child.label, vscode.Uri.file(path.resolve(projectAbsPath, child.id)));
this.targets.set(item, filesInFolder(child).map((file): PlanTarget => ({ kind: 'file', projectKey, fileId: file.id })));
item.children.replace(this.buildFolderChildren(controller, projectKey, projectAbsPath, child, projectItems));
return item;
});
return [...folderItems, ...folder.files.map((file) => this.buildFileItem(controller, projectKey, file, projectItems))];
}

private buildFileItem(
controller: vscode.TestController, projectKey: string, file: CeedlingFileNode, projectItems: Map<string, vscode.TestItem>,
): vscode.TestItem {
Expand Down Expand Up @@ -436,7 +457,7 @@ export class CeedlingTestController {
if (!target) {
this.logger.warn(`planFor: no target for TestItem '${item.id}', skipping`);
}
return target ? [target] : [];
return target ?? [];
});
return buildRunPlan(this.projects, request.include && toTargets(request.include), toTargets(request.exclude ?? []));
}
Expand Down
35 changes: 35 additions & 0 deletions src/testFileHierarchy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Pure, `vscode`-free grouping of test files by folder for ceedlingExplorer.testFileHierarchy, unit-testable in plain Node.

export type TestFolder<T> = {
// Path relative to the project, '/'-separated with a trailing '/', so it never equals a test file's id.
id: string,
label: string,
folders: TestFolder<T>[],
files: T[],
};

// `relativePath` is a file's path relative to the project; both '/' and '\' separate folders. The returned root has
// an empty id and holds the top-level folders and the files without a folder.
export function groupByFolder<T>(files: readonly T[], relativePath: (file: T) => string): TestFolder<T> {
const root: TestFolder<T> = { id: '', label: '', folders: [], files: [] };
for (const file of files) {
const names = relativePath(file).split(/[\\/]/);
names.pop();
let folder = root;
for (const name of names) {
const id = `${folder.id}${name}/`;
let child = folder.folders.find((f) => f.id === id);
if (child === undefined) {
child = { id, label: name, folders: [], files: [] };
folder.folders.push(child);
}
folder = child;
}
folder.files.push(file);
}
return root;
}

export function filesInFolder<T>(folder: TestFolder<T>): T[] {
return [...folder.files, ...folder.folders.flatMap((child) => filesInFolder(child))];
}
16 changes: 10 additions & 6 deletions src/testFileNodes.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
// A project's test files as the Testing view's nodes: each file's test functions and parametrized
// cases, found in its source, with pretty labels when they're on. Ids name tests as Ceedling's
// report does, `file::function` and `file::function(args)`. It has no `vscode` dependency.
// cases, found in its source, with pretty labels when they're on. A file nested under its folders
// drops its path from its label. Ids name tests as Ceedling's report does, `file::function` and
// `file::function(args)`. It has no `vscode` dependency.
import util from 'util';
import { buildFileLabelRegex, buildTestLabelRegex } from './ceedlingOutputParsing';
import type { LoadedProject } from './ceedlingProjectConfig';
import { type EngineIo, readText } from './engineFileSystem';
import type { CeedlingFileNode } from './testModel';
import { discoverTests } from './unityTestDiscovery';

// `nested` when the Testing view nests each file under its folders, which already show its path.
export type FileLabels = { prettyTests: boolean, prettyFiles: boolean, nested: boolean };

// `source`, when given, stands in for the contents of a single file. Sources are read concurrently,
// within the engine's shared read limit, then parsed in listed order. A file that can't be read or
// parsed is left out, with a warning.
export async function testFileNodes(
io: EngineIo, project: LoadedProject, files: readonly string[], pretty: { tests: boolean, files: boolean }, source?: string,
io: EngineIo, project: LoadedProject, files: readonly string[], labels: FileLabels, source?: string,
): Promise<CeedlingFileNode[]> {
const options = { testPrefix: project.state.testPrefix, useParamTests: project.state.useParamTests };
const testLabel = pretty.tests ? labelRegex(io, () => buildTestLabelRegex(project.state.testPrefix)) : undefined;
const fileLabel = pretty.files ? labelRegex(io, () => buildFileLabelRegex(project.state.testFilePrefix)) : undefined;
const testLabel = labels.prettyTests ? labelRegex(io, () => buildTestLabelRegex(project.state.testPrefix)) : undefined;
const fileLabel = labels.prettyFiles ? labelRegex(io, () => buildFileLabelRegex(project.state.testFilePrefix)) : undefined;
// `||`, not `??`: an empty capture, such as a file named only by its prefix, keeps the full text.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- see above
const label = (regex: RegExp | undefined, text: string) => regex?.exec(text)?.[1] || text;
Expand Down Expand Up @@ -46,7 +50,7 @@ export async function testFileNodes(
}
nodes.push({
id: file,
label: label(fileLabel, file),
label: label(fileLabel, labels.nested ? io.paths.basename(file) : file),
absPath,
projectKey: project.key,
functions: discovered.tests.map((test) => ({
Expand Down
Loading