authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-19 20:26:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-19 20:26:48-07:00
log6959b177ef27f88d6fc9ef1f0a6301f58d36d730
tree5848e8e30718bfa8f389cb2d69ef2f0f3060b1a4
parent8fee41b1d528d598521525574206e200fd332c67

stage2: test harness: panic on OOM rather than assert

also add a prefix to test names for C backend

1 files changed, 13 insertions(+), 11 deletions(-)

src/test.zig+13-11
...@@ -155,7 +155,7 @@ pub const TestContext = struct {...@@ -155,7 +155,7 @@ pub const TestContext = struct {
155 self.updates.append(.{155 self.updates.append(.{
156 .src = src,156 .src = src,
157 .case = .{ .Header = result },157 .case = .{ .Header = result },
158 }) catch unreachable;158 }) catch @panic("out of memory");
159 }159 }
160160
161 /// Adds a subcase in which the module is updated with `src`, compiled,161 /// Adds a subcase in which the module is updated with `src`, compiled,
...@@ -164,7 +164,7 @@ pub const TestContext = struct {...@@ -164,7 +164,7 @@ pub const TestContext = struct {
164 self.updates.append(.{164 self.updates.append(.{
165 .src = src,165 .src = src,
166 .case = .{ .Execution = result },166 .case = .{ .Execution = result },
167 }) catch unreachable;167 }) catch @panic("out of memory");
168 }168 }
169169
170 /// Adds a subcase in which the module is updated with `src`, compiled,170 /// Adds a subcase in which the module is updated with `src`, compiled,
...@@ -173,7 +173,7 @@ pub const TestContext = struct {...@@ -173,7 +173,7 @@ pub const TestContext = struct {
173 self.updates.append(.{173 self.updates.append(.{
174 .src = src,174 .src = src,
175 .case = .{ .CompareObjectFile = result },175 .case = .{ .CompareObjectFile = result },
176 }) catch unreachable;176 }) catch @panic("out of memory");
177 }177 }
178178
179 /// Adds a subcase in which the module is updated with `src`, which179 /// Adds a subcase in which the module is updated with `src`, which
...@@ -181,7 +181,7 @@ pub const TestContext = struct {...@@ -181,7 +181,7 @@ pub const TestContext = struct {
181 /// for the expected reasons, given in sequential order in `errors` in181 /// for the expected reasons, given in sequential order in `errors` in
182 /// the form `:line:column: error: message`.182 /// the form `:line:column: error: message`.
183 pub fn addError(self: *Case, src: [:0]const u8, errors: []const []const u8) void {183 pub fn addError(self: *Case, src: [:0]const u8, errors: []const []const u8) void {
184 var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch unreachable;184 var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch @panic("out of memory");
185 for (errors) |err_msg_line, i| {185 for (errors) |err_msg_line, i| {
186 if (std.mem.startsWith(u8, err_msg_line, "error: ")) {186 if (std.mem.startsWith(u8, err_msg_line, "error: ")) {
187 array[i] = .{187 array[i] = .{
...@@ -224,7 +224,7 @@ pub const TestContext = struct {...@@ -224,7 +224,7 @@ pub const TestContext = struct {
224 },224 },
225 };225 };
226 }226 }
227 self.updates.append(.{ .src = src, .case = .{ .Error = array } }) catch unreachable;227 self.updates.append(.{ .src = src, .case = .{ .Error = array } }) catch @panic("out of memory");
228 }228 }
229229
230 /// Adds a subcase in which the module is updated with `src`, and230 /// Adds a subcase in which the module is updated with `src`, and
...@@ -247,7 +247,7 @@ pub const TestContext = struct {...@@ -247,7 +247,7 @@ pub const TestContext = struct {
247 .output_mode = .Exe,247 .output_mode = .Exe,
248 .extension = extension,248 .extension = extension,
249 .files = std.ArrayList(File).init(ctx.cases.allocator),249 .files = std.ArrayList(File).init(ctx.cases.allocator),
250 }) catch unreachable;250 }) catch @panic("out of memory");
251 return &ctx.cases.items[ctx.cases.items.len - 1];251 return &ctx.cases.items[ctx.cases.items.len - 1];
252 }252 }
253253
...@@ -262,15 +262,17 @@ pub const TestContext = struct {...@@ -262,15 +262,17 @@ pub const TestContext = struct {
262 }262 }
263263
264 pub fn exeFromCompiledC(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case {264 pub fn exeFromCompiledC(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case {
265 const prefixed_name = std.fmt.allocPrint(ctx.cases.allocator, "CBE: {s}", .{name}) catch
266 @panic("out of memory");
265 ctx.cases.append(Case{267 ctx.cases.append(Case{
266 .name = name,268 .name = prefixed_name,
267 .target = target,269 .target = target,
268 .updates = std.ArrayList(Update).init(ctx.cases.allocator),270 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
269 .output_mode = .Exe,271 .output_mode = .Exe,
270 .extension = .Zig,272 .extension = .Zig,
271 .object_format = .c,273 .object_format = .c,
272 .files = std.ArrayList(File).init(ctx.cases.allocator),274 .files = std.ArrayList(File).init(ctx.cases.allocator),
273 }) catch unreachable;275 }) catch @panic("out of memory");
274 return &ctx.cases.items[ctx.cases.items.len - 1];276 return &ctx.cases.items[ctx.cases.items.len - 1];
275 }277 }
276278
...@@ -285,7 +287,7 @@ pub const TestContext = struct {...@@ -285,7 +287,7 @@ pub const TestContext = struct {
285 .extension = .Zig,287 .extension = .Zig,
286 .files = std.ArrayList(File).init(ctx.cases.allocator),288 .files = std.ArrayList(File).init(ctx.cases.allocator),
287 .llvm_backend = true,289 .llvm_backend = true,
288 }) catch unreachable;290 }) catch @panic("out of memory");
289 return &ctx.cases.items[ctx.cases.items.len - 1];291 return &ctx.cases.items[ctx.cases.items.len - 1];
290 }292 }
291293
...@@ -302,7 +304,7 @@ pub const TestContext = struct {...@@ -302,7 +304,7 @@ pub const TestContext = struct {
302 .output_mode = .Obj,304 .output_mode = .Obj,
303 .extension = extension,305 .extension = extension,
304 .files = std.ArrayList(File).init(ctx.cases.allocator),306 .files = std.ArrayList(File).init(ctx.cases.allocator),
305 }) catch unreachable;307 }) catch @panic("out of memory");
306 return &ctx.cases.items[ctx.cases.items.len - 1];308 return &ctx.cases.items[ctx.cases.items.len - 1];
307 }309 }
308310
...@@ -326,7 +328,7 @@ pub const TestContext = struct {...@@ -326,7 +328,7 @@ pub const TestContext = struct {
326 .extension = ext,328 .extension = ext,
327 .object_format = .c,329 .object_format = .c,
328 .files = std.ArrayList(File).init(ctx.cases.allocator),330 .files = std.ArrayList(File).init(ctx.cases.allocator),
329 }) catch unreachable;331 }) catch @panic("out of memory");
330 return &ctx.cases.items[ctx.cases.items.len - 1];332 return &ctx.cases.items[ctx.cases.items.len - 1];
331 }333 }
332334