Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,18 @@ This tool finds all tests with `todo: true` in their metadata and returns the on
4. Implement the necessary AST types in `ast/`
5. Add parser logic in `parser/parser.go`
6. Add JSON marshaling functions in `parser/parser.go`
7. Enable the test by removing `todo: true` from its `metadata.json` (set it to `{}`)
8. Run `go test ./parser/...` to verify
9. **Check if other todo tests now pass** (see below)
7. Run `go test ./parser/... -check-todo -v` to auto-enable passing todo tests
8. Run `go test ./parser/...` to verify all enabled tests pass

## Checking for Newly Passing Todo Tests

After implementing parser changes, run:

```bash
go test ./parser/... -only-todo -v 2>&1 | grep "PASS:"
go test ./parser/... -check-todo -v
```

This shows any todo tests that now pass. Enable those tests by removing `todo: true` from their `metadata.json`.

Available test flags:
- `-only-todo` - Run only todo/invalid_syntax tests (find newly passing tests)
- `-run-todo` - Run todo/invalid_syntax tests along with normal tests
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.

## Test Structure

Expand Down
36 changes: 28 additions & 8 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ type testMetadata struct {
InvalidSyntax bool `json:"invalid_syntax"`
}

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

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

// Skip tests marked with todo or invalid_syntax unless running with -run-todo or -only-todo
// Skip tests marked with todo or invalid_syntax unless running with -check-todo
shouldSkip := metadata.Todo || metadata.InvalidSyntax
if shouldSkip && !*runTodoTests && !*onlyTodoTests {
if shouldSkip && !*checkTodoTests {
t.Skip("skipped via metadata.json (todo or invalid_syntax)")
}
if !shouldSkip && *onlyTodoTests {
if !shouldSkip && *checkTodoTests {
t.Skip("not a todo/invalid_syntax test")
}

// For -check-todo, track if the test passes to update metadata (only for todo, not invalid_syntax)
checkTodoMode := *checkTodoTests && metadata.Todo && !metadata.InvalidSyntax

// Read the test SQL file
sqlPath := filepath.Join(testDir, "query.sql")
sqlData, err := os.ReadFile(sqlPath)
Expand Down Expand Up @@ -100,6 +101,25 @@ func TestParse(t *testing.T) {
if string(gotNormalized) != string(expectedNormalized) {
t.Errorf("JSON mismatch:\ngot:\n%s\n\nexpected:\n%s", gotNormalized, expectedNormalized)
}

// If running with -check-todo and the test passed, update metadata.json to remove todo flag
if checkTodoMode && !t.Failed() {
// Re-parse as map to preserve any extra fields
var metadataMap map[string]any
if err := json.Unmarshal(metadataData, &metadataMap); err != nil {
t.Errorf("failed to parse metadata.json as map: %v", err)
} else {
delete(metadataMap, "todo")
updatedMetadata, err := json.MarshalIndent(metadataMap, "", " ")
if err != nil {
t.Errorf("failed to marshal metadata: %v", err)
} else if err := os.WriteFile(metadataPath, append(updatedMetadata, '\n'), 0644); err != nil {
t.Errorf("failed to update metadata.json: %v", err)
} else {
t.Logf("ENABLED: updated %s (removed todo flag)", metadataPath)
}
}
}
})
}
}
Loading