aboutsummaryrefslogtreecommitdiff
path: root/std/io.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 /std/io.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 'std/io.zig')
-rw-r--r--std/io.zig17
1 files changed, 9 insertions, 8 deletions
diff --git a/std/io.zig b/std/io.zig
index 81d90def6e..d7e8507f9b 100644
--- a/std/io.zig
+++ b/std/io.zig
@@ -13,6 +13,7 @@ const trait = meta.trait;
const Buffer = std.Buffer;
const fmt = std.fmt;
const File = std.os.File;
+const testing = std.testing;
const is_posix = builtin.os != builtin.Os.windows;
const is_windows = builtin.os == builtin.Os.windows;
@@ -664,7 +665,7 @@ test "io.SliceOutStream" {
const stream = &slice_stream.stream;
try stream.print("{}{}!", "Hello", "World");
- debug.assertOrPanic(mem.eql(u8, "HelloWorld!", slice_stream.getWritten()));
+ testing.expectEqualSlices(u8, "HelloWorld!", slice_stream.getWritten());
}
var null_out_stream_state = NullOutStream.init();
@@ -726,7 +727,7 @@ test "io.CountingOutStream" {
const bytes = "yay" ** 10000;
stream.write(bytes) catch unreachable;
- debug.assertOrPanic(counting_stream.bytes_written == bytes.len);
+ testing.expect(counting_stream.bytes_written == bytes.len);
}
pub fn BufferedOutStream(comptime Error: type) type {
@@ -1014,10 +1015,10 @@ test "io.readLineFrom" {
);
const stream = &mem_stream.stream;
- debug.assertOrPanic(mem.eql(u8, "Line 1", try readLineFrom(stream, &buf)));
- debug.assertOrPanic(mem.eql(u8, "Line 22", try readLineFrom(stream, &buf)));
- debug.assertError(readLineFrom(stream, &buf), error.EndOfStream);
- debug.assertOrPanic(mem.eql(u8, buf.toSlice(), "Line 1Line 22Line 333"));
+ testing.expectEqualSlices(u8, "Line 1", try readLineFrom(stream, &buf));
+ testing.expectEqualSlices(u8, "Line 22", try readLineFrom(stream, &buf));
+ testing.expectError(error.EndOfStream, readLineFrom(stream, &buf));
+ testing.expectEqualSlices(u8, "Line 1Line 22Line 333", buf.toSlice());
}
pub fn readLineSlice(slice: []u8) ![]u8 {
@@ -1045,8 +1046,8 @@ test "io.readLineSliceFrom" {
);
const stream = &mem_stream.stream;
- debug.assertOrPanic(mem.eql(u8, "Line 1", try readLineSliceFrom(stream, buf[0..])));
- debug.assertError(readLineSliceFrom(stream, buf[0..]), error.OutOfMemory);
+ testing.expectEqualSlices(u8, "Line 1", try readLineSliceFrom(stream, buf[0..]));
+ testing.expectError(error.OutOfMemory, readLineSliceFrom(stream, buf[0..]));
}
/// Creates a deserializer that deserializes types from any stream.