(t *testing.T)
| 22 | } |
| 23 | |
| 24 | func TestAstGrepAnalyzer(t *testing.T) { |
| 25 | analyzer := NewAstGrepAnalyzer() |
| 26 | if !analyzer.Available() { |
| 27 | t.Skip("ast-grep (sg) not installed") |
| 28 | } |
| 29 | |
| 30 | // Test Go file |
| 31 | tmpDir := t.TempDir() |
| 32 | goFile := filepath.Join(tmpDir, "test.go") |
| 33 | os.WriteFile(goFile, []byte(`package main |
| 34 | |
| 35 | import ( |
| 36 | "fmt" |
| 37 | "os" |
| 38 | ) |
| 39 | |
| 40 | func main() { |
| 41 | fmt.Println("hello") |
| 42 | } |
| 43 | |
| 44 | func helper(x int) int { |
| 45 | return x * 2 |
| 46 | } |
| 47 | `), 0644) |
| 48 | |
| 49 | analysis, err := analyzer.AnalyzeFile(goFile) |
| 50 | if err != nil { |
| 51 | t.Fatalf("AnalyzeFile failed: %v", err) |
| 52 | } |
| 53 | |
| 54 | if analysis == nil { |
| 55 | t.Fatal("Expected analysis, got nil") |
| 56 | } |
| 57 | |
| 58 | // Check functions |
| 59 | funcs := make(map[string]bool) |
| 60 | for _, f := range analysis.Functions { |
| 61 | funcs[f] = true |
| 62 | } |
| 63 | if !funcs["main"] { |
| 64 | t.Error("Expected main function") |
| 65 | } |
| 66 | if !funcs["helper"] { |
| 67 | t.Error("Expected helper function") |
| 68 | } |
| 69 | |
| 70 | // Check imports |
| 71 | imports := make(map[string]bool) |
| 72 | for _, i := range analysis.Imports { |
| 73 | imports[i] = true |
| 74 | } |
| 75 | if !imports["fmt"] { |
| 76 | t.Errorf("Expected fmt import, got: %v", analysis.Imports) |
| 77 | } |
| 78 | if !imports["os"] { |
| 79 | t.Errorf("Expected os import, got: %v", analysis.Imports) |
| 80 | } |
| 81 | } |
nothing calls this directly
no test coverage detected