102 lines
2.3 KiB
Markdown
102 lines
2.3 KiB
Markdown
# Mock Flag Update
|
|
|
|
## Summary
|
|
|
|
Updated the `--mocks` flag to accept an explicit output path, improving usability and integration with build systems.
|
|
|
|
## Changes Made
|
|
|
|
### 1. Flag Syntax Change
|
|
**Before:**
|
|
```bash
|
|
zig build run -- header.h --output=bindings.zig --mocks
|
|
# Automatically created: header_mock.c
|
|
```
|
|
|
|
**After:**
|
|
```bash
|
|
zig build run -- header.h --output=bindings.zig --mocks=mocks.c
|
|
# Explicitly creates: mocks.c
|
|
```
|
|
|
|
### 2. Benefits
|
|
- **Explicit control**: Users specify exactly where mock file goes
|
|
- **Build system friendly**: Easy to integrate with Zig build system
|
|
- **Cleaner**: No automatic filename generation logic
|
|
- **Flexible**: Can output mocks anywhere in the project structure
|
|
|
|
### 3. Build Target Added
|
|
New `test-mocks` target for quick testing:
|
|
```bash
|
|
zig build test-mocks
|
|
# Generates: zig-out/test_small.zig and zig-out/test_small_mock.c
|
|
```
|
|
|
|
### 4. Files Modified
|
|
|
|
**build.zig**:
|
|
- Added `test-mocks` build step
|
|
- Outputs to `zig-out/` directory by default
|
|
- Uses absolute paths for consistency
|
|
|
|
**parser.zig**:
|
|
- Changed from `--mocks` (boolean flag) to `--mocks=<path>` (value flag)
|
|
- Removed automatic filename generation
|
|
- Updated usage documentation
|
|
|
|
**docs/usage.md**:
|
|
- Updated with new flag syntax
|
|
- Added command line options reference
|
|
- Added `test-mocks` target documentation
|
|
|
|
**PHASE1_COMPLETE.md**:
|
|
- Updated examples with new syntax
|
|
- Documented build system integration
|
|
|
|
## Examples
|
|
|
|
### Simple test:
|
|
```bash
|
|
zig build test-mocks
|
|
```
|
|
|
|
### Custom paths:
|
|
```bash
|
|
zig build run -- SDL_gpu.h --output=gen/bindings.zig --mocks=gen/mocks.c
|
|
```
|
|
|
|
### Just bindings (no mocks):
|
|
```bash
|
|
zig build run -- header.h --output=bindings.zig
|
|
```
|
|
|
|
## Backward Compatibility
|
|
|
|
**Breaking change**: The old `--mocks` flag (without a value) no longer works.
|
|
|
|
**Migration**:
|
|
```bash
|
|
# Old (no longer works)
|
|
zig build run -- header.h --output=out.zig --mocks
|
|
|
|
# New (required)
|
|
zig build run -- header.h --output=out.zig --mocks=header_mock.c
|
|
```
|
|
|
|
## Testing
|
|
|
|
All existing tests pass:
|
|
- ✅ 7 mock generation unit tests
|
|
- ✅ Parser tests
|
|
- ✅ Integration with test_small.h
|
|
- ✅ Integration with SDL_gpu.h (169 declarations)
|
|
- ✅ New `test-mocks` build target
|
|
|
|
## Implementation Time
|
|
|
|
- **Estimated**: 30 minutes
|
|
- **Actual**: 25 minutes
|
|
- Flag update: 10 minutes
|
|
- Build target: 10 minutes
|
|
- Documentation: 5 minutes
|