authorgravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2024-01-15 16:01:13+11:00
committergravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2024-01-15 20:55:01+11:00
log8108c9f4d2580680e3ed2fc6a289b1af1c939b5c
treea1be69b29e073349218b1937c742e82e6790748c
parent1861423862194e845c631d0e0eea5c7bca5d284b

test/behavior: replace all 'comptime expect' with 'comptime assert'


23 files changed, 214 insertions(+), 200 deletions(-)

test/behavior/align.zig+6-6
......@@ -7,11 +7,11 @@ const assert = std.debug.assert;
77var foo: u8 align(4) = 100;
88
99test "global variable alignment" {
10 try comptime expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
11 try comptime expect(@TypeOf(&foo) == *align(4) u8);
10 comptime assert(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
11 comptime assert(@TypeOf(&foo) == *align(4) u8);
1212 {
1313 const slice = @as(*align(4) [1]u8, &foo)[0..];
14 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);
14 comptime assert(@TypeOf(slice) == *align(4) [1]u8);
1515 }
1616}
1717
......@@ -455,10 +455,10 @@ test "runtime-known array index has best alignment possible" {
455455 try testIndex2(&array, 3, *u8);
456456}
457457fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void {
458 try comptime expect(@TypeOf(&smaller[index]) == T);
458 comptime assert(@TypeOf(&smaller[index]) == T);
459459}
460460fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void {
461 try comptime expect(@TypeOf(&ptr[index]) == T);
461 comptime assert(@TypeOf(&ptr[index]) == T);
462462}
463463
464464test "alignment of function with c calling convention" {
......@@ -524,7 +524,7 @@ test "struct field explicit alignment" {
524524 var node: S.Node = undefined;
525525 node.massive_byte = 100;
526526 try expect(node.massive_byte == 100);
527 try comptime expect(@TypeOf(&node.massive_byte) == *align(64) u8);
527 comptime assert(@TypeOf(&node.massive_byte) == *align(64) u8);
528528 try expect(@intFromPtr(&node.massive_byte) % 64 == 0);
529529}
530530
test/behavior/alignof.zig+3-2
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const assert = std.debug.assert;
23const expect = std.testing.expect;
34const builtin = @import("builtin");
45const native_arch = builtin.target.cpu.arch;
......@@ -11,9 +12,9 @@ const Foo = struct {
1112};
1213
1314test "@alignOf(T) before referencing T" {
14 try comptime expect(@alignOf(Foo) != maxInt(usize));
15 comptime assert(@alignOf(Foo) != maxInt(usize));
1516 if (native_arch == .x86_64) {
16 try comptime expect(@alignOf(Foo) == 4);
17 comptime assert(@alignOf(Foo) == 4);
1718 }
1819}
1920
test/behavior/array.zig+4-3
......@@ -2,6 +2,7 @@ const std = @import("std");
22const builtin = @import("builtin");
33const testing = std.testing;
44const mem = std.mem;
5const assert = std.debug.assert;
56const expect = testing.expect;
67const expectEqual = testing.expectEqual;
78
......@@ -149,9 +150,9 @@ test "array len field" {
149150 var arr = [4]u8{ 0, 0, 0, 0 };
150151 const ptr = &arr;
151152 try expect(arr.len == 4);
152 try comptime expect(arr.len == 4);
153 comptime assert(arr.len == 4);
153154 try expect(ptr.len == 4);
154 try comptime expect(ptr.len == 4);
155 comptime assert(ptr.len == 4);
155156 try expect(@TypeOf(arr.len) == usize);
156157}
157158
......@@ -904,7 +905,7 @@ test "store array of array of structs at comptime" {
904905 };
905906
906907 try expect(S.storeArrayOfArrayOfStructs() == 15);
907 try comptime expect(S.storeArrayOfArrayOfStructs() == 15);
908 comptime assert(S.storeArrayOfArrayOfStructs() == 15);
908909}
909910
910911test "accessing multidimensional global array at comptime" {
test/behavior/async_fn.zig+5-4
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const assert = std.debug.assert;
34const expect = std.testing.expect;
45const expectEqual = std.testing.expectEqual;
56const expectEqualStrings = std.testing.expectEqualStrings;
......@@ -221,7 +222,7 @@ var a_promise: anyframe = undefined;
221222var global_result = false;
222223fn testSuspendBlock() callconv(.Async) void {
223224 suspend {
224 comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable;
225 comptime assert(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable;
225226 a_promise = @frame();
226227 }
227228
......@@ -334,7 +335,7 @@ test "async fn pointer in a struct field" {
334335 _ = &foo;
335336 var bytes: [64]u8 align(16) = undefined;
336337 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
337 try comptime expect(@TypeOf(f) == anyframe->void);
338 comptime assert(@TypeOf(f) == anyframe->void);
338339 try expect(data == 2);
339340 resume f;
340341 try expect(data == 4);
......@@ -1150,7 +1151,7 @@ test "@asyncCall using the result location inside the frame" {
11501151 _ = &foo;
11511152 var bytes: [64]u8 align(16) = undefined;
11521153 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
1153 try comptime expect(@TypeOf(f) == anyframe->i32);
1154 comptime assert(@TypeOf(f) == anyframe->i32);
11541155 try expect(data == 2);
11551156 resume f;
11561157 try expect(data == 4);
......@@ -1165,7 +1166,7 @@ test "@TypeOf an async function call of generic fn with error union type" {
11651166 const S = struct {
11661167 fn func(comptime x: anytype) anyerror!i32 {
11671168 const T = @TypeOf(async func(x));
1168 try comptime expect(T == @typeInfo(@TypeOf(@frame())).Pointer.child);
1169 comptime assert(T == @typeInfo(@TypeOf(@frame())).Pointer.child);
11691170 return undefined;
11701171 }
11711172 };
test/behavior/basic.zig+5-5
......@@ -17,7 +17,7 @@ test "empty function with comments" {
1717
1818test "truncate" {
1919 try expect(testTruncate(0x10fd) == 0xfd);
20 try comptime expect(testTruncate(0x10fd) == 0xfd);
20 comptime assert(testTruncate(0x10fd) == 0xfd);
2121}
2222fn testTruncate(x: u32) u8 {
2323 return @as(u8, @truncate(x));
......@@ -568,7 +568,7 @@ fn emptyFn() void {}
568568const addr1 = @as(*const u8, @ptrCast(&emptyFn));
569569test "comptime cast fn to ptr" {
570570 const addr2 = @as(*const u8, @ptrCast(&emptyFn));
571 try comptime expect(addr1 == addr2);
571 comptime assert(addr1 == addr2);
572572}
573573
574574test "equality compare fn ptrs" {
......@@ -678,8 +678,8 @@ test "string concatenation" {
678678 const a = "OK" ++ " IT " ++ "WORKED";
679679 const b = "OK IT WORKED";
680680
681 try comptime expect(@TypeOf(a) == *const [12:0]u8);
682 try comptime expect(@TypeOf(b) == *const [12:0]u8);
681 comptime assert(@TypeOf(a) == *const [12:0]u8);
682 comptime assert(@TypeOf(b) == *const [12:0]u8);
683683
684684 const len = b.len;
685685 const len_with_null = len + 1;
......@@ -747,7 +747,7 @@ test "auto created variables have correct alignment" {
747747 }
748748 };
749749 try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
750 try comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
750 comptime assert(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
751751}
752752
753753test "extern variable with non-pointer opaque type" {
test/behavior/bitcast.zig+3-2
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const assert = std.debug.assert;
34const expect = std.testing.expect;
45const expectEqual = std.testing.expectEqual;
56const math = std.math;
......@@ -273,7 +274,7 @@ test "comptime bitcast used in expression has the correct type" {
273274test "bitcast passed as tuple element" {
274275 const S = struct {
275276 fn foo(args: anytype) !void {
276 try comptime expect(@TypeOf(args[0]) == f32);
277 comptime assert(@TypeOf(args[0]) == f32);
277278 try expect(args[0] == 12.34);
278279 }
279280 };
......@@ -283,7 +284,7 @@ test "bitcast passed as tuple element" {
283284test "triple level result location with bitcast sandwich passed as tuple element" {
284285 const S = struct {
285286 fn foo(args: anytype) !void {
286 try comptime expect(@TypeOf(args[0]) == f64);
287 comptime assert(@TypeOf(args[0]) == f64);
287288 try expect(args[0] > 12.33 and args[0] < 12.35);
288289 }
289290 };
test/behavior/call.zig+5-4
......@@ -1,5 +1,6 @@
11const builtin = @import("builtin");
22const std = @import("std");
3const assert = std.debug.assert;
34const expect = std.testing.expect;
45const expectEqual = std.testing.expectEqual;
56
......@@ -10,11 +11,11 @@ test "super basic invocations" {
1011 }
1112 }.foo;
1213 try expect(@call(.auto, foo, .{}) == 1234);
13 try comptime expect(@call(.always_inline, foo, .{}) == 1234);
14 comptime assert(@call(.always_inline, foo, .{}) == 1234);
1415 {
1516 // comptime call without comptime keyword
1617 const result = @call(.compile_time, foo, .{}) == 1234;
17 try comptime expect(result);
18 comptime assert(result);
1819 }
1920}
2021
......@@ -42,7 +43,7 @@ test "basic invocations" {
4243 {
4344 // comptime call without comptime keyword
4445 const result = @call(.compile_time, foo, .{}) == 1234;
45 try comptime expect(result);
46 comptime assert(result);
4647 }
4748 {
4849 // call of non comptime-known function
......@@ -73,7 +74,7 @@ test "tuple parameters" {
7374 try expect(@call(.auto, add, .{ a, b }) == 46);
7475 try expect(@call(.auto, add, .{ 12, 34 }) == 46);
7576 if (false) {
76 try comptime expect(@call(.auto, add, .{ 12, 34 }) == 46); // TODO
77 comptime assert(@call(.auto, add, .{ 12, 34 }) == 46); // TODO
7778 }
7879 try expect(comptime @call(.auto, add, .{ 12, 34 }) == 46);
7980 {
test/behavior/cast.zig+22-22
......@@ -63,7 +63,7 @@ test "implicit cast comptime numbers to any type when the value fits" {
6363}
6464
6565test "implicit cast comptime_int to comptime_float" {
66 try comptime expect(@as(comptime_float, 10) == @as(f32, 10));
66 comptime assert(@as(comptime_float, 10) == @as(f32, 10));
6767 try expect(2 == 2.0);
6868}
6969
......@@ -313,11 +313,11 @@ test "peer result null and comptime_int" {
313313 };
314314
315315 try expect(S.blah(0) == null);
316 try comptime expect(S.blah(0) == null);
316 comptime assert(S.blah(0) == null);
317317 try expect(S.blah(10).? == 1);
318 try comptime expect(S.blah(10).? == 1);
318 comptime assert(S.blah(10).? == 1);
319319 try expect(S.blah(-10).? == -1);
320 try comptime expect(S.blah(-10).? == -1);
320 comptime assert(S.blah(-10).? == -1);
321321}
322322
323323test "*const ?[*]const T to [*c]const [*c]const T" {
......@@ -393,7 +393,7 @@ test "peer type unsigned int to signed" {
393393 var y: i32 = -5;
394394 _ = .{ &w, &x, &y };
395395 const a = w + y + x;
396 try comptime expect(@TypeOf(a) == i32);
396 comptime assert(@TypeOf(a) == i32);
397397 try expect(a == 7);
398398}
399399
......@@ -542,9 +542,9 @@ test "peer type resolution: error and [N]T" {
542542 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
543543
544544 try expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
545 try comptime expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
545 comptime assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
546546 try expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
547 try comptime expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
547 comptime assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
548548}
549549
550550fn testPeerErrorAndArray(x: u8) anyerror![]const u8 {
......@@ -1038,15 +1038,15 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" {
10381038 var array: [4:0]u8 = undefined;
10391039 array[4] = 0; // TODO remove this when #4372 is solved
10401040 const slice: [:0]u8 = array[0..4 :0];
1041 try comptime expect(@TypeOf(slice, "hi") == [:0]const u8);
1042 try comptime expect(@TypeOf("hi", slice) == [:0]const u8);
1041 comptime assert(@TypeOf(slice, "hi") == [:0]const u8);
1042 comptime assert(@TypeOf("hi", slice) == [:0]const u8);
10431043}
10441044
10451045test "peer type resolve array pointers, one of them const" {
10461046 var array1: [4]u8 = undefined;
10471047 const array2: [5]u8 = undefined;
1048 try comptime expect(@TypeOf(&array1, &array2) == []const u8);
1049 try comptime expect(@TypeOf(&array2, &array1) == []const u8);
1048 comptime assert(@TypeOf(&array1, &array2) == []const u8);
1049 comptime assert(@TypeOf(&array2, &array1) == []const u8);
10501050}
10511051
10521052test "peer type resolve array pointer and unknown pointer" {
......@@ -1056,17 +1056,17 @@ test "peer type resolve array pointer and unknown pointer" {
10561056 var ptr: [*]u8 = undefined;
10571057 _ = .{ &const_ptr, &ptr };
10581058
1059 try comptime expect(@TypeOf(&array, ptr) == [*]u8);
1060 try comptime expect(@TypeOf(ptr, &array) == [*]u8);
1059 comptime assert(@TypeOf(&array, ptr) == [*]u8);
1060 comptime assert(@TypeOf(ptr, &array) == [*]u8);
10611061
1062 try comptime expect(@TypeOf(&const_array, ptr) == [*]const u8);
1063 try comptime expect(@TypeOf(ptr, &const_array) == [*]const u8);
1062 comptime assert(@TypeOf(&const_array, ptr) == [*]const u8);
1063 comptime assert(@TypeOf(ptr, &const_array) == [*]const u8);
10641064
1065 try comptime expect(@TypeOf(&array, const_ptr) == [*]const u8);
1066 try comptime expect(@TypeOf(const_ptr, &array) == [*]const u8);
1065 comptime assert(@TypeOf(&array, const_ptr) == [*]const u8);
1066 comptime assert(@TypeOf(const_ptr, &array) == [*]const u8);
10671067
1068 try comptime expect(@TypeOf(&const_array, const_ptr) == [*]const u8);
1069 try comptime expect(@TypeOf(const_ptr, &const_array) == [*]const u8);
1068 comptime assert(@TypeOf(&const_array, const_ptr) == [*]const u8);
1069 comptime assert(@TypeOf(const_ptr, &const_array) == [*]const u8);
10701070}
10711071
10721072test "comptime float casts" {
......@@ -1214,7 +1214,7 @@ test "implicitly cast from [N]T to ?[]const T" {
12141214 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
12151215
12161216 try expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
1217 try comptime expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
1217 comptime assert(mem.eql(u8, castToOptionalSlice().?, "hi"));
12181218}
12191219
12201220fn castToOptionalSlice() ?[]const u8 {
......@@ -1351,8 +1351,8 @@ test "peer resolve arrays of different size to const slice" {
13511351
13521352 try expect(mem.eql(u8, boolToStr(true), "true"));
13531353 try expect(mem.eql(u8, boolToStr(false), "false"));
1354 try comptime expect(mem.eql(u8, boolToStr(true), "true"));
1355 try comptime expect(mem.eql(u8, boolToStr(false), "false"));
1354 comptime assert(mem.eql(u8, boolToStr(true), "true"));
1355 comptime assert(mem.eql(u8, boolToStr(false), "false"));
13561356}
13571357fn boolToStr(b: bool) []const u8 {
13581358 return if (b) "true" else "false";
test/behavior/enum.zig+9-9
......@@ -773,12 +773,12 @@ test "set enum tag type" {
773773 {
774774 var x = Small.One;
775775 x = Small.Two;
776 try comptime expect(Tag(Small) == u2);
776 comptime assert(Tag(Small) == u2);
777777 }
778778 {
779779 var x = Small2.One;
780780 x = Small2.Two;
781 try comptime expect(Tag(Small2) == u2);
781 comptime assert(Tag(Small2) == u2);
782782 }
783783}
784784
......@@ -795,7 +795,7 @@ test "enum with 1 field but explicit tag type should still have the tag type" {
795795 const Enum = enum(u8) {
796796 B = 2,
797797 };
798 try comptime expect(@sizeOf(Enum) == @sizeOf(u8));
798 comptime assert(@sizeOf(Enum) == @sizeOf(u8));
799799}
800800
801801test "signed integer as enum tag" {
......@@ -834,12 +834,12 @@ test "enum with comptime_int tag type" {
834834 Two = 2,
835835 Three = 1,
836836 };
837 try comptime expect(Tag(Enum) == comptime_int);
837 comptime assert(Tag(Enum) == comptime_int);
838838}
839839
840840test "enum with one member default to u0 tag type" {
841841 const E0 = enum { X };
842 try comptime expect(Tag(E0) == u0);
842 comptime assert(Tag(E0) == u0);
843843}
844844
845845const EnumWithOneMember = enum { Eof };
......@@ -989,7 +989,7 @@ test "@tagName" {
989989 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
990990
991991 try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
992 try comptime expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
992 comptime assert(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
993993}
994994
995995fn testEnumTagNameBare(n: anytype) []const u8 {
......@@ -1005,7 +1005,7 @@ test "@tagName non-exhaustive enum" {
10051005 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
10061006
10071007 try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
1008 try comptime expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
1008 comptime assert(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
10091009}
10101010const NonExhaustive = enum(u8) { A, B, _ };
10111011
......@@ -1044,7 +1044,7 @@ test "@tagName on enum literals" {
10441044 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
10451045
10461046 try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
1047 try comptime expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
1047 comptime assert(mem.eql(u8, @tagName(.FooBar), "FooBar"));
10481048}
10491049
10501050test "tag name with signed enum values" {
......@@ -1101,7 +1101,7 @@ test "bit field access with enum fields" {
11011101 try expect(getA(&data) == A.Two);
11021102 try expect(getB(&data) == B.Three3);
11031103 try expect(getC(&data) == C.Four4);
1104 try comptime expect(@sizeOf(BitFieldOfEnums) == 1);
1104 comptime assert(@sizeOf(BitFieldOfEnums) == 1);
11051105
11061106 data.b = B.Four3;
11071107 try expect(data.b == B.Four3);
test/behavior/error.zig+5-4
......@@ -1,5 +1,6 @@
11const builtin = @import("builtin");
22const std = @import("std");
3const assert = std.debug.assert;
34const expect = std.testing.expect;
45const expectEqual = std.testing.expectEqual;
56const mem = std.mem;
......@@ -458,7 +459,7 @@ test "return function call to error set from error union function" {
458459 }
459460 };
460461 try expectError(error.Failure, S.errorable());
461 try comptime expectError(error.Failure, S.errorable());
462 comptime assert(error.Failure == S.errorable());
462463}
463464
464465test "optional error set is the same size as error set" {
......@@ -466,15 +467,15 @@ test "optional error set is the same size as error set" {
466467 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
467468 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
468469
469 try comptime expect(@sizeOf(?anyerror) == @sizeOf(anyerror));
470 try comptime expect(@alignOf(?anyerror) == @alignOf(anyerror));
470 comptime assert(@sizeOf(?anyerror) == @sizeOf(anyerror));
471 comptime assert(@alignOf(?anyerror) == @alignOf(anyerror));
471472 const S = struct {
472473 fn returnsOptErrSet() ?anyerror {
473474 return null;
474475 }
475476 };
476477 try expect(S.returnsOptErrSet() == null);
477 try comptime expect(S.returnsOptErrSet() == null);
478 comptime assert(S.returnsOptErrSet() == null);
478479}
479480
480481test "nested catch" {
test/behavior/eval.zig+8-8
......@@ -55,7 +55,7 @@ fn staticAdd(a: i32, b: i32) i32 {
5555
5656test "const expr eval on single expr blocks" {
5757 try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
58 try comptime expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
58 comptime assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
5959}
6060
6161fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
......@@ -426,7 +426,7 @@ test "f64 at compile time is lossy" {
426426}
427427
428428test {
429 try comptime expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192);
429 comptime assert(@as(f128, 1 << 113) == 10384593717069655257060992658440192);
430430}
431431
432432fn copyWithPartialInline(s: []u32, b: []u8) void {
......@@ -613,7 +613,7 @@ test "const global shares pointer with other same one" {
613613 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
614614
615615 try assertEqualPtrs(&hi1[0], &hi2[0]);
616 try comptime expect(&hi1[0] == &hi2[0]);
616 comptime assert(&hi1[0] == &hi2[0]);
617617}
618618fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void {
619619 try expect(ptr1 == ptr2);
......@@ -634,8 +634,8 @@ fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void {
634634test "string literal used as comptime slice is memoized" {
635635 const a = "link";
636636 const b = "link";
637 try comptime expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);
638 try comptime expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);
637 comptime assert(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);
638 comptime assert(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);
639639}
640640
641641pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
......@@ -953,7 +953,7 @@ test "const local with comptime init through array init" {
953953 S.declarations(E1),
954954 };
955955
956 try comptime expect(decls[0][0].name[0] == 'a');
956 comptime assert(decls[0][0].name[0] == 'a');
957957}
958958
959959test "closure capture type of runtime-known parameter" {
......@@ -1339,7 +1339,7 @@ test "value in if block is comptime-known" {
13391339 const s = if (false) S{ .str = "a" } else S{ .str = "b" };
13401340 break :blk "foo" ++ s.str;
13411341 };
1342 try comptime expect(std.mem.eql(u8, first, second));
1342 comptime assert(std.mem.eql(u8, first, second));
13431343}
13441344
13451345test "lazy sizeof is resolved in division" {
......@@ -1561,7 +1561,7 @@ test "comptime function turns function value to function pointer" {
15611561 fnPtr(Nil),
15621562 };
15631563 };
1564 try comptime expect(S.foo[0] == &S.Nil);
1564 comptime assert(S.foo[0] == &S.Nil);
15651565}
15661566
15671567test "container level const and var have unique addresses" {
test/behavior/fn.zig+2-1
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const testing = std.testing;
4const assert = std.debug.assert;
45const expect = testing.expect;
56const expectEqual = testing.expectEqual;
67
......@@ -207,7 +208,7 @@ test "pass by non-copying value through var arg" {
207208}
208209
209210fn addPointCoordsVar(pt: anytype) !i32 {
210 try comptime expect(@TypeOf(pt) == Point);
211 comptime assert(@TypeOf(pt) == Point);
211212 return pt.x + pt.y;
212213}
213214
test/behavior/math.zig+3-2
......@@ -1,5 +1,6 @@
11const builtin = @import("builtin");
22const std = @import("std");
3const assert = std.debug.assert;
34const expect = std.testing.expect;
45const expectEqual = std.testing.expectEqual;
56const expectEqualSlices = std.testing.expectEqualSlices;
......@@ -246,7 +247,7 @@ fn testFloatEqualityImpl(x: f64, y: f64) !void {
246247}
247248
248249test "hex float literal parsing" {
249 try comptime expect(0x1.0 == 1.0);
250 comptime assert(0x1.0 == 1.0);
250251}
251252
252253test "hex float literal within range" {
......@@ -1530,7 +1531,7 @@ test "@round f32/f64" {
15301531 const x = 14.0;
15311532 const y = x + 0.4;
15321533 const z = @round(y);
1533 try comptime expect(x == z);
1534 comptime assert(x == z);
15341535}
15351536
15361537test "@round f80" {
test/behavior/optional.zig+2-1
......@@ -1,6 +1,7 @@
11const builtin = @import("builtin");
22const std = @import("std");
33const testing = std.testing;
4const assert = std.debug.assert;
45const expect = testing.expect;
56const expectEqual = testing.expectEqual;
67const expectEqualStrings = std.testing.expectEqualStrings;
......@@ -20,7 +21,7 @@ test "passing an optional integer as a parameter" {
2021 }
2122 };
2223 try expect(S.entry());
23 try comptime expect(S.entry());
24 comptime assert(S.entry());
2425}
2526
2627pub const EmptyStruct = struct {};
test/behavior/pointers.zig+22-21
......@@ -1,6 +1,7 @@
11const builtin = @import("builtin");
22const std = @import("std");
33const testing = std.testing;
4const assert = std.debug.assert;
45const expect = testing.expect;
56const expectError = testing.expectError;
67
......@@ -42,7 +43,7 @@ test "pointer arithmetic" {
4243}
4344
4445test "double pointer parsing" {
45 try comptime expect(PtrOf(PtrOf(i32)) == **i32);
46 comptime assert(PtrOf(PtrOf(i32)) == **i32);
4647}
4748
4849fn PtrOf(comptime T: type) type {
......@@ -62,7 +63,7 @@ test "implicit cast single item pointer to C pointer and back" {
6263test "initialize const optional C pointer to null" {
6364 const a: ?[*c]i32 = null;
6465 try expect(a == null);
65 try comptime expect(a == null);
66 comptime assert(a == null);
6667}
6768
6869test "assigning integer to C pointer" {
......@@ -204,11 +205,11 @@ test "allowzero pointer and slice" {
204205 var runtime_zero: usize = 0;
205206 _ = &runtime_zero;
206207 var slice = ptr[runtime_zero..10];
207 try comptime expect(@TypeOf(slice) == []allowzero i32);
208 comptime assert(@TypeOf(slice) == []allowzero i32);
208209 try expect(@intFromPtr(&slice[5]) == 20);
209210
210 try comptime expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero);
211 try comptime expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero);
211 comptime assert(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero);
212 comptime assert(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero);
212213}
213214
214215test "assign null directly to C pointer and test null equality" {
......@@ -230,17 +231,17 @@ test "assign null directly to C pointer and test null equality" {
230231 try expect((x orelse &otherx) == &otherx);
231232
232233 const y: [*c]i32 = null;
233 try comptime expect(y == null);
234 try comptime expect(null == y);
235 try comptime expect(!(y != null));
236 try comptime expect(!(null != y));
234 comptime assert(y == null);
235 comptime assert(null == y);
236 comptime assert(!(y != null));
237 comptime assert(!(null != y));
237238 if (y) |same_y| {
238239 _ = same_y;
239240 @panic("fail");
240241 }
241242 const othery: i32 = undefined;
242243 const ptr_othery = &othery;
243 try comptime expect((y orelse ptr_othery) == ptr_othery);
244 comptime assert((y orelse ptr_othery) == ptr_othery);
244245
245246 var n: i32 = 1234;
246247 const x1: [*c]i32 = &n;
......@@ -258,17 +259,17 @@ test "assign null directly to C pointer and test null equality" {
258259
259260 const nc: i32 = 1234;
260261 const y1: [*c]const i32 = &nc;
261 try comptime expect(!(y1 == null));
262 try comptime expect(!(null == y1));
263 try comptime expect(y1 != null);
264 try comptime expect(null != y1);
265 try comptime expect(y1.?.* == 1234);
262 comptime assert(!(y1 == null));
263 comptime assert(!(null == y1));
264 comptime assert(y1 != null);
265 comptime assert(null != y1);
266 comptime assert(y1.?.* == 1234);
266267 if (y1) |same_y1| {
267268 try expect(same_y1.* == 1234);
268269 } else {
269270 @compileError("fail");
270271 }
271 try comptime expect((y1 orelse &othery) == y1);
272 comptime assert((y1 orelse &othery) == y1);
272273}
273274
274275test "array initialization types" {
......@@ -325,7 +326,7 @@ test "pointer sentinel with enums" {
325326 fn doTheTest() !void {
326327 var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one };
327328 _ = &ptr;
328 try expect(ptr[4] == .sentinel); // TODO this should be try comptime expect, see #3731
329 try expect(ptr[4] == .sentinel); // TODO this should be comptime assert, see #3731
329330 }
330331 };
331332 try S.doTheTest();
......@@ -341,7 +342,7 @@ test "pointer sentinel with optional element" {
341342 fn doTheTest() !void {
342343 var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 };
343344 _ = &ptr;
344 try expect(ptr[4] == null); // TODO this should be try comptime expect, see #3731
345 try expect(ptr[4] == null); // TODO this should be comptime assert, see #3731
345346 }
346347 };
347348 try S.doTheTest();
......@@ -358,7 +359,7 @@ test "pointer sentinel with +inf" {
358359 const inf_f32 = comptime std.math.inf(f32);
359360 var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 };
360361 _ = &ptr;
361 try expect(ptr[4] == inf_f32); // TODO this should be try comptime expect, see #3731
362 try expect(ptr[4] == inf_f32); // TODO this should be comptime assert, see #3731
362363 }
363364 };
364365 try S.doTheTest();
......@@ -409,11 +410,11 @@ test "@intFromPtr on null optional at comptime" {
409410 const pointer = @as(?*u8, @ptrFromInt(0x000));
410411 const x = @intFromPtr(pointer);
411412 _ = x;
412 try comptime expect(0 == @intFromPtr(pointer));
413 comptime assert(0 == @intFromPtr(pointer));
413414 }
414415 {
415416 const pointer = @as(?*u8, @ptrFromInt(0xf00));
416 try comptime expect(0xf00 == @intFromPtr(pointer));
417 comptime assert(0xf00 == @intFromPtr(pointer));
417418 }
418419}
419420
test/behavior/sizeof_and_typeof.zig+9-8
......@@ -1,5 +1,6 @@
11const builtin = @import("builtin");
22const std = @import("std");
3const assert = std.debug.assert;
34const expect = std.testing.expect;
45const expectEqual = std.testing.expectEqual;
56
......@@ -23,24 +24,24 @@ test "@TypeOf() with multiple arguments" {
2324 var var_2: u8 = undefined;
2425 var var_3: u64 = undefined;
2526 _ = .{ &var_1, &var_2, &var_3 };
26 try comptime expect(@TypeOf(var_1, var_2, var_3) == u64);
27 comptime assert(@TypeOf(var_1, var_2, var_3) == u64);
2728 }
2829 {
2930 var var_1: f16 = undefined;
3031 var var_2: f32 = undefined;
3132 var var_3: f64 = undefined;
3233 _ = .{ &var_1, &var_2, &var_3 };
33 try comptime expect(@TypeOf(var_1, var_2, var_3) == f64);
34 comptime assert(@TypeOf(var_1, var_2, var_3) == f64);
3435 }
3536 {
3637 var var_1: u16 = undefined;
3738 _ = &var_1;
38 try comptime expect(@TypeOf(var_1, 0xffff) == u16);
39 comptime assert(@TypeOf(var_1, 0xffff) == u16);
3940 }
4041 {
4142 var var_1: f32 = undefined;
4243 _ = &var_1;
43 try comptime expect(@TypeOf(var_1, 3.1415) == f32);
44 comptime assert(@TypeOf(var_1, 3.1415) == f32);
4445 }
4546}
4647
......@@ -150,7 +151,7 @@ test "@TypeOf() has no runtime side effects" {
150151 };
151152 var data: i32 = 0;
152153 const T = @TypeOf(S.foo(i32, &data));
153 try comptime expect(T == i32);
154 comptime assert(T == i32);
154155 try expect(data == 0);
155156}
156157
......@@ -165,7 +166,7 @@ test "branching logic inside @TypeOf" {
165166 }
166167 };
167168 const T = @TypeOf(S.foo() catch undefined);
168 try comptime expect(T == i32);
169 comptime assert(T == i32);
169170 try expect(S.data == 0);
170171}
171172
......@@ -238,7 +239,7 @@ test "hardcoded address in typeof expression" {
238239 }
239240 };
240241 try expect(S.func() == 0);
241 try comptime expect(S.func() == 0);
242 comptime assert(S.func() == 0);
242243}
243244
244245test "array access of generic param in typeof expression" {
......@@ -248,7 +249,7 @@ test "array access of generic param in typeof expression" {
248249 }
249250 };
250251 try expect(S.first("a") == 'a');
251 try comptime expect(S.first("a") == 'a');
252 comptime assert(S.first("a") == 'a');
252253}
253254
254255test "lazy size cast to float" {
test/behavior/slice.zig+77-76
......@@ -1,5 +1,6 @@
11const builtin = @import("builtin");
22const std = @import("std");
3const assert = std.debug.assert;
34const expect = std.testing.expect;
45const expectEqualSlices = std.testing.expectEqualSlices;
56const expectEqualStrings = std.testing.expectEqualStrings;
......@@ -137,7 +138,7 @@ test "slice of hardcoded address to pointer" {
137138 const S = struct {
138139 fn doTheTest() !void {
139140 const pointer = @as([*]u8, @ptrFromInt(0x04))[0..2];
140 try comptime expect(@TypeOf(pointer) == *[2]u8);
141 comptime assert(@TypeOf(pointer) == *[2]u8);
141142 const slice: []const u8 = pointer;
142143 try expect(@intFromPtr(slice.ptr) == 4);
143144 try expect(slice.len == 2);
......@@ -210,9 +211,9 @@ test "slice string literal has correct type" {
210211 }
211212 var runtime_zero: usize = 0;
212213 _ = &runtime_zero;
213 try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8);
214 comptime assert(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8);
214215 const array = [_]i32{ 1, 2, 3, 4 };
215 try comptime expect(@TypeOf(array[runtime_zero..]) == []const i32);
216 comptime assert(@TypeOf(array[runtime_zero..]) == []const i32);
216217}
217218
218219test "result location zero sized array inside struct field implicit cast to slice" {
......@@ -260,8 +261,8 @@ test "C pointer slice access" {
260261
261262 var runtime_zero: usize = 0;
262263 _ = &runtime_zero;
263 try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));
264 try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1]));
264 comptime assert(@TypeOf(c_ptr[runtime_zero..1]) == []const u32);
265 comptime assert(@TypeOf(c_ptr[0..1]) == *const [1]u32);
265266
266267 for (c_ptr[0..5]) |*cl| {
267268 try expect(@as(u32, 42) == cl.*);
......@@ -314,11 +315,11 @@ test "obtaining a null terminated slice" {
314315 _ = &runtime_len;
315316 const ptr2 = buf[0..runtime_len :0];
316317 // ptr2 is a null-terminated slice
317 try comptime expect(@TypeOf(ptr2) == [:0]u8);
318 try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8);
318 comptime assert(@TypeOf(ptr2) == [:0]u8);
319 comptime assert(@TypeOf(ptr2[0..2]) == *[2]u8);
319320 var runtime_zero: usize = 0;
320321 _ = &runtime_zero;
321 try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8);
322 comptime assert(@TypeOf(ptr2[runtime_zero..2]) == []u8);
322323}
323324
324325test "empty array to slice" {
......@@ -366,7 +367,7 @@ test "slice multi-pointer without end" {
366367 var array = [5]u8{ 1, 2, 3, 4, 5 };
367368 const pointer: [*]u8 = &array;
368369 const slice = pointer[1..];
369 try comptime expect(@TypeOf(slice) == [*]u8);
370 comptime assert(@TypeOf(slice) == [*]u8);
370371 try expect(slice[0] == 2);
371372 try expect(slice[1] == 3);
372373 }
......@@ -375,12 +376,12 @@ test "slice multi-pointer without end" {
375376 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
376377 const pointer: [*:0]u8 = &array;
377378
378 try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8);
379 try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
380 try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8);
379 comptime assert(@TypeOf(pointer[1..3]) == *[2]u8);
380 comptime assert(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
381 comptime assert(@TypeOf(pointer[1..5 :0]) == *[4:0]u8);
381382
382383 const slice = pointer[1..];
383 try comptime expect(@TypeOf(slice) == [*:0]u8);
384 comptime assert(@TypeOf(slice) == [*:0]u8);
384385 try expect(slice[0] == 2);
385386 try expect(slice[1] == 3);
386387 }
......@@ -422,29 +423,29 @@ test "slice syntax resulting in pointer-to-array" {
422423 fn testArray() !void {
423424 var array = [5]u8{ 1, 2, 3, 4, 5 };
424425 const slice = array[1..3];
425 try comptime expect(@TypeOf(slice) == *[2]u8);
426 comptime assert(@TypeOf(slice) == *[2]u8);
426427 try expect(slice[0] == 2);
427428 try expect(slice[1] == 3);
428429 }
429430
430431 fn testArrayZ() !void {
431432 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
432 try comptime expect(@TypeOf(array[1..3]) == *[2]u8);
433 try comptime expect(@TypeOf(array[1..5]) == *[4:0]u8);
434 try comptime expect(@TypeOf(array[1..]) == *[4:0]u8);
435 try comptime expect(@TypeOf(array[1..3 :4]) == *[2:4]u8);
433 comptime assert(@TypeOf(array[1..3]) == *[2]u8);
434 comptime assert(@TypeOf(array[1..5]) == *[4:0]u8);
435 comptime assert(@TypeOf(array[1..]) == *[4:0]u8);
436 comptime assert(@TypeOf(array[1..3 :4]) == *[2:4]u8);
436437 }
437438
438439 fn testArray0() !void {
439440 {
440441 var array = [0]u8{};
441442 const slice = array[0..0];
442 try comptime expect(@TypeOf(slice) == *[0]u8);
443 comptime assert(@TypeOf(slice) == *[0]u8);
443444 }
444445 {
445446 var array = [0:0]u8{};
446447 const slice = array[0..0];
447 try comptime expect(@TypeOf(slice) == *[0:0]u8);
448 comptime assert(@TypeOf(slice) == *[0:0]u8);
448449 try expect(slice[0] == 0);
449450 }
450451 }
......@@ -452,16 +453,16 @@ test "slice syntax resulting in pointer-to-array" {
452453 fn testArrayAlign() !void {
453454 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
454455 const slice = array[4..5];
455 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);
456 comptime assert(@TypeOf(slice) == *align(4) [1]u8);
456457 try expect(slice[0] == 5);
457 try comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8);
458 comptime assert(@TypeOf(array[0..2]) == *align(4) [2]u8);
458459 }
459460
460461 fn testPointer() !void {
461462 var array = [5]u8{ 1, 2, 3, 4, 5 };
462463 var pointer: [*]u8 = &array;
463464 const slice = pointer[1..3];
464 try comptime expect(@TypeOf(slice) == *[2]u8);
465 comptime assert(@TypeOf(slice) == *[2]u8);
465466 try expect(slice[0] == 2);
466467 try expect(slice[1] == 3);
467468 }
......@@ -469,14 +470,14 @@ test "slice syntax resulting in pointer-to-array" {
469470 fn testPointerZ() !void {
470471 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
471472 var pointer: [*:0]u8 = &array;
472 try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8);
473 try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
473 comptime assert(@TypeOf(pointer[1..3]) == *[2]u8);
474 comptime assert(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
474475 }
475476
476477 fn testPointer0() !void {
477478 var pointer: [*]const u0 = &[1]u0{0};
478479 const slice = pointer[0..1];
479 try comptime expect(@TypeOf(slice) == *const [1]u0);
480 comptime assert(@TypeOf(slice) == *const [1]u0);
480481 try expect(slice[0] == 0);
481482 }
482483
......@@ -484,16 +485,16 @@ test "slice syntax resulting in pointer-to-array" {
484485 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
485486 var pointer: [*]align(4) u8 = &array;
486487 const slice = pointer[4..5];
487 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);
488 comptime assert(@TypeOf(slice) == *align(4) [1]u8);
488489 try expect(slice[0] == 5);
489 try comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8);
490 comptime assert(@TypeOf(pointer[0..2]) == *align(4) [2]u8);
490491 }
491492
492493 fn testSlice() !void {
493494 var array = [5]u8{ 1, 2, 3, 4, 5 };
494495 var src_slice: []u8 = &array;
495496 const slice = src_slice[1..3];
496 try comptime expect(@TypeOf(slice) == *[2]u8);
497 comptime assert(@TypeOf(slice) == *[2]u8);
497498 try expect(slice[0] == 2);
498499 try expect(slice[1] == 3);
499500 }
......@@ -501,30 +502,30 @@ test "slice syntax resulting in pointer-to-array" {
501502 fn testSliceZ() !void {
502503 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
503504 var slice: [:0]u8 = &array;
504 try comptime expect(@TypeOf(slice[1..3]) == *[2]u8);
505 try comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
505 comptime assert(@TypeOf(slice[1..3]) == *[2]u8);
506 comptime assert(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
506507 if (@inComptime()) {
507 try comptime expect(@TypeOf(slice[1..]) == *[4:0]u8);
508 comptime assert(@TypeOf(slice[1..]) == *[4:0]u8);
508509 } else {
509 try comptime expect(@TypeOf(slice[1..]) == [:0]u8);
510 comptime assert(@TypeOf(slice[1..]) == [:0]u8);
510511 }
511512 }
512513
513514 fn testSliceOpt() !void {
514515 var array: [2]u8 = [2]u8{ 1, 2 };
515516 var slice: ?[]u8 = &array;
516 try comptime expect(@TypeOf(&array, slice) == ?[]u8);
517 try comptime expect(@TypeOf(slice, &array) == ?[]u8);
518 try comptime expect(@TypeOf(slice.?[0..2]) == *[2]u8);
517 comptime assert(@TypeOf(&array, slice) == ?[]u8);
518 comptime assert(@TypeOf(slice, &array) == ?[]u8);
519 comptime assert(@TypeOf(slice.?[0..2]) == *[2]u8);
519520 }
520521
521522 fn testSliceAlign() !void {
522523 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
523524 var src_slice: []align(4) u8 = &array;
524525 const slice = src_slice[4..5];
525 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);
526 comptime assert(@TypeOf(slice) == *align(4) [1]u8);
526527 try expect(slice[0] == 5);
527 try comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8);
528 comptime assert(@TypeOf(src_slice[0..2]) == *align(4) [2]u8);
528529 }
529530
530531 fn testConcatStrLiterals() !void {
......@@ -535,62 +536,62 @@ test "slice syntax resulting in pointer-to-array" {
535536 fn testSliceLength() !void {
536537 var array = [5]u8{ 1, 2, 3, 4, 5 };
537538 var slice: []u8 = &array;
538 try comptime expect(@TypeOf(slice[1..][0..2]) == *[2]u8);
539 try comptime expect(@TypeOf(slice[1..][0..4]) == *[4]u8);
540 try comptime expect(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8);
539 comptime assert(@TypeOf(slice[1..][0..2]) == *[2]u8);
540 comptime assert(@TypeOf(slice[1..][0..4]) == *[4]u8);
541 comptime assert(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8);
541542 }
542543
543544 fn testSliceLengthZ() !void {
544545 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
545546 var slice: [:0]u8 = &array;
546 try comptime expect(@TypeOf(slice[1..][0..2]) == *[2]u8);
547 try comptime expect(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8);
548 try comptime expect(@TypeOf(slice[1.. :0][0..2]) == *[2]u8);
549 try comptime expect(@TypeOf(slice[1.. :0][0..2 :4]) == *[2:4]u8);
547 comptime assert(@TypeOf(slice[1..][0..2]) == *[2]u8);
548 comptime assert(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8);
549 comptime assert(@TypeOf(slice[1.. :0][0..2]) == *[2]u8);
550 comptime assert(@TypeOf(slice[1.. :0][0..2 :4]) == *[2:4]u8);
550551 }
551552
552553 fn testArrayLength() !void {
553554 var array = [5]u8{ 1, 2, 3, 4, 5 };
554 try comptime expect(@TypeOf(array[1..][0..2]) == *[2]u8);
555 try comptime expect(@TypeOf(array[1..][0..4]) == *[4]u8);
556 try comptime expect(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8);
555 comptime assert(@TypeOf(array[1..][0..2]) == *[2]u8);
556 comptime assert(@TypeOf(array[1..][0..4]) == *[4]u8);
557 comptime assert(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8);
557558 }
558559
559560 fn testArrayLengthZ() !void {
560561 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
561 try comptime expect(@TypeOf(array[1..][0..2]) == *[2]u8);
562 try comptime expect(@TypeOf(array[1..][0..4]) == *[4:0]u8);
563 try comptime expect(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8);
564 try comptime expect(@TypeOf(array[1.. :0][0..2]) == *[2]u8);
565 try comptime expect(@TypeOf(array[1.. :0][0..4]) == *[4:0]u8);
566 try comptime expect(@TypeOf(array[1.. :0][0..2 :4]) == *[2:4]u8);
562 comptime assert(@TypeOf(array[1..][0..2]) == *[2]u8);
563 comptime assert(@TypeOf(array[1..][0..4]) == *[4:0]u8);
564 comptime assert(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8);
565 comptime assert(@TypeOf(array[1.. :0][0..2]) == *[2]u8);
566 comptime assert(@TypeOf(array[1.. :0][0..4]) == *[4:0]u8);
567 comptime assert(@TypeOf(array[1.. :0][0..2 :4]) == *[2:4]u8);
567568 }
568569
569570 fn testMultiPointer() !void {
570571 var array = [5]u8{ 1, 2, 3, 4, 5 };
571572 var ptr: [*]u8 = &array;
572 try comptime expect(@TypeOf(ptr[1..][0..2]) == *[2]u8);
573 try comptime expect(@TypeOf(ptr[1..][0..4]) == *[4]u8);
574 try comptime expect(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8);
573 comptime assert(@TypeOf(ptr[1..][0..2]) == *[2]u8);
574 comptime assert(@TypeOf(ptr[1..][0..4]) == *[4]u8);
575 comptime assert(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8);
575576 }
576577
577578 fn testMultiPointerLengthZ() !void {
578579 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
579580 var ptr: [*]u8 = &array;
580 try comptime expect(@TypeOf(ptr[1..][0..2]) == *[2]u8);
581 try comptime expect(@TypeOf(ptr[1..][0..4]) == *[4]u8);
582 try comptime expect(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8);
583 try comptime expect(@TypeOf(ptr[1.. :0][0..2]) == *[2]u8);
584 try comptime expect(@TypeOf(ptr[1.. :0][0..4]) == *[4]u8);
585 try comptime expect(@TypeOf(ptr[1.. :0][0..2 :4]) == *[2:4]u8);
581 comptime assert(@TypeOf(ptr[1..][0..2]) == *[2]u8);
582 comptime assert(@TypeOf(ptr[1..][0..4]) == *[4]u8);
583 comptime assert(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8);
584 comptime assert(@TypeOf(ptr[1.. :0][0..2]) == *[2]u8);
585 comptime assert(@TypeOf(ptr[1.. :0][0..4]) == *[4]u8);
586 comptime assert(@TypeOf(ptr[1.. :0][0..2 :4]) == *[2:4]u8);
586587
587588 var ptr_z: [*:0]u8 = &array;
588 try comptime expect(@TypeOf(ptr_z[1..][0..2]) == *[2]u8);
589 try comptime expect(@TypeOf(ptr_z[1..][0..4]) == *[4]u8);
590 try comptime expect(@TypeOf(ptr_z[1..][0..2 :4]) == *[2:4]u8);
591 try comptime expect(@TypeOf(ptr_z[1.. :0][0..2]) == *[2]u8);
592 try comptime expect(@TypeOf(ptr_z[1.. :0][0..4]) == *[4]u8);
593 try comptime expect(@TypeOf(ptr_z[1.. :0][0..2 :4]) == *[2:4]u8);
589 comptime assert(@TypeOf(ptr_z[1..][0..2]) == *[2]u8);
590 comptime assert(@TypeOf(ptr_z[1..][0..4]) == *[4]u8);
591 comptime assert(@TypeOf(ptr_z[1..][0..2 :4]) == *[2:4]u8);
592 comptime assert(@TypeOf(ptr_z[1.. :0][0..2]) == *[2]u8);
593 comptime assert(@TypeOf(ptr_z[1.. :0][0..4]) == *[4]u8);
594 comptime assert(@TypeOf(ptr_z[1.. :0][0..2 :4]) == *[2:4]u8);
594595 }
595596
596597 fn testSingleItemPointer() !void {
......@@ -598,10 +599,10 @@ test "slice syntax resulting in pointer-to-array" {
598599 var ptr = &value;
599600
600601 const slice = ptr[0..1];
601 try comptime expect(@TypeOf(slice) == *[1]u8);
602 comptime assert(@TypeOf(slice) == *[1]u8);
602603 try expect(slice[0] == 1);
603604
604 try comptime expect(@TypeOf(ptr[0..0]) == *[0]u8);
605 comptime assert(@TypeOf(ptr[0..0]) == *[0]u8);
605606 }
606607 };
607608
......@@ -623,9 +624,9 @@ test "slice pointer-to-array null terminated" {
623624
624625 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
625626 var slice: [:0]u8 = &array;
626 try comptime expect(@TypeOf(slice[1..3]) == *[2]u8);
627 try comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
628 try comptime expect(@TypeOf(slice[1..]) == [:0]u8);
627 comptime assert(@TypeOf(slice[1..3]) == *[2]u8);
628 comptime assert(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
629 comptime assert(@TypeOf(slice[1..]) == [:0]u8);
629630}
630631
631632test "slice pointer-to-array zero length" {
......@@ -650,13 +651,13 @@ test "slice pointer-to-array zero length" {
650651 var array = [0]u8{};
651652 var src_slice: []u8 = &array;
652653 const slice = src_slice[0..0];
653 try comptime expect(@TypeOf(slice) == *[0]u8);
654 comptime assert(@TypeOf(slice) == *[0]u8);
654655 }
655656 {
656657 var array = [0:0]u8{};
657658 var src_slice: [:0]u8 = &array;
658659 const slice = src_slice[0..0];
659 try comptime expect(@TypeOf(slice) == *[0]u8);
660 comptime assert(@TypeOf(slice) == *[0]u8);
660661 }
661662}
662663
test/behavior/struct.zig+3-3
......@@ -591,7 +591,7 @@ test "bit field access" {
591591 try expect(getA(&data) == 1);
592592 try expect(getB(&data) == 2);
593593 try expect(getC(&data) == 3);
594 try comptime expect(@sizeOf(BitField1) == 1);
594 comptime assert(@sizeOf(BitField1) == 1);
595595
596596 data.b += 1;
597597 try expect(data.b == 3);
......@@ -730,7 +730,7 @@ test "packed struct with u0 field access" {
730730 };
731731 var s = S{ .f0 = 0 };
732732 _ = &s;
733 try comptime expect(s.f0 == 0);
733 comptime assert(s.f0 == 0);
734734}
735735
736736test "access to global struct fields" {
......@@ -947,7 +947,7 @@ test "comptime struct field" {
947947
948948 var foo: T = undefined;
949949 _ = &foo;
950 try comptime expect(foo.b == 1234);
950 comptime assert(foo.b == 1234);
951951}
952952
953953test "tuple element initialized with fn call" {
test/behavior/switch.zig+3-3
......@@ -600,9 +600,9 @@ test "switch on pointer type" {
600600 try expect(1 == S.doTheTest(S.P1));
601601 try expect(2 == S.doTheTest(S.P2));
602602 try expect(3 == S.doTheTest(S.P3));
603 try comptime expect(1 == S.doTheTest(S.P1));
604 try comptime expect(2 == S.doTheTest(S.P2));
605 try comptime expect(3 == S.doTheTest(S.P3));
603 comptime assert(1 == S.doTheTest(S.P1));
604 comptime assert(2 == S.doTheTest(S.P2));
605 comptime assert(3 == S.doTheTest(S.P3));
606606}
607607
608608test "switch on error set with single else" {
test/behavior/truncate.zig+3-2
......@@ -1,12 +1,13 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const assert = std.debug.assert;
34const expect = std.testing.expect;
45
56test "truncate u0 to larger integer allowed and has comptime-known result" {
67 var x: u0 = 0;
78 _ = &x;
89 const y = @as(u8, @truncate(x));
9 try comptime expect(y == 0);
10 comptime assert(y == 0);
1011}
1112
1213test "truncate.u0.literal" {
......@@ -31,7 +32,7 @@ test "truncate i0 to larger integer allowed and has comptime-known result" {
3132 var x: i0 = 0;
3233 _ = &x;
3334 const y: i8 = @truncate(x);
34 try comptime expect(y == 0);
35 comptime assert(y == 0);
3536}
3637
3738test "truncate.i0.literal" {
test/behavior/type_info.zig+2-1
......@@ -5,6 +5,7 @@ const mem = std.mem;
55const Type = std.builtin.Type;
66const TypeId = std.builtin.TypeId;
77
8const assert = std.debug.assert;
89const expect = std.testing.expect;
910const expectEqualStrings = std.testing.expectEqualStrings;
1011
......@@ -484,7 +485,7 @@ test "@typeInfo does not force declarations into existence" {
484485 @compileError("test failed");
485486 }
486487 };
487 try comptime expect(@typeInfo(S).Struct.fields.len == 1);
488 comptime assert(@typeInfo(S).Struct.fields.len == 1);
488489}
489490
490491fn add(a: i32, b: i32) i32 {
test/behavior/union.zig+11-11
......@@ -109,7 +109,7 @@ const ExternPtrOrInt = extern union {
109109 int: u64,
110110};
111111test "extern union size" {
112 try comptime expect(@sizeOf(ExternPtrOrInt) == 8);
112 comptime assert(@sizeOf(ExternPtrOrInt) == 8);
113113}
114114
115115test "0-sized extern union definition" {
......@@ -161,7 +161,7 @@ test "access a member of tagged union with conflicting enum tag name" {
161161 const B = void;
162162 };
163163
164 try comptime expect(Bar.A == u8);
164 comptime assert(Bar.A == u8);
165165}
166166
167167test "constant tagged union with payload" {
......@@ -371,14 +371,14 @@ const PackedPtrOrInt = packed union {
371371 int: u64,
372372};
373373test "packed union size" {
374 try comptime expect(@sizeOf(PackedPtrOrInt) == 8);
374 comptime assert(@sizeOf(PackedPtrOrInt) == 8);
375375}
376376
377377const ZeroBits = union {
378378 OnlyField: void,
379379};
380380test "union with only 1 field which is void should be zero bits" {
381 try comptime expect(@sizeOf(ZeroBits) == 0);
381 comptime assert(@sizeOf(ZeroBits) == 0);
382382}
383383
384384test "tagged union initialization with runtime void" {
......@@ -428,7 +428,7 @@ test "union with only 1 field casted to its enum type" {
428428 var e = Expr{ .Literal = Literal{ .Bool = true } };
429429 _ = &e;
430430 const ExprTag = Tag(Expr);
431 try comptime expect(Tag(ExprTag) == u0);
431 comptime assert(Tag(ExprTag) == u0);
432432 var t = @as(ExprTag, e);
433433 _ = &t;
434434 try expect(t == Expr.Literal);
......@@ -438,7 +438,7 @@ test "union with one member defaults to u0 tag type" {
438438 const U0 = union(enum) {
439439 X: u32,
440440 };
441 try comptime expect(Tag(Tag(U0)) == u0);
441 comptime assert(Tag(Tag(U0)) == u0);
442442}
443443
444444const Foo1 = union(enum) {
......@@ -629,7 +629,7 @@ test "union(enum(u32)) with specified and unspecified tag values" {
629629 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
630630 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
631631
632 try comptime expect(Tag(Tag(MultipleChoice2)) == u32);
632 comptime assert(Tag(Tag(MultipleChoice2)) == u32);
633633 try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
634634 try comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
635635}
......@@ -709,11 +709,11 @@ test "union with only 1 field casted to its enum type which has enum value speci
709709
710710 var e = Expr{ .Literal = Literal{ .Bool = true } };
711711 _ = &e;
712 try comptime expect(Tag(ExprTag) == comptime_int);
712 comptime assert(Tag(ExprTag) == comptime_int);
713713 const t = comptime @as(ExprTag, e);
714714 try expect(t == Expr.Literal);
715715 try expect(@intFromEnum(t) == 33);
716 try comptime expect(@intFromEnum(t) == 33);
716 comptime assert(@intFromEnum(t) == 33);
717717}
718718
719719test "@intFromEnum works on unions" {
......@@ -894,7 +894,7 @@ test "union with comptime_int tag" {
894894 Y: u16,
895895 Z: u8,
896896 };
897 try comptime expect(Tag(Tag(Union)) == comptime_int);
897 comptime assert(Tag(Tag(Union)) == comptime_int);
898898}
899899
900900test "extern union doesn't trigger field check at comptime" {
......@@ -904,7 +904,7 @@ test "extern union doesn't trigger field check at comptime" {
904904 };
905905
906906 const x = U{ .x = 0x55AAAA55 };
907 try comptime expect(x.y == 0x55);
907 comptime assert(x.y == 0x55);
908908}
909909
910910test "anonymous union literal syntax" {
test/behavior/vector.zig+2-2
......@@ -904,9 +904,9 @@ test "vector @reduce comptime" {
904904 const value = V{ 1, -1, 1, -1 };
905905 const result = value > @as(V, @splat(0));
906906 // result is { true, false, true, false };
907 try comptime expect(@TypeOf(result) == @Vector(4, bool));
907 comptime assert(@TypeOf(result) == @Vector(4, bool));
908908 const is_all_true = @reduce(.And, result);
909 try comptime expect(@TypeOf(is_all_true) == bool);
909 comptime assert(@TypeOf(is_all_true) == bool);
910910 try expect(is_all_true == false);
911911}
912912