Skip to content

Commit f114854

Browse files
committed
Add -check-explain flag for explain_todo tests
Add a new -check-explain flag that runs tests marked in explain_todo to see if they now pass. Similar to -check-format but for explain tests. Usage: go test ./parser/... -check-explain -v 2>&1 | grep "EXPLAIN PASSES NOW" When a test passes, it automatically removes the statement from explain_todo in metadata.json.
1 parent 7db6940 commit f114854

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

CLAUDE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ go test ./parser/... -check-format -v 2>&1 | grep "FORMAT PASSES NOW"
3030

3131
Tests that output `FORMAT PASSES NOW` can have their `todo_format` flag removed from `metadata.json`.
3232

33+
## Checking for Newly Passing Explain Tests
34+
35+
After implementing parser/explain changes, run:
36+
37+
```bash
38+
go test ./parser/... -check-explain -v 2>&1 | grep "EXPLAIN PASSES NOW"
39+
```
40+
41+
Tests that output `EXPLAIN PASSES NOW` can have their statement removed from `explain_todo` in `metadata.json`.
42+
3343
## Test Structure
3444

3545
Each test in `parser/testdata/` contains:

parser/parser_test.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import (
1919
// Use with: go test ./parser -check-format -v
2020
var checkFormat = flag.Bool("check-format", false, "Run skipped todo_format tests to see which ones now pass")
2121

22+
// checkExplain runs skipped explain_todo tests to see which ones now pass.
23+
// Use with: go test ./parser -check-explain -v
24+
var checkExplain = flag.Bool("check-explain", false, "Run skipped explain_todo tests to see which ones now pass")
25+
2226
// testMetadata holds optional metadata for a test case
2327
type testMetadata struct {
2428
TodoFormat bool `json:"todo_format,omitempty"` // true if format roundtrip test is pending
@@ -191,9 +195,10 @@ func TestParser(t *testing.T) {
191195
}
192196
}
193197

194-
// Skip statements marked in explain_todo
198+
// Skip statements marked in explain_todo (unless -check-explain is set)
195199
stmtKey := fmt.Sprintf("stmt%d", stmtIndex)
196-
if metadata.ExplainTodo[stmtKey] {
200+
isExplainTodo := metadata.ExplainTodo[stmtKey]
201+
if isExplainTodo && !*checkExplain {
197202
t.Skipf("TODO: explain_todo[%s] is true", stmtKey)
198203
return
199204
}
@@ -235,7 +240,25 @@ func TestParser(t *testing.T) {
235240
actual := strings.TrimSpace(parser.Explain(stmts[0]))
236241
// Use case-insensitive comparison since ClickHouse EXPLAIN AST has inconsistent casing
237242
if !strings.EqualFold(actual, expected) {
238-
t.Errorf("Explain output mismatch\nQuery: %s\nExpected:\n%s\n\nGot:\n%s", stmt, expected, actual)
243+
if isExplainTodo && *checkExplain {
244+
t.Logf("EXPLAIN STILL FAILING:\nExpected:\n%s\n\nGot:\n%s", expected, actual)
245+
} else {
246+
t.Errorf("Explain output mismatch\nQuery: %s\nExpected:\n%s\n\nGot:\n%s", stmt, expected, actual)
247+
}
248+
} else if isExplainTodo && *checkExplain {
249+
// Test passes now - remove from explain_todo
250+
delete(metadata.ExplainTodo, stmtKey)
251+
if len(metadata.ExplainTodo) == 0 {
252+
metadata.ExplainTodo = nil
253+
}
254+
updatedBytes, err := json.Marshal(metadata)
255+
if err != nil {
256+
t.Errorf("Failed to marshal updated metadata: %v", err)
257+
} else if err := os.WriteFile(metadataPath, append(updatedBytes, '\n'), 0644); err != nil {
258+
t.Errorf("Failed to write updated metadata.json: %v", err)
259+
} else {
260+
t.Logf("EXPLAIN PASSES NOW - removed explain_todo[%s] from: %s", stmtKey, entry.Name())
261+
}
239262
}
240263
}
241264

0 commit comments

Comments
 (0)