From 60c386180570d9d3830f8375bbad761cf721c6d3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 11 Jun 2019 14:46:46 -0400 Subject: [PATCH] temporarily simplify test_runner.zig so that this branch can start passing behavior tests. after the tests pass, go back and undo the changes in this commit --- BRANCH_TODO | 4 ++++ std/io.zig | 20 ++++++++++---------- std/os.zig | 2 +- std/special/panic.zig | 24 ++++-------------------- std/special/test_runner.zig | 22 ++++++++++++++-------- 5 files changed, 33 insertions(+), 39 deletions(-) diff --git a/BRANCH_TODO b/BRANCH_TODO index e531441021..43b04a9813 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -1,6 +1,10 @@ Scratch pad for stuff to do before merging master ================================================= +restore test_runner.zig to master branch + - also the default panic function and unexpected_error_tracing. see the commit + that adds this text to BRANCH_TODO file. + get an empty file compiling successfully (with no panic fn override) uncomment all the behavior tests diff --git a/std/io.zig b/std/io.zig index a02fb56e24..3a8da3ed3e 100644 --- a/std/io.zig +++ b/std/io.zig @@ -164,32 +164,32 @@ pub fn InStream(comptime ReadError: type) type { /// Reads a native-endian integer pub fn readIntNative(self: *Self, comptime T: type) !T { - var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined; + var bytes: [(T.bit_count + 7) / 8]u8 = undefined; try self.readNoEof(bytes[0..]); return mem.readIntNative(T, &bytes); } /// Reads a foreign-endian integer pub fn readIntForeign(self: *Self, comptime T: type) !T { - var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined; + var bytes: [(T.bit_count + 7) / 8]u8 = undefined; try self.readNoEof(bytes[0..]); return mem.readIntForeign(T, &bytes); } pub fn readIntLittle(self: *Self, comptime T: type) !T { - var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined; + var bytes: [(T.bit_count + 7) / 8]u8 = undefined; try self.readNoEof(bytes[0..]); return mem.readIntLittle(T, &bytes); } pub fn readIntBig(self: *Self, comptime T: type) !T { - var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined; + var bytes: [(T.bit_count + 7) / 8]u8 = undefined; try self.readNoEof(bytes[0..]); return mem.readIntBig(T, &bytes); } pub fn readInt(self: *Self, comptime T: type, endian: builtin.Endian) !T { - var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined; + var bytes: [(T.bit_count + 7) / 8]u8 = undefined; try self.readNoEof(bytes[0..]); return mem.readInt(T, &bytes, endian); } @@ -249,32 +249,32 @@ pub fn OutStream(comptime WriteError: type) type { /// Write a native-endian integer. pub fn writeIntNative(self: *Self, comptime T: type, value: T) Error!void { - var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined; + var bytes: [(T.bit_count + 7) / 8]u8 = undefined; mem.writeIntNative(T, &bytes, value); return self.writeFn(self, bytes); } /// Write a foreign-endian integer. pub fn writeIntForeign(self: *Self, comptime T: type, value: T) Error!void { - var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined; + var bytes: [(T.bit_count + 7) / 8]u8 = undefined; mem.writeIntForeign(T, &bytes, value); return self.writeFn(self, bytes); } pub fn writeIntLittle(self: *Self, comptime T: type, value: T) Error!void { - var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined; + var bytes: [(T.bit_count + 7) / 8]u8 = undefined; mem.writeIntLittle(T, &bytes, value); return self.writeFn(self, bytes); } pub fn writeIntBig(self: *Self, comptime T: type, value: T) Error!void { - var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined; + var bytes: [(T.bit_count + 7) / 8]u8 = undefined; mem.writeIntBig(T, &bytes, value); return self.writeFn(self, bytes); } pub fn writeInt(self: *Self, comptime T: type, value: T, endian: builtin.Endian) Error!void { - var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined; + var bytes: [(T.bit_count + 7) / 8]u8 = undefined; mem.writeInt(T, &bytes, value, endian); return self.writeFn(self, bytes); } diff --git a/std/os.zig b/std/os.zig index a0f8d1f12b..3409dcf6c6 100644 --- a/std/os.zig +++ b/std/os.zig @@ -2487,7 +2487,7 @@ pub fn toPosixPath(file_path: []const u8) ![PATH_MAX]u8 { /// if this happens the fix is to add the error code to the corresponding /// switch expression, possibly introduce a new error in the error set, and /// send a patch to Zig. -pub const unexpected_error_tracing = builtin.mode == .Debug; +pub const unexpected_error_tracing = false; pub const UnexpectedError = error{ /// The Operating System returned an undocumented error code. diff --git a/std/special/panic.zig b/std/special/panic.zig index 40b1d5e7fe..50dc5e0c65 100644 --- a/std/special/panic.zig +++ b/std/special/panic.zig @@ -7,24 +7,8 @@ const builtin = @import("builtin"); const std = @import("std"); pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { - @setCold(true); - switch (builtin.os) { - // TODO: fix panic in zen - builtin.Os.freestanding, builtin.Os.zen => { - while (true) {} - }, - builtin.Os.wasi => { - std.debug.warn("{}", msg); - _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT); - unreachable; - }, - builtin.Os.uefi => { - // TODO look into using the debug info and logging helpful messages - std.os.abort(); - }, - else => { - const first_trace_addr = @returnAddress(); - std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg); - }, - } + const stderr = std.io.getStdErr() catch std.process.abort(); + stderr.write("panic: ") catch std.process.abort(); + stderr.write(msg) catch std.process.abort(); + std.process.abort(); } diff --git a/std/special/test_runner.zig b/std/special/test_runner.zig index db01293059..001b26ebb0 100644 --- a/std/special/test_runner.zig +++ b/std/special/test_runner.zig @@ -2,28 +2,34 @@ const std = @import("std"); const io = std.io; const builtin = @import("builtin"); const test_fn_list = builtin.test_functions; -const warn = std.debug.warn; -pub fn main() !void { +pub fn main() void { + const stderr = io.getStdErr() catch std.process.abort(); + var ok_count: usize = 0; var skip_count: usize = 0; for (test_fn_list) |test_fn, i| { - warn("{}/{} {}...", i + 1, test_fn_list.len, test_fn.name); + stderr.write("test ") catch std.process.abort(); + stderr.write(test_fn.name) catch std.process.abort(); if (test_fn.func()) |_| { ok_count += 1; - warn("OK\n"); + stderr.write("...OK\n") catch std.process.abort(); } else |err| switch (err) { error.SkipZigTest => { skip_count += 1; - warn("SKIP\n"); + stderr.write("...SKIP\n") catch std.process.abort(); + }, + else => { + stderr.write("error: ") catch std.process.abort(); + stderr.write(@errorName(err)) catch std.process.abort(); + std.process.abort(); }, - else => return err, } } if (ok_count == test_fn_list.len) { - warn("All tests passed.\n"); + stderr.write("All tests passed.\n") catch std.process.abort(); } else { - warn("{} passed; {} skipped.\n", ok_count, skip_count); + stderr.write("Some tests skipped.\n") catch std.process.abort(); } }