aboutsummaryrefslogtreecommitdiff
path: root/test/tests.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-03-08 22:53:35 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-03-08 23:23:11 -0500
commit91955dee587214722daa09e6f3dbff059ac3752e (patch)
tree7f56bf31f93081c63a4bcf03b9e38b7c5b1ca29c /test/tests.zig
parent1e634a384ccc0ae57e0343369f7adb0b1b4b9875 (diff)
downloadzig-91955dee587214722daa09e6f3dbff059ac3752e.tar.gz
zig-91955dee587214722daa09e6f3dbff059ac3752e.zip
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function to call, unless setOutputDir() was used, or within a custom make() function. Instead there is more convenient API to use which takes advantage of the caching system. Search this commit diff for `exe.run()` for an example. * Zig build by default enables caching. All build artifacts will go into zig-cache. If you want to access build artifacts in a convenient location, it is recommended to add an `install` step. Otherwise you can use the `run()` API mentioned above to execute programs directly from their location in the cache. Closes #330. `addSystemCommand` is available for programs not built with Zig build. * Please note that Zig does no cache evicting yet. You may have to manually delete zig-cache directories periodically to keep disk usage down. It's planned for this to be a simple Least Recently Used eviction system eventually. * `--output`, `--output-lib`, and `--output-h` are removed. Instead, use `--output-dir` which defaults to the current working directory. Or take advantage of `--cache on`, which will print the main output path to stdout, and the other artifacts will be in the same directory with predictable file names. `--disable-gen-h` is available when one wants to prevent .h file generation. * `@cImport` is always independently cached now. Closes #2015. It always writes the generated Zig code to disk which makes debug info and compile errors better. No more "TODO: remember C source location to display here" * Fix .d file parsing. (Fixes the MacOS CI failure) * Zig no longer creates "temporary files" other than inside a zig-cache directory. This breaks the CLI API that Godbolt uses. The suggested new invocation can be found in this commit diff, in the changes to `test/cli.zig`.
Diffstat (limited to 'test/tests.zig')
-rw-r--r--test/tests.zig82
1 files changed, 49 insertions, 33 deletions
diff --git a/test/tests.zig b/test/tests.zig
index d3a27f3e94..ba713902ba 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -12,6 +12,7 @@ const fmt = std.fmt;
const ArrayList = std.ArrayList;
const builtin = @import("builtin");
const Mode = builtin.Mode;
+const LibExeObjStep = build.LibExeObjStep;
const compare_output = @import("compare_output.zig");
const build_examples = @import("build_examples.zig");
@@ -111,12 +112,11 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M
const step = b.step("test-cli", "Test the command line interface");
const exe = b.addExecutable("test-cli", "test/cli.zig");
- const run_cmd = b.addCommand(null, b.env_map, [][]const u8{
- b.pathFromRoot(exe.getOutputPath()),
+ const run_cmd = exe.run();
+ run_cmd.addArgs([][]const u8{
os.path.realAlloc(b.allocator, b.zig_exe) catch unreachable,
b.pathFromRoot(b.cache_root),
});
- run_cmd.step.dependOn(&exe.step);
step.dependOn(&run_cmd.step);
return step;
@@ -246,24 +246,31 @@ pub const CompareOutputContext = struct {
const RunCompareOutputStep = struct {
step: build.Step,
context: *CompareOutputContext,
- exe_path: []const u8,
+ exe: *LibExeObjStep,
name: []const u8,
expected_output: []const u8,
test_index: usize,
cli_args: []const []const u8,
- pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8, expected_output: []const u8, cli_args: []const []const u8) *RunCompareOutputStep {
+ pub fn create(
+ context: *CompareOutputContext,
+ exe: *LibExeObjStep,
+ name: []const u8,
+ expected_output: []const u8,
+ cli_args: []const []const u8,
+ ) *RunCompareOutputStep {
const allocator = context.b.allocator;
const ptr = allocator.create(RunCompareOutputStep) catch unreachable;
ptr.* = RunCompareOutputStep{
.context = context,
- .exe_path = exe_path,
+ .exe = exe,
.name = name,
.expected_output = expected_output,
.test_index = context.test_index,
.step = build.Step.init("RunCompareOutput", allocator, make),
.cli_args = cli_args,
};
+ ptr.step.dependOn(&exe.step);
context.test_index += 1;
return ptr;
}
@@ -272,7 +279,7 @@ pub const CompareOutputContext = struct {
const self = @fieldParentPtr(RunCompareOutputStep, "step", step);
const b = self.context.b;
- const full_exe_path = b.pathFromRoot(self.exe_path);
+ const full_exe_path = self.exe.getOutputPath();
var args = ArrayList([]const u8).init(b.allocator);
defer args.deinit();
@@ -336,21 +343,21 @@ pub const CompareOutputContext = struct {
const RuntimeSafetyRunStep = struct {
step: build.Step,
context: *CompareOutputContext,
- exe_path: []const u8,
+ exe: *LibExeObjStep,
name: []const u8,
test_index: usize,
- pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8) *RuntimeSafetyRunStep {
+ pub fn create(context: *CompareOutputContext, exe: *LibExeObjStep, name: []const u8) *RuntimeSafetyRunStep {
const allocator = context.b.allocator;
const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable;
ptr.* = RuntimeSafetyRunStep{
.context = context,
- .exe_path = exe_path,
+ .exe = exe,
.name = name,
.test_index = context.test_index,
.step = build.Step.init("RuntimeSafetyRun", allocator, make),
};
-
+ ptr.step.dependOn(&exe.step);
context.test_index += 1;
return ptr;
}
@@ -359,11 +366,11 @@ pub const CompareOutputContext = struct {
const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step);
const b = self.context.b;
- const full_exe_path = b.pathFromRoot(self.exe_path);
+ const full_exe_path = self.exe.getOutputPath();
warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
- const child = os.ChildProcess.init([][]u8{full_exe_path}, b.allocator) catch unreachable;
+ const child = os.ChildProcess.init([][]const u8{full_exe_path}, b.allocator) catch unreachable;
defer child.deinit();
child.env_map = b.env_map;
@@ -463,8 +470,13 @@ pub const CompareOutputContext = struct {
exe.step.dependOn(&write_src.step);
}
- const run_and_cmp_output = RunCompareOutputStep.create(self, exe.getOutputPath(), annotated_case_name, case.expected_output, case.cli_args);
- run_and_cmp_output.step.dependOn(&exe.step);
+ const run_and_cmp_output = RunCompareOutputStep.create(
+ self,
+ exe,
+ annotated_case_name,
+ case.expected_output,
+ case.cli_args,
+ );
self.step.dependOn(&run_and_cmp_output.step);
},
@@ -490,8 +502,13 @@ pub const CompareOutputContext = struct {
exe.step.dependOn(&write_src.step);
}
- const run_and_cmp_output = RunCompareOutputStep.create(self, exe.getOutputPath(), annotated_case_name, case.expected_output, case.cli_args);
- run_and_cmp_output.step.dependOn(&exe.step);
+ const run_and_cmp_output = RunCompareOutputStep.create(
+ self,
+ exe,
+ annotated_case_name,
+ case.expected_output,
+ case.cli_args,
+ );
self.step.dependOn(&run_and_cmp_output.step);
}
@@ -516,8 +533,7 @@ pub const CompareOutputContext = struct {
exe.step.dependOn(&write_src.step);
}
- const run_and_cmp_output = RuntimeSafetyRunStep.create(self, exe.getOutputPath(), annotated_case_name);
- run_and_cmp_output.step.dependOn(&exe.step);
+ const run_and_cmp_output = RuntimeSafetyRunStep.create(self, exe, annotated_case_name);
self.step.dependOn(&run_and_cmp_output.step);
},
@@ -608,10 +624,6 @@ pub const CompileErrorContext = struct {
b.allocator,
[][]const u8{ b.cache_root, self.case.sources.items[0].filename },
) catch unreachable;
- const obj_path = os.path.join(
- b.allocator,
- [][]const u8{ b.cache_root, "test.o" },
- ) catch unreachable;
var zig_args = ArrayList([]const u8).init(b.allocator);
zig_args.append(b.zig_exe) catch unreachable;
@@ -628,8 +640,8 @@ pub const CompileErrorContext = struct {
zig_args.append("--name") catch unreachable;
zig_args.append("test") catch unreachable;
- zig_args.append("--output") catch unreachable;
- zig_args.append(b.pathFromRoot(obj_path)) catch unreachable;
+ zig_args.append("--output-dir") catch unreachable;
+ zig_args.append(b.pathFromRoot(b.cache_root)) catch unreachable;
switch (self.build_mode) {
Mode.Debug => {},
@@ -851,7 +863,7 @@ pub const BuildExamplesContext = struct {
zig_args.append("--verbose") catch unreachable;
}
- const run_cmd = b.addCommand(null, b.env_map, zig_args.toSliceConst());
+ const run_cmd = b.addSystemCommand(zig_args.toSliceConst());
const log_step = b.addLog("PASS {}\n", annotated_case_name);
log_step.step.dependOn(&run_cmd.step);
@@ -1118,23 +1130,28 @@ pub const GenHContext = struct {
const GenHCmpOutputStep = struct {
step: build.Step,
context: *GenHContext,
- h_path: []const u8,
+ obj: *LibExeObjStep,
name: []const u8,
test_index: usize,
case: *const TestCase,
- pub fn create(context: *GenHContext, h_path: []const u8, name: []const u8, case: *const TestCase) *GenHCmpOutputStep {
+ pub fn create(
+ context: *GenHContext,
+ obj: *LibExeObjStep,
+ name: []const u8,
+ case: *const TestCase,
+ ) *GenHCmpOutputStep {
const allocator = context.b.allocator;
const ptr = allocator.create(GenHCmpOutputStep) catch unreachable;
ptr.* = GenHCmpOutputStep{
.step = build.Step.init("ParseCCmpOutput", allocator, make),
.context = context,
- .h_path = h_path,
+ .obj = obj,
.name = name,
.test_index = context.test_index,
.case = case,
};
-
+ ptr.step.dependOn(&obj.step);
context.test_index += 1;
return ptr;
}
@@ -1145,7 +1162,7 @@ pub const GenHContext = struct {
warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
- const full_h_path = b.pathFromRoot(self.h_path);
+ const full_h_path = self.obj.getOutputHPath();
const actual_h = try io.readFileAlloc(b.allocator, full_h_path);
for (self.case.expected_lines.toSliceConst()) |expected_line| {
@@ -1218,8 +1235,7 @@ pub const GenHContext = struct {
obj.step.dependOn(&write_src.step);
}
- const cmp_h = GenHCmpOutputStep.create(self, obj.getOutputHPath(), annotated_case_name, case);
- cmp_h.step.dependOn(&obj.step);
+ const cmp_h = GenHCmpOutputStep.create(self, obj, annotated_case_name, case);
self.step.dependOn(&cmp_h.step);
}