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