|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "fmt" |
| 6 | + "os" |
| 7 | + "path/filepath" |
| 8 | + "sort" |
| 9 | +) |
| 10 | + |
| 11 | +type testMetadata struct { |
| 12 | + Todo bool `json:"todo,omitempty"` |
| 13 | + Explain *bool `json:"explain,omitempty"` |
| 14 | + Skip bool `json:"skip,omitempty"` |
| 15 | + ParseError bool `json:"parse_error,omitempty"` |
| 16 | +} |
| 17 | + |
| 18 | +type todoTest struct { |
| 19 | + name string |
| 20 | + querySize int |
| 21 | +} |
| 22 | + |
| 23 | +func main() { |
| 24 | + testdataDir := "parser/testdata" |
| 25 | + entries, err := os.ReadDir(testdataDir) |
| 26 | + if err != nil { |
| 27 | + fmt.Fprintf(os.Stderr, "Error reading testdata: %v\n", err) |
| 28 | + os.Exit(1) |
| 29 | + } |
| 30 | + |
| 31 | + var todoTests []todoTest |
| 32 | + |
| 33 | + for _, entry := range entries { |
| 34 | + if !entry.IsDir() { |
| 35 | + continue |
| 36 | + } |
| 37 | + |
| 38 | + testDir := filepath.Join(testdataDir, entry.Name()) |
| 39 | + metadataPath := filepath.Join(testDir, "metadata.json") |
| 40 | + |
| 41 | + // Read metadata |
| 42 | + metadataBytes, err := os.ReadFile(metadataPath) |
| 43 | + if err != nil { |
| 44 | + continue |
| 45 | + } |
| 46 | + |
| 47 | + var metadata testMetadata |
| 48 | + if err := json.Unmarshal(metadataBytes, &metadata); err != nil { |
| 49 | + continue |
| 50 | + } |
| 51 | + |
| 52 | + // Only include tests marked as todo |
| 53 | + if !metadata.Todo { |
| 54 | + continue |
| 55 | + } |
| 56 | + |
| 57 | + // Skip tests with skip or explain=false or parse_error |
| 58 | + if metadata.Skip || (metadata.Explain != nil && !*metadata.Explain) || metadata.ParseError { |
| 59 | + continue |
| 60 | + } |
| 61 | + |
| 62 | + // Read query to get its size |
| 63 | + queryPath := filepath.Join(testDir, "query.sql") |
| 64 | + queryBytes, err := os.ReadFile(queryPath) |
| 65 | + if err != nil { |
| 66 | + continue |
| 67 | + } |
| 68 | + |
| 69 | + todoTests = append(todoTests, todoTest{ |
| 70 | + name: entry.Name(), |
| 71 | + querySize: len(queryBytes), |
| 72 | + }) |
| 73 | + } |
| 74 | + |
| 75 | + if len(todoTests) == 0 { |
| 76 | + fmt.Println("No todo tests found!") |
| 77 | + return |
| 78 | + } |
| 79 | + |
| 80 | + // Sort by query size (shortest first) |
| 81 | + sort.Slice(todoTests, func(i, j int) bool { |
| 82 | + return todoTests[i].querySize < todoTests[j].querySize |
| 83 | + }) |
| 84 | + |
| 85 | + // Print the shortest one |
| 86 | + next := todoTests[0] |
| 87 | + testDir := filepath.Join(testdataDir, next.name) |
| 88 | + |
| 89 | + fmt.Printf("Next test: %s\n\n", next.name) |
| 90 | + |
| 91 | + // Print query.sql contents |
| 92 | + queryPath := filepath.Join(testDir, "query.sql") |
| 93 | + queryBytes, _ := os.ReadFile(queryPath) |
| 94 | + fmt.Printf("Query (%d bytes):\n%s\n", next.querySize, string(queryBytes)) |
| 95 | + |
| 96 | + // Print explain.txt contents if it exists |
| 97 | + explainPath := filepath.Join(testDir, "explain.txt") |
| 98 | + if explainBytes, err := os.ReadFile(explainPath); err == nil { |
| 99 | + fmt.Printf("\nExpected EXPLAIN output:\n%s\n", string(explainBytes)) |
| 100 | + } |
| 101 | + |
| 102 | + fmt.Printf("\nRemaining todo tests: %d\n", len(todoTests)) |
| 103 | +} |
0 commit comments