diff --git a/src/TestProvider/TestCases/TestMethod.ts b/src/TestProvider/TestCases/TestMethod.ts index 8e4c40a..e98f3b6 100644 --- a/src/TestProvider/TestCases/TestMethod.ts +++ b/src/TestProvider/TestCases/TestMethod.ts @@ -4,6 +4,8 @@ import { PhpunitArgBuilder } from "../../PhpunitCommand/PhpunitArgBuilder"; import { SpawnSyncReturns } from "child_process"; import { getTestFailedDiff } from "../../PhpParser/TestDiffParser"; import { ITestCase } from "./ITestCase"; +import { IRunConfig } from "../../RunConfig"; +import * as os from "os"; export class TestMethod implements ITestCase { constructor( @@ -36,27 +38,48 @@ export class TestMethod implements ITestCase { argBuilder.addDirectoryOrFile(this.fileName); argBuilder.withFilter(this.method); - const { status, stdout, stderr, error } = (await PHPUnitTestRunner.runArgs( + const { spawnResult, runConfig } = (await PHPUnitTestRunner.runArgs( argBuilder, true, - )) as SpawnSyncReturns; + )) as { spawnResult: SpawnSyncReturns; runConfig: IRunConfig }; const duration = Date.now() - start; - if (status === 0) { + options.appendOutput( + `${[runConfig.exec, ...runConfig.args].join(" ")}${os.EOL}${os.EOL}`, + undefined, + item, + ); + if (spawnResult.stdout) { + options.appendOutput(`${spawnResult.stdout}${os.EOL}`, undefined, item); + } + if (spawnResult.stderr) { + console.error(spawnResult.stderr); + } + + if (spawnResult.status === 0) { options.passed(item, duration); return true; } try { - const testDiff = getTestFailedDiff(stdout); + const testDiff = getTestFailedDiff(spawnResult.stdout); const message = TestMessage.diff( testDiff.message, testDiff.expected, testDiff.actual, ); - message.location = new Location(item.uri!, item.range!); + const lineNumber = /.*\.php:(\d+)/im.exec(spawnResult.stdout); + const range = lineNumber?.[1] + ? new Range( + parseInt(lineNumber[1]) - 1, + 0, + parseInt(lineNumber[1]) - 1, + 0, + ) + : item.range!; + message.location = new Location(item.uri!, range); options.failed(item, message, duration); diff --git a/src/TestProvider/TestExplorerFeature.ts b/src/TestProvider/TestExplorerFeature.ts index dac6f13..af04499 100644 --- a/src/TestProvider/TestExplorerFeature.ts +++ b/src/TestProvider/TestExplorerFeature.ts @@ -128,15 +128,12 @@ class TestExplorerFeature { const runTestQueue = async () => { for (const { test, data } of queue) { - run.appendOutput(`Running ${test.id}\r\n`); if (run.token.isCancellationRequested) { run.skipped(test); } else { run.started(test); await data.run(test, run); } - - run.appendOutput(`Completed ${test.id}\r\n`); } run.end(); diff --git a/src/phpunittest.ts b/src/phpunittest.ts index 9527da2..9b66e05 100644 --- a/src/phpunittest.ts +++ b/src/phpunittest.ts @@ -272,15 +272,8 @@ export class TestRunner { return undefined; } - public async runArgs(argBuilder: PhpunitArgBuilder, childProcess = false) { + populateArgBuilder(argBuilder: PhpunitArgBuilder) { const config = vscode.workspace.getConfiguration("phpunit"); - const order = config.get("driverPriority"); - - const driver = await this.getDriver(order); - if (!driver) { - console.error(`Wasn't able to start phpunit.`); - return; - } const configArgs = config.get("args", []); argBuilder.addArgs(configArgs); @@ -299,6 +292,18 @@ export class TestRunner { vscode.workspace.workspaceFolders![0].uri.fsPath, ); } + } + + public async runArgs(argBuilder: PhpunitArgBuilder, childProcess = false) { + const config = vscode.workspace.getConfiguration("phpunit"); + const order = config.get("driverPriority"); + const driver = await this.getDriver(order); + if (!driver) { + console.error(`Wasn't able to start phpunit.`); + return; + } + + this.populateArgBuilder(argBuilder); this.lastArgBuilder = argBuilder; const runConfig = await driver.run(argBuilder.buildArgs()); @@ -323,13 +328,15 @@ export class TestRunner { .replace(/'$/g, ""); } } - return await new Promise((r) => + const spawnResult = await new Promise((r) => r( spawnSync(runConfig.exec, runConfig.args, { encoding: "utf8", }), ), ); + + return { spawnResult, runConfig }; } else { await vscode.commands.executeCommand("workbench.action.terminal.clear"); await vscode.commands.executeCommand( @@ -340,37 +347,20 @@ export class TestRunner { } public async run(type: RunType) { - let argBuilder = new PhpunitArgBuilder(); - const config = vscode.workspace.getConfiguration("phpunit"); const order = config.get("driverPriority"); - const driver = await this.getDriver(order); if (!driver) { console.error(`Wasn't able to start phpunit.`); return; } + let argBuilder = new PhpunitArgBuilder(); + if (type === "rerun-last-test" && this.lastArgBuilder) { argBuilder = this.lastArgBuilder; } else { - const configArgs = config.get("args", []); - argBuilder.addArgs(configArgs); - - const colors = config.get("colors"); - if (colors && configArgs.indexOf(colors) === -1) { - argBuilder.withColors( - colors.replace(/--colors=?/i, "") as "never" | "auto" | "always", - ); - } - - const pathMappings = config.get<{ [key: string]: string }>("paths"); - if (pathMappings) { - argBuilder.withPathMappings( - pathMappings, - vscode.workspace.workspaceFolders![0].uri.fsPath, - ); - } + this.populateArgBuilder(argBuilder); const preferRunClassTestOverQuickPickWindow = config.get( "preferRunClassTestOverQuickPickWindow",