MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestAstGrepScanDirectoryTimeout

Function TestAstGrepScanDirectoryTimeout

scanner/astgrep_test.go:187–216  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

185}
186
187func TestAstGrepScanDirectoryTimeout(t *testing.T) {
188 if runtime.GOOS == "windows" {
189 t.Skip("requires shell script execution")
190 }
191
192 tmpDir := t.TempDir()
193 fakeBinary := filepath.Join(tmpDir, "fake-sg.sh")
194 if err := os.WriteFile(fakeBinary, []byte("#!/bin/sh\nsleep 5\n"), 0755); err != nil {
195 t.Fatalf("failed to create fake ast-grep binary: %v", err)
196 }
197
198 scanner := &AstGrepScanner{
199 rulesDir: tmpDir,
200 binary: fakeBinary,
201 }
202
203 prevTimeout := astGrepScanTimeout
204 astGrepScanTimeout = 20 * time.Millisecond
205 t.Cleanup(func() {
206 astGrepScanTimeout = prevTimeout
207 })
208
209 results, err := scanner.ScanDirectory(tmpDir)
210 if err != nil {
211 t.Fatalf("expected graceful timeout handling, got error: %v", err)
212 }
213 if results != nil {
214 t.Fatalf("expected nil results on timeout, got: %v", results)
215 }
216}
217
218func TestScanForDepsRejectsNonAstGrepSg(t *testing.T) {
219 if runtime.GOOS == "windows" {

Callers

nothing calls this directly

Calls 1

ScanDirectoryMethod · 0.95

Tested by

no test coverage detected