Skip to content

Commit

Permalink
fix: respect go test flags usage
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiaohei committed Oct 10, 2024
1 parent c107653 commit cc35f55
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions extension/src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,14 @@ export function computeTestCommand(
addJSONFlag: boolean | undefined; // true if we add extra -json flag for stream processing.
} {
const args: Array<string> = ['test'];
const outArgs: Array<string> = ['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=^$');
Expand Down Expand Up @@ -587,32 +590,29 @@ 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('<long arguments omitted>');
} 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) {
removeRunFlag(userFlags);
}

args.push(...userFlags);
outArgs.push(...userFlags);

args.push(...userArgsFlags);
outArgs.push(...userArgsFlags);

// build outArgs
if (targets.length > 4) {
outArgs.push('<long arguments omitted>');
} else {
outArgs.push(...targets);
}

outArgs.push(...args.slice(targets.length + 1));

return {
args,
Expand Down

0 comments on commit cc35f55

Please sign in to comment.