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 {
155155 self.updates.append(.{
156156 .src = src,
157157 .case = .{ .Header = result },
158 }) catch unreachable;
158 }) catch @panic("out of memory");
159159 }
160160
161161 /// Adds a subcase in which the module is updated with `src`, compiled,
......@@ -164,7 +164,7 @@ pub const TestContext = struct {
164164 self.updates.append(.{
165165 .src = src,
166166 .case = .{ .Execution = result },
167 }) catch unreachable;
167 }) catch @panic("out of memory");
168168 }
169169
170170 /// Adds a subcase in which the module is updated with `src`, compiled,
......@@ -173,7 +173,7 @@ pub const TestContext = struct {
173173 self.updates.append(.{
174174 .src = src,
175175 .case = .{ .CompareObjectFile = result },
176 }) catch unreachable;
176 }) catch @panic("out of memory");
177177 }
178178
179179 /// Adds a subcase in which the module is updated with `src`, which
......@@ -181,7 +181,7 @@ pub const TestContext = struct {
181181 /// for the expected reasons, given in sequential order in `errors` in
182182 /// the form `:line:column: error: message`.
183183 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");
185185 for (errors) |err_msg_line, i| {
186186 if (std.mem.startsWith(u8, err_msg_line, "error: ")) {
187187 array[i] = .{
......@@ -224,7 +224,7 @@ pub const TestContext = struct {
224224 },
225225 };
226226 }
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");
228228 }
229229
230230 /// Adds a subcase in which the module is updated with `src`, and
......@@ -247,7 +247,7 @@ pub const TestContext = struct {
247247 .output_mode = .Exe,
248248 .extension = extension,
249249 .files = std.ArrayList(File).init(ctx.cases.allocator),
250 }) catch unreachable;
250 }) catch @panic("out of memory");
251251 return &ctx.cases.items[ctx.cases.items.len - 1];
252252 }
253253
......@@ -262,15 +262,17 @@ pub const TestContext = struct {
262262 }
263263
264264 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");
265267 ctx.cases.append(Case{
266 .name = name,
268 .name = prefixed_name,
267269 .target = target,
268270 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
269271 .output_mode = .Exe,
270272 .extension = .Zig,
271273 .object_format = .c,
272274 .files = std.ArrayList(File).init(ctx.cases.allocator),
273 }) catch unreachable;
275 }) catch @panic("out of memory");
274276 return &ctx.cases.items[ctx.cases.items.len - 1];
275277 }
276278
......@@ -285,7 +287,7 @@ pub const TestContext = struct {
285287 .extension = .Zig,
286288 .files = std.ArrayList(File).init(ctx.cases.allocator),
287289 .llvm_backend = true,
288 }) catch unreachable;
290 }) catch @panic("out of memory");
289291 return &ctx.cases.items[ctx.cases.items.len - 1];
290292 }
291293
......@@ -302,7 +304,7 @@ pub const TestContext = struct {
302304 .output_mode = .Obj,
303305 .extension = extension,
304306 .files = std.ArrayList(File).init(ctx.cases.allocator),
305 }) catch unreachable;
307 }) catch @panic("out of memory");
306308 return &ctx.cases.items[ctx.cases.items.len - 1];
307309 }
308310
......@@ -326,7 +328,7 @@ pub const TestContext = struct {
326328 .extension = ext,
327329 .object_format = .c,
328330 .files = std.ArrayList(File).init(ctx.cases.allocator),
329 }) catch unreachable;
331 }) catch @panic("out of memory");
330332 return &ctx.cases.items[ctx.cases.items.len - 1];
331333 }
332334