TestCorpus walks testdata/corpus/ recursively and attempts to parse every .sql file. Each file may contain multiple statements separated by semicolons. Failures are reported per-file as subtests for independent tracking.
(t *testing.T)
| 27 | // Each file may contain multiple statements separated by semicolons. |
| 28 | // Failures are reported per-file as subtests for independent tracking. |
| 29 | func TestCorpus(t *testing.T) { |
| 30 | corpusRoot := filepath.Join("..", "..", "..", "testdata", "corpus") |
| 31 | |
| 32 | if _, err := os.Stat(corpusRoot); os.IsNotExist(err) { |
| 33 | t.Skipf("corpus directory not found at %s", corpusRoot) |
| 34 | } |
| 35 | |
| 36 | var files []string |
| 37 | err := filepath.Walk(corpusRoot, func(path string, info os.FileInfo, err error) error { |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | if !info.IsDir() && strings.HasSuffix(info.Name(), ".sql") { |
| 42 | files = append(files, path) |
| 43 | } |
| 44 | return nil |
| 45 | }) |
| 46 | if err != nil { |
| 47 | t.Fatalf("failed to walk corpus directory: %v", err) |
| 48 | } |
| 49 | |
| 50 | if len(files) == 0 { |
| 51 | t.Fatal("no .sql files found in corpus directory") |
| 52 | } |
| 53 | |
| 54 | t.Logf("found %d SQL corpus files", len(files)) |
| 55 | |
| 56 | for _, file := range files { |
| 57 | file := file // capture |
| 58 | relPath, _ := filepath.Rel(corpusRoot, file) |
| 59 | t.Run(relPath, func(t *testing.T) { |
| 60 | t.Parallel() |
| 61 | |
| 62 | data, err := os.ReadFile(file) |
| 63 | if err != nil { |
| 64 | t.Fatalf("failed to read file: %v", err) |
| 65 | } |
| 66 | |
| 67 | content := string(data) |
| 68 | // Split into individual statements by semicolon (skip empty) |
| 69 | statements := splitStatements(content) |
| 70 | |
| 71 | if len(statements) == 0 { |
| 72 | t.Skip("no statements found in file") |
| 73 | } |
| 74 | |
| 75 | for i, stmt := range statements { |
| 76 | stmt = strings.TrimSpace(stmt) |
| 77 | if stmt == "" { |
| 78 | continue |
| 79 | } |
| 80 | |
| 81 | tkz := tokenizer.GetTokenizer() |
| 82 | tokens, err := tkz.Tokenize([]byte(stmt)) |
| 83 | tokenizer.PutTokenizer(tkz) |
| 84 | if err != nil { |
| 85 | t.Skipf("statement %d: tokenize error: %v\n SQL: %.200s", i+1, err, stmt) |
| 86 | continue |
nothing calls this directly
no test coverage detected