Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ibokuri/protest
A set of modules for easy testing in Zig
https://github.com/ibokuri/protest
assert assertions require testing zig ziglang
Last synced: about 2 months ago
JSON representation
A set of modules for easy testing in Zig
- Host: GitHub
- URL: https://github.com/ibokuri/protest
- Owner: ibokuri
- License: mit
- Created: 2023-11-19T05:11:52.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-12T14:05:23.000Z (7 months ago)
- Last Synced: 2024-06-12T19:59:30.993Z (7 months ago)
- Topics: assert, assertions, require, testing, zig, ziglang
- Language: Zig
- Homepage: https://ibokuri.github.io/protest/
- Size: 24.4 MB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Protest
Protest is a set of modules for testing and validating Zig code. A
[testify](https://github.com/stretchr/testify) for Zig, if you will, cause testify's awesome!## [`require`](https://ibokuri.github.io/protest/#A;protest:require) Module
The `require` module some provides helpful functions to help you write tests.
- Descriptive and easy to read failure descriptions.
- Simplified testing code.
- Requirements can be annotated with a custom message.```zig
const require = @import("protest").require;test {
// Require equality.
try require.equalf(123, 123, "They should be {s}", .{"equal"});// Require inequality.
try require.notEqualf(123, 456, "They should not be {s}", .{"equal"});// Require that `value` is not null.
try require.notNull(value);// Since `value` cannot be null, safely unwrap it and check its payload.
try require.equal("Foobar", value.?);
}
``````
run test: error: 'test_0' failed:Error: Not equal:
expected: "Foobar"
actual: "Barfoo"
Error Trace:/tmp/example/src/main.zig:14:5: 0x1048a5027 in test_0 (test)
try require.equal("Foobar", value.?);
^
```## Installation
1. Declare Protest as a dependency in `build.zig.zon`:
```diff
.{
.name = "my-project",
.version = "1.0.0",
.paths = .{""},
.dependencies = .{
+ .protest = .{
+ .url = "https://github.com/ibokuri/protest/archive/.tar.gz",
+ },
},
}
```2. Add Protest as a module in `build.zig`:
```diff
const std = @import("std");pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});+ const opts = .{ .target = target, .optimize = optimize };
+ const protest_mod = b.dependency("protest", opts).module("protest");const tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});+ tests.addModule("protest", protest_mod);
...
}
```3. Obtain Protest's package hash:
```
$ zig build --fetch
my-project/build.zig.zon:7:20: error: url field is missing corresponding hash field
.url = "https://github.com/ibokuri/protest/archive/.tar.gz",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: expected .hash = "",
```4. Update `build.zig.zon` with Protest's package hash:
```diff
.{
.name = "my-project",
.version = "1.0.0",
.paths = .{""},
.dependencies = .{
.protest = .{
.url = "https://github.com/ibokuri/protest/archive/.tar.gz",
+ .hash = "",
},
},
}
```