Skip to content

Commit c845547

Browse files
committed
[release] src/goTest: remove '#' in subtest name parsing cutset
Subtests are detected dynamically - while running tests. GoTestRunner heuristically builds subtest trees by parsing the test names observed while running tests. Before this CL, it used both '/' and '#' as the separator for parsing. For example, it placed a test item for Foo as a child of TestXxx when it observed TestXxx/Foo, and a test item 01 as a child of TestXxx if it saw TestXxx#01. However, go test uses '#' to resolve conflicts in subtest names, so it's not right to assume TestXXX#01 is a subtest of TestXXX. Moreover, treating TestXXX/subtest#01 or TestXXX/subtest#02 as a subtest of TestXXX/subtest confuses the text UI API because `go test -json` will generate event sequence like TestXXX run TestXXX/subtest run TestXXX/subtest#01 run TestXXX/subtest#02 run TestXXX/subtest pass TestXXX/subtest#01 pass TestXXX/subtest#02 pass TestXXX pass That causes the test UI to show only the last item for TestXXX/subtest#02 to appear in TestXXX/subtest's child. This bug also makes Fuzz test's crasher and seed case listing confusing. This CL removes '#' from the cutset. Fixes #2023 For #1922 Change-Id: I33ba5c17e9095686a87c719d44fe7330269d9cc3 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/380501 Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Suzy Mueller <[email protected]> (cherry picked from commit 2735f15) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/383935 Reviewed-by: Robert Findley <[email protected]>
1 parent 0e33c84 commit c845547

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/goTest/run.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,16 @@ export class GoTestRunner {
477477
}
478478

479479
// Resolve a test name to a test item. If the test name is TestXxx/Foo, Foo is
480-
// created as a child of TestXxx. The same is true for TestXxx#Foo and
481-
// TestXxx/#Foo.
480+
// created as a child of TestXxx.
482481
resolveTestName(tests: Record<string, TestItem>, name: string): TestItem | undefined {
483482
if (!name) {
484483
return;
485484
}
486485

487-
const re = /[#/]+/;
486+
// Heuristically determines whether a test is a subtest by checking the existence of "/".
487+
// BUG: go test does not escape "/" included in the name passed to t.Run, so that
488+
// can result in confusing presentation.
489+
const re = /\/+/;
488490

489491
const resolve = (parent?: TestItem, start = 0, length = 0): TestItem | undefined => {
490492
const pos = start + length;

test/integration/goTest.run.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ suite('Go Test Runner', () => {
144144
const tSub = tMain.children.get(GoTest.id(uri, 'test', 'TestMain/Sub'));
145145
assert(tSub, 'Subtest was not created');
146146

147+
console.log('Locate subtests with conflicting names');
148+
const tSub2 = tMain.children.get(GoTest.id(uri, 'test', 'TestMain/Sub#01'));
149+
assert(tSub2, 'Subtest #01 was not created');
150+
const tSub3 = tMain.children.get(GoTest.id(uri, 'test', 'TestMain/Sub#01#01'));
151+
assert(tSub3, 'Subtest #01#01 was not created');
152+
147153
// Run subtest by itself
148154
console.log('Run subtest by itself');
149155
assert(await testExplorer.runner.run({ include: [tSub] }), 'Failed to execute `go test`');

test/testdata/subTest/sub_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import "testing"
55
func TestMain(t *testing.T) {
66
t.Log("Main")
77
t.Run("Sub", func(t *testing.T) { t.Log("Sub") })
8+
t.Run("Sub", func(t *testing.T) { t.Log("Sub#01") })
9+
t.Run("Sub#01", func(t *testing.T) { t.Log("Sub#01#01") })
810
}
911

1012
func TestOther(t *testing.T) {

0 commit comments

Comments
 (0)