Skip to content

Commit 34b38c8

Browse files
committed
docs: cover new work with end-to-end tests
State the testing strategy in CLAUDE.md — a change is exercised by running sqlc the way a user does, against a schema, a query file and a committed golden, rather than by a unit test on an internal function — and describe how an endtoend case is laid out. Drop the seed package's unit test accordingly. The dialect descriptions it covered are exercised by the analyze cases under internal/endtoend/testdata, which run every dialect through the catalog it seeds. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011MnoUabwBWW9gaEn2Nj7eG
1 parent be9f5fd commit 34b38c8

2 files changed

Lines changed: 27 additions & 100 deletions

File tree

CLAUDE.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,23 @@ go test -v ./internal/config -run TestConfig
8989
go test -race ./internal/config
9090
```
9191

92-
## Test Types
92+
## Testing Strategy
9393

94-
### 1. Unit Tests
94+
**Cover new work with end-to-end tests, not unit tests.** A change to the
95+
compiler, an engine, the analysis core or codegen is exercised by running sqlc
96+
the way a user does — a schema, a query file and a committed golden output —
97+
so the test says what sqlc produces rather than what an internal function
98+
returns. Internal APIs move around; the SQL that goes in and the output that
99+
comes out is the contract worth pinning down.
95100

96-
- **Location:** Throughout the codebase as `*_test.go` files
97-
- **Run without:** Database or external dependencies
98-
- **Examples:**
99-
- `/internal/config/config_test.go` - Configuration parsing
100-
- `/internal/compiler/selector_test.go` - Compiler logic
101-
- `/internal/metadata/metadata_test.go` - Query metadata parsing
101+
Adding coverage means adding a directory under `/internal/endtoend/testdata/`,
102+
not a `*_test.go` next to the code. Reach for a unit test only when the
103+
behavior genuinely cannot be reached through the CLI, and say why in the test.
102104

103-
### 2. End-to-End Tests
105+
Some `*_test.go` files predate this and remain; they are not a precedent for
106+
new ones.
107+
108+
### End-to-End Tests
104109

105110
- **Location:** `/internal/endtoend/`
106111
- **Requirements:** `--tags=examples` flag and running databases
@@ -111,7 +116,15 @@ go test -race ./internal/config
111116
- `TestJsonSchema` - JSON schema validation
112117
- `TestExamplesVet` - Static analysis tests
113118

114-
### 3. Example Tests
119+
A case is a directory holding the inputs and the expected output. `exec.json`
120+
names the command and its arguments — omit it and the case runs `generate`,
121+
comparing the generated files against the ones committed alongside; give it
122+
`{"command": "analyze", "args": [...]}` and the case compares the command's
123+
stdout against `stdout.txt`. A case that is expected to fail commits its
124+
`stderr.txt`. Regenerate a golden by running the command in its directory and
125+
writing the output back over the committed file.
126+
127+
### Example Tests
115128

116129
- **Location:** `/examples/` directory
117130
- **Requirements:** Tagged with "examples", requires live databases
@@ -232,9 +245,10 @@ go run ./cmd/sqlc-test-setup start
232245
## Tips for Contributors
233246

234247
1. **Run tests before committing:** `go test --tags=examples -timeout 20m ./...`
235-
2. **Check for race conditions:** Use `-race` flag when testing concurrent code
236-
3. **Use specific package tests:** Faster iteration during development
237-
4. **Read existing tests:** Good examples in `/internal/engine/postgresql/*_test.go`
248+
2. **Cover new behavior end to end:** Add a case under `/internal/endtoend/testdata/`
249+
3. **Check for race conditions:** Use `-race` flag when testing concurrent code
250+
4. **Iterate on one case:** `go test ./internal/endtoend -run 'TestReplay/base/<case>'`
251+
5. **Read existing cases:** `/internal/endtoend/testdata/` has one per feature
238252

239253
## Git Workflow
240254

internal/core/seed/seed_test.go

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)