@@ -19,6 +19,10 @@ import (
1919// Use with: go test ./parser -check-format -v
2020var 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
2327type 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\n Query: %s\n Expected:\n %s\n \n Got:\n %s" , stmt , expected , actual )
243+ if isExplainTodo && * checkExplain {
244+ t .Logf ("EXPLAIN STILL FAILING:\n Expected:\n %s\n \n Got:\n %s" , expected , actual )
245+ } else {
246+ t .Errorf ("Explain output mismatch\n Query: %s\n Expected:\n %s\n \n Got:\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