diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-02-08 19:23:46 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-02-08 19:23:46 -0500 |
| commit | 46ddd5f5f4db7977010f78129fade7dfa5b9d8d3 (patch) | |
| tree | 1247e46cfd016c69e23620f9370670fe02caad4b /test | |
| parent | c2db077574be841da586fa62d67619c901dd535d (diff) | |
| download | zig-46ddd5f5f4db7977010f78129fade7dfa5b9d8d3.tar.gz zig-46ddd5f5f4db7977010f78129fade7dfa5b9d8d3.zip | |
fix compiler assertion failure when returning value from test
closes #1935
Diffstat (limited to 'test')
| -rw-r--r-- | test/compile_errors.zig | 7 | ||||
| -rw-r--r-- | test/tests.zig | 16 |
2 files changed, 22 insertions, 1 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig index acd1eada06..de01a5ac45 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -1,6 +1,13 @@ const tests = @import("tests.zig"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.addTest( + "return invalid type from test", + \\test "example" { return 1; } + , + ".tmp_source.zig:1:25: error: integer value 1 cannot be implicitly casted to type 'void'", + ); + cases.add( "threadlocal qualifier on const", \\threadlocal const x: i32 = 1234; diff --git a/test/tests.zig b/test/tests.zig index 670c410509..800ddc1ccd 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -538,6 +538,7 @@ pub const CompileErrorContext = struct { expected_errors: ArrayList([]const u8), link_libc: bool, is_exe: bool, + is_test: bool, const SourceFile = struct { filename: []const u8, @@ -596,7 +597,13 @@ pub const CompileErrorContext = struct { var zig_args = ArrayList([]const u8).init(b.allocator); zig_args.append(b.zig_exe) catch unreachable; - zig_args.append(if (self.case.is_exe) "build-exe" else "build-obj") catch unreachable; + if (self.case.is_exe) { + try zig_args.append("build-exe"); + } else if (self.case.is_test) { + try zig_args.append("test"); + } else { + try zig_args.append("build-obj"); + } zig_args.append(b.pathFromRoot(root_src)) catch unreachable; zig_args.append("--name") catch unreachable; @@ -699,6 +706,7 @@ pub const CompileErrorContext = struct { .expected_errors = ArrayList([]const u8).init(self.b.allocator), .link_libc = false, .is_exe = false, + .is_test = false, }; tc.addSourceFile(".tmp_source.zig", source); @@ -726,6 +734,12 @@ pub const CompileErrorContext = struct { self.addCase(tc); } + pub fn addTest(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void { + const tc = self.create(name, source, expected_lines); + tc.is_test = true; + self.addCase(tc); + } + pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void { const b = self.b; |
