diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-05-17 23:21:44 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-05-17 23:21:44 -0400 |
| commit | c38b165db4a16ba6a5c6d13537177db656fc4033 (patch) | |
| tree | a8639a11bea5a2fc2b9c5aebf30011f7675f37d7 /test/tests.zig | |
| parent | 99fc2bd4ddbe36994153f6426f0001d338e90bef (diff) | |
| download | zig-c38b165db4a16ba6a5c6d13537177db656fc4033.tar.gz zig-c38b165db4a16ba6a5c6d13537177db656fc4033.zip | |
all tests passing with postfix deref syntax
Diffstat (limited to 'test/tests.zig')
| -rw-r--r-- | test/tests.zig | 190 |
1 files changed, 90 insertions, 100 deletions
diff --git a/test/tests.zig b/test/tests.zig index 5fbb56b736..b59b954122 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -27,18 +27,18 @@ const TestTarget = struct { environ: builtin.Environ, }; -const test_targets = []TestTarget { - TestTarget { +const test_targets = []TestTarget{ + TestTarget{ .os = builtin.Os.linux, .arch = builtin.Arch.x86_64, .environ = builtin.Environ.gnu, }, - TestTarget { + TestTarget{ .os = builtin.Os.macosx, .arch = builtin.Arch.x86_64, .environ = builtin.Environ.unknown, }, - TestTarget { + TestTarget{ .os = builtin.Os.windows, .arch = builtin.Arch.x86_64, .environ = builtin.Environ.msvc, @@ -49,7 +49,7 @@ const max_stdout_size = 1 * 1024 * 1024; // 1 MB pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { const cases = b.allocator.create(CompareOutputContext) catch unreachable; - *cases = CompareOutputContext { + cases.* = CompareOutputContext{ .b = b, .step = b.step("test-compare-output", "Run the compare output tests"), .test_index = 0, @@ -63,7 +63,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { const cases = b.allocator.create(CompareOutputContext) catch unreachable; - *cases = CompareOutputContext { + cases.* = CompareOutputContext{ .b = b, .step = b.step("test-runtime-safety", "Run the runtime safety tests"), .test_index = 0, @@ -77,7 +77,7 @@ pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) &build pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { const cases = b.allocator.create(CompileErrorContext) catch unreachable; - *cases = CompileErrorContext { + cases.* = CompileErrorContext{ .b = b, .step = b.step("test-compile-errors", "Run the compile error tests"), .test_index = 0, @@ -91,7 +91,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) &build. pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { const cases = b.allocator.create(BuildExamplesContext) catch unreachable; - *cases = BuildExamplesContext { + cases.* = BuildExamplesContext{ .b = b, .step = b.step("test-build-examples", "Build the examples"), .test_index = 0, @@ -105,7 +105,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) &build. pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { const cases = b.allocator.create(CompareOutputContext) catch unreachable; - *cases = CompareOutputContext { + cases.* = CompareOutputContext{ .b = b, .step = b.step("test-asm-link", "Run the assemble and link tests"), .test_index = 0, @@ -119,7 +119,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) &bui pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { const cases = b.allocator.create(TranslateCContext) catch unreachable; - *cases = TranslateCContext { + cases.* = TranslateCContext{ .b = b, .step = b.step("test-translate-c", "Run the C transation tests"), .test_index = 0, @@ -133,7 +133,7 @@ pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) &build.St pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { const cases = b.allocator.create(GenHContext) catch unreachable; - *cases = GenHContext { + cases.* = GenHContext{ .b = b, .step = b.step("test-gen-h", "Run the C header file generation tests"), .test_index = 0, @@ -145,22 +145,26 @@ pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { return cases.step; } - -pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8, - name:[] const u8, desc: []const u8, with_lldb: bool) &build.Step -{ +pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8, name: []const u8, desc: []const u8, with_lldb: bool) &build.Step { const step = b.step(b.fmt("test-{}", name), desc); for (test_targets) |test_target| { const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch); - for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast, Mode.ReleaseSmall}) |mode| { - for ([]bool{false, true}) |link_libc| { + for ([]Mode{ + Mode.Debug, + Mode.ReleaseSafe, + Mode.ReleaseFast, + Mode.ReleaseSmall, + }) |mode| { + for ([]bool{ + false, + true, + }) |link_libc| { if (link_libc and !is_native) { // don't assume we have a cross-compiling libc set up continue; } const these_tests = b.addTest(root_src); - these_tests.setNamePrefix(b.fmt("{}-{}-{}-{}-{} ", name, @tagName(test_target.os), - @tagName(test_target.arch), @tagName(mode), if (link_libc) "c" else "bare")); + these_tests.setNamePrefix(b.fmt("{}-{}-{}-{}-{} ", name, @tagName(test_target.os), @tagName(test_target.arch), @tagName(mode), if (link_libc) "c" else "bare")); these_tests.setFilter(test_filter); these_tests.setBuildMode(mode); if (!is_native) { @@ -171,7 +175,15 @@ pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []cons } if (with_lldb) { these_tests.setExecCmd([]?[]const u8{ - "lldb", null, "-o", "run", "-o", "bt", "-o", "exit"}); + "lldb", + null, + "-o", + "run", + "-o", + "bt", + "-o", + "exit", + }); } step.dependOn(&these_tests.step); } @@ -206,7 +218,7 @@ pub const CompareOutputContext = struct { }; pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void { - self.sources.append(SourceFile { + self.sources.append(SourceFile{ .filename = filename, .source = source, }) catch unreachable; @@ -226,13 +238,10 @@ pub const CompareOutputContext = struct { 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_path: []const u8, 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 { + ptr.* = RunCompareOutputStep{ .context = context, .exe_path = exe_path, .name = name, @@ -258,7 +267,7 @@ pub const CompareOutputContext = struct { args.append(arg) catch unreachable; } - warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); + warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); const child = os.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; defer child.deinit(); @@ -295,7 +304,6 @@ pub const CompareOutputContext = struct { }, } - if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) { warn( \\ @@ -318,12 +326,10 @@ pub const CompareOutputContext = struct { 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_path: []const u8, name: []const u8) &RuntimeSafetyRunStep { const allocator = context.b.allocator; const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable; - *ptr = RuntimeSafetyRunStep { + ptr.* = RuntimeSafetyRunStep{ .context = context, .exe_path = exe_path, .name = name, @@ -340,7 +346,7 @@ pub const CompareOutputContext = struct { const full_exe_path = b.pathFromRoot(self.exe_path); - warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); + 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; defer child.deinit(); @@ -358,19 +364,16 @@ pub const CompareOutputContext = struct { switch (term) { Term.Exited => |code| { if (code != expected_exit_code) { - warn("\nProgram expected to exit with code {} " ++ - "but exited with code {}\n", expected_exit_code, code); + warn("\nProgram expected to exit with code {} " ++ "but exited with code {}\n", expected_exit_code, code); return error.TestFailed; } }, Term.Signal => |sig| { - warn("\nProgram expected to exit with code {} " ++ - "but instead signaled {}\n", expected_exit_code, sig); + warn("\nProgram expected to exit with code {} " ++ "but instead signaled {}\n", expected_exit_code, sig); return error.TestFailed; }, else => { - warn("\nProgram expected to exit with code {}" ++ - " but exited in an unexpected way\n", expected_exit_code); + warn("\nProgram expected to exit with code {}" ++ " but exited in an unexpected way\n", expected_exit_code); return error.TestFailed; }, } @@ -379,10 +382,8 @@ pub const CompareOutputContext = struct { } }; - pub fn createExtra(self: &CompareOutputContext, name: []const u8, source: []const u8, - expected_output: []const u8, special: Special) TestCase - { - var tc = TestCase { + pub fn createExtra(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8, special: Special) TestCase { + var tc = TestCase{ .name = name, .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), .expected_output = expected_output, @@ -395,9 +396,7 @@ pub const CompareOutputContext = struct { return tc; } - pub fn create(self: &CompareOutputContext, name: []const u8, source: []const u8, - expected_output: []const u8) TestCase - { + pub fn create(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) TestCase { return createExtra(self, name, source, expected_output, Special.None); } @@ -431,8 +430,7 @@ pub const CompareOutputContext = struct { Special.Asm => { const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name) catch unreachable; if (self.test_filter) |filter| { - if (mem.indexOf(u8, annotated_case_name, filter) == null) - return; + if (mem.indexOf(u8, annotated_case_name, filter) == null) return; } const exe = b.addExecutable("test", null); @@ -444,19 +442,21 @@ 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); + 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); self.step.dependOn(&run_and_cmp_output.step); }, Special.None => { - for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast, Mode.ReleaseSmall}) |mode| { - const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", - "compare-output", case.name, @tagName(mode)) catch unreachable; + for ([]Mode{ + Mode.Debug, + Mode.ReleaseSafe, + Mode.ReleaseFast, + Mode.ReleaseSmall, + }) |mode| { + const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "compare-output", case.name, @tagName(mode)) catch unreachable; if (self.test_filter) |filter| { - if (mem.indexOf(u8, annotated_case_name, filter) == null) - continue; + if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; } const exe = b.addExecutable("test", root_src); @@ -471,8 +471,7 @@ 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); + 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); self.step.dependOn(&run_and_cmp_output.step); @@ -481,8 +480,7 @@ pub const CompareOutputContext = struct { Special.RuntimeSafety => { const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", case.name) catch unreachable; if (self.test_filter) |filter| { - if (mem.indexOf(u8, annotated_case_name, filter) == null) - return; + if (mem.indexOf(u8, annotated_case_name, filter) == null) return; } const exe = b.addExecutable("test", root_src); @@ -524,7 +522,7 @@ pub const CompileErrorContext = struct { }; pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void { - self.sources.append(SourceFile { + self.sources.append(SourceFile{ .filename = filename, .source = source, }) catch unreachable; @@ -543,12 +541,10 @@ pub const CompileErrorContext = struct { case: &const TestCase, build_mode: Mode, - pub fn create(context: &CompileErrorContext, name: []const u8, - case: &const TestCase, build_mode: Mode) &CompileCmpOutputStep - { + pub fn create(context: &CompileErrorContext, name: []const u8, case: &const TestCase, build_mode: Mode) &CompileCmpOutputStep { const allocator = context.b.allocator; const ptr = allocator.create(CompileCmpOutputStep) catch unreachable; - *ptr = CompileCmpOutputStep { + ptr.* = CompileCmpOutputStep{ .step = build.Step.init("CompileCmpOutput", allocator, make), .context = context, .name = name, @@ -586,7 +582,7 @@ pub const CompileErrorContext = struct { Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable, } - warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); + warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); if (b.verbose) { printInvocation(zig_args.toSliceConst()); @@ -626,7 +622,6 @@ pub const CompileErrorContext = struct { }, } - const stdout = stdout_buf.toSliceConst(); const stderr = stderr_buf.toSliceConst(); @@ -666,11 +661,9 @@ pub const CompileErrorContext = struct { warn("\n"); } - pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8, - expected_lines: ...) &TestCase - { + pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) &TestCase { const tc = self.b.allocator.create(TestCase) catch unreachable; - *tc = TestCase { + tc.* = TestCase{ .name = name, .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), .expected_errors = ArrayList([]const u8).init(self.b.allocator), @@ -705,12 +698,13 @@ pub const CompileErrorContext = struct { pub fn addCase(self: &CompileErrorContext, case: &const TestCase) void { const b = self.b; - for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| { - const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {} ({})", - case.name, @tagName(mode)) catch unreachable; + for ([]Mode{ + Mode.Debug, + Mode.ReleaseFast, + }) |mode| { + const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {} ({})", case.name, @tagName(mode)) catch unreachable; if (self.test_filter) |filter| { - if (mem.indexOf(u8, annotated_case_name, filter) == null) - continue; + if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; } const compile_and_cmp_errors = CompileCmpOutputStep.create(self, annotated_case_name, case, mode); @@ -744,8 +738,7 @@ pub const BuildExamplesContext = struct { const annotated_case_name = b.fmt("build {} (Debug)", build_file); if (self.test_filter) |filter| { - if (mem.indexOf(u8, annotated_case_name, filter) == null) - return; + if (mem.indexOf(u8, annotated_case_name, filter) == null) return; } var zig_args = ArrayList([]const u8).init(b.allocator); @@ -773,12 +766,15 @@ pub const BuildExamplesContext = struct { pub fn addAllArgs(self: &BuildExamplesContext, root_src: []const u8, link_libc: bool) void { const b = self.b; - for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast, Mode.ReleaseSmall}) |mode| { - const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", - root_src, @tagName(mode)) catch unreachable; + for ([]Mode{ + Mode.Debug, + Mode.ReleaseSafe, + Mode.ReleaseFast, + Mode.ReleaseSmall, + }) |mode| { + const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", root_src, @tagName(mode)) catch unreachable; if (self.test_filter) |filter| { - if (mem.indexOf(u8, annotated_case_name, filter) == null) - continue; + if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; } const exe = b.addExecutable("test", root_src); @@ -813,7 +809,7 @@ pub const TranslateCContext = struct { }; pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void { - self.sources.append(SourceFile { + self.sources.append(SourceFile{ .filename = filename, .source = source, }) catch unreachable; @@ -834,7 +830,7 @@ pub const TranslateCContext = struct { pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) &TranslateCCmpOutputStep { const allocator = context.b.allocator; const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable; - *ptr = TranslateCCmpOutputStep { + ptr.* = TranslateCCmpOutputStep{ .step = build.Step.init("ParseCCmpOutput", allocator, make), .context = context, .name = name, @@ -857,7 +853,7 @@ pub const TranslateCContext = struct { zig_args.append("translate-c") catch unreachable; zig_args.append(b.pathFromRoot(root_src)) catch unreachable; - warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); + warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); if (b.verbose) { printInvocation(zig_args.toSliceConst()); @@ -939,11 +935,9 @@ pub const TranslateCContext = struct { warn("\n"); } - pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, - source: []const u8, expected_lines: ...) &TestCase - { + pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) &TestCase { const tc = self.b.allocator.create(TestCase) catch unreachable; - *tc = TestCase { + tc.* = TestCase{ .name = name, .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), .expected_lines = ArrayList([]const u8).init(self.b.allocator), @@ -977,8 +971,7 @@ pub const TranslateCContext = struct { const annotated_case_name = fmt.allocPrint(self.b.allocator, "translate-c {}", case.name) catch unreachable; if (self.test_filter) |filter| { - if (mem.indexOf(u8, annotated_case_name, filter) == null) - return; + if (mem.indexOf(u8, annotated_case_name, filter) == null) return; } const translate_c_and_cmp = TranslateCCmpOutputStep.create(self, annotated_case_name, case); @@ -1009,7 +1002,7 @@ pub const GenHContext = struct { }; pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void { - self.sources.append(SourceFile { + self.sources.append(SourceFile{ .filename = filename, .source = source, }) catch unreachable; @@ -1031,7 +1024,7 @@ pub const GenHContext = struct { pub fn create(context: &GenHContext, h_path: []const u8, name: []const u8, case: &const TestCase) &GenHCmpOutputStep { const allocator = context.b.allocator; const ptr = allocator.create(GenHCmpOutputStep) catch unreachable; - *ptr = GenHCmpOutputStep { + ptr.* = GenHCmpOutputStep{ .step = build.Step.init("ParseCCmpOutput", allocator, make), .context = context, .h_path = h_path, @@ -1047,7 +1040,7 @@ pub const GenHContext = struct { const self = @fieldParentPtr(GenHCmpOutputStep, "step", step); const b = self.context.b; - warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); + warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); const full_h_path = b.pathFromRoot(self.h_path); const actual_h = try io.readFileAlloc(b.allocator, full_h_path); @@ -1076,11 +1069,9 @@ pub const GenHContext = struct { warn("\n"); } - pub fn create(self: &GenHContext, filename: []const u8, name: []const u8, - source: []const u8, expected_lines: ...) &TestCase - { + pub fn create(self: &GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) &TestCase { const tc = self.b.allocator.create(TestCase) catch unreachable; - *tc = TestCase { + tc.* = TestCase{ .name = name, .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), .expected_lines = ArrayList([]const u8).init(self.b.allocator), @@ -1105,8 +1096,7 @@ pub const GenHContext = struct { const mode = builtin.Mode.Debug; const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", case.name, @tagName(mode)) catch unreachable; if (self.test_filter) |filter| { - if (mem.indexOf(u8, annotated_case_name, filter) == null) - return; + if (mem.indexOf(u8, annotated_case_name, filter) == null) return; } const obj = b.addObject("test", root_src); |
