Skip to content

Commit e4dec68

Browse files
authored
Run all tests when none are specified in TestRunRequest (#1765)
VS Code provides commands like `Tests: Run Tests` that can be executed before we have a list of tests from the LSP. When we recieve an empty `TestRunRequest` today we gather up all the tests we know about and run those by creating the appropriate `--filter` arguments to pass to `swift test`. To ensure we run all the tests whether the LSP has informed us of them or not, run `swift test` with no filter when we recieve an empty `vscode.TestRunRequest`. Issue: #1764
1 parent 9836774 commit e4dec68

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/TestExplorer/TestRunArguments.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,26 @@ export class TestRunArguments {
3838
this.swiftTestArgs = this.annotateTestArgs(swiftTestArgs, isDebug);
3939
}
4040

41+
/**
42+
* Returns true if there are XCTests specified in the request.
43+
*/
4144
public get hasXCTests(): boolean {
42-
return this.xcTestArgs.length > 0;
45+
return this.xcTestArgs.length > 0 || this.hasNoSpecifiedTests;
4346
}
4447

48+
/**
49+
* Returns true if there are swift-testing tests specified in the request.
50+
*/
4551
public get hasSwiftTestingTests(): boolean {
46-
return this.swiftTestArgs.length > 0;
52+
return this.swiftTestArgs.length > 0 || this.hasNoSpecifiedTests;
53+
}
54+
55+
/**
56+
* Returns true if there are no tests specified in the request,
57+
* which indicates that we should run all tests.
58+
*/
59+
private get hasNoSpecifiedTests(): boolean {
60+
return this.testItems.length === 0;
4761
}
4862

4963
/**

test/integration-tests/testexplorer/TestRunArguments.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ suite("TestRunArguments Suite", () => {
7676

7777
function assertRunArguments(
7878
args: TestRunArguments,
79-
expected: Omit<
80-
Omit<Omit<TestRunArguments, "testItems">, "hasXCTests">,
81-
"hasSwiftTestingTests"
82-
> & { testItems: string[] }
79+
expected: Partial<Omit<TestRunArguments, "testItems">> & { testItems: string[] }
8380
) {
8481
// Order of testItems doesn't matter, that they contain the same elements.
8582
assert.deepStrictEqual(
@@ -132,12 +129,15 @@ suite("TestRunArguments Suite", () => {
132129
const xcTest = new TestRunArguments(runRequestByIds([xcTestId]), false);
133130
const swiftTestingTest = new TestRunArguments(runRequestByIds([swiftTestId]), false);
134131
const bothTests = new TestRunArguments(runRequestByIds([xcTestId, swiftTestId]), false);
132+
const noTests = new TestRunArguments(runRequestByIds([]), false);
135133
assert.strictEqual(xcTest.hasXCTests, true);
136134
assert.strictEqual(xcTest.hasSwiftTestingTests, false);
137135
assert.strictEqual(swiftTestingTest.hasXCTests, false);
138136
assert.strictEqual(swiftTestingTest.hasSwiftTestingTests, true);
139137
assert.strictEqual(bothTests.hasXCTests, true);
140138
assert.strictEqual(bothTests.hasSwiftTestingTests, true);
139+
assert.strictEqual(noTests.hasXCTests, true);
140+
assert.strictEqual(noTests.hasSwiftTestingTests, true);
141141
});
142142

143143
test("Single XCTest", () => {

0 commit comments

Comments
 (0)