From 98a9bdb777b44fe3e34de12888140eaad1ea8c7a Mon Sep 17 00:00:00 2001 From: luoxiaohei Date: Fri, 26 Aug 2022 16:39:04 +0800 Subject: [PATCH] debug: respect go test flags usage --- src/testUtils.ts | 24 ++++++++++++------------ test/integration/test.test.ts | 32 ++++++++++++++++---------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/testUtils.ts b/src/testUtils.ts index e9a43b5d94..d58ddcfb55 100644 --- a/src/testUtils.ts +++ b/src/testUtils.ts @@ -427,11 +427,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=^$'); @@ -469,21 +472,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) { @@ -491,10 +485,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, diff --git a/test/integration/test.test.ts b/test/integration/test.test.ts index 1ca2431a47..23f51a4b3d 100644 --- a/test/integration/test.test.ts +++ b/test/integration/test.test.ts @@ -42,57 +42,57 @@ suite('Test Go Test Args', () => { test('default config', () => { runTest({ - expectedArgs: 'test -timeout 30s ./...', - expectedOutArgs: 'test -timeout 30s ./...' + expectedArgs: 'test ./... -timeout 30s', + expectedOutArgs: 'test ./... -timeout 30s' }); }); test('user flag [-v] enables -json flag', () => { runTest({ - expectedArgs: 'test -timeout 30s -json ./... -v', - expectedOutArgs: 'test -timeout 30s ./... -v', + expectedArgs: 'test ./... -timeout 30s -json -v', + expectedOutArgs: 'test ./... -timeout 30s -json -v', flags: ['-v'] }); }); test('user flag [-json -v] prevents -json flag addition', () => { runTest({ - expectedArgs: 'test -timeout 30s ./... -json -v', - expectedOutArgs: 'test -timeout 30s ./... -json -v', + expectedArgs: 'test ./... -timeout 30s -json -v', + expectedOutArgs: 'test ./... -timeout 30s -json -v', flags: ['-json', '-v'] }); }); test('user flag [-args] does not crash', () => { runTest({ - expectedArgs: 'test -timeout 30s ./... -args', - expectedOutArgs: 'test -timeout 30s ./... -args', + expectedArgs: 'test ./... -timeout 30s -args', + expectedOutArgs: 'test ./... -timeout 30s -args', flags: ['-args'] }); }); test('user flag [-args -v] does not enable -json flag', () => { runTest({ - expectedArgs: 'test -timeout 30s ./... -args -v', - expectedOutArgs: 'test -timeout 30s ./... -args -v', + expectedArgs: 'test ./... -timeout 30s -args -v', + expectedOutArgs: 'test ./... -timeout 30s -args -v', flags: ['-args', '-v'] }); }); test('specifying functions adds -run flags', () => { runTest({ - expectedArgs: 'test -timeout 30s -run ^(TestA|TestB)$ ./...', - expectedOutArgs: 'test -timeout 30s -run ^(TestA|TestB)$ ./...', + expectedArgs: 'test ./... -timeout 30s -run ^(TestA|TestB)$', + expectedOutArgs: 'test ./... -timeout 30s -run ^(TestA|TestB)$', functions: ['TestA', 'TestB'] }); }); test('functions & benchmark adds -bench flags and skips timeout', () => { runTest({ - expectedArgs: 'test -benchmem -run=^$ -bench ^(TestA|TestB)$ ./...', - expectedOutArgs: 'test -benchmem -run=^$ -bench ^(TestA|TestB)$ ./...', + expectedArgs: 'test ./... -benchmem -run=^$ -bench ^(TestA|TestB)$', + expectedOutArgs: 'test ./... -benchmem -run=^$ -bench ^(TestA|TestB)$', functions: ['TestA', 'TestB'], isBenchmark: true }); }); test('user -run flag is ignored when functions are provided', () => { runTest({ - expectedArgs: 'test -timeout 30s -run ^(TestA|TestB)$ ./...', - expectedOutArgs: 'test -timeout 30s -run ^(TestA|TestB)$ ./...', + expectedArgs: 'test ./... -timeout 30s -run ^(TestA|TestB)$', + expectedOutArgs: 'test ./... -timeout 30s -run ^(TestA|TestB)$', functions: ['TestA', 'TestB'], flags: ['-run', 'TestC'] });