@@ -688,24 +688,35 @@ export class TestRunner {
688
688
}
689
689
}
690
690
691
+ const compositeToken = new CompositeCancellationToken ( token ) ;
692
+
691
693
// Create a cancellation token source for this test run
692
- const compositeToken = new CompositeCancellationTokenSource ( token ) ;
694
+ const compositeTokenSource = new CompositeCancellationTokenSource ( token ) ;
693
695
694
696
// Create and run the test runner
695
697
const runner = new TestRunner (
696
698
testKind ,
697
699
request ,
698
700
folderContext ,
699
701
controller ,
700
- compositeToken . token
702
+ compositeTokenSource . token
701
703
) ;
702
704
703
705
// If the user terminates a debugging session for swift-testing
704
706
// 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
+ ) ;
706
717
707
718
// Register the test run with the manager
708
- folderContext . registerTestRun ( runner . testRun , compositeToken ) ;
719
+ folderContext . registerTestRun ( runner . testRun , compositeTokenSource ) ;
709
720
710
721
// Fire the event to notify that a test run was created
711
722
onCreateTestRun . fire ( runner . testRun ) ;
@@ -714,6 +725,7 @@ export class TestRunner {
714
725
await runner . runHandler ( ) ;
715
726
716
727
terminationListener . dispose ( ) ;
728
+ cancellationListener . dispose ( ) ;
717
729
718
730
// Run the post-run handler if provided
719
731
if ( postRunHandler ) {
0 commit comments