Skip to content

Commit

Permalink
Don't mark swift-testing test case results as runnable (#1151)
Browse files Browse the repository at this point in the history
When running a swift-testing test that takes arguments the results are
added to the Test Explorer showing their pass/fail status. At this time
these tests cannot be run with a specific argument so these tests should
not be marked as runnable. This prevents the "Run", "Debug" and
"Coverage" buttons from appearing on the test items in the explorer.

Issue: #1147
  • Loading branch information
plemarquand authored Oct 22, 2024
1 parent 3e45bd1 commit ee88108
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/TestExplorer/TestDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,13 @@ export function upsertTestItem(
// parent tags down the tree as children are upserted.
testItem = applyTagsToChildren(testItem);

// Manually add the test style as a tag so we can filter by test type.
newItem.tags = [{ id: testItem.style }, ...testItem.tags];
const hasTestStyleTag = testItem.tags.find(tag => tag.id === testItem.style);

// Manually add the test style as a tag if it isn't already in the tags list.
// This lets the user filter by test type.
newItem.tags = hasTestStyleTag
? [...testItem.tags]
: [{ id: testItem.style }, ...testItem.tags];

if (testItem.disabled === false) {
newItem.tags = [...newItem.tags, runnableTag];
Expand Down
9 changes: 7 additions & 2 deletions src/TestExplorer/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as stream from "stream";
import * as os from "os";
import * as asyncfs from "fs/promises";
import { FolderContext } from "../FolderContext";
import { execFile, getErrorDescription } from "../utilities/utilities";
import { compactMap, execFile, getErrorDescription } from "../utilities/utilities";
import { createSwiftTask } from "../tasks/SwiftTaskProvider";
import configuration from "../configuration";
import { WorkspaceContext } from "../WorkspaceContext";
Expand Down Expand Up @@ -135,7 +135,12 @@ export class TestRunProxy {
testClass.location = undefined;

// Results should inherit any tags from the parent.
testClass.tags = parent.tags.map(t => new vscode.TestTag(t.id));
// Until we can rerun a swift-testing test with an individual argument, mark
// the argument test items as not runnable. This should be revisited when
// https://github.com/swiftlang/swift-testing/issues/671 is resolved.
testClass.tags = compactMap(parent.tags, t =>
t.id === runnableTag.id ? null : new vscode.TestTag(t.id)
);

const added = upsertTestItem(this.controller, testClass, parent);

Expand Down
20 changes: 20 additions & 0 deletions src/utilities/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,26 @@ export function wait(milliseconds: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}

/**
* Returns an array containing the non-null and non-undefined results of calling
* the given transformation with each element of this sequence.
*
* @param arr An array to map
* @param transform A transformation function to apply to each element
* @returns An array containing the non-null and non-undefined results of calling transform on each element
*/
export function compactMap<T, U>(
arr: readonly T[],
transform: (value: T) => U | null | undefined
): U[] {
return arr.reduce<U[]>((acc, item) => {
const result = transform(item);
if (result !== null && result !== undefined) {
acc.push(result);
}
return acc;
}, []);
}
/**
* Get path to swift executable, or executable in swift bin folder
*
Expand Down

0 comments on commit ee88108

Please sign in to comment.