deblasis/zioprop

GitHub: deblasis/zioprop

面向 Zig 语言的基于属性的测试库,通过随机输入生成和边界用例自动发现代码缺陷。

Stars: 0 | Forks: 0

# zioprop 面向 Zig 的基于属性的测试。从类型生成随机值,运行任意次数的迭代。 ## 卖点 通过随机输入发现 bug,而不是使用手工挑选的示例。 ``` const zioprop = @import("zioprop"); // Test a property with random inputs try zioprop.forAll1(u32, struct { fn check(x: u32) bool { return x + 0 == x; } }.check, .{ .iterations = 1000 }); // Test with two random inputs try zioprop.forAll2(u8, u8, struct { fn check(a: u8, b: u8) bool { return @as(u16, a) + @as(u16, b) == @as(u16, b) + @as(u16, a); } }.check, .{ .iterations = 1000 }); // Generate random values var prng = std.Random.DefaultPrng.init(42); const val = zioprop.randomValue(i32, prng.random()); ``` ## 安装 ``` zig fetch --save git+https://github.com/deblasis/zioprop ``` 然后在你的 `build.zig` 中: ``` const dep = b.dependency("zioprop", .{ .target = target, .optimize = optimize, }); exe.root_module.addImport("zioprop", dep.module("zioprop")); ``` 需要 Zig 0.16。 ## API - `forAll1(T, property, config)` / `forAll2(T1, T2, property, config)` - 属性检查 - `randomValue(T, rng)` - 生成一个随机值(bool、固定宽度整数 u8..u64 和 i8..i64、f32、f64) - `Config{ .iterations, .seed }` ## 兼容性 - **Zig**: 0.16.0 - **平台**: Linux, macOS, Windows - **破坏性变更**: 遵循[语义化版本](https://semver.org/spec/v2.0.0.html)。次版本号添加功能,修订号修复 bug。 ## 许可证 MIT。版权所有 (c) 2026 Alessandro De Blasis。
标签:SOC Prime, Zig, 属性测试, 开发工具, 测试框架, 随机测试