Skip to content

Commit 0e33c84

Browse files
committed
[release] src/goTest: detect Fuzz tests and list them in test explorer UI
Detected fuzz functions are classified as a 'fuzz' type, so we can later add special handling for fuzzing functionality. Now they are like other test functions. For #2023 Change-Id: I7f3998ec6acf8a766c05380077d41c459d685079 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/380500 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 c42b3cd) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/383218 Reviewed-by: Robert Findley <[email protected]>
1 parent 94d18e4 commit 0e33c84

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/goTest/resolve.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { walk, WalkStop } from './walk';
2727

2828
export type ProvideSymbols = (doc: TextDocument, token: CancellationToken) => Thenable<DocumentSymbol[]>;
2929

30-
const testFuncRegex = /^(?<name>(?<kind>Test|Benchmark|Example)($|\P{Ll}.*))/u;
30+
const testFuncRegex = /^(?<name>(?<kind>Test|Benchmark|Example|Fuzz)($|\P{Ll}.*))/u;
3131
const testMethodRegex = /^\(\*(?<type>[^)]+)\)\.(?<name>(?<kind>Test)($|\P{Ll}.*))$/u;
3232
const runTestSuiteRegex = /^\s*suite\.Run\(\w+,\s*(?:&?(?<type1>\w+)\{\}|new\((?<type2>\w+)\))\)/mu;
3333

@@ -393,7 +393,7 @@ export class GoTestResolver {
393393
return suite;
394394
}
395395

396-
// Recursively process a Go AST symbol. If the symbol represents a test,
396+
// Recursively process a Go AST symbol. If the symbol represents a test, fuzz test,
397397
// benchmark, or example function, a test item will be created for it, if one
398398
// does not already exist. If the symbol is not a function and contains
399399
// children, those children will be processed recursively.

src/goTest/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import { GoTestResolver } from './resolve';
1313
// - A 'package' is a folder that contains .go files (and is not a module)
1414
// - A 'file' is a file ending with _test.go
1515
// - A 'test' is a Go test, e.g. func TestXxx(t *testing.T)
16-
// - A 'benchmark' is a Go benchmark, e.g. func BenchmarkXxx(t *testing.T)
16+
// - A 'benchmark' is a Go benchmark, e.g. func BenchmarkXxx(t *testing.B)
17+
// - A 'fuzz' is a Fuzz test, e.g., func TestFuzz(f *testing.F)
1718
// - An 'example' is a Go example, e.g. func ExampleXxx()
1819
//
1920
// The top-level test item for a workspace folder is always either a module or a
2021
// workspace. If the user opens a file (containing tests) that is not contained
2122
// within any workspace folder, a top-level package will be created as a parent
2223
// of that file.
23-
export type GoTestKind = 'module' | 'workspace' | 'package' | 'file' | 'test' | 'benchmark' | 'example';
24+
export type GoTestKind = 'module' | 'workspace' | 'package' | 'file' | 'test' | 'benchmark' | 'fuzz' | 'example';
2425

2526
export class GoTest {
2627
// Constructs an ID for an item. The ID of a test item consists of the URI
@@ -34,6 +35,7 @@ export class GoTest {
3435
// - File: file:///path/to/mod/file.go?file
3536
// - Test: file:///path/to/mod/file.go?test#TestXxx
3637
// - Benchmark: file:///path/to/mod/file.go?benchmark#BenchmarkXxx
38+
// - Fuzz: file:///path/to/mod/file.go?test#FuzzXxx
3739
// - Example: file:///path/to/mod/file.go?example#ExampleXxx
3840
static id(uri: vscode.Uri, kind: GoTestKind, name?: string): string {
3941
uri = uri.with({ query: kind });
@@ -49,7 +51,7 @@ export class GoTest {
4951
const u = vscode.Uri.parse(id);
5052
const kind = u.query as GoTestKind;
5153
const name = u.fragment;
52-
return { name, kind };
54+
return { kind, name };
5355
}
5456
}
5557

test/integration/goTest.resolve.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ suite('Go Test Resolver', () => {
172172
func TestFoo(*testing.T) {}
173173
func BenchmarkBar(*testing.B) {}
174174
func ExampleBaz() {}
175+
func FuzzFuss(*testing.F) {}
175176
`
176177
},
177178
item: [
@@ -181,7 +182,8 @@ suite('Go Test Resolver', () => {
181182
expect: [
182183
'file:///src/proj/main_test.go?test#TestFoo',
183184
'file:///src/proj/main_test.go?benchmark#BenchmarkBar',
184-
'file:///src/proj/main_test.go?example#ExampleBaz'
185+
'file:///src/proj/main_test.go?example#ExampleBaz',
186+
'file:///src/proj/main_test.go?fuzz#FuzzFuss'
185187
]
186188
}
187189
}

test/integration/goTest.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { MockTestWorkspace } from '../mocks/MockTest';
1313
export function getSymbols_Regex(doc: TextDocument, token: unknown): Thenable<DocumentSymbol[]> {
1414
const syms: DocumentSymbol[] = [];
1515
const range = new Range(new Position(0, 0), new Position(0, 0));
16-
doc.getText().replace(/^func (Test|Benchmark|Example)([A-Z]\w+)(\(.*\))/gm, (m, type, name, details) => {
16+
doc.getText().replace(/^func (Test|Benchmark|Example|Fuzz)([A-Z]\w+)(\(.*\))/gm, (m, type, name, details) => {
1717
syms.push(new DocumentSymbol(type + name, details, SymbolKind.Function, range, range));
1818
return m;
1919
});

0 commit comments

Comments
 (0)