TestBenchmarkAstGrep benchmarks the ast-grep scanner
(t *testing.T)
| 8 | |
| 9 | // TestBenchmarkAstGrep benchmarks the ast-grep scanner |
| 10 | func TestBenchmarkAstGrep(t *testing.T) { |
| 11 | testDir := os.Getenv("BENCH_DIR") |
| 12 | if testDir == "" { |
| 13 | testDir = ".." |
| 14 | } |
| 15 | |
| 16 | scanner, err := NewAstGrepScanner() |
| 17 | if err != nil { |
| 18 | t.Fatalf("ast-grep scanner error: %v", err) |
| 19 | } |
| 20 | if !scanner.Available() { |
| 21 | t.Skip("sg not available") |
| 22 | } |
| 23 | defer scanner.Close() |
| 24 | |
| 25 | start := time.Now() |
| 26 | results, err := scanner.ScanDirectory(testDir) |
| 27 | if err != nil { |
| 28 | t.Fatalf("ast-grep scan error: %v", err) |
| 29 | } |
| 30 | |
| 31 | var totalFuncs, totalImports int |
| 32 | for _, r := range results { |
| 33 | totalFuncs += len(r.Functions) |
| 34 | totalImports += len(r.Imports) |
| 35 | } |
| 36 | t.Logf("ast-grep: %v (%d functions, %d imports, %d files)", |
| 37 | time.Since(start), totalFuncs, totalImports, len(results)) |
| 38 | } |
| 39 | |
| 40 | func TestAstGrepScanner(t *testing.T) { |
| 41 | scanner, err := NewAstGrepScanner() |
nothing calls this directly
no test coverage detected