Skip to content

Commit 5c0f5ff

Browse files
committed
Map file path for fuzz tests
1 parent d8bab5b commit 5c0f5ff

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

tools/flakeguard/reports/codebase_scanner.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,39 @@ type TestFileMap map[string]string
1616
func ScanTestFiles(rootDir string) (TestFileMap, error) {
1717
testFileMap := make(TestFileMap)
1818

19+
// Walk through the root directory to find test files
1920
err := filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
2021
if err != nil {
2122
return err
2223
}
24+
25+
// Skip files that are not Go test files
2326
if !strings.HasSuffix(path, "_test.go") {
2427
return nil
2528
}
2629

27-
// Parse the file
30+
// Parse the Go file
2831
fset := token.NewFileSet()
2932
node, err := parser.ParseFile(fset, path, nil, parser.AllErrors)
3033
if err != nil {
3134
return err
3235
}
3336

34-
// Traverse the AST to find test functions
37+
// Traverse the AST to find test or fuzz functions
3538
ast.Inspect(node, func(n ast.Node) bool {
3639
funcDecl, ok := n.(*ast.FuncDecl)
3740
if !ok {
3841
return true
3942
}
40-
if strings.HasPrefix(funcDecl.Name.Name, "Test") {
41-
// Add both the package and test function to the map
43+
44+
// Match both "Test" and "Fuzz" prefixes
45+
if strings.HasPrefix(funcDecl.Name.Name, "Test") || strings.HasPrefix(funcDecl.Name.Name, "Fuzz") {
46+
// Add the function to the map
4247
testFileMap[funcDecl.Name.Name] = path
4348
}
4449
return true
4550
})
51+
4652
return nil
4753
})
4854

0 commit comments

Comments
 (0)