[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 golang/vscode-go#2023
For golang/vscode-go#1922
Change-Id: I33ba5c17e9095686a87c719d44fe7330269d9cc3
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/380501
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
(cherry picked from commit 2735f152fe31270cdb0595e001d37a66b540f94f)
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/383935
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/src/goTest/run.ts b/src/goTest/run.ts
index 6958011..5005243 100644
--- a/src/goTest/run.ts
+++ b/src/goTest/run.ts
@@ -477,14 +477,16 @@
}
// Resolve a test name to a test item. If the test name is TestXxx/Foo, Foo is
- // created as a child of TestXxx. The same is true for TestXxx#Foo and
- // TestXxx/#Foo.
+ // created as a child of TestXxx.
resolveTestName(tests: Record<string, TestItem>, name: string): TestItem | undefined {
if (!name) {
return;
}
- const re = /[#/]+/;
+ // Heuristically determines whether a test is a subtest by checking the existence of "/".
+ // BUG: go test does not escape "/" included in the name passed to t.Run, so that
+ // can result in confusing presentation.
+ const re = /\/+/;
const resolve = (parent?: TestItem, start = 0, length = 0): TestItem | undefined => {
const pos = start + length;
diff --git a/test/integration/goTest.run.test.ts b/test/integration/goTest.run.test.ts
index 23d6833..e52d7df 100644
--- a/test/integration/goTest.run.test.ts
+++ b/test/integration/goTest.run.test.ts
@@ -144,6 +144,12 @@
const tSub = tMain.children.get(GoTest.id(uri, 'test', 'TestMain/Sub'));
assert(tSub, 'Subtest was not created');
+ console.log('Locate subtests with conflicting names');
+ const tSub2 = tMain.children.get(GoTest.id(uri, 'test', 'TestMain/Sub#01'));
+ assert(tSub2, 'Subtest #01 was not created');
+ const tSub3 = tMain.children.get(GoTest.id(uri, 'test', 'TestMain/Sub#01#01'));
+ assert(tSub3, 'Subtest #01#01 was not created');
+
// Run subtest by itself
console.log('Run subtest by itself');
assert(await testExplorer.runner.run({ include: [tSub] }), 'Failed to execute `go test`');
diff --git a/test/testdata/subTest/sub_test.go b/test/testdata/subTest/sub_test.go
index d78d47a..ce66fe9 100644
--- a/test/testdata/subTest/sub_test.go
+++ b/test/testdata/subTest/sub_test.go
@@ -5,6 +5,8 @@
func TestMain(t *testing.T) {
t.Log("Main")
t.Run("Sub", func(t *testing.T) { t.Log("Sub") })
+ t.Run("Sub", func(t *testing.T) { t.Log("Sub#01") })
+ t.Run("Sub#01", func(t *testing.T) { t.Log("Sub#01#01") })
}
func TestOther(t *testing.T) {