Skip to content

Commit 9c21ac5

Browse files
authored
Add -check-todo flag to auto-update metadata.json for passing tests (#51)
1 parent 4e4bc70 commit 9c21ac5

2 files changed

Lines changed: 32 additions & 17 deletions

File tree

CLAUDE.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,18 @@ This tool finds all tests with `todo: true` in their metadata and returns the on
1818
4. Implement the necessary AST types in `ast/`
1919
5. Add parser logic in `parser/parser.go`
2020
6. Add JSON marshaling functions in `parser/parser.go`
21-
7. Enable the test by removing `todo: true` from its `metadata.json` (set it to `{}`)
22-
8. Run `go test ./parser/...` to verify
23-
9. **Check if other todo tests now pass** (see below)
21+
7. Run `go test ./parser/... -check-todo -v` to auto-enable passing todo tests
22+
8. Run `go test ./parser/...` to verify all enabled tests pass
2423

2524
## Checking for Newly Passing Todo Tests
2625

2726
After implementing parser changes, run:
2827

2928
```bash
30-
go test ./parser/... -only-todo -v 2>&1 | grep "PASS:"
29+
go test ./parser/... -check-todo -v
3130
```
3231

33-
This shows any todo tests that now pass. Enable those tests by removing `todo: true` from their `metadata.json`.
34-
35-
Available test flags:
36-
- `-only-todo` - Run only todo/invalid_syntax tests (find newly passing tests)
37-
- `-run-todo` - Run todo/invalid_syntax tests along with normal tests
32+
This runs todo tests and **automatically updates `metadata.json`** for any tests that now pass (removes the `todo: true` flag). Look for "ENABLED:" in the output to see which tests were updated.
3833

3934
## Test Structure
4035

parser/parser_test.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ type testMetadata struct {
1515
InvalidSyntax bool `json:"invalid_syntax"`
1616
}
1717

18-
// Test flags for running todo/invalid_syntax tests
19-
// Usage: go test ./parser/... -run-todo # run all tests including todo tests
20-
// Usage: go test ./parser/... -only-todo # run only todo tests (find newly passing tests)
21-
var runTodoTests = flag.Bool("run-todo", false, "run todo tests along with normal tests")
22-
var onlyTodoTests = flag.Bool("only-todo", false, "run only todo tests (useful to find tests that now pass)")
18+
// Test flag for running todo tests and auto-enabling passing ones
19+
// Usage: go test ./parser/... -check-todo # run todo tests and auto-update metadata.json for passing tests
20+
var checkTodoTests = flag.Bool("check-todo", false, "run todo tests and auto-update metadata.json for passing tests")
2321

2422
func TestParse(t *testing.T) {
2523
entries, err := os.ReadDir("testdata")
@@ -48,15 +46,18 @@ func TestParse(t *testing.T) {
4846
t.Fatalf("failed to parse metadata.json: %v", err)
4947
}
5048

51-
// Skip tests marked with todo or invalid_syntax unless running with -run-todo or -only-todo
49+
// Skip tests marked with todo or invalid_syntax unless running with -check-todo
5250
shouldSkip := metadata.Todo || metadata.InvalidSyntax
53-
if shouldSkip && !*runTodoTests && !*onlyTodoTests {
51+
if shouldSkip && !*checkTodoTests {
5452
t.Skip("skipped via metadata.json (todo or invalid_syntax)")
5553
}
56-
if !shouldSkip && *onlyTodoTests {
54+
if !shouldSkip && *checkTodoTests {
5755
t.Skip("not a todo/invalid_syntax test")
5856
}
5957

58+
// For -check-todo, track if the test passes to update metadata (only for todo, not invalid_syntax)
59+
checkTodoMode := *checkTodoTests && metadata.Todo && !metadata.InvalidSyntax
60+
6061
// Read the test SQL file
6162
sqlPath := filepath.Join(testDir, "query.sql")
6263
sqlData, err := os.ReadFile(sqlPath)
@@ -100,6 +101,25 @@ func TestParse(t *testing.T) {
100101
if string(gotNormalized) != string(expectedNormalized) {
101102
t.Errorf("JSON mismatch:\ngot:\n%s\n\nexpected:\n%s", gotNormalized, expectedNormalized)
102103
}
104+
105+
// If running with -check-todo and the test passed, update metadata.json to remove todo flag
106+
if checkTodoMode && !t.Failed() {
107+
// Re-parse as map to preserve any extra fields
108+
var metadataMap map[string]any
109+
if err := json.Unmarshal(metadataData, &metadataMap); err != nil {
110+
t.Errorf("failed to parse metadata.json as map: %v", err)
111+
} else {
112+
delete(metadataMap, "todo")
113+
updatedMetadata, err := json.MarshalIndent(metadataMap, "", " ")
114+
if err != nil {
115+
t.Errorf("failed to marshal metadata: %v", err)
116+
} else if err := os.WriteFile(metadataPath, append(updatedMetadata, '\n'), 0644); err != nil {
117+
t.Errorf("failed to update metadata.json: %v", err)
118+
} else {
119+
t.Logf("ENABLED: updated %s (removed todo flag)", metadataPath)
120+
}
121+
}
122+
}
103123
})
104124
}
105125
}

0 commit comments

Comments
 (0)