Skip to content

Commit c3de634

Browse files
nlepagehyangah
authored andcommitted
codelens: fix regexps for test funcs names
Include funcs without suffixes such as "Test", "Example" and "Benchmark". Change-Id: I7d813f88c5f9dafdaea95de8f10d57a4d1a28aeb Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/344130 Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Trust: Hyang-Ah Hana Kim <[email protected]> Trust: Suzy Mueller <[email protected]>
1 parent 2f484bd commit c3de634

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

src/testUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ const runningTestProcesses: cp.ChildProcess[] = [];
3737
// There could be slight difference between \P{Ll} (not lowercase letter)
3838
// & go unicode package's uppercase detection. But hopefully
3939
// these will be replaced by gopls's codelens computation soon.
40-
const testFuncRegex = /^Test\P{Ll}.*|^Example\P{Ll}.*/u;
41-
const testMethodRegex = /^\(([^)]+)\)\.(Test\P{Ll}.*)$/u;
42-
const benchmarkRegex = /^Benchmark\P{Ll}.*/u;
40+
const testFuncRegex = /^Test$|^Test\P{Ll}.*|^Example$|^Example\P{Ll}.*/u;
41+
const testMethodRegex = /^\(([^)]+)\)\.(Test|Test\P{Ll}.*)$/u;
42+
const benchmarkRegex = /^Benchmark$|^Benchmark\P{Ll}.*/u;
4343

4444
/**
4545
* Input to goTest.

test/integration/codelens.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ suite('Code lenses for testing and benchmarking', function () {
143143
const uri = vscode.Uri.file(path.join(fixturePath, 'codelens2_test.go'));
144144
const benchmarkDocument = await vscode.workspace.openTextDocument(uri);
145145
const codeLenses = await codeLensProvider.provideCodeLenses(benchmarkDocument, cancellationTokenSource.token);
146-
assert.equal(codeLenses.length, 12, JSON.stringify(codeLenses, null, 2));
146+
assert.equal(codeLenses.length, 18, JSON.stringify(codeLenses, null, 2));
147147
const found = [] as string[];
148148
for (let i = 0; i < codeLenses.length; i++) {
149149
const lens = codeLenses[i];
@@ -153,6 +153,15 @@ suite('Code lenses for testing and benchmarking', function () {
153153
}
154154
found.sort();
155155
// Results should match `go test -list`.
156-
assert.deepStrictEqual(found, ['Test1Function', 'TestFunction', 'Test_foobar', 'TestΣυνάρτηση', 'Test함수']);
156+
assert.deepStrictEqual(found, [
157+
'Example',
158+
'ExampleFunction',
159+
'Test',
160+
'Test1Function',
161+
'TestFunction',
162+
'Test_foobar',
163+
'TestΣυνάρτηση',
164+
'Test함수'
165+
]);
157166
});
158167
});

test/testdata/codelens/codelens2_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"testing"
56
)
67

@@ -10,6 +11,7 @@ import (
1011
// TestΣυνάρτηση
1112
// Test함수
1213
// Test_foobar
14+
// Test
1315
func TestFunction(t *testing.T) {
1416
t.Log("this is a valid test function")
1517
}
@@ -36,4 +38,20 @@ func Test함수(t *testing.T) {
3638

3739
func Test_foobar(t *testing.T) {
3840
t.Log("this is an acceptable test function")
39-
}
41+
}
42+
43+
func Test(t *testing.T) {
44+
t.Log("this is a valid test function")
45+
}
46+
47+
func ExampleFunction() {
48+
fmt.Println("this is a valid example function")
49+
// Output:
50+
// this is a valid example function
51+
}
52+
53+
func Example() {
54+
fmt.Println("this is a valid example function")
55+
// Output:
56+
// this is a valid example function
57+
}

0 commit comments

Comments
 (0)