diff --git a/src/TestExplorer/TestRunner.ts b/src/TestExplorer/TestRunner.ts index 1e13e3486..d9fae8a14 100644 --- a/src/TestExplorer/TestRunner.ts +++ b/src/TestExplorer/TestRunner.ts @@ -729,7 +729,14 @@ export class TestRunner { outputStream.write(replaced); }); + // If the test run is iterrupted by a cancellation request from VS Code, ensure the task is terminated. + const cancellationDisposable = this.testRun.token.onCancellationRequested(() => { + task.execution.terminate("SIGINT"); + }); + task.execution.onDidClose(code => { + cancellationDisposable.dispose(); + // undefined or 0 are viewed as success if (!code) { resolve(); @@ -925,7 +932,6 @@ export class TestRunner { return; } - // add cancelation const startSession = vscode.debug.onDidStartDebugSession(session => { if (config.testType === TestLibrary.xctest) { this.testRun.testRunStarted(); @@ -945,6 +951,7 @@ export class TestRunner { } ); + // add cancellation const cancellation = this.testRun.token.onCancellationRequested(() => { this.workspaceContext.outputChannel.logDiagnostic( "Test Debugging Cancelled", diff --git a/src/tasks/SwiftExecution.ts b/src/tasks/SwiftExecution.ts index d7b23e515..f9c6c5502 100644 --- a/src/tasks/SwiftExecution.ts +++ b/src/tasks/SwiftExecution.ts @@ -30,7 +30,7 @@ export class SwiftExecution extends vscode.CustomExecution { public readonly command: string, public readonly args: string[], public readonly options: SwiftExecutionOptions, - swiftProcess: SwiftProcess = new SwiftPtyProcess(command, args, options) + private readonly swiftProcess: SwiftProcess = new SwiftPtyProcess(command, args, options) ) { super(async () => { return new SwiftPseudoterminal(swiftProcess, options.presentation || {}); @@ -54,4 +54,11 @@ export class SwiftExecution extends vscode.CustomExecution { * @see {@link SwiftProcess.onDidClose} */ onDidClose: vscode.Event; + + /** + * Terminate the underlying executable. + */ + terminate(signal?: NodeJS.Signals) { + this.swiftProcess.terminate(signal); + } }