master
 1const std = @import("std");
 2const builtin = @import("builtin");
 3
 4pub fn build(b: *std.Build) void {
 5    const test_step = b.step("test", "Test it");
 6    b.default_step = test_step;
 7
 8    const optimize: std.builtin.OptimizeMode = .Debug;
 9    const target = b.graph.host;
10
11    if (builtin.os.tag == .windows) {
12        // https://github.com/ziglang/zig/issues/12419
13        return;
14    }
15
16    const exe = b.addExecutable(.{
17        .name = "zigtest",
18        .root_module = b.createModule(.{
19            .root_source_file = b.path("main.zig"),
20            .target = target,
21            .optimize = optimize,
22        }),
23    });
24    b.installArtifact(exe);
25
26    const c_sources = [_][]const u8{
27        "test.c",
28    };
29
30    exe.root_module.addCSourceFiles(.{ .files = &c_sources });
31    exe.root_module.link_libc = true;
32
33    var i: i32 = 0;
34    while (i < 1000) : (i += 1) {
35        exe.root_module.addCMacro("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
36    }
37
38    exe.root_module.addCMacro("FOO", "42");
39    exe.root_module.addCMacro("BAR", "\"BAR\"");
40    exe.root_module.addCMacro("BAZ",
41        \\"\"BAZ\""
42    );
43    exe.root_module.addCMacro("QUX", "\"Q\" \"UX\"");
44    exe.root_module.addCMacro("QUUX", "\"QU\\\"UX\"");
45
46    b.default_step.dependOn(&exe.step);
47
48    const run_cmd = b.addRunArtifact(exe);
49    run_cmd.skip_foreign_checks = true;
50    run_cmd.expectExitCode(0);
51
52    test_step.dependOn(&run_cmd.step);
53}