From cc35f552994d131a0526d41050c9a7f551b9406d Mon Sep 17 00:00:00 2001 From: luoxiaohei Date: Mon, 8 Jan 2024 21:08:13 +0800 Subject: [PATCH] fix: respect go test flags usage --- extension/src/testUtils.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/extension/src/testUtils.ts b/extension/src/testUtils.ts index 4070f6e6d1..801a6ed4b3 100644 --- a/extension/src/testUtils.ts +++ b/extension/src/testUtils.ts @@ -545,11 +545,14 @@ export function computeTestCommand( addJSONFlag: boolean | undefined; // true if we add extra -json flag for stream processing. } { const args: Array = ['test']; + const outArgs: Array = ['test']; // command to show // user-specified flags const argsFlagIdx = testconfig.flags?.indexOf('-args') ?? -1; const userFlags = argsFlagIdx < 0 ? testconfig.flags : testconfig.flags.slice(0, argsFlagIdx); const userArgsFlags = argsFlagIdx < 0 ? [] : testconfig.flags.slice(argsFlagIdx); + args.push(...targets); + // flags to limit test time if (testconfig.isBenchmark) { args.push('-benchmem', '-run=^$'); @@ -587,21 +590,12 @@ export function computeTestCommand( // all other test run/benchmark flags args.push(...targetArgs(testconfig)); - const outArgs = args.slice(0); // command to show - // if user set -v, set -json to emulate streaming test output const addJSONFlag = (userFlags.includes('-v') || testconfig.goTestOutputConsumer) && !userFlags.includes('-json'); if (addJSONFlag) { args.push('-json'); // this is not shown to the user. } - if (targets.length > 4) { - outArgs.push(''); - } else { - outArgs.push(...targets); - } - args.push(...targets); - // ensure that user provided flags are appended last (allow use of -args ...) // ignore user provided -run flag if we are already using it if (args.indexOf('-run') > -1) { @@ -609,10 +603,16 @@ export function computeTestCommand( } args.push(...userFlags); - outArgs.push(...userFlags); - args.push(...userArgsFlags); - outArgs.push(...userArgsFlags); + + // build outArgs + if (targets.length > 4) { + outArgs.push(''); + } else { + outArgs.push(...targets); + } + + outArgs.push(...args.slice(targets.length + 1)); return { args,