aboutsummaryrefslogtreecommitdiff
path: root/test/tests.zig
diff options
context:
space:
mode:
authorxavier <xavierb@gmail.com>2021-05-03 08:48:14 +0200
committerxavier <xavierb@gmail.com>2021-05-25 00:19:23 +0200
commit7e4f28fac9a20fb548c85cf81f4a62b069cf4ac8 (patch)
tree96a444a5b8f212a9ab2bf054ee5ddbb4e8b0d49c /test/tests.zig
parent8c5d4295e5f6459ba99d219c1922a30ec6da24bf (diff)
downloadzig-7e4f28fac9a20fb548c85cf81f4a62b069cf4ac8.tar.gz
zig-7e4f28fac9a20fb548c85cf81f4a62b069cf4ac8.zip
standalone tests may now test cross targets and build modes.
Diffstat (limited to 'test/tests.zig')
-rw-r--r--test/tests.zig36
1 files changed, 29 insertions, 7 deletions
diff --git a/test/tests.zig b/test/tests.zig
index 243428a537..63b851e90b 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -399,7 +399,7 @@ pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8, modes:
return cases.step;
}
-pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
+pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode, skip_non_native: bool, target: std.zig.CrossTarget) *build.Step {
const cases = b.allocator.create(StandaloneContext) catch unreachable;
cases.* = StandaloneContext{
.b = b,
@@ -407,6 +407,8 @@ pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: []
.test_index = 0,
.test_filter = test_filter,
.modes = modes,
+ .skip_non_native = skip_non_native,
+ .target = target,
};
standalone.addCases(cases);
@@ -1136,6 +1138,8 @@ pub const StandaloneContext = struct {
test_index: usize,
test_filter: ?[]const u8,
modes: []const Mode,
+ skip_non_native: bool,
+ target: std.zig.CrossTarget,
pub fn addC(self: *StandaloneContext, root_src: []const u8) void {
self.addAllArgs(root_src, true);
@@ -1145,10 +1149,10 @@ pub const StandaloneContext = struct {
self.addAllArgs(root_src, false);
}
- pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8) void {
+ pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8, features: struct { build_modes: bool = false, cross_targets: bool = false }) void {
const b = self.b;
- const annotated_case_name = b.fmt("build {s} (Debug)", .{build_file});
+ const annotated_case_name = b.fmt("build {s}", .{build_file});
if (self.test_filter) |filter| {
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
}
@@ -1167,12 +1171,30 @@ pub const StandaloneContext = struct {
zig_args.append("--verbose") catch unreachable;
}
- const run_cmd = b.addSystemCommand(zig_args.items);
+ if (features.cross_targets and !self.target.isNative()) {
+ const target_arg = fmt.allocPrint(b.allocator, "-Dtarget={s}", .{self.target.zigTriple(b.allocator) catch unreachable}) catch unreachable;
+ zig_args.append(target_arg) catch unreachable;
+ }
+
+ const modes = if (features.build_modes) self.modes else &[1]Mode{.Debug};
+ for (modes) |mode| {
+ const arg = switch (mode) {
+ .Debug => "",
+ .ReleaseFast => "-Drelease-fast",
+ .ReleaseSafe => "-Drelease-safe",
+ .ReleaseSmall => "-Drelease-small",
+ };
+ const zig_args_base_len = zig_args.items.len;
+ if (arg.len > 0)
+ zig_args.append(arg) catch unreachable;
+ defer zig_args.resize(zig_args_base_len) catch unreachable;
- const log_step = b.addLog("PASS {s}\n", .{annotated_case_name});
- log_step.step.dependOn(&run_cmd.step);
+ const run_cmd = b.addSystemCommand(zig_args.items);
+ const log_step = b.addLog("PASS {s} ({s})\n", .{ annotated_case_name, @tagName(mode) });
+ log_step.step.dependOn(&run_cmd.step);
- self.step.dependOn(&log_step.step);
+ self.step.dependOn(&log_step.step);
+ }
}
pub fn addAllArgs(self: *StandaloneContext, root_src: []const u8, link_libc: bool) void {