diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-06-15 12:28:21 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-06-15 12:28:21 -0400 |
| commit | 6bf193af192ffaf3465958a243ec8fc8941cfe4d (patch) | |
| tree | 7271c30c7c6657765535002421c65a2377171477 /std | |
| parent | 60025a37045835c8bbf914eccdbeba6d6e2c275f (diff) | |
| download | zig-6bf193af192ffaf3465958a243ec8fc8941cfe4d.tar.gz zig-6bf193af192ffaf3465958a243ec8fc8941cfe4d.zip | |
better result location semantics with optionals and return locations
somewhere along this branch, #1901 has been fixed.
Diffstat (limited to 'std')
| -rw-r--r-- | std/os.zig | 2 | ||||
| -rw-r--r-- | std/special/panic.zig | 23 | ||||
| -rw-r--r-- | std/special/test_runner.zig | 22 |
3 files changed, 28 insertions, 19 deletions
diff --git a/std/os.zig b/std/os.zig index 3409dcf6c6..a0f8d1f12b 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 = false; +pub const unexpected_error_tracing = builtin.mode == .Debug; 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 50dc5e0c65..92e0d9164c 100644 --- a/std/special/panic.zig +++ b/std/special/panic.zig @@ -7,8 +7,23 @@ const builtin = @import("builtin"); const std = @import("std"); pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { - 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(); + @setCold(true); + switch (builtin.os) { + .freestanding => { + while (true) {} + }, + .wasi => { + std.debug.warn("{}", msg); + _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT); + unreachable; + }, + .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); + }, + } } diff --git a/std/special/test_runner.zig b/std/special/test_runner.zig index 001b26ebb0..db01293059 100644 --- a/std/special/test_runner.zig +++ b/std/special/test_runner.zig @@ -2,34 +2,28 @@ 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 { - const stderr = io.getStdErr() catch std.process.abort(); - +pub fn main() !void { var ok_count: usize = 0; var skip_count: usize = 0; for (test_fn_list) |test_fn, i| { - stderr.write("test ") catch std.process.abort(); - stderr.write(test_fn.name) catch std.process.abort(); + warn("{}/{} {}...", i + 1, test_fn_list.len, test_fn.name); if (test_fn.func()) |_| { ok_count += 1; - stderr.write("...OK\n") catch std.process.abort(); + warn("OK\n"); } else |err| switch (err) { error.SkipZigTest => { skip_count += 1; - 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(); + warn("SKIP\n"); }, + else => return err, } } if (ok_count == test_fn_list.len) { - stderr.write("All tests passed.\n") catch std.process.abort(); + warn("All tests passed.\n"); } else { - stderr.write("Some tests skipped.\n") catch std.process.abort(); + warn("{} passed; {} skipped.\n", ok_count, skip_count); } } |
