You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: complete code generation architecture for assert/require packages
Inverts the generation model: internal/assertions is now the single source
of truth, with assert/ and require/ packages fully generated including all
variants (format, forward, tests, examples).
Architecture:
- Scanner: AST/types analysis extracts functions, signatures, and test examples
- Generator: Template-based generation of 76 functions × 8 variants = 608 functions
- Model: Structured representation bridging scanner and generator
Key improvements:
- Example-driven test generation from godoc "Examples:" sections
- Achieves ~100% coverage in generated packages (99.5% - 0.5% gap from helpers)
- Modern Go 1.23 iterator-based table-driven tests throughout
- Domain-organized source (boolean, collection, compare, equal, error, etc.)
- Function type detection for proper generation of type/var function signatures
- Comprehensive documentation (MAINTAINERS.md, CLAUDE.md)
- Codegen smoke tests (24.4% coverage)
Generated packages:
- assert/require: assertions, format variants, forward methods
- All with corresponding tests and runnable examples
- Helper types and interfaces
This replaces the previous semi-hand-written/semi-generated approach where adding a single
assertion required manually updating 6+ files that already had thousands of lines.
Now: write once in internal/assertions/ in small focused source files, run go generate, done.
Trade-off: the existing code generator has been rewritten entirely.
The new one is more complex, but also more readable.
This added (mostly stable) complexity should be outweighted by the
simplification of the assertion development workflow.
Signed-off-by: Frederic BIDON <[email protected]>
ci: enforced Windows TMP to reside on the same drive
Signed-off-by: Frederic BIDON <[email protected]>
The code generator looks for functions with signature `func(TestingT, ...) bool` in the assert package and creates corresponding variants.
186
+
From this, it generates tests that verify:
187
+
- Success case works correctly
188
+
- Failure case works correctly and calls appropriate failure methods
189
+
- Format variants work with message parameter
190
+
- Forward methods work with chaining
191
+
192
+
**Test case types:**
193
+
-`success: <args>` - Test should pass
194
+
-`failure: <args>` - Test should fail
195
+
-`panic: <args>` - Test should panic (followed by assertion message on next line)
196
+
`<expected panic message>`
64
197
65
198
### Build and Verify
66
199
```bash
67
200
# Tidy dependencies
68
201
go mod tidy
69
202
70
203
# Build code generator
71
-
cd_codegen&& go build
204
+
cdcodegen&& go build
72
205
73
206
# Format code
74
207
go fmt ./...
208
+
209
+
# Run all tests
210
+
go test ./...
211
+
212
+
# Check coverage
213
+
go test -cover ./internal/assertions
214
+
go test -cover ./assert
215
+
go test -cover ./require
75
216
```
76
217
77
218
## Important Constraints
@@ -106,3 +247,89 @@ When using YAML assertions (YAMLEq, YAMLEqf):
106
247
## Testing Philosophy
107
248
108
249
Keep tests simple and focused. The assert package provides detailed failure messages automatically, so test code should be minimal and readable. Use `require` when a test cannot continue meaningfully after a failure, and `assert` when subsequent checks might provide additional context.
250
+
251
+
### Testing Strategy: Layered Coverage
252
+
253
+
**Layer 1: Exhaustive Tests in `internal/assertions/`** (94% coverage)
254
+
- Comprehensive table-driven tests using Go 1.23 `iter.Seq` patterns
255
+
- Error message content and format validation
256
+
- Edge cases, nil handling, type coercion scenarios
257
+
- Domain-organized test files mirroring implementation
258
+
- Source of truth for assertion correctness
259
+
260
+
**Layer 2: Generated Smoke Tests in `assert/` and `require/`** (~100% coverage)
261
+
- Minimal mechanical tests proving functions exist and work
262
+
- Success case: verify correct return value / no FailNow
263
+
- Failure case: verify correct return value / FailNow called
264
+
- Generated from "Examples:" in doc comments
265
+
- No error message testing (already covered in Layer 1)
266
+
267
+
**Layer 3: Meta Tests for Generator** (future)
268
+
- Test that code generation produces correct output
269
+
- Verify function signatures, imports, structure
270
+
- Optional golden file testing
271
+
272
+
This layered approach ensures:
273
+
- Deep testing where it matters (source implementation)
274
+
- Complete coverage of generated forwarding code
275
+
- Simple, maintainable test generation
276
+
- No duplication of complex test logic
277
+
278
+
## Architecture Benefits
279
+
280
+
### Why This Design Wins
281
+
282
+
**For Contributors:**
283
+
- Add assertion in focused, domain-organized file
284
+
- Write tests once in single location
285
+
- Run `go generate` and get all variants for free
286
+
- Clear separation: source vs generated code
287
+
288
+
**For Maintainers:**
289
+
- Mechanical consistency across 608 generated functions
290
+
- Template changes affect all functions uniformly
291
+
- Easy to add new variants (e.g., generics)
292
+
- Single source of truth prevents drift
293
+
294
+
**For Users:**
295
+
- Comprehensive API with 76 assertions
296
+
- All expected variants (package, format, forward, require)
0 commit comments