Skip to content

Commit a74f2e9

Browse files
authored
Skip remaining tests when cancelling a regular run (#1798)
1 parent a598753 commit a74f2e9

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/TestExplorer/TestRunner.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,24 +688,35 @@ export class TestRunner {
688688
}
689689
}
690690

691+
const compositeToken = new CompositeCancellationToken(token);
692+
691693
// Create a cancellation token source for this test run
692-
const compositeToken = new CompositeCancellationTokenSource(token);
694+
const compositeTokenSource = new CompositeCancellationTokenSource(token);
693695

694696
// Create and run the test runner
695697
const runner = new TestRunner(
696698
testKind,
697699
request,
698700
folderContext,
699701
controller,
700-
compositeToken.token
702+
compositeTokenSource.token
701703
);
702704

703705
// If the user terminates a debugging session for swift-testing
704706
// we want to prevent XCTest from starting.
705-
const terminationListener = runner.onDebugSessionTerminated(() => compositeToken.cancel());
707+
const terminationListener = runner.onDebugSessionTerminated(() =>
708+
compositeTokenSource.cancel()
709+
);
710+
711+
// If the user cancels the test run via the VS Code UI, skip the pending tests
712+
// so they don't appear as failed. Any pending tests left over at the end of a run
713+
// are assumed to have crashed.
714+
const cancellationListener = compositeToken.onCancellationRequested(() =>
715+
runner.testRun.skipPendingTests()
716+
);
706717

707718
// Register the test run with the manager
708-
folderContext.registerTestRun(runner.testRun, compositeToken);
719+
folderContext.registerTestRun(runner.testRun, compositeTokenSource);
709720

710721
// Fire the event to notify that a test run was created
711722
onCreateTestRun.fire(runner.testRun);
@@ -714,6 +725,7 @@ export class TestRunner {
714725
await runner.runHandler();
715726

716727
terminationListener.dispose();
728+
cancellationListener.dispose();
717729

718730
// Run the post-run handler if provided
719731
if (postRunHandler) {

0 commit comments

Comments
 (0)