Skip to content

Commit

Permalink
src/testUtils: add test codelenses for Fuzz* functions
Browse files Browse the repository at this point in the history
Add 'run test', 'debug test' codelenses for Fuzz* functions.

Updates #1794

Change-Id: I5089926fd6cabcaf844be21217a9a77baad09ca4
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/361935
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>
  • Loading branch information
hyangah committed Nov 10, 2021
1 parent ae78458 commit 08f9065
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const runningTestProcesses: cp.ChildProcess[] = [];
const testFuncRegex = /^Test$|^Test\P{Ll}.*|^Example$|^Example\P{Ll}.*/u;
const testMethodRegex = /^\(([^)]+)\)\.(Test|Test\P{Ll}.*)$/u;
const benchmarkRegex = /^Benchmark$|^Benchmark\P{Ll}.*/u;

const fuzzFuncRegx = /^Fuzz$|^Fuzz\P{Ll}.*/u;
/**
* Input to goTest.
*/
Expand Down Expand Up @@ -158,7 +158,7 @@ export async function getTestFunctions(
return children.filter(
(sym) =>
sym.kind === vscode.SymbolKind.Function &&
(testFuncRegex.test(sym.name) || (testify && testMethodRegex.test(sym.name)))
(testFuncRegex.test(sym.name) || fuzzFuncRegx.test(sym.name) || (testify && testMethodRegex.test(sym.name)))
);
}

Expand Down
22 changes: 21 additions & 1 deletion test/integration/codelens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getGoConfig } from '../../src/config';
import { updateGoVarsFromConfig } from '../../src/goInstallTools';
import { GoRunTestCodeLensProvider } from '../../src/goRunTestCodelens';
import { subTestAtCursor } from '../../src/goTest';
import { getCurrentGoPath } from '../../src/util';
import { getCurrentGoPath, getGoVersion } from '../../src/util';

suite('Code lenses for testing and benchmarking', function () {
this.timeout(20000);
Expand Down Expand Up @@ -164,4 +164,24 @@ suite('Code lenses for testing and benchmarking', function () {
'Test함수'
]);
});

test('Test codelenses include valid fuzz function names', async function () {
if ((await getGoVersion()).lt('1.18')) {
this.skip();
}
const uri = vscode.Uri.file(path.join(fixturePath, 'codelens_go118_test.go'));
const testDocument = await vscode.workspace.openTextDocument(uri);
const codeLenses = await codeLensProvider.provideCodeLenses(testDocument, cancellationTokenSource.token);
assert.equal(codeLenses.length, 8, JSON.stringify(codeLenses, null, 2));
const found = [] as string[];
for (let i = 0; i < codeLenses.length; i++) {
const lens = codeLenses[i];
if (lens.command.command === 'go.test.cursor') {
found.push(lens.command.arguments[0].functionName);
}
}
found.sort();
// Results should match `go test -list`.
assert.deepStrictEqual(found, ['Fuzz', 'FuzzFunc', 'TestGo118']);
});
});
17 changes: 17 additions & 0 deletions test/testdata/codelens/codelens_go118_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build go1.18
// +build go1.18

package main

import (
"testing"
)

func FuzzFunc(f *testing.F) {
}

func Fuzz(f *testing.F) {
}

func TestGo118(t *testing.T) {
}

0 comments on commit 08f9065

Please sign in to comment.