- i hate searching for the right commit hash and manually calling zig fetch --save git+...#aEfowkjdfwfd..
- this lib called
update_tool
gets the hash from your specified branch and runs zig fetch --save
- with
addTestFolder
all zig files in the specified folder get added as test steps
- in build.zig.zon you add:
.dependencies = .{
// zig 0.15.1
.update_tool = .{
.url = "git+https://github.com/nat3Github/zig-lib-update#a0ef597d694e1d5f9752841cbf737095bb9c4cf9",
.hash = "update_tool-1.0.0-MwAI-VgaAAB2y3AVVByTm1A6kQhyGB-QzWhGObaJhaKY",
},
// ...
},
- in build.zig you define your dependencies:
const update = @import("update_tool");
const deps: []const update.GitDependency = &.{
.{
// if you leave this the update_tool will update itself
.url = "https://github.com/nat3Github/zig-lib-update",
.branch = "main",
},
.{
// update osmr
.url = "https://github.com/nat3Github/zig-lib-osmr",
.branch = "zig",
},
// add more dependencies here
};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
if (update.updateDependencies(b, deps)) return;
- run
zig build -Dupdate
to invoke the update tool
- in build.zig you define your test folder:
const update = @import("update_tool");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
...
try update.addTestFolder(
b,
// this is the folder path (from build root)
"tests",
optimize,
target,
// add modules that are used in the tests
&.{
.{ .name = "my-module", .mod = my_module_i_want_to_test },
},
// this is the prefix- for the tests
"testprefix",
);
add a new file (first-test.zig) to the test folder
run `zig build testprefix-first-test.zig` to run the tests in first-test.zig
or run `zig build testprefix-all` to run all tests of that folder
this is Public Domain feel free to use it!
- it gets slow with a lot of dependencies
- this is due to zig fetch --save being slow
- i hope this gets improved on in future zig versions