aboutsummaryrefslogtreecommitdiff
path: root/src-self-hosted/arg.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-02-08 18:18:47 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-02-08 18:23:38 -0500
commitc2db077574be841da586fa62d67619c901dd535d (patch)
treec8eb64846fa7ffb9027fa1ca035dd8ca5712b9d4 /src-self-hosted/arg.zig
parentbe6d022257d8d7e99bd080823d4d8f0175f320c5 (diff)
downloadzig-c2db077574be841da586fa62d67619c901dd535d.tar.gz
zig-c2db077574be841da586fa62d67619c901dd535d.zip
std.debug.assert: remove special case for test builds
Previously, std.debug.assert would `@panic` in test builds, if the assertion failed. Now, it's always `unreachable`. This makes release mode test builds more accurately test the actual code that will be run. However this requires tests to call `std.testing.expect` rather than `std.debug.assert` to make sure output is correct. Here is the explanation of when to use either one, copied from the assert doc comments: Inside a test block, it is best to use the `std.testing` module rather than assert, because assert may not detect a test failure in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert is the correct function to use. closes #1304
Diffstat (limited to 'src-self-hosted/arg.zig')
-rw-r--r--src-self-hosted/arg.zig23
1 files changed, 12 insertions, 11 deletions
diff --git a/src-self-hosted/arg.zig b/src-self-hosted/arg.zig
index 99e6ecc17a..7bbd233a75 100644
--- a/src-self-hosted/arg.zig
+++ b/src-self-hosted/arg.zig
@@ -1,5 +1,6 @@
const std = @import("std");
const debug = std.debug;
+const testing = std.testing;
const mem = std.mem;
const Allocator = mem.Allocator;
@@ -272,21 +273,21 @@ test "parse arguments" {
var args = try Args.parse(std.debug.global_allocator, spec1, cliargs);
- debug.assert(args.present("help"));
- debug.assert(!args.present("help2"));
- debug.assert(!args.present("init"));
+ testing.expect(args.present("help"));
+ testing.expect(!args.present("help2"));
+ testing.expect(!args.present("init"));
- debug.assert(mem.eql(u8, args.single("build-file").?, "build.zig"));
- debug.assert(mem.eql(u8, args.single("color").?, "on"));
+ testing.expect(mem.eql(u8, args.single("build-file").?, "build.zig"));
+ testing.expect(mem.eql(u8, args.single("color").?, "on"));
const objects = args.many("object").?;
- debug.assert(mem.eql(u8, objects[0], "obj1"));
- debug.assert(mem.eql(u8, objects[1], "obj2"));
+ testing.expect(mem.eql(u8, objects[0], "obj1"));
+ testing.expect(mem.eql(u8, objects[1], "obj2"));
- debug.assert(mem.eql(u8, args.single("library").?, "lib2"));
+ testing.expect(mem.eql(u8, args.single("library").?, "lib2"));
const pos = args.positionals.toSliceConst();
- debug.assert(mem.eql(u8, pos[0], "build"));
- debug.assert(mem.eql(u8, pos[1], "pos1"));
- debug.assert(mem.eql(u8, pos[2], "pos2"));
+ testing.expect(mem.eql(u8, pos[0], "build"));
+ testing.expect(mem.eql(u8, pos[1], "pos1"));
+ testing.expect(mem.eql(u8, pos[2], "pos2"));
}