Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f9633df

Browse files
committedOct 10, 2024·
fix: respect go test flags usage
1 parent c107653 commit f9633df

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed
 

‎extension/src/testUtils.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,14 @@ export function computeTestCommand(
545545
addJSONFlag: boolean | undefined; // true if we add extra -json flag for stream processing.
546546
} {
547547
const args: Array<string> = ['test'];
548+
const outArgs: Array<string> = ['test']; // command to show
548549
// user-specified flags
549550
const argsFlagIdx = testconfig.flags?.indexOf('-args') ?? -1;
550551
const userFlags = argsFlagIdx < 0 ? testconfig.flags : testconfig.flags.slice(0, argsFlagIdx);
551552
const userArgsFlags = argsFlagIdx < 0 ? [] : testconfig.flags.slice(argsFlagIdx);
552553

554+
args.push(...targets);
555+
553556
// flags to limit test time
554557
if (testconfig.isBenchmark) {
555558
args.push('-benchmem', '-run=^$');
@@ -587,32 +590,29 @@ export function computeTestCommand(
587590
// all other test run/benchmark flags
588591
args.push(...targetArgs(testconfig));
589592

590-
const outArgs = args.slice(0); // command to show
591-
592593
// if user set -v, set -json to emulate streaming test output
593594
const addJSONFlag = (userFlags.includes('-v') || testconfig.goTestOutputConsumer) && !userFlags.includes('-json');
594595
if (addJSONFlag) {
595596
args.push('-json'); // this is not shown to the user.
596597
}
597598

598-
if (targets.length > 4) {
599-
outArgs.push('<long arguments omitted>');
600-
} else {
601-
outArgs.push(...targets);
602-
}
603-
args.push(...targets);
604-
605599
// ensure that user provided flags are appended last (allow use of -args ...)
606600
// ignore user provided -run flag if we are already using it
607601
if (args.indexOf('-run') > -1) {
608602
removeRunFlag(userFlags);
609603
}
610604

611605
args.push(...userFlags);
612-
outArgs.push(...userFlags);
613-
614606
args.push(...userArgsFlags);
615-
outArgs.push(...userArgsFlags);
607+
608+
// build outArgs
609+
if (targets.length > 4) {
610+
outArgs.push('<long arguments omitted>');
611+
} else {
612+
outArgs.push(...targets);
613+
}
614+
615+
outArgs.push(...args.slice(targets.length + 1));
616616

617617
return {
618618
args,

‎extension/test/integration/test.test.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -42,67 +42,67 @@ suite('Test Go Test Args', () => {
4242

4343
test('default config', () => {
4444
runTest({
45-
expectedArgs: 'test -timeout 30s ./...',
46-
expectedOutArgs: 'test -timeout 30s ./...'
45+
expectedArgs: 'test ./... -timeout 30s',
46+
expectedOutArgs: 'test ./... -timeout 30s'
4747
});
4848
});
4949
test('user flag [-v] enables -json flag', () => {
5050
runTest({
51-
expectedArgs: 'test -timeout 30s -json ./... -v',
52-
expectedOutArgs: 'test -timeout 30s ./... -v',
51+
expectedArgs: 'test ./... -timeout 30s -json -v',
52+
expectedOutArgs: 'test ./... -timeout 30s -v',
5353
flags: ['-v']
5454
});
5555
});
5656
test('user flag [-json -v] prevents -json flag addition', () => {
5757
runTest({
58-
expectedArgs: 'test -timeout 30s ./... -json -v',
59-
expectedOutArgs: 'test -timeout 30s ./... -json -v',
58+
expectedArgs: 'test ./... -timeout 30s -json -v',
59+
expectedOutArgs: 'test ./... -timeout 30s -json -v',
6060
flags: ['-json', '-v']
6161
});
6262
});
6363
test('user flag [-args] does not crash', () => {
6464
runTest({
65-
expectedArgs: 'test -timeout 30s ./... -args',
66-
expectedOutArgs: 'test -timeout 30s ./... -args',
65+
expectedArgs: 'test ./... -timeout 30s -args',
66+
expectedOutArgs: 'test ./... -timeout 30s -args',
6767
flags: ['-args']
6868
});
6969
});
7070
test('user flag [-args -v] does not enable -json flag', () => {
7171
runTest({
72-
expectedArgs: 'test -timeout 30s ./... -args -v',
73-
expectedOutArgs: 'test -timeout 30s ./... -args -v',
72+
expectedArgs: 'test ./... -timeout 30s -args -v',
73+
expectedOutArgs: 'test ./... -timeout 30s -args -v',
7474
flags: ['-args', '-v']
7575
});
7676
});
7777
test('specifying functions adds -run flags', () => {
7878
runTest({
79-
expectedArgs: 'test -timeout 30s -run ^(TestA|TestB)$ ./...',
80-
expectedOutArgs: 'test -timeout 30s -run ^(TestA|TestB)$ ./...',
79+
expectedArgs: 'test ./... -timeout 30s -run ^(TestA|TestB)$',
80+
expectedOutArgs: 'test ./... -timeout 30s -run ^(TestA|TestB)$',
8181
functions: ['TestA', 'TestB']
8282
});
8383
});
8484
test('functions & benchmark adds -bench flags and skips timeout', () => {
8585
runTest({
86-
expectedArgs: 'test -benchmem -run=^$ -bench ^(TestA|TestB)$ ./...',
87-
expectedOutArgs: 'test -benchmem -run=^$ -bench ^(TestA|TestB)$ ./...',
86+
expectedArgs: 'test ./... -benchmem -run=^$ -bench ^(TestA|TestB)$',
87+
expectedOutArgs: 'test ./... -benchmem -run=^$ -bench ^(TestA|TestB)$',
8888
functions: ['TestA', 'TestB'],
8989
isBenchmark: true
9090
});
9191
});
9292
test('user -run flag is ignored when functions are provided', () => {
9393
runTest({
94-
expectedArgs: 'test -timeout 30s -run ^(TestA|TestB)$ ./...',
95-
expectedOutArgs: 'test -timeout 30s -run ^(TestA|TestB)$ ./...',
94+
expectedArgs: 'test ./... -timeout 30s -run ^(TestA|TestB)$',
95+
expectedOutArgs: 'test ./... -timeout 30s -run ^(TestA|TestB)$',
9696
functions: ['TestA', 'TestB'],
9797
flags: ['-run', 'TestC']
9898
});
9999
});
100100
test('use -testify.m for methods', () => {
101101
runTest({
102102
expectedArgs:
103-
'test -timeout 30s -run ^TestExampleTestSuite$ -testify.m ^(TestExample|TestAnotherExample)$ ./...',
103+
'test ./... -timeout 30s -run ^TestExampleTestSuite$ -testify.m ^(TestExample|TestAnotherExample)$',
104104
expectedOutArgs:
105-
'test -timeout 30s -run ^TestExampleTestSuite$ -testify.m ^(TestExample|TestAnotherExample)$ ./...',
105+
'test ./... -timeout 30s -run ^TestExampleTestSuite$ -testify.m ^(TestExample|TestAnotherExample)$',
106106
functions: [
107107
'(*ExampleTestSuite).TestExample',
108108
'(*ExampleTestSuite).TestAnotherExample',

0 commit comments

Comments
 (0)
Please sign in to comment.