Im on zig 0.14. I’m trying to use the builtin fuzz testing.
When i run zig build test --fuzz
in the default project set up from zig init
, it runs fine. I tried copying the same test over into my main.zig
, but zig build test --fuzz
gives me error: no fuzz tests found
.
const std = @import("std");
const Parser = @import("Parser.zig");
const html = @import("html.zig");
pub fn main() !void {
// ....
}
test "fuzz example" {
const Context = struct {
fn testOne(context: @This(), input: []const u8) anyerror!void {
_ = context;
// Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case!
try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input));
}
};
try std.testing.fuzz(Context{}, Context.testOne, .{});
}
Maybe it has to do with my build.zig
?
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const mod = b.addModule("md", .{
.root_source_file = b.path("src/md.zig"),
.target = target,
.optimize = optimize,
});
const unit_tests = b.addTest(.{
.root_module = mod,
});
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "md", .module = mod },
},
});
const exe_unit_tests = b.addTest(.{
.root_module = exe_mod,
});
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&unit_tests.step);
test_step.dependOn(&exe_unit_tests.step);
const exe = b.addExecutable(.{
.name = "md",
.root_module = exe_mod,
});
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| run_cmd.addArgs(args);
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const check_exe = b.addExecutable(.{
.name = "md-check",
.root_module = exe_mod,
});
const check_step = b.step("check", "Check for compile errors");
check_step.dependOn(&check_exe.step);
}
I tried deleting both the local and global zig caches.
I’m at a loss.