aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-03-10 13:48:06 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-03-10 13:48:06 -0400
commit3cdd2c0bddebf82a3ec7b187014acf2e7507a79c (patch)
tree4f38ce2307e32b518c8c65b12a186d054876f8dc /test
parent0714e19598e91f457d3d0119856fd7a24dd4f150 (diff)
parent0a8a7a57e7a6b4b5a0d1523bde57b2a4b93fa50a (diff)
downloadzig-3cdd2c0bddebf82a3ec7b187014acf2e7507a79c.tar.gz
zig-3cdd2c0bddebf82a3ec7b187014acf2e7507a79c.zip
Merge remote-tracking branch 'origin/master' into llvm8
Diffstat (limited to 'test')
-rw-r--r--test/cli.zig6
-rw-r--r--test/stage1/behavior/type_info.zig10
-rw-r--r--test/standalone/load_dynamic_library/build.zig8
-rw-r--r--test/standalone/pkg_import/build.zig3
-rw-r--r--test/tests.zig90
5 files changed, 72 insertions, 45 deletions
diff --git a/test/cli.zig b/test/cli.zig
index d7490dcc76..1e7f1d0a73 100644
--- a/test/cli.zig
+++ b/test/cli.zig
@@ -116,12 +116,12 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
const args = [][]const u8{
zig_exe, "build-obj",
"--cache-dir", dir_path,
- "--output", example_s_path,
- "--output-h", "/dev/null",
+ "--name", "example",
+ "--output-dir", dir_path,
"--emit", "asm",
"-mllvm", "--x86-asm-syntax=intel",
"--strip", "--release-fast",
- example_zig_path,
+ example_zig_path, "--disable-gen-h",
};
_ = try exec(dir_path, args);
diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig
index 510a56f619..12a7c118b7 100644
--- a/test/stage1/behavior/type_info.zig
+++ b/test/stage1/behavior/type_info.zig
@@ -289,3 +289,13 @@ fn testVector() void {
expect(vec_info.Vector.len == 4);
expect(vec_info.Vector.child == i32);
}
+
+test "type info: optional field unwrapping" {
+ const Struct = struct {
+ cdOffset: u32,
+ };
+
+ const field = @typeInfo(Struct).Struct.fields[0];
+
+ _ = field.offset orelse 0;
+}
diff --git a/test/standalone/load_dynamic_library/build.zig b/test/standalone/load_dynamic_library/build.zig
index 2d47a893f2..109c742c6f 100644
--- a/test/standalone/load_dynamic_library/build.zig
+++ b/test/standalone/load_dynamic_library/build.zig
@@ -9,12 +9,8 @@ pub fn build(b: *Builder) void {
const main = b.addExecutable("main", "main.zig");
main.setBuildMode(opts);
- const run = b.addCommand(".", b.env_map, [][]const u8{
- main.getOutputPath(),
- lib.getOutputPath(),
- });
- run.step.dependOn(&lib.step);
- run.step.dependOn(&main.step);
+ const run = main.run();
+ run.addArtifactArg(lib);
const test_step = b.step("test", "Test the program");
test_step.dependOn(&run.step);
diff --git a/test/standalone/pkg_import/build.zig b/test/standalone/pkg_import/build.zig
index e0b3885dc3..7529d106f9 100644
--- a/test/standalone/pkg_import/build.zig
+++ b/test/standalone/pkg_import/build.zig
@@ -9,8 +9,7 @@ pub fn build(b: *Builder) void {
exe.setBuildMode(b.standardReleaseOptions());
exe.setBuildMode(b.standardReleaseOptions());
- const run = b.addCommand(".", b.env_map, [][]const u8{exe.getOutputPath()});
- run.step.dependOn(&exe.step);
+ const run = exe.run();
const test_step = b.step("test", "Test it");
test_step.dependOn(&run.step);
diff --git a/test/tests.zig b/test/tests.zig
index d3a27f3e94..ad7e5d3652 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;
@@ -158,6 +158,7 @@ pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
.step = b.step("test-gen-h", "Run the C header file generation tests"),
.test_index = 0,
.test_filter = test_filter,
+ .counter = 0,
};
gen_h.addCases(cases);
@@ -246,24 +247,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 +280,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 +344,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 +367,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 +471,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 +503,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 +534,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 +625,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 +641,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 +864,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);
@@ -1092,6 +1105,7 @@ pub const GenHContext = struct {
step: *build.Step,
test_index: usize,
test_filter: ?[]const u8,
+ counter: usize,
const TestCase = struct {
name: []const u8,
@@ -1118,23 +1132,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 +1164,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| {
@@ -1189,7 +1208,11 @@ pub const GenHContext = struct {
}
pub fn add(self: *GenHContext, name: []const u8, source: []const u8, expected_lines: ...) void {
- const tc = self.create("test.zig", name, source, expected_lines);
+ // MacOS appears to not be returning nanoseconds in fstat mtime,
+ // which causes fast test executions to think the file contents are unchanged.
+ const modified_name = self.b.fmt("test-{}.zig", self.counter);
+ self.counter += 1;
+ const tc = self.create(modified_name, name, source, expected_lines);
self.addCase(tc);
}
@@ -1218,8 +1241,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);
}