85 lines
3.2 KiB
Zig
85 lines
3.2 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
const exe = b.addExecutable(.{
|
|
.name = "have",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("have.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
}),
|
|
});
|
|
b.installArtifact(exe);
|
|
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
if (b.args) |args| run_cmd.addArgs(args);
|
|
b.step("run", "Run have").dependOn(&run_cmd.step);
|
|
|
|
const tests = b.addTest(.{
|
|
.root_module = exe.root_module,
|
|
});
|
|
const run_tests = b.addRunArtifact(tests);
|
|
|
|
const smoke = b.addSystemCommand(&.{ "sh", "smoke.sh", b.getInstallPath(.bin, "have") });
|
|
smoke.setCwd(b.path("."));
|
|
smoke.step.dependOn(b.getInstallStep());
|
|
|
|
const contract = b.addSystemCommand(&.{ "sh", "-c",
|
|
\\set -eu
|
|
\\tool=$1
|
|
\\root=.zig-cache/have-contract
|
|
\\rm -rf "$root"
|
|
\\mkdir -p "$root/a" "$root/b" "$root/dup-a" "$root/dup-b" "$root/filter"
|
|
\\cat > "$root/a/alpha" <<'SCRIPT'
|
|
\\#!/bin/sh
|
|
\\echo ran >> .zig-cache/have-contract/ran
|
|
\\SCRIPT
|
|
\\cat > "$root/b/beta" <<'SCRIPT'
|
|
\\#!/bin/sh
|
|
\\echo ran >> .zig-cache/have-contract/ran
|
|
\\SCRIPT
|
|
\\cat > "$root/dup-a/dup" <<'SCRIPT'
|
|
\\#!/bin/sh
|
|
\\echo ran >> .zig-cache/have-contract/ran
|
|
\\SCRIPT
|
|
\\cat > "$root/dup-b/dup" <<'SCRIPT'
|
|
\\#!/bin/sh
|
|
\\echo ran >> .zig-cache/have-contract/ran
|
|
\\SCRIPT
|
|
\\chmod +x "$root/a/alpha" "$root/b/beta" "$root/dup-a/dup" "$root/dup-b/dup"
|
|
\\printf nope > "$root/filter/not-exec"
|
|
\\mkdir "$root/filter/exec-dir"
|
|
\\chmod +x "$root/filter/exec-dir"
|
|
\\ln -s exec-dir "$root/filter/dir-link"
|
|
\\PATH="$root/a:$root/b" "$tool" > "$root/list.out"
|
|
\\test "$(sed -n '1p' "$root/list.out")" = alpha
|
|
\\test "$(sed -n '2p' "$root/list.out")" = beta
|
|
\\test ! -e "$root/ran"
|
|
\\PATH="$root/dup-a:$root/dup-b" "$tool" > "$root/dup.out"
|
|
\\test "$(grep -c '^dup$' "$root/dup.out")" = 1
|
|
\\PATH="$root/filter" "$tool" > "$root/filter.out"
|
|
\\! grep -q '^not-exec$' "$root/filter.out"
|
|
\\! grep -q '^exec-dir$' "$root/filter.out"
|
|
\\! grep -q '^dir-link$' "$root/filter.out"
|
|
\\PATH="$root/a" "$tool" alpha > "$root/query.out"
|
|
\\grep -q '^alpha$' "$root/query.out"
|
|
\\test ! -e "$root/ran"
|
|
\\PATH="$root/a" "$tool" ./alpha > "$root/slash.out" && exit 1 || true
|
|
\\test ! -s "$root/slash.out"
|
|
\\"$tool" --help > "$root/help.out" 2> "$root/help.err"
|
|
\\grep -q '^usage:' "$root/help.out"
|
|
\\test ! -s "$root/help.err"
|
|
, "have-contract", b.getInstallPath(.bin, "have") });
|
|
contract.setCwd(b.path("."));
|
|
contract.step.dependOn(b.getInstallStep());
|
|
|
|
const test_step = b.step("test", "Run unit and smoke tests");
|
|
test_step.dependOn(&run_tests.step);
|
|
test_step.dependOn(&smoke.step);
|
|
test_step.dependOn(&contract.step);
|
|
}
|