(t *testing.T)
| 81 | } |
| 82 | |
| 83 | func TestAstGrepPython(t *testing.T) { |
| 84 | analyzer := NewAstGrepAnalyzer() |
| 85 | if !analyzer.Available() { |
| 86 | t.Skip("ast-grep (sg) not installed") |
| 87 | } |
| 88 | |
| 89 | tmpDir := t.TempDir() |
| 90 | pyFile := filepath.Join(tmpDir, "test.py") |
| 91 | os.WriteFile(pyFile, []byte(`import os |
| 92 | from pathlib import Path |
| 93 | |
| 94 | def hello(name): |
| 95 | print(f"Hello {name}") |
| 96 | |
| 97 | def greet(): |
| 98 | pass |
| 99 | `), 0644) |
| 100 | |
| 101 | analysis, err := analyzer.AnalyzeFile(pyFile) |
| 102 | if err != nil { |
| 103 | t.Fatalf("AnalyzeFile failed: %v", err) |
| 104 | } |
| 105 | |
| 106 | funcs := make(map[string]bool) |
| 107 | for _, f := range analysis.Functions { |
| 108 | funcs[f] = true |
| 109 | } |
| 110 | if !funcs["hello"] { |
| 111 | t.Errorf("Expected hello function, got: %v", analysis.Functions) |
| 112 | } |
| 113 | if !funcs["greet"] { |
| 114 | t.Errorf("Expected greet function, got: %v", analysis.Functions) |
| 115 | } |
| 116 | |
| 117 | imports := make(map[string]bool) |
| 118 | for _, i := range analysis.Imports { |
| 119 | imports[i] = true |
| 120 | } |
| 121 | if !imports["os"] { |
| 122 | t.Errorf("Expected os import, got: %v", analysis.Imports) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | func TestAstGrepCSharp(t *testing.T) { |
| 127 | analyzer := NewAstGrepAnalyzer() |
nothing calls this directly
no test coverage detected