also looking at this
feat: load strict JSON configuration files
#19
10 files
+249
-286
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -258,12 +258,10 @@ This document provides a comprehensive overview of all implemented features in t | ||
| 258 | 258 | - **Status:** Production Ready |
| 259 | 259 | - **Module:** `src/config.zig` |
| 260 | 260 | - **Features:** |
| 261 | - YAML configuration support | |
| 262 | - JSON configuration support | |
| 263 | - TOML configuration support | |
| 264 | - Configuration validation | |
| 261 | - Strict JSON configuration support | |
| 262 | - Unknown-key, type, and runtime-value validation | |
| 263 | - CLI-over-config precedence | |
| 265 | 264 | - Default configuration |
| 266 | - Environment-specific configs | |
| 267 | 265 | |
| 268 | 266 | ### 16. Test History ✅ |
| 269 | 267 | |
| @@ -24,7 +24,7 @@ A modern, feature-rich testing framework for Zig inspired by Jest, Vitest, and B | ||
| 24 | 24 | - **Watch Mode** - Automatically re-run tests on file changes |
| 25 | 25 | - **Memory Profiling** - Track memory usage and detect leaks |
| 26 | 26 | - **Parallel Execution** - Run tests in parallel for faster execution |
| 27 | - **Configuration Files** - YAML/JSON/TOML config file support | |
| 27 | - **Configuration Files** - Strict JSON config files with CLI overrides | |
| 28 | 28 | |
| 29 | 29 | ## Installation |
| 30 | 30 | |
| @@ -100,8 +100,8 @@ This will automatically discover and run all `*.test.zig` files in the `tests` d | ||
| 100 | 100 | |
| 101 | 101 | Discovery mode rejects options that it cannot honor yet instead of silently |
| 102 | 102 | ignoring them. Reporter selection, quiet output, timeouts, parallel jobs, |
| 103 | snapshot updates, memory profiling, configuration files, JUnit output, and the | |
| 104 | web UI require the shared execution pipeline planned for future releases. | |
| 103 | snapshot updates, memory profiling, JUnit output, and the web UI require the | |
| 104 | shared execution pipeline planned for future releases. | |
| 105 | 105 | |
| 106 | 106 | **Examples:** |
| 107 | 107 | |
| @@ -119,6 +119,33 @@ zig-test --test-dir tests --no-recursive | ||
| 119 | 119 | zig-test --test-dir tests --bail |
| 120 | 120 | ``` |
| 121 | 121 | |
| 122 | ### Configuration files | |
| 123 | ||
| 124 | `--config <file>` loads a strict JSON configuration before test discovery. | |
| 125 | Unknown keys, duplicate keys, wrong value types, unsupported extensions, and | |
| 126 | invalid runtime values fail with a configuration error. TOML and YAML are not | |
| 127 | currently supported. Explicit CLI options are parsed after the file and take | |
| 128 | precedence over configured values. | |
| 129 | ||
| 130 | ```json | |
| 131 | { | |
| 132 | "test": { | |
| 133 | "test_dir": "tests", | |
| 134 | "pattern": "*.test.zig", | |
| 135 | "recursive": true, | |
| 136 | "filter": "database" | |
| 137 | }, | |
| 138 | "coverage": { | |
| 139 | "enabled": false, | |
| 140 | "output_dir": "coverage" | |
| 141 | } | |
| 142 | } | |
| 143 | ``` | |
| 144 | ||
| 145 | The accepted top-level sections are `test`, `parallel`, `reporter`, `snapshot`, | |
| 146 | `watch`, `memory`, `ui`, and `coverage`. Options retain the same execution-mode | |
| 147 | limitations as their CLI equivalents; unsupported combinations fail explicitly. | |
| 148 | ||
| 122 | 149 | ### Programmatic Mode |
| 123 | 150 | |
| 124 | 151 | For more control, you can manually register tests: |
| @@ -824,7 +851,7 @@ MIT License - see [LICENSE](LICENSE) for details. | ||
| 824 | 851 | - [x] Watch mode for file changes |
| 825 | 852 | - [x] TAP/JUnit reporters |
| 826 | 853 | - [x] Memory profiling |
| 827 | - [x] Configuration files (YAML/JSON/TOML) | |
| 854 | - [x] Strict JSON configuration files | |
| 828 | 855 | - [x] Parallel test execution |
| 829 | 856 | - [ ] Parameterized tests (it.each) |
| 830 | 857 | - [ ] Property-based testing |
| @@ -242,6 +242,22 @@ pub fn build(b: *std.Build) void { | ||
| 242 | 242 | test_step.dependOn(&run_snapshot_usage_tests.step); |
| 243 | 243 | test_step.dependOn(&run_time_tests.step); |
| 244 | 244 | |
| 245 | // Exercise configuration through the real CLI. The second invocation | |
| 246 | // proves that an explicit CLI filter overrides the configured filter. | |
| 247 | const run_config_fixture = b.addRunArtifact(exe); | |
| 248 | run_config_fixture.addArgs(&.{ "--config", "tests/fixtures/zig-test.json" }); | |
| 249 | test_step.dependOn(&run_config_fixture.step); | |
| 250 | ||
| 251 | const run_config_override = b.addRunArtifact(exe); | |
| 252 | run_config_override.addArgs(&.{ "--config", "tests/fixtures/zig-test.json", "--filter", "unselected test fails" }); | |
| 253 | run_config_override.expectExitCode(1); | |
| 254 | test_step.dependOn(&run_config_override.step); | |
| 255 | ||
| 256 | const run_invalid_config = b.addRunArtifact(exe); | |
| 257 | run_invalid_config.addArgs(&.{ "--config", "tests/fixtures/invalid-zig-test.json" }); | |
| 258 | run_invalid_config.expectExitCode(2); | |
| 259 | test_step.dependOn(&run_invalid_config.step); | |
| 260 | ||
| 245 | 261 | // Examples |
| 246 | 262 | const basic_example = b.addExecutable(.{ |
| 247 | 263 | .name = "basic_example", |