| ... | @@ -10,13 +10,15 @@ const ZigCompiler = @import("compilation.zig").ZigCompiler; | ... | @@ -10,13 +10,15 @@ const ZigCompiler = @import("compilation.zig").ZigCompiler; |
| 10 | var ctx: TestContext = undefined; | 10 | var ctx: TestContext = undefined; |
| 11 | | 11 | |
| 12 | test "stage2" { | 12 | test "stage2" { |
| | 13 | // TODO provide a way to run tests in evented I/O mode |
| | 14 | if (!std.io.is_async) return error.SkipZigTest; |
| | 15 | |
| 13 | try ctx.init(); | 16 | try ctx.init(); |
| 14 | defer ctx.deinit(); | 17 | defer ctx.deinit(); |
| 15 | | 18 | |
| 16 | try @import("../test/stage2/compile_errors.zig").addCases(&ctx); | 19 | try @import("stage2_tests").addCases(&ctx); |
| 17 | try @import("../test/stage2/compare_output.zig").addCases(&ctx); | | |
| 18 | | 20 | |
| 19 | async ctx.run(); | 21 | _ = async ctx.run(); |
| 20 | } | 22 | } |
| 21 | | 23 | |
| 22 | const file1 = "1.zig"; | 24 | const file1 = "1.zig"; |
| ... | @@ -40,7 +42,7 @@ pub const TestContext = struct { | ... | @@ -40,7 +42,7 @@ pub const TestContext = struct { |
| 40 | .file_index = std.atomic.Int(usize).init(0), | 42 | .file_index = std.atomic.Int(usize).init(0), |
| 41 | }; | 43 | }; |
| 42 | | 44 | |
| 43 | self.zig_compiler = try ZigCompiler.init(); | 45 | self.zig_compiler = try ZigCompiler.init(allocator); |
| 44 | errdefer self.zig_compiler.deinit(); | 46 | errdefer self.zig_compiler.deinit(); |
| 45 | | 47 | |
| 46 | self.group = std.event.Group(anyerror!void).init(allocator); | 48 | self.group = std.event.Group(anyerror!void).init(allocator); |
| ... | @@ -75,7 +77,7 @@ pub const TestContext = struct { | ... | @@ -75,7 +77,7 @@ pub const TestContext = struct { |
| 75 | ) !void { | 77 | ) !void { |
| 76 | var file_index_buf: [20]u8 = undefined; | 78 | var file_index_buf: [20]u8 = undefined; |
| 77 | const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.incr()); | 79 | const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.incr()); |
| 78 | const file1_path = try std.fs.path.join(allocator, [][]const u8{ tmp_dir_name, file_index, file1 }); | 80 | const file1_path = try std.fs.path.join(allocator, [_][]const u8{ tmp_dir_name, file_index, file1 }); |
| 79 | | 81 | |
| 80 | if (std.fs.path.dirname(file1_path)) |dirname| { | 82 | if (std.fs.path.dirname(file1_path)) |dirname| { |
| 81 | try std.fs.makePath(allocator, dirname); | 83 | try std.fs.makePath(allocator, dirname); |
| ... | @@ -108,9 +110,9 @@ pub const TestContext = struct { | ... | @@ -108,9 +110,9 @@ pub const TestContext = struct { |
| 108 | ) !void { | 110 | ) !void { |
| 109 | var file_index_buf: [20]u8 = undefined; | 111 | var file_index_buf: [20]u8 = undefined; |
| 110 | const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.incr()); | 112 | const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.incr()); |
| 111 | const file1_path = try std.fs.path.join(allocator, [][]const u8{ tmp_dir_name, file_index, file1 }); | 113 | const file1_path = try std.fs.path.join(allocator, [_][]const u8{ tmp_dir_name, file_index, file1 }); |
| 112 | | 114 | |
| 113 | const output_file = try std.fmt.allocPrint(allocator, "{}-out{}", file1_path, Target(Target.Native).exeFileExt()); | 115 | const output_file = try std.fmt.allocPrint(allocator, "{}-out{}", file1_path, (Target{.Native = {}}).exeFileExt()); |
| 114 | if (std.fs.path.dirname(file1_path)) |dirname| { | 116 | if (std.fs.path.dirname(file1_path)) |dirname| { |
| 115 | try std.fs.makePath(allocator, dirname); | 117 | try std.fs.makePath(allocator, dirname); |
| 116 | } | 118 | } |
| ... | @@ -141,7 +143,7 @@ pub const TestContext = struct { | ... | @@ -141,7 +143,7 @@ pub const TestContext = struct { |
| 141 | comp: *Compilation, | 143 | comp: *Compilation, |
| 142 | exe_file: []const u8, | 144 | exe_file: []const u8, |
| 143 | expected_output: []const u8, | 145 | expected_output: []const u8, |
| 144 | ) !void { | 146 | ) anyerror!void { |
| 145 | // TODO this should not be necessary | 147 | // TODO this should not be necessary |
| 146 | const exe_file_2 = try std.mem.dupe(allocator, u8, exe_file); | 148 | const exe_file_2 = try std.mem.dupe(allocator, u8, exe_file); |
| 147 | | 149 | |
| ... | @@ -150,7 +152,7 @@ pub const TestContext = struct { | ... | @@ -150,7 +152,7 @@ pub const TestContext = struct { |
| 150 | | 152 | |
| 151 | switch (build_event) { | 153 | switch (build_event) { |
| 152 | .Ok => { | 154 | .Ok => { |
| 153 | const argv = []const []const u8{exe_file_2}; | 155 | const argv = [_][]const u8{exe_file_2}; |
| 154 | // TODO use event loop | 156 | // TODO use event loop |
| 155 | const child = try std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024); | 157 | const child = try std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024); |
| 156 | switch (child.term) { | 158 | switch (child.term) { |
| ... | @@ -186,7 +188,7 @@ pub const TestContext = struct { | ... | @@ -186,7 +188,7 @@ pub const TestContext = struct { |
| 186 | line: usize, | 188 | line: usize, |
| 187 | column: usize, | 189 | column: usize, |
| 188 | text: []const u8, | 190 | text: []const u8, |
| 189 | ) !void { | 191 | ) anyerror!void { |
| 190 | defer comp.destroy(); | 192 | defer comp.destroy(); |
| 191 | const build_event = comp.events.get(); | 193 | const build_event = comp.events.get(); |
| 192 | | 194 | |