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;...@@ -7,11 +7,11 @@ const assert = std.debug.assert;
7var foo: u8 align(4) = 100;7var foo: u8 align(4) = 100;
88
9test "global variable alignment" {9test "global variable alignment" {
10 try comptime expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);10 comptime assert(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
11 try comptime expect(@TypeOf(&foo) == *align(4) u8);11 comptime assert(@TypeOf(&foo) == *align(4) u8);
12 {12 {
13 const slice = @as(*align(4) [1]u8, &foo)[0..];13 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);
15 }15 }
16}16}
1717
...@@ -455,10 +455,10 @@ test "runtime-known array index has best alignment possible" {...@@ -455,10 +455,10 @@ test "runtime-known array index has best alignment possible" {
455 try testIndex2(&array, 3, *u8);455 try testIndex2(&array, 3, *u8);
456}456}
457fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void {457fn 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);
459}459}
460fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void {460fn 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);
462}462}
463463
464test "alignment of function with c calling convention" {464test "alignment of function with c calling convention" {
...@@ -524,7 +524,7 @@ test "struct field explicit alignment" {...@@ -524,7 +524,7 @@ test "struct field explicit alignment" {
524 var node: S.Node = undefined;524 var node: S.Node = undefined;
525 node.massive_byte = 100;525 node.massive_byte = 100;
526 try expect(node.massive_byte == 100);526 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);
528 try expect(@intFromPtr(&node.massive_byte) % 64 == 0);528 try expect(@intFromPtr(&node.massive_byte) % 64 == 0);
529}529}
530530
test/behavior/alignof.zig+3-2
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assert = std.debug.assert;
2const expect = std.testing.expect;3const expect = std.testing.expect;
3const builtin = @import("builtin");4const builtin = @import("builtin");
4const native_arch = builtin.target.cpu.arch;5const native_arch = builtin.target.cpu.arch;
...@@ -11,9 +12,9 @@ const Foo = struct {...@@ -11,9 +12,9 @@ const Foo = struct {
11};12};
1213
13test "@alignOf(T) before referencing T" {14test "@alignOf(T) before referencing T" {
14 try comptime expect(@alignOf(Foo) != maxInt(usize));15 comptime assert(@alignOf(Foo) != maxInt(usize));
15 if (native_arch == .x86_64) {16 if (native_arch == .x86_64) {
16 try comptime expect(@alignOf(Foo) == 4);17 comptime assert(@alignOf(Foo) == 4);
17 }18 }
18}19}
1920
test/behavior/array.zig+4-3
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const testing = std.testing;3const testing = std.testing;
4const mem = std.mem;4const mem = std.mem;
5const assert = std.debug.assert;
5const expect = testing.expect;6const expect = testing.expect;
6const expectEqual = testing.expectEqual;7const expectEqual = testing.expectEqual;
78
...@@ -149,9 +150,9 @@ test "array len field" {...@@ -149,9 +150,9 @@ test "array len field" {
149 var arr = [4]u8{ 0, 0, 0, 0 };150 var arr = [4]u8{ 0, 0, 0, 0 };
150 const ptr = &arr;151 const ptr = &arr;
151 try expect(arr.len == 4);152 try expect(arr.len == 4);
152 try comptime expect(arr.len == 4);153 comptime assert(arr.len == 4);
153 try expect(ptr.len == 4);154 try expect(ptr.len == 4);
154 try comptime expect(ptr.len == 4);155 comptime assert(ptr.len == 4);
155 try expect(@TypeOf(arr.len) == usize);156 try expect(@TypeOf(arr.len) == usize);
156}157}
157158
...@@ -904,7 +905,7 @@ test "store array of array of structs at comptime" {...@@ -904,7 +905,7 @@ test "store array of array of structs at comptime" {
904 };905 };
905906
906 try expect(S.storeArrayOfArrayOfStructs() == 15);907 try expect(S.storeArrayOfArrayOfStructs() == 15);
907 try comptime expect(S.storeArrayOfArrayOfStructs() == 15);908 comptime assert(S.storeArrayOfArrayOfStructs() == 15);
908}909}
909910
910test "accessing multidimensional global array at comptime" {911test "accessing multidimensional global array at comptime" {
test/behavior/async_fn.zig+5-4
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assert = std.debug.assert;
3const expect = std.testing.expect;4const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;5const expectEqual = std.testing.expectEqual;
5const expectEqualStrings = std.testing.expectEqualStrings;6const expectEqualStrings = std.testing.expectEqualStrings;
...@@ -221,7 +222,7 @@ var a_promise: anyframe = undefined;...@@ -221,7 +222,7 @@ var a_promise: anyframe = undefined;
221var global_result = false;222var global_result = false;
222fn testSuspendBlock() callconv(.Async) void {223fn testSuspendBlock() callconv(.Async) void {
223 suspend {224 suspend {
224 comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable;225 comptime assert(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable;
225 a_promise = @frame();226 a_promise = @frame();
226 }227 }
227228
...@@ -334,7 +335,7 @@ test "async fn pointer in a struct field" {...@@ -334,7 +335,7 @@ test "async fn pointer in a struct field" {
334 _ = &foo;335 _ = &foo;
335 var bytes: [64]u8 align(16) = undefined;336 var bytes: [64]u8 align(16) = undefined;
336 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});337 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
337 try comptime expect(@TypeOf(f) == anyframe->void);338 comptime assert(@TypeOf(f) == anyframe->void);
338 try expect(data == 2);339 try expect(data == 2);
339 resume f;340 resume f;
340 try expect(data == 4);341 try expect(data == 4);
...@@ -1150,7 +1151,7 @@ test "@asyncCall using the result location inside the frame" {...@@ -1150,7 +1151,7 @@ test "@asyncCall using the result location inside the frame" {
1150 _ = &foo;1151 _ = &foo;
1151 var bytes: [64]u8 align(16) = undefined;1152 var bytes: [64]u8 align(16) = undefined;
1152 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});1153 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
1153 try comptime expect(@TypeOf(f) == anyframe->i32);1154 comptime assert(@TypeOf(f) == anyframe->i32);
1154 try expect(data == 2);1155 try expect(data == 2);
1155 resume f;1156 resume f;
1156 try expect(data == 4);1157 try expect(data == 4);
...@@ -1165,7 +1166,7 @@ test "@TypeOf an async function call of generic fn with error union type" {...@@ -1165,7 +1166,7 @@ test "@TypeOf an async function call of generic fn with error union type" {
1165 const S = struct {1166 const S = struct {
1166 fn func(comptime x: anytype) anyerror!i32 {1167 fn func(comptime x: anytype) anyerror!i32 {
1167 const T = @TypeOf(async func(x));1168 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);
1169 return undefined;1170 return undefined;
1170 }1171 }
1171 };1172 };
test/behavior/basic.zig+5-5
...@@ -17,7 +17,7 @@ test "empty function with comments" {...@@ -17,7 +17,7 @@ test "empty function with comments" {
1717
18test "truncate" {18test "truncate" {
19 try expect(testTruncate(0x10fd) == 0xfd);19 try expect(testTruncate(0x10fd) == 0xfd);
20 try comptime expect(testTruncate(0x10fd) == 0xfd);20 comptime assert(testTruncate(0x10fd) == 0xfd);
21}21}
22fn testTruncate(x: u32) u8 {22fn testTruncate(x: u32) u8 {
23 return @as(u8, @truncate(x));23 return @as(u8, @truncate(x));
...@@ -568,7 +568,7 @@ fn emptyFn() void {}...@@ -568,7 +568,7 @@ fn emptyFn() void {}
568const addr1 = @as(*const u8, @ptrCast(&emptyFn));568const addr1 = @as(*const u8, @ptrCast(&emptyFn));
569test "comptime cast fn to ptr" {569test "comptime cast fn to ptr" {
570 const addr2 = @as(*const u8, @ptrCast(&emptyFn));570 const addr2 = @as(*const u8, @ptrCast(&emptyFn));
571 try comptime expect(addr1 == addr2);571 comptime assert(addr1 == addr2);
572}572}
573573
574test "equality compare fn ptrs" {574test "equality compare fn ptrs" {
...@@ -678,8 +678,8 @@ test "string concatenation" {...@@ -678,8 +678,8 @@ test "string concatenation" {
678 const a = "OK" ++ " IT " ++ "WORKED";678 const a = "OK" ++ " IT " ++ "WORKED";
679 const b = "OK IT WORKED";679 const b = "OK IT WORKED";
680680
681 try comptime expect(@TypeOf(a) == *const [12:0]u8);681 comptime assert(@TypeOf(a) == *const [12:0]u8);
682 try comptime expect(@TypeOf(b) == *const [12:0]u8);682 comptime assert(@TypeOf(b) == *const [12:0]u8);
683683
684 const len = b.len;684 const len = b.len;
685 const len_with_null = len + 1;685 const len_with_null = len + 1;
...@@ -747,7 +747,7 @@ test "auto created variables have correct alignment" {...@@ -747,7 +747,7 @@ test "auto created variables have correct alignment" {
747 }747 }
748 };748 };
749 try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);749 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);
751}751}
752752
753test "extern variable with non-pointer opaque type" {753test "extern variable with non-pointer opaque type" {
test/behavior/bitcast.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assert = std.debug.assert;
3const expect = std.testing.expect;4const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;5const expectEqual = std.testing.expectEqual;
5const math = std.math;6const math = std.math;
...@@ -273,7 +274,7 @@ test "comptime bitcast used in expression has the correct type" {...@@ -273,7 +274,7 @@ test "comptime bitcast used in expression has the correct type" {
273test "bitcast passed as tuple element" {274test "bitcast passed as tuple element" {
274 const S = struct {275 const S = struct {
275 fn foo(args: anytype) !void {276 fn foo(args: anytype) !void {
276 try comptime expect(@TypeOf(args[0]) == f32);277 comptime assert(@TypeOf(args[0]) == f32);
277 try expect(args[0] == 12.34);278 try expect(args[0] == 12.34);
278 }279 }
279 };280 };
...@@ -283,7 +284,7 @@ test "bitcast passed as tuple element" {...@@ -283,7 +284,7 @@ test "bitcast passed as tuple element" {
283test "triple level result location with bitcast sandwich passed as tuple element" {284test "triple level result location with bitcast sandwich passed as tuple element" {
284 const S = struct {285 const S = struct {
285 fn foo(args: anytype) !void {286 fn foo(args: anytype) !void {
286 try comptime expect(@TypeOf(args[0]) == f64);287 comptime assert(@TypeOf(args[0]) == f64);
287 try expect(args[0] > 12.33 and args[0] < 12.35);288 try expect(args[0] > 12.33 and args[0] < 12.35);
288 }289 }
289 };290 };
test/behavior/call.zig+5-4
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const assert = std.debug.assert;
3const expect = std.testing.expect;4const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;5const expectEqual = std.testing.expectEqual;
56
...@@ -10,11 +11,11 @@ test "super basic invocations" {...@@ -10,11 +11,11 @@ test "super basic invocations" {
10 }11 }
11 }.foo;12 }.foo;
12 try expect(@call(.auto, foo, .{}) == 1234);13 try expect(@call(.auto, foo, .{}) == 1234);
13 try comptime expect(@call(.always_inline, foo, .{}) == 1234);14 comptime assert(@call(.always_inline, foo, .{}) == 1234);
14 {15 {
15 // comptime call without comptime keyword16 // comptime call without comptime keyword
16 const result = @call(.compile_time, foo, .{}) == 1234;17 const result = @call(.compile_time, foo, .{}) == 1234;
17 try comptime expect(result);18 comptime assert(result);
18 }19 }
19}20}
2021
...@@ -42,7 +43,7 @@ test "basic invocations" {...@@ -42,7 +43,7 @@ test "basic invocations" {
42 {43 {
43 // comptime call without comptime keyword44 // comptime call without comptime keyword
44 const result = @call(.compile_time, foo, .{}) == 1234;45 const result = @call(.compile_time, foo, .{}) == 1234;
45 try comptime expect(result);46 comptime assert(result);
46 }47 }
47 {48 {
48 // call of non comptime-known function49 // call of non comptime-known function
...@@ -73,7 +74,7 @@ test "tuple parameters" {...@@ -73,7 +74,7 @@ test "tuple parameters" {
73 try expect(@call(.auto, add, .{ a, b }) == 46);74 try expect(@call(.auto, add, .{ a, b }) == 46);
74 try expect(@call(.auto, add, .{ 12, 34 }) == 46);75 try expect(@call(.auto, add, .{ 12, 34 }) == 46);
75 if (false) {76 if (false) {
76 try comptime expect(@call(.auto, add, .{ 12, 34 }) == 46); // TODO77 comptime assert(@call(.auto, add, .{ 12, 34 }) == 46); // TODO
77 }78 }
78 try expect(comptime @call(.auto, add, .{ 12, 34 }) == 46);79 try expect(comptime @call(.auto, add, .{ 12, 34 }) == 46);
79 {80 {
test/behavior/cast.zig+22-22
...@@ -63,7 +63,7 @@ test "implicit cast comptime numbers to any type when the value fits" {...@@ -63,7 +63,7 @@ test "implicit cast comptime numbers to any type when the value fits" {
63}63}
6464
65test "implicit cast comptime_int to comptime_float" {65test "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));
67 try expect(2 == 2.0);67 try expect(2 == 2.0);
68}68}
6969
...@@ -313,11 +313,11 @@ test "peer result null and comptime_int" {...@@ -313,11 +313,11 @@ test "peer result null and comptime_int" {
313 };313 };
314314
315 try expect(S.blah(0) == null);315 try expect(S.blah(0) == null);
316 try comptime expect(S.blah(0) == null);316 comptime assert(S.blah(0) == null);
317 try expect(S.blah(10).? == 1);317 try expect(S.blah(10).? == 1);
318 try comptime expect(S.blah(10).? == 1);318 comptime assert(S.blah(10).? == 1);
319 try expect(S.blah(-10).? == -1);319 try expect(S.blah(-10).? == -1);
320 try comptime expect(S.blah(-10).? == -1);320 comptime assert(S.blah(-10).? == -1);
321}321}
322322
323test "*const ?[*]const T to [*c]const [*c]const T" {323test "*const ?[*]const T to [*c]const [*c]const T" {
...@@ -393,7 +393,7 @@ test "peer type unsigned int to signed" {...@@ -393,7 +393,7 @@ test "peer type unsigned int to signed" {
393 var y: i32 = -5;393 var y: i32 = -5;
394 _ = .{ &w, &x, &y };394 _ = .{ &w, &x, &y };
395 const a = w + y + x;395 const a = w + y + x;
396 try comptime expect(@TypeOf(a) == i32);396 comptime assert(@TypeOf(a) == i32);
397 try expect(a == 7);397 try expect(a == 7);
398}398}
399399
...@@ -542,9 +542,9 @@ test "peer type resolution: error and [N]T" {...@@ -542,9 +542,9 @@ test "peer type resolution: error and [N]T" {
542 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO542 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
543543
544 try expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));544 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"));
546 try expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));546 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"));
548}548}
549549
550fn testPeerErrorAndArray(x: u8) anyerror![]const u8 {550fn testPeerErrorAndArray(x: u8) anyerror![]const u8 {
...@@ -1038,15 +1038,15 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" {...@@ -1038,15 +1038,15 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" {
1038 var array: [4:0]u8 = undefined;1038 var array: [4:0]u8 = undefined;
1039 array[4] = 0; // TODO remove this when #4372 is solved1039 array[4] = 0; // TODO remove this when #4372 is solved
1040 const slice: [:0]u8 = array[0..4 :0];1040 const slice: [:0]u8 = array[0..4 :0];
1041 try comptime expect(@TypeOf(slice, "hi") == [:0]const u8);1041 comptime assert(@TypeOf(slice, "hi") == [:0]const u8);
1042 try comptime expect(@TypeOf("hi", slice) == [:0]const u8);1042 comptime assert(@TypeOf("hi", slice) == [:0]const u8);
1043}1043}
10441044
1045test "peer type resolve array pointers, one of them const" {1045test "peer type resolve array pointers, one of them const" {
1046 var array1: [4]u8 = undefined;1046 var array1: [4]u8 = undefined;
1047 const array2: [5]u8 = undefined;1047 const array2: [5]u8 = undefined;
1048 try comptime expect(@TypeOf(&array1, &array2) == []const u8);1048 comptime assert(@TypeOf(&array1, &array2) == []const u8);
1049 try comptime expect(@TypeOf(&array2, &array1) == []const u8);1049 comptime assert(@TypeOf(&array2, &array1) == []const u8);
1050}1050}
10511051
1052test "peer type resolve array pointer and unknown pointer" {1052test "peer type resolve array pointer and unknown pointer" {
...@@ -1056,17 +1056,17 @@ test "peer type resolve array pointer and unknown pointer" {...@@ -1056,17 +1056,17 @@ test "peer type resolve array pointer and unknown pointer" {
1056 var ptr: [*]u8 = undefined;1056 var ptr: [*]u8 = undefined;
1057 _ = .{ &const_ptr, &ptr };1057 _ = .{ &const_ptr, &ptr };
10581058
1059 try comptime expect(@TypeOf(&array, ptr) == [*]u8);1059 comptime assert(@TypeOf(&array, ptr) == [*]u8);
1060 try comptime expect(@TypeOf(ptr, &array) == [*]u8);1060 comptime assert(@TypeOf(ptr, &array) == [*]u8);
10611061
1062 try comptime expect(@TypeOf(&const_array, ptr) == [*]const u8);1062 comptime assert(@TypeOf(&const_array, ptr) == [*]const u8);
1063 try comptime expect(@TypeOf(ptr, &const_array) == [*]const u8);1063 comptime assert(@TypeOf(ptr, &const_array) == [*]const u8);
10641064
1065 try comptime expect(@TypeOf(&array, const_ptr) == [*]const u8);1065 comptime assert(@TypeOf(&array, const_ptr) == [*]const u8);
1066 try comptime expect(@TypeOf(const_ptr, &array) == [*]const u8);1066 comptime assert(@TypeOf(const_ptr, &array) == [*]const u8);
10671067
1068 try comptime expect(@TypeOf(&const_array, const_ptr) == [*]const u8);1068 comptime assert(@TypeOf(&const_array, const_ptr) == [*]const u8);
1069 try comptime expect(@TypeOf(const_ptr, &const_array) == [*]const u8);1069 comptime assert(@TypeOf(const_ptr, &const_array) == [*]const u8);
1070}1070}
10711071
1072test "comptime float casts" {1072test "comptime float casts" {
...@@ -1214,7 +1214,7 @@ test "implicitly cast from [N]T to ?[]const T" {...@@ -1214,7 +1214,7 @@ test "implicitly cast from [N]T to ?[]const T" {
1214 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1214 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
12151215
1216 try expect(mem.eql(u8, castToOptionalSlice().?, "hi"));1216 try expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
1217 try comptime expect(mem.eql(u8, castToOptionalSlice().?, "hi"));1217 comptime assert(mem.eql(u8, castToOptionalSlice().?, "hi"));
1218}1218}
12191219
1220fn castToOptionalSlice() ?[]const u8 {1220fn castToOptionalSlice() ?[]const u8 {
...@@ -1351,8 +1351,8 @@ test "peer resolve arrays of different size to const slice" {...@@ -1351,8 +1351,8 @@ test "peer resolve arrays of different size to const slice" {
13511351
1352 try expect(mem.eql(u8, boolToStr(true), "true"));1352 try expect(mem.eql(u8, boolToStr(true), "true"));
1353 try expect(mem.eql(u8, boolToStr(false), "false"));1353 try expect(mem.eql(u8, boolToStr(false), "false"));
1354 try comptime expect(mem.eql(u8, boolToStr(true), "true"));1354 comptime assert(mem.eql(u8, boolToStr(true), "true"));
1355 try comptime expect(mem.eql(u8, boolToStr(false), "false"));1355 comptime assert(mem.eql(u8, boolToStr(false), "false"));
1356}1356}
1357fn boolToStr(b: bool) []const u8 {1357fn boolToStr(b: bool) []const u8 {
1358 return if (b) "true" else "false";1358 return if (b) "true" else "false";
test/behavior/enum.zig+9-9
...@@ -773,12 +773,12 @@ test "set enum tag type" {...@@ -773,12 +773,12 @@ test "set enum tag type" {
773 {773 {
774 var x = Small.One;774 var x = Small.One;
775 x = Small.Two;775 x = Small.Two;
776 try comptime expect(Tag(Small) == u2);776 comptime assert(Tag(Small) == u2);
777 }777 }
778 {778 {
779 var x = Small2.One;779 var x = Small2.One;
780 x = Small2.Two;780 x = Small2.Two;
781 try comptime expect(Tag(Small2) == u2);781 comptime assert(Tag(Small2) == u2);
782 }782 }
783}783}
784784
...@@ -795,7 +795,7 @@ test "enum with 1 field but explicit tag type should still have the tag type" {...@@ -795,7 +795,7 @@ test "enum with 1 field but explicit tag type should still have the tag type" {
795 const Enum = enum(u8) {795 const Enum = enum(u8) {
796 B = 2,796 B = 2,
797 };797 };
798 try comptime expect(@sizeOf(Enum) == @sizeOf(u8));798 comptime assert(@sizeOf(Enum) == @sizeOf(u8));
799}799}
800800
801test "signed integer as enum tag" {801test "signed integer as enum tag" {
...@@ -834,12 +834,12 @@ test "enum with comptime_int tag type" {...@@ -834,12 +834,12 @@ test "enum with comptime_int tag type" {
834 Two = 2,834 Two = 2,
835 Three = 1,835 Three = 1,
836 };836 };
837 try comptime expect(Tag(Enum) == comptime_int);837 comptime assert(Tag(Enum) == comptime_int);
838}838}
839839
840test "enum with one member default to u0 tag type" {840test "enum with one member default to u0 tag type" {
841 const E0 = enum { X };841 const E0 = enum { X };
842 try comptime expect(Tag(E0) == u0);842 comptime assert(Tag(E0) == u0);
843}843}
844844
845const EnumWithOneMember = enum { Eof };845const EnumWithOneMember = enum { Eof };
...@@ -989,7 +989,7 @@ test "@tagName" {...@@ -989,7 +989,7 @@ test "@tagName" {
989 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;989 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
990990
991 try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));991 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"));
993}993}
994994
995fn testEnumTagNameBare(n: anytype) []const u8 {995fn testEnumTagNameBare(n: anytype) []const u8 {
...@@ -1005,7 +1005,7 @@ test "@tagName non-exhaustive enum" {...@@ -1005,7 +1005,7 @@ test "@tagName non-exhaustive enum" {
1005 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1005 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
10061006
1007 try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));1007 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"));
1009}1009}
1010const NonExhaustive = enum(u8) { A, B, _ };1010const NonExhaustive = enum(u8) { A, B, _ };
10111011
...@@ -1044,7 +1044,7 @@ test "@tagName on enum literals" {...@@ -1044,7 +1044,7 @@ test "@tagName on enum literals" {
1044 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1044 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
10451045
1046 try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));1046 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"));
1048}1048}
10491049
1050test "tag name with signed enum values" {1050test "tag name with signed enum values" {
...@@ -1101,7 +1101,7 @@ test "bit field access with enum fields" {...@@ -1101,7 +1101,7 @@ test "bit field access with enum fields" {
1101 try expect(getA(&data) == A.Two);1101 try expect(getA(&data) == A.Two);
1102 try expect(getB(&data) == B.Three3);1102 try expect(getB(&data) == B.Three3);
1103 try expect(getC(&data) == C.Four4);1103 try expect(getC(&data) == C.Four4);
1104 try comptime expect(@sizeOf(BitFieldOfEnums) == 1);1104 comptime assert(@sizeOf(BitFieldOfEnums) == 1);
11051105
1106 data.b = B.Four3;1106 data.b = B.Four3;
1107 try expect(data.b == B.Four3);1107 try expect(data.b == B.Four3);
test/behavior/error.zig+5-4
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const assert = std.debug.assert;
3const expect = std.testing.expect;4const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;5const expectEqual = std.testing.expectEqual;
5const mem = std.mem;6const mem = std.mem;
...@@ -458,7 +459,7 @@ test "return function call to error set from error union function" {...@@ -458,7 +459,7 @@ test "return function call to error set from error union function" {
458 }459 }
459 };460 };
460 try expectError(error.Failure, S.errorable());461 try expectError(error.Failure, S.errorable());
461 try comptime expectError(error.Failure, S.errorable());462 comptime assert(error.Failure == S.errorable());
462}463}
463464
464test "optional error set is the same size as error set" {465test "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" {...@@ -466,15 +467,15 @@ test "optional error set is the same size as error set" {
466 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO467 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
467 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO468 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
468469
469 try comptime expect(@sizeOf(?anyerror) == @sizeOf(anyerror));470 comptime assert(@sizeOf(?anyerror) == @sizeOf(anyerror));
470 try comptime expect(@alignOf(?anyerror) == @alignOf(anyerror));471 comptime assert(@alignOf(?anyerror) == @alignOf(anyerror));
471 const S = struct {472 const S = struct {
472 fn returnsOptErrSet() ?anyerror {473 fn returnsOptErrSet() ?anyerror {
473 return null;474 return null;
474 }475 }
475 };476 };
476 try expect(S.returnsOptErrSet() == null);477 try expect(S.returnsOptErrSet() == null);
477 try comptime expect(S.returnsOptErrSet() == null);478 comptime assert(S.returnsOptErrSet() == null);
478}479}
479480
480test "nested catch" {481test "nested catch" {
test/behavior/eval.zig+8-8
...@@ -55,7 +55,7 @@ fn staticAdd(a: i32, b: i32) i32 {...@@ -55,7 +55,7 @@ fn staticAdd(a: i32, b: i32) i32 {
5555
56test "const expr eval on single expr blocks" {56test "const expr eval on single expr blocks" {
57 try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);57 try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
58 try comptime expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);58 comptime assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
59}59}
6060
61fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {61fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
...@@ -426,7 +426,7 @@ test "f64 at compile time is lossy" {...@@ -426,7 +426,7 @@ test "f64 at compile time is lossy" {
426}426}
427427
428test {428test {
429 try comptime expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192);429 comptime assert(@as(f128, 1 << 113) == 10384593717069655257060992658440192);
430}430}
431431
432fn copyWithPartialInline(s: []u32, b: []u8) void {432fn copyWithPartialInline(s: []u32, b: []u8) void {
...@@ -613,7 +613,7 @@ test "const global shares pointer with other same one" {...@@ -613,7 +613,7 @@ test "const global shares pointer with other same one" {
613 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO613 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
614614
615 try assertEqualPtrs(&hi1[0], &hi2[0]);615 try assertEqualPtrs(&hi1[0], &hi2[0]);
616 try comptime expect(&hi1[0] == &hi2[0]);616 comptime assert(&hi1[0] == &hi2[0]);
617}617}
618fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void {618fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void {
619 try expect(ptr1 == ptr2);619 try expect(ptr1 == ptr2);
...@@ -634,8 +634,8 @@ fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void {...@@ -634,8 +634,8 @@ fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void {
634test "string literal used as comptime slice is memoized" {634test "string literal used as comptime slice is memoized" {
635 const a = "link";635 const a = "link";
636 const b = "link";636 const b = "link";
637 try comptime expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);637 comptime assert(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);
638 try comptime expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);638 comptime assert(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);
639}639}
640640
641pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {641pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
...@@ -953,7 +953,7 @@ test "const local with comptime init through array init" {...@@ -953,7 +953,7 @@ test "const local with comptime init through array init" {
953 S.declarations(E1),953 S.declarations(E1),
954 };954 };
955955
956 try comptime expect(decls[0][0].name[0] == 'a');956 comptime assert(decls[0][0].name[0] == 'a');
957}957}
958958
959test "closure capture type of runtime-known parameter" {959test "closure capture type of runtime-known parameter" {
...@@ -1339,7 +1339,7 @@ test "value in if block is comptime-known" {...@@ -1339,7 +1339,7 @@ test "value in if block is comptime-known" {
1339 const s = if (false) S{ .str = "a" } else S{ .str = "b" };1339 const s = if (false) S{ .str = "a" } else S{ .str = "b" };
1340 break :blk "foo" ++ s.str;1340 break :blk "foo" ++ s.str;
1341 };1341 };
1342 try comptime expect(std.mem.eql(u8, first, second));1342 comptime assert(std.mem.eql(u8, first, second));
1343}1343}
13441344
1345test "lazy sizeof is resolved in division" {1345test "lazy sizeof is resolved in division" {
...@@ -1561,7 +1561,7 @@ test "comptime function turns function value to function pointer" {...@@ -1561,7 +1561,7 @@ test "comptime function turns function value to function pointer" {
1561 fnPtr(Nil),1561 fnPtr(Nil),
1562 };1562 };
1563 };1563 };
1564 try comptime expect(S.foo[0] == &S.Nil);1564 comptime assert(S.foo[0] == &S.Nil);
1565}1565}
15661566
1567test "container level const and var have unique addresses" {1567test "container level const and var have unique addresses" {
test/behavior/fn.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const testing = std.testing;3const testing = std.testing;
4const assert = std.debug.assert;
4const expect = testing.expect;5const expect = testing.expect;
5const expectEqual = testing.expectEqual;6const expectEqual = testing.expectEqual;
67
...@@ -207,7 +208,7 @@ test "pass by non-copying value through var arg" {...@@ -207,7 +208,7 @@ test "pass by non-copying value through var arg" {
207}208}
208209
209fn addPointCoordsVar(pt: anytype) !i32 {210fn addPointCoordsVar(pt: anytype) !i32 {
210 try comptime expect(@TypeOf(pt) == Point);211 comptime assert(@TypeOf(pt) == Point);
211 return pt.x + pt.y;212 return pt.x + pt.y;
212}213}
213214
test/behavior/math.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const assert = std.debug.assert;
3const expect = std.testing.expect;4const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;5const expectEqual = std.testing.expectEqual;
5const expectEqualSlices = std.testing.expectEqualSlices;6const expectEqualSlices = std.testing.expectEqualSlices;
...@@ -246,7 +247,7 @@ fn testFloatEqualityImpl(x: f64, y: f64) !void {...@@ -246,7 +247,7 @@ fn testFloatEqualityImpl(x: f64, y: f64) !void {
246}247}
247248
248test "hex float literal parsing" {249test "hex float literal parsing" {
249 try comptime expect(0x1.0 == 1.0);250 comptime assert(0x1.0 == 1.0);
250}251}
251252
252test "hex float literal within range" {253test "hex float literal within range" {
...@@ -1530,7 +1531,7 @@ test "@round f32/f64" {...@@ -1530,7 +1531,7 @@ test "@round f32/f64" {
1530 const x = 14.0;1531 const x = 14.0;
1531 const y = x + 0.4;1532 const y = x + 0.4;
1532 const z = @round(y);1533 const z = @round(y);
1533 try comptime expect(x == z);1534 comptime assert(x == z);
1534}1535}
15351536
1536test "@round f80" {1537test "@round f80" {
test/behavior/optional.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const testing = std.testing;3const testing = std.testing;
4const assert = std.debug.assert;
4const expect = testing.expect;5const expect = testing.expect;
5const expectEqual = testing.expectEqual;6const expectEqual = testing.expectEqual;
6const expectEqualStrings = std.testing.expectEqualStrings;7const expectEqualStrings = std.testing.expectEqualStrings;
...@@ -20,7 +21,7 @@ test "passing an optional integer as a parameter" {...@@ -20,7 +21,7 @@ test "passing an optional integer as a parameter" {
20 }21 }
21 };22 };
22 try expect(S.entry());23 try expect(S.entry());
23 try comptime expect(S.entry());24 comptime assert(S.entry());
24}25}
2526
26pub const EmptyStruct = struct {};27pub const EmptyStruct = struct {};
test/behavior/pointers.zig+22-21
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const testing = std.testing;3const testing = std.testing;
4const assert = std.debug.assert;
4const expect = testing.expect;5const expect = testing.expect;
5const expectError = testing.expectError;6const expectError = testing.expectError;
67
...@@ -42,7 +43,7 @@ test "pointer arithmetic" {...@@ -42,7 +43,7 @@ test "pointer arithmetic" {
42}43}
4344
44test "double pointer parsing" {45test "double pointer parsing" {
45 try comptime expect(PtrOf(PtrOf(i32)) == **i32);46 comptime assert(PtrOf(PtrOf(i32)) == **i32);
46}47}
4748
48fn PtrOf(comptime T: type) type {49fn PtrOf(comptime T: type) type {
...@@ -62,7 +63,7 @@ test "implicit cast single item pointer to C pointer and back" {...@@ -62,7 +63,7 @@ test "implicit cast single item pointer to C pointer and back" {
62test "initialize const optional C pointer to null" {63test "initialize const optional C pointer to null" {
63 const a: ?[*c]i32 = null;64 const a: ?[*c]i32 = null;
64 try expect(a == null);65 try expect(a == null);
65 try comptime expect(a == null);66 comptime assert(a == null);
66}67}
6768
68test "assigning integer to C pointer" {69test "assigning integer to C pointer" {
...@@ -204,11 +205,11 @@ test "allowzero pointer and slice" {...@@ -204,11 +205,11 @@ test "allowzero pointer and slice" {
204 var runtime_zero: usize = 0;205 var runtime_zero: usize = 0;
205 _ = &runtime_zero;206 _ = &runtime_zero;
206 var slice = ptr[runtime_zero..10];207 var slice = ptr[runtime_zero..10];
207 try comptime expect(@TypeOf(slice) == []allowzero i32);208 comptime assert(@TypeOf(slice) == []allowzero i32);
208 try expect(@intFromPtr(&slice[5]) == 20);209 try expect(@intFromPtr(&slice[5]) == 20);
209210
210 try comptime expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero);211 comptime assert(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero);
211 try comptime expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero);212 comptime assert(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero);
212}213}
213214
214test "assign null directly to C pointer and test null equality" {215test "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" {...@@ -230,17 +231,17 @@ test "assign null directly to C pointer and test null equality" {
230 try expect((x orelse &otherx) == &otherx);231 try expect((x orelse &otherx) == &otherx);
231232
232 const y: [*c]i32 = null;233 const y: [*c]i32 = null;
233 try comptime expect(y == null);234 comptime assert(y == null);
234 try comptime expect(null == y);235 comptime assert(null == y);
235 try comptime expect(!(y != null));236 comptime assert(!(y != null));
236 try comptime expect(!(null != y));237 comptime assert(!(null != y));
237 if (y) |same_y| {238 if (y) |same_y| {
238 _ = same_y;239 _ = same_y;
239 @panic("fail");240 @panic("fail");
240 }241 }
241 const othery: i32 = undefined;242 const othery: i32 = undefined;
242 const ptr_othery = &othery;243 const ptr_othery = &othery;
243 try comptime expect((y orelse ptr_othery) == ptr_othery);244 comptime assert((y orelse ptr_othery) == ptr_othery);
244245
245 var n: i32 = 1234;246 var n: i32 = 1234;
246 const x1: [*c]i32 = &n;247 const x1: [*c]i32 = &n;
...@@ -258,17 +259,17 @@ test "assign null directly to C pointer and test null equality" {...@@ -258,17 +259,17 @@ test "assign null directly to C pointer and test null equality" {
258259
259 const nc: i32 = 1234;260 const nc: i32 = 1234;
260 const y1: [*c]const i32 = &nc;261 const y1: [*c]const i32 = &nc;
261 try comptime expect(!(y1 == null));262 comptime assert(!(y1 == null));
262 try comptime expect(!(null == y1));263 comptime assert(!(null == y1));
263 try comptime expect(y1 != null);264 comptime assert(y1 != null);
264 try comptime expect(null != y1);265 comptime assert(null != y1);
265 try comptime expect(y1.?.* == 1234);266 comptime assert(y1.?.* == 1234);
266 if (y1) |same_y1| {267 if (y1) |same_y1| {
267 try expect(same_y1.* == 1234);268 try expect(same_y1.* == 1234);
268 } else {269 } else {
269 @compileError("fail");270 @compileError("fail");
270 }271 }
271 try comptime expect((y1 orelse &othery) == y1);272 comptime assert((y1 orelse &othery) == y1);
272}273}
273274
274test "array initialization types" {275test "array initialization types" {
...@@ -325,7 +326,7 @@ test "pointer sentinel with enums" {...@@ -325,7 +326,7 @@ test "pointer sentinel with enums" {
325 fn doTheTest() !void {326 fn doTheTest() !void {
326 var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one };327 var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one };
327 _ = &ptr;328 _ = &ptr;
328 try expect(ptr[4] == .sentinel); // TODO this should be try comptime expect, see #3731329 try expect(ptr[4] == .sentinel); // TODO this should be comptime assert, see #3731
329 }330 }
330 };331 };
331 try S.doTheTest();332 try S.doTheTest();
...@@ -341,7 +342,7 @@ test "pointer sentinel with optional element" {...@@ -341,7 +342,7 @@ test "pointer sentinel with optional element" {
341 fn doTheTest() !void {342 fn doTheTest() !void {
342 var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 };343 var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 };
343 _ = &ptr;344 _ = &ptr;
344 try expect(ptr[4] == null); // TODO this should be try comptime expect, see #3731345 try expect(ptr[4] == null); // TODO this should be comptime assert, see #3731
345 }346 }
346 };347 };
347 try S.doTheTest();348 try S.doTheTest();
...@@ -358,7 +359,7 @@ test "pointer sentinel with +inf" {...@@ -358,7 +359,7 @@ test "pointer sentinel with +inf" {
358 const inf_f32 = comptime std.math.inf(f32);359 const inf_f32 = comptime std.math.inf(f32);
359 var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 };360 var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 };
360 _ = &ptr;361 _ = &ptr;
361 try expect(ptr[4] == inf_f32); // TODO this should be try comptime expect, see #3731362 try expect(ptr[4] == inf_f32); // TODO this should be comptime assert, see #3731
362 }363 }
363 };364 };
364 try S.doTheTest();365 try S.doTheTest();
...@@ -409,11 +410,11 @@ test "@intFromPtr on null optional at comptime" {...@@ -409,11 +410,11 @@ test "@intFromPtr on null optional at comptime" {
409 const pointer = @as(?*u8, @ptrFromInt(0x000));410 const pointer = @as(?*u8, @ptrFromInt(0x000));
410 const x = @intFromPtr(pointer);411 const x = @intFromPtr(pointer);
411 _ = x;412 _ = x;
412 try comptime expect(0 == @intFromPtr(pointer));413 comptime assert(0 == @intFromPtr(pointer));
413 }414 }
414 {415 {
415 const pointer = @as(?*u8, @ptrFromInt(0xf00));416 const pointer = @as(?*u8, @ptrFromInt(0xf00));
416 try comptime expect(0xf00 == @intFromPtr(pointer));417 comptime assert(0xf00 == @intFromPtr(pointer));
417 }418 }
418}419}
419420
test/behavior/sizeof_and_typeof.zig+9-8
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const assert = std.debug.assert;
3const expect = std.testing.expect;4const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;5const expectEqual = std.testing.expectEqual;
56
...@@ -23,24 +24,24 @@ test "@TypeOf() with multiple arguments" {...@@ -23,24 +24,24 @@ test "@TypeOf() with multiple arguments" {
23 var var_2: u8 = undefined;24 var var_2: u8 = undefined;
24 var var_3: u64 = undefined;25 var var_3: u64 = undefined;
25 _ = .{ &var_1, &var_2, &var_3 };26 _ = .{ &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);
27 }28 }
28 {29 {
29 var var_1: f16 = undefined;30 var var_1: f16 = undefined;
30 var var_2: f32 = undefined;31 var var_2: f32 = undefined;
31 var var_3: f64 = undefined;32 var var_3: f64 = undefined;
32 _ = .{ &var_1, &var_2, &var_3 };33 _ = .{ &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);
34 }35 }
35 {36 {
36 var var_1: u16 = undefined;37 var var_1: u16 = undefined;
37 _ = &var_1;38 _ = &var_1;
38 try comptime expect(@TypeOf(var_1, 0xffff) == u16);39 comptime assert(@TypeOf(var_1, 0xffff) == u16);
39 }40 }
40 {41 {
41 var var_1: f32 = undefined;42 var var_1: f32 = undefined;
42 _ = &var_1;43 _ = &var_1;
43 try comptime expect(@TypeOf(var_1, 3.1415) == f32);44 comptime assert(@TypeOf(var_1, 3.1415) == f32);
44 }45 }
45}46}
4647
...@@ -150,7 +151,7 @@ test "@TypeOf() has no runtime side effects" {...@@ -150,7 +151,7 @@ test "@TypeOf() has no runtime side effects" {
150 };151 };
151 var data: i32 = 0;152 var data: i32 = 0;
152 const T = @TypeOf(S.foo(i32, &data));153 const T = @TypeOf(S.foo(i32, &data));
153 try comptime expect(T == i32);154 comptime assert(T == i32);
154 try expect(data == 0);155 try expect(data == 0);
155}156}
156157
...@@ -165,7 +166,7 @@ test "branching logic inside @TypeOf" {...@@ -165,7 +166,7 @@ test "branching logic inside @TypeOf" {
165 }166 }
166 };167 };
167 const T = @TypeOf(S.foo() catch undefined);168 const T = @TypeOf(S.foo() catch undefined);
168 try comptime expect(T == i32);169 comptime assert(T == i32);
169 try expect(S.data == 0);170 try expect(S.data == 0);
170}171}
171172
...@@ -238,7 +239,7 @@ test "hardcoded address in typeof expression" {...@@ -238,7 +239,7 @@ test "hardcoded address in typeof expression" {
238 }239 }
239 };240 };
240 try expect(S.func() == 0);241 try expect(S.func() == 0);
241 try comptime expect(S.func() == 0);242 comptime assert(S.func() == 0);
242}243}
243244
244test "array access of generic param in typeof expression" {245test "array access of generic param in typeof expression" {
...@@ -248,7 +249,7 @@ test "array access of generic param in typeof expression" {...@@ -248,7 +249,7 @@ test "array access of generic param in typeof expression" {
248 }249 }
249 };250 };
250 try expect(S.first("a") == 'a');251 try expect(S.first("a") == 'a');
251 try comptime expect(S.first("a") == 'a');252 comptime assert(S.first("a") == 'a');
252}253}
253254
254test "lazy size cast to float" {255test "lazy size cast to float" {
test/behavior/slice.zig+77-76
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const assert = std.debug.assert;
3const expect = std.testing.expect;4const expect = std.testing.expect;
4const expectEqualSlices = std.testing.expectEqualSlices;5const expectEqualSlices = std.testing.expectEqualSlices;
5const expectEqualStrings = std.testing.expectEqualStrings;6const expectEqualStrings = std.testing.expectEqualStrings;
...@@ -137,7 +138,7 @@ test "slice of hardcoded address to pointer" {...@@ -137,7 +138,7 @@ test "slice of hardcoded address to pointer" {
137 const S = struct {138 const S = struct {
138 fn doTheTest() !void {139 fn doTheTest() !void {
139 const pointer = @as([*]u8, @ptrFromInt(0x04))[0..2];140 const pointer = @as([*]u8, @ptrFromInt(0x04))[0..2];
140 try comptime expect(@TypeOf(pointer) == *[2]u8);141 comptime assert(@TypeOf(pointer) == *[2]u8);
141 const slice: []const u8 = pointer;142 const slice: []const u8 = pointer;
142 try expect(@intFromPtr(slice.ptr) == 4);143 try expect(@intFromPtr(slice.ptr) == 4);
143 try expect(slice.len == 2);144 try expect(slice.len == 2);
...@@ -210,9 +211,9 @@ test "slice string literal has correct type" {...@@ -210,9 +211,9 @@ test "slice string literal has correct type" {
210 }211 }
211 var runtime_zero: usize = 0;212 var runtime_zero: usize = 0;
212 _ = &runtime_zero;213 _ = &runtime_zero;
213 try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8);214 comptime assert(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8);
214 const array = [_]i32{ 1, 2, 3, 4 };215 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);
216}217}
217218
218test "result location zero sized array inside struct field implicit cast to slice" {219test "result location zero sized array inside struct field implicit cast to slice" {
...@@ -260,8 +261,8 @@ test "C pointer slice access" {...@@ -260,8 +261,8 @@ test "C pointer slice access" {
260261
261 var runtime_zero: usize = 0;262 var runtime_zero: usize = 0;
262 _ = &runtime_zero;263 _ = &runtime_zero;
263 try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));264 comptime assert(@TypeOf(c_ptr[runtime_zero..1]) == []const u32);
264 try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1]));265 comptime assert(@TypeOf(c_ptr[0..1]) == *const [1]u32);
265266
266 for (c_ptr[0..5]) |*cl| {267 for (c_ptr[0..5]) |*cl| {
267 try expect(@as(u32, 42) == cl.*);268 try expect(@as(u32, 42) == cl.*);
...@@ -314,11 +315,11 @@ test "obtaining a null terminated slice" {...@@ -314,11 +315,11 @@ test "obtaining a null terminated slice" {
314 _ = &runtime_len;315 _ = &runtime_len;
315 const ptr2 = buf[0..runtime_len :0];316 const ptr2 = buf[0..runtime_len :0];
316 // ptr2 is a null-terminated slice317 // ptr2 is a null-terminated slice
317 try comptime expect(@TypeOf(ptr2) == [:0]u8);318 comptime assert(@TypeOf(ptr2) == [:0]u8);
318 try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8);319 comptime assert(@TypeOf(ptr2[0..2]) == *[2]u8);
319 var runtime_zero: usize = 0;320 var runtime_zero: usize = 0;
320 _ = &runtime_zero;321 _ = &runtime_zero;
321 try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8);322 comptime assert(@TypeOf(ptr2[runtime_zero..2]) == []u8);
322}323}
323324
324test "empty array to slice" {325test "empty array to slice" {
...@@ -366,7 +367,7 @@ test "slice multi-pointer without end" {...@@ -366,7 +367,7 @@ test "slice multi-pointer without end" {
366 var array = [5]u8{ 1, 2, 3, 4, 5 };367 var array = [5]u8{ 1, 2, 3, 4, 5 };
367 const pointer: [*]u8 = &array;368 const pointer: [*]u8 = &array;
368 const slice = pointer[1..];369 const slice = pointer[1..];
369 try comptime expect(@TypeOf(slice) == [*]u8);370 comptime assert(@TypeOf(slice) == [*]u8);
370 try expect(slice[0] == 2);371 try expect(slice[0] == 2);
371 try expect(slice[1] == 3);372 try expect(slice[1] == 3);
372 }373 }
...@@ -375,12 +376,12 @@ test "slice multi-pointer without end" {...@@ -375,12 +376,12 @@ test "slice multi-pointer without end" {
375 var array = [5:0]u8{ 1, 2, 3, 4, 5 };376 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
376 const pointer: [*:0]u8 = &array;377 const pointer: [*:0]u8 = &array;
377378
378 try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8);379 comptime assert(@TypeOf(pointer[1..3]) == *[2]u8);
379 try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);380 comptime assert(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
380 try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8);381 comptime assert(@TypeOf(pointer[1..5 :0]) == *[4:0]u8);
381382
382 const slice = pointer[1..];383 const slice = pointer[1..];
383 try comptime expect(@TypeOf(slice) == [*:0]u8);384 comptime assert(@TypeOf(slice) == [*:0]u8);
384 try expect(slice[0] == 2);385 try expect(slice[0] == 2);
385 try expect(slice[1] == 3);386 try expect(slice[1] == 3);
386 }387 }
...@@ -422,29 +423,29 @@ test "slice syntax resulting in pointer-to-array" {...@@ -422,29 +423,29 @@ test "slice syntax resulting in pointer-to-array" {
422 fn testArray() !void {423 fn testArray() !void {
423 var array = [5]u8{ 1, 2, 3, 4, 5 };424 var array = [5]u8{ 1, 2, 3, 4, 5 };
424 const slice = array[1..3];425 const slice = array[1..3];
425 try comptime expect(@TypeOf(slice) == *[2]u8);426 comptime assert(@TypeOf(slice) == *[2]u8);
426 try expect(slice[0] == 2);427 try expect(slice[0] == 2);
427 try expect(slice[1] == 3);428 try expect(slice[1] == 3);
428 }429 }
429430
430 fn testArrayZ() !void {431 fn testArrayZ() !void {
431 var array = [5:0]u8{ 1, 2, 3, 4, 5 };432 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
432 try comptime expect(@TypeOf(array[1..3]) == *[2]u8);433 comptime assert(@TypeOf(array[1..3]) == *[2]u8);
433 try comptime expect(@TypeOf(array[1..5]) == *[4:0]u8);434 comptime assert(@TypeOf(array[1..5]) == *[4:0]u8);
434 try comptime expect(@TypeOf(array[1..]) == *[4:0]u8);435 comptime assert(@TypeOf(array[1..]) == *[4:0]u8);
435 try comptime expect(@TypeOf(array[1..3 :4]) == *[2:4]u8);436 comptime assert(@TypeOf(array[1..3 :4]) == *[2:4]u8);
436 }437 }
437438
438 fn testArray0() !void {439 fn testArray0() !void {
439 {440 {
440 var array = [0]u8{};441 var array = [0]u8{};
441 const slice = array[0..0];442 const slice = array[0..0];
442 try comptime expect(@TypeOf(slice) == *[0]u8);443 comptime assert(@TypeOf(slice) == *[0]u8);
443 }444 }
444 {445 {
445 var array = [0:0]u8{};446 var array = [0:0]u8{};
446 const slice = array[0..0];447 const slice = array[0..0];
447 try comptime expect(@TypeOf(slice) == *[0:0]u8);448 comptime assert(@TypeOf(slice) == *[0:0]u8);
448 try expect(slice[0] == 0);449 try expect(slice[0] == 0);
449 }450 }
450 }451 }
...@@ -452,16 +453,16 @@ test "slice syntax resulting in pointer-to-array" {...@@ -452,16 +453,16 @@ test "slice syntax resulting in pointer-to-array" {
452 fn testArrayAlign() !void {453 fn testArrayAlign() !void {
453 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };454 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
454 const slice = array[4..5];455 const slice = array[4..5];
455 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);456 comptime assert(@TypeOf(slice) == *align(4) [1]u8);
456 try expect(slice[0] == 5);457 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);
458 }459 }
459460
460 fn testPointer() !void {461 fn testPointer() !void {
461 var array = [5]u8{ 1, 2, 3, 4, 5 };462 var array = [5]u8{ 1, 2, 3, 4, 5 };
462 var pointer: [*]u8 = &array;463 var pointer: [*]u8 = &array;
463 const slice = pointer[1..3];464 const slice = pointer[1..3];
464 try comptime expect(@TypeOf(slice) == *[2]u8);465 comptime assert(@TypeOf(slice) == *[2]u8);
465 try expect(slice[0] == 2);466 try expect(slice[0] == 2);
466 try expect(slice[1] == 3);467 try expect(slice[1] == 3);
467 }468 }
...@@ -469,14 +470,14 @@ test "slice syntax resulting in pointer-to-array" {...@@ -469,14 +470,14 @@ test "slice syntax resulting in pointer-to-array" {
469 fn testPointerZ() !void {470 fn testPointerZ() !void {
470 var array = [5:0]u8{ 1, 2, 3, 4, 5 };471 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
471 var pointer: [*:0]u8 = &array;472 var pointer: [*:0]u8 = &array;
472 try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8);473 comptime assert(@TypeOf(pointer[1..3]) == *[2]u8);
473 try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);474 comptime assert(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
474 }475 }
475476
476 fn testPointer0() !void {477 fn testPointer0() !void {
477 var pointer: [*]const u0 = &[1]u0{0};478 var pointer: [*]const u0 = &[1]u0{0};
478 const slice = pointer[0..1];479 const slice = pointer[0..1];
479 try comptime expect(@TypeOf(slice) == *const [1]u0);480 comptime assert(@TypeOf(slice) == *const [1]u0);
480 try expect(slice[0] == 0);481 try expect(slice[0] == 0);
481 }482 }
482483
...@@ -484,16 +485,16 @@ test "slice syntax resulting in pointer-to-array" {...@@ -484,16 +485,16 @@ test "slice syntax resulting in pointer-to-array" {
484 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };485 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
485 var pointer: [*]align(4) u8 = &array;486 var pointer: [*]align(4) u8 = &array;
486 const slice = pointer[4..5];487 const slice = pointer[4..5];
487 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);488 comptime assert(@TypeOf(slice) == *align(4) [1]u8);
488 try expect(slice[0] == 5);489 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);
490 }491 }
491492
492 fn testSlice() !void {493 fn testSlice() !void {
493 var array = [5]u8{ 1, 2, 3, 4, 5 };494 var array = [5]u8{ 1, 2, 3, 4, 5 };
494 var src_slice: []u8 = &array;495 var src_slice: []u8 = &array;
495 const slice = src_slice[1..3];496 const slice = src_slice[1..3];
496 try comptime expect(@TypeOf(slice) == *[2]u8);497 comptime assert(@TypeOf(slice) == *[2]u8);
497 try expect(slice[0] == 2);498 try expect(slice[0] == 2);
498 try expect(slice[1] == 3);499 try expect(slice[1] == 3);
499 }500 }
...@@ -501,30 +502,30 @@ test "slice syntax resulting in pointer-to-array" {...@@ -501,30 +502,30 @@ test "slice syntax resulting in pointer-to-array" {
501 fn testSliceZ() !void {502 fn testSliceZ() !void {
502 var array = [5:0]u8{ 1, 2, 3, 4, 5 };503 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
503 var slice: [:0]u8 = &array;504 var slice: [:0]u8 = &array;
504 try comptime expect(@TypeOf(slice[1..3]) == *[2]u8);505 comptime assert(@TypeOf(slice[1..3]) == *[2]u8);
505 try comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);506 comptime assert(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
506 if (@inComptime()) {507 if (@inComptime()) {
507 try comptime expect(@TypeOf(slice[1..]) == *[4:0]u8);508 comptime assert(@TypeOf(slice[1..]) == *[4:0]u8);
508 } else {509 } else {
509 try comptime expect(@TypeOf(slice[1..]) == [:0]u8);510 comptime assert(@TypeOf(slice[1..]) == [:0]u8);
510 }511 }
511 }512 }
512513
513 fn testSliceOpt() !void {514 fn testSliceOpt() !void {
514 var array: [2]u8 = [2]u8{ 1, 2 };515 var array: [2]u8 = [2]u8{ 1, 2 };
515 var slice: ?[]u8 = &array;516 var slice: ?[]u8 = &array;
516 try comptime expect(@TypeOf(&array, slice) == ?[]u8);517 comptime assert(@TypeOf(&array, slice) == ?[]u8);
517 try comptime expect(@TypeOf(slice, &array) == ?[]u8);518 comptime assert(@TypeOf(slice, &array) == ?[]u8);
518 try comptime expect(@TypeOf(slice.?[0..2]) == *[2]u8);519 comptime assert(@TypeOf(slice.?[0..2]) == *[2]u8);
519 }520 }
520521
521 fn testSliceAlign() !void {522 fn testSliceAlign() !void {
522 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };523 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
523 var src_slice: []align(4) u8 = &array;524 var src_slice: []align(4) u8 = &array;
524 const slice = src_slice[4..5];525 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);
526 try expect(slice[0] == 5);527 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);
528 }529 }
529530
530 fn testConcatStrLiterals() !void {531 fn testConcatStrLiterals() !void {
...@@ -535,62 +536,62 @@ test "slice syntax resulting in pointer-to-array" {...@@ -535,62 +536,62 @@ test "slice syntax resulting in pointer-to-array" {
535 fn testSliceLength() !void {536 fn testSliceLength() !void {
536 var array = [5]u8{ 1, 2, 3, 4, 5 };537 var array = [5]u8{ 1, 2, 3, 4, 5 };
537 var slice: []u8 = &array;538 var slice: []u8 = &array;
538 try comptime expect(@TypeOf(slice[1..][0..2]) == *[2]u8);539 comptime assert(@TypeOf(slice[1..][0..2]) == *[2]u8);
539 try comptime expect(@TypeOf(slice[1..][0..4]) == *[4]u8);540 comptime assert(@TypeOf(slice[1..][0..4]) == *[4]u8);
540 try comptime expect(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8);541 comptime assert(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8);
541 }542 }
542543
543 fn testSliceLengthZ() !void {544 fn testSliceLengthZ() !void {
544 var array = [5:0]u8{ 1, 2, 3, 4, 5 };545 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
545 var slice: [:0]u8 = &array;546 var slice: [:0]u8 = &array;
546 try comptime expect(@TypeOf(slice[1..][0..2]) == *[2]u8);547 comptime assert(@TypeOf(slice[1..][0..2]) == *[2]u8);
547 try comptime expect(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8);548 comptime assert(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8);
548 try comptime expect(@TypeOf(slice[1.. :0][0..2]) == *[2]u8);549 comptime assert(@TypeOf(slice[1.. :0][0..2]) == *[2]u8);
549 try comptime expect(@TypeOf(slice[1.. :0][0..2 :4]) == *[2:4]u8);550 comptime assert(@TypeOf(slice[1.. :0][0..2 :4]) == *[2:4]u8);
550 }551 }
551552
552 fn testArrayLength() !void {553 fn testArrayLength() !void {
553 var array = [5]u8{ 1, 2, 3, 4, 5 };554 var array = [5]u8{ 1, 2, 3, 4, 5 };
554 try comptime expect(@TypeOf(array[1..][0..2]) == *[2]u8);555 comptime assert(@TypeOf(array[1..][0..2]) == *[2]u8);
555 try comptime expect(@TypeOf(array[1..][0..4]) == *[4]u8);556 comptime assert(@TypeOf(array[1..][0..4]) == *[4]u8);
556 try comptime expect(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8);557 comptime assert(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8);
557 }558 }
558559
559 fn testArrayLengthZ() !void {560 fn testArrayLengthZ() !void {
560 var array = [5:0]u8{ 1, 2, 3, 4, 5 };561 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
561 try comptime expect(@TypeOf(array[1..][0..2]) == *[2]u8);562 comptime assert(@TypeOf(array[1..][0..2]) == *[2]u8);
562 try comptime expect(@TypeOf(array[1..][0..4]) == *[4:0]u8);563 comptime assert(@TypeOf(array[1..][0..4]) == *[4:0]u8);
563 try comptime expect(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8);564 comptime assert(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8);
564 try comptime expect(@TypeOf(array[1.. :0][0..2]) == *[2]u8);565 comptime assert(@TypeOf(array[1.. :0][0..2]) == *[2]u8);
565 try comptime expect(@TypeOf(array[1.. :0][0..4]) == *[4:0]u8);566 comptime assert(@TypeOf(array[1.. :0][0..4]) == *[4:0]u8);
566 try comptime expect(@TypeOf(array[1.. :0][0..2 :4]) == *[2:4]u8);567 comptime assert(@TypeOf(array[1.. :0][0..2 :4]) == *[2:4]u8);
567 }568 }
568569
569 fn testMultiPointer() !void {570 fn testMultiPointer() !void {
570 var array = [5]u8{ 1, 2, 3, 4, 5 };571 var array = [5]u8{ 1, 2, 3, 4, 5 };
571 var ptr: [*]u8 = &array;572 var ptr: [*]u8 = &array;
572 try comptime expect(@TypeOf(ptr[1..][0..2]) == *[2]u8);573 comptime assert(@TypeOf(ptr[1..][0..2]) == *[2]u8);
573 try comptime expect(@TypeOf(ptr[1..][0..4]) == *[4]u8);574 comptime assert(@TypeOf(ptr[1..][0..4]) == *[4]u8);
574 try comptime expect(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8);575 comptime assert(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8);
575 }576 }
576577
577 fn testMultiPointerLengthZ() !void {578 fn testMultiPointerLengthZ() !void {
578 var array = [5:0]u8{ 1, 2, 3, 4, 5 };579 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
579 var ptr: [*]u8 = &array;580 var ptr: [*]u8 = &array;
580 try comptime expect(@TypeOf(ptr[1..][0..2]) == *[2]u8);581 comptime assert(@TypeOf(ptr[1..][0..2]) == *[2]u8);
581 try comptime expect(@TypeOf(ptr[1..][0..4]) == *[4]u8);582 comptime assert(@TypeOf(ptr[1..][0..4]) == *[4]u8);
582 try comptime expect(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8);583 comptime assert(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8);
583 try comptime expect(@TypeOf(ptr[1.. :0][0..2]) == *[2]u8);584 comptime assert(@TypeOf(ptr[1.. :0][0..2]) == *[2]u8);
584 try comptime expect(@TypeOf(ptr[1.. :0][0..4]) == *[4]u8);585 comptime assert(@TypeOf(ptr[1.. :0][0..4]) == *[4]u8);
585 try comptime expect(@TypeOf(ptr[1.. :0][0..2 :4]) == *[2:4]u8);586 comptime assert(@TypeOf(ptr[1.. :0][0..2 :4]) == *[2:4]u8);
586587
587 var ptr_z: [*:0]u8 = &array;588 var ptr_z: [*:0]u8 = &array;
588 try comptime expect(@TypeOf(ptr_z[1..][0..2]) == *[2]u8);589 comptime assert(@TypeOf(ptr_z[1..][0..2]) == *[2]u8);
589 try comptime expect(@TypeOf(ptr_z[1..][0..4]) == *[4]u8);590 comptime assert(@TypeOf(ptr_z[1..][0..4]) == *[4]u8);
590 try comptime expect(@TypeOf(ptr_z[1..][0..2 :4]) == *[2:4]u8);591 comptime assert(@TypeOf(ptr_z[1..][0..2 :4]) == *[2:4]u8);
591 try comptime expect(@TypeOf(ptr_z[1.. :0][0..2]) == *[2]u8);592 comptime assert(@TypeOf(ptr_z[1.. :0][0..2]) == *[2]u8);
592 try comptime expect(@TypeOf(ptr_z[1.. :0][0..4]) == *[4]u8);593 comptime assert(@TypeOf(ptr_z[1.. :0][0..4]) == *[4]u8);
593 try comptime expect(@TypeOf(ptr_z[1.. :0][0..2 :4]) == *[2:4]u8);594 comptime assert(@TypeOf(ptr_z[1.. :0][0..2 :4]) == *[2:4]u8);
594 }595 }
595596
596 fn testSingleItemPointer() !void {597 fn testSingleItemPointer() !void {
...@@ -598,10 +599,10 @@ test "slice syntax resulting in pointer-to-array" {...@@ -598,10 +599,10 @@ test "slice syntax resulting in pointer-to-array" {
598 var ptr = &value;599 var ptr = &value;
599600
600 const slice = ptr[0..1];601 const slice = ptr[0..1];
601 try comptime expect(@TypeOf(slice) == *[1]u8);602 comptime assert(@TypeOf(slice) == *[1]u8);
602 try expect(slice[0] == 1);603 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);
605 }606 }
606 };607 };
607608
...@@ -623,9 +624,9 @@ test "slice pointer-to-array null terminated" {...@@ -623,9 +624,9 @@ test "slice pointer-to-array null terminated" {
623624
624 var array = [5:0]u8{ 1, 2, 3, 4, 5 };625 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
625 var slice: [:0]u8 = &array;626 var slice: [:0]u8 = &array;
626 try comptime expect(@TypeOf(slice[1..3]) == *[2]u8);627 comptime assert(@TypeOf(slice[1..3]) == *[2]u8);
627 try comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);628 comptime assert(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
628 try comptime expect(@TypeOf(slice[1..]) == [:0]u8);629 comptime assert(@TypeOf(slice[1..]) == [:0]u8);
629}630}
630631
631test "slice pointer-to-array zero length" {632test "slice pointer-to-array zero length" {
...@@ -650,13 +651,13 @@ test "slice pointer-to-array zero length" {...@@ -650,13 +651,13 @@ test "slice pointer-to-array zero length" {
650 var array = [0]u8{};651 var array = [0]u8{};
651 var src_slice: []u8 = &array;652 var src_slice: []u8 = &array;
652 const slice = src_slice[0..0];653 const slice = src_slice[0..0];
653 try comptime expect(@TypeOf(slice) == *[0]u8);654 comptime assert(@TypeOf(slice) == *[0]u8);
654 }655 }
655 {656 {
656 var array = [0:0]u8{};657 var array = [0:0]u8{};
657 var src_slice: [:0]u8 = &array;658 var src_slice: [:0]u8 = &array;
658 const slice = src_slice[0..0];659 const slice = src_slice[0..0];
659 try comptime expect(@TypeOf(slice) == *[0]u8);660 comptime assert(@TypeOf(slice) == *[0]u8);
660 }661 }
661}662}
662663
test/behavior/struct.zig+3-3
...@@ -591,7 +591,7 @@ test "bit field access" {...@@ -591,7 +591,7 @@ test "bit field access" {
591 try expect(getA(&data) == 1);591 try expect(getA(&data) == 1);
592 try expect(getB(&data) == 2);592 try expect(getB(&data) == 2);
593 try expect(getC(&data) == 3);593 try expect(getC(&data) == 3);
594 try comptime expect(@sizeOf(BitField1) == 1);594 comptime assert(@sizeOf(BitField1) == 1);
595595
596 data.b += 1;596 data.b += 1;
597 try expect(data.b == 3);597 try expect(data.b == 3);
...@@ -730,7 +730,7 @@ test "packed struct with u0 field access" {...@@ -730,7 +730,7 @@ test "packed struct with u0 field access" {
730 };730 };
731 var s = S{ .f0 = 0 };731 var s = S{ .f0 = 0 };
732 _ = &s;732 _ = &s;
733 try comptime expect(s.f0 == 0);733 comptime assert(s.f0 == 0);
734}734}
735735
736test "access to global struct fields" {736test "access to global struct fields" {
...@@ -947,7 +947,7 @@ test "comptime struct field" {...@@ -947,7 +947,7 @@ test "comptime struct field" {
947947
948 var foo: T = undefined;948 var foo: T = undefined;
949 _ = &foo;949 _ = &foo;
950 try comptime expect(foo.b == 1234);950 comptime assert(foo.b == 1234);
951}951}
952952
953test "tuple element initialized with fn call" {953test "tuple element initialized with fn call" {
test/behavior/switch.zig+3-3
...@@ -600,9 +600,9 @@ test "switch on pointer type" {...@@ -600,9 +600,9 @@ test "switch on pointer type" {
600 try expect(1 == S.doTheTest(S.P1));600 try expect(1 == S.doTheTest(S.P1));
601 try expect(2 == S.doTheTest(S.P2));601 try expect(2 == S.doTheTest(S.P2));
602 try expect(3 == S.doTheTest(S.P3));602 try expect(3 == S.doTheTest(S.P3));
603 try comptime expect(1 == S.doTheTest(S.P1));603 comptime assert(1 == S.doTheTest(S.P1));
604 try comptime expect(2 == S.doTheTest(S.P2));604 comptime assert(2 == S.doTheTest(S.P2));
605 try comptime expect(3 == S.doTheTest(S.P3));605 comptime assert(3 == S.doTheTest(S.P3));
606}606}
607607
608test "switch on error set with single else" {608test "switch on error set with single else" {
test/behavior/truncate.zig+3-2
...@@ -1,12 +1,13 @@...@@ -1,12 +1,13 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assert = std.debug.assert;
3const expect = std.testing.expect;4const expect = std.testing.expect;
45
5test "truncate u0 to larger integer allowed and has comptime-known result" {6test "truncate u0 to larger integer allowed and has comptime-known result" {
6 var x: u0 = 0;7 var x: u0 = 0;
7 _ = &x;8 _ = &x;
8 const y = @as(u8, @truncate(x));9 const y = @as(u8, @truncate(x));
9 try comptime expect(y == 0);10 comptime assert(y == 0);
10}11}
1112
12test "truncate.u0.literal" {13test "truncate.u0.literal" {
...@@ -31,7 +32,7 @@ test "truncate i0 to larger integer allowed and has comptime-known result" {...@@ -31,7 +32,7 @@ test "truncate i0 to larger integer allowed and has comptime-known result" {
31 var x: i0 = 0;32 var x: i0 = 0;
32 _ = &x;33 _ = &x;
33 const y: i8 = @truncate(x);34 const y: i8 = @truncate(x);
34 try comptime expect(y == 0);35 comptime assert(y == 0);
35}36}
3637
37test "truncate.i0.literal" {38test "truncate.i0.literal" {
test/behavior/type_info.zig+2-1
...@@ -5,6 +5,7 @@ const mem = std.mem;...@@ -5,6 +5,7 @@ const mem = std.mem;
5const Type = std.builtin.Type;5const Type = std.builtin.Type;
6const TypeId = std.builtin.TypeId;6const TypeId = std.builtin.TypeId;
77
8const assert = std.debug.assert;
8const expect = std.testing.expect;9const expect = std.testing.expect;
9const expectEqualStrings = std.testing.expectEqualStrings;10const expectEqualStrings = std.testing.expectEqualStrings;
1011
...@@ -484,7 +485,7 @@ test "@typeInfo does not force declarations into existence" {...@@ -484,7 +485,7 @@ test "@typeInfo does not force declarations into existence" {
484 @compileError("test failed");485 @compileError("test failed");
485 }486 }
486 };487 };
487 try comptime expect(@typeInfo(S).Struct.fields.len == 1);488 comptime assert(@typeInfo(S).Struct.fields.len == 1);
488}489}
489490
490fn add(a: i32, b: i32) i32 {491fn add(a: i32, b: i32) i32 {
test/behavior/union.zig+11-11
...@@ -109,7 +109,7 @@ const ExternPtrOrInt = extern union {...@@ -109,7 +109,7 @@ const ExternPtrOrInt = extern union {
109 int: u64,109 int: u64,
110};110};
111test "extern union size" {111test "extern union size" {
112 try comptime expect(@sizeOf(ExternPtrOrInt) == 8);112 comptime assert(@sizeOf(ExternPtrOrInt) == 8);
113}113}
114114
115test "0-sized extern union definition" {115test "0-sized extern union definition" {
...@@ -161,7 +161,7 @@ test "access a member of tagged union with conflicting enum tag name" {...@@ -161,7 +161,7 @@ test "access a member of tagged union with conflicting enum tag name" {
161 const B = void;161 const B = void;
162 };162 };
163163
164 try comptime expect(Bar.A == u8);164 comptime assert(Bar.A == u8);
165}165}
166166
167test "constant tagged union with payload" {167test "constant tagged union with payload" {
...@@ -371,14 +371,14 @@ const PackedPtrOrInt = packed union {...@@ -371,14 +371,14 @@ const PackedPtrOrInt = packed union {
371 int: u64,371 int: u64,
372};372};
373test "packed union size" {373test "packed union size" {
374 try comptime expect(@sizeOf(PackedPtrOrInt) == 8);374 comptime assert(@sizeOf(PackedPtrOrInt) == 8);
375}375}
376376
377const ZeroBits = union {377const ZeroBits = union {
378 OnlyField: void,378 OnlyField: void,
379};379};
380test "union with only 1 field which is void should be zero bits" {380test "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);
382}382}
383383
384test "tagged union initialization with runtime void" {384test "tagged union initialization with runtime void" {
...@@ -428,7 +428,7 @@ test "union with only 1 field casted to its enum type" {...@@ -428,7 +428,7 @@ test "union with only 1 field casted to its enum type" {
428 var e = Expr{ .Literal = Literal{ .Bool = true } };428 var e = Expr{ .Literal = Literal{ .Bool = true } };
429 _ = &e;429 _ = &e;
430 const ExprTag = Tag(Expr);430 const ExprTag = Tag(Expr);
431 try comptime expect(Tag(ExprTag) == u0);431 comptime assert(Tag(ExprTag) == u0);
432 var t = @as(ExprTag, e);432 var t = @as(ExprTag, e);
433 _ = &t;433 _ = &t;
434 try expect(t == Expr.Literal);434 try expect(t == Expr.Literal);
...@@ -438,7 +438,7 @@ test "union with one member defaults to u0 tag type" {...@@ -438,7 +438,7 @@ test "union with one member defaults to u0 tag type" {
438 const U0 = union(enum) {438 const U0 = union(enum) {
439 X: u32,439 X: u32,
440 };440 };
441 try comptime expect(Tag(Tag(U0)) == u0);441 comptime assert(Tag(Tag(U0)) == u0);
442}442}
443443
444const Foo1 = union(enum) {444const Foo1 = union(enum) {
...@@ -629,7 +629,7 @@ test "union(enum(u32)) with specified and unspecified tag values" {...@@ -629,7 +629,7 @@ test "union(enum(u32)) with specified and unspecified tag values" {
629 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;629 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
630 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO630 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);
633 try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });633 try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
634 try comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });634 try comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
635}635}
...@@ -709,11 +709,11 @@ test "union with only 1 field casted to its enum type which has enum value speci...@@ -709,11 +709,11 @@ test "union with only 1 field casted to its enum type which has enum value speci
709709
710 var e = Expr{ .Literal = Literal{ .Bool = true } };710 var e = Expr{ .Literal = Literal{ .Bool = true } };
711 _ = &e;711 _ = &e;
712 try comptime expect(Tag(ExprTag) == comptime_int);712 comptime assert(Tag(ExprTag) == comptime_int);
713 const t = comptime @as(ExprTag, e);713 const t = comptime @as(ExprTag, e);
714 try expect(t == Expr.Literal);714 try expect(t == Expr.Literal);
715 try expect(@intFromEnum(t) == 33);715 try expect(@intFromEnum(t) == 33);
716 try comptime expect(@intFromEnum(t) == 33);716 comptime assert(@intFromEnum(t) == 33);
717}717}
718718
719test "@intFromEnum works on unions" {719test "@intFromEnum works on unions" {
...@@ -894,7 +894,7 @@ test "union with comptime_int tag" {...@@ -894,7 +894,7 @@ test "union with comptime_int tag" {
894 Y: u16,894 Y: u16,
895 Z: u8,895 Z: u8,
896 };896 };
897 try comptime expect(Tag(Tag(Union)) == comptime_int);897 comptime assert(Tag(Tag(Union)) == comptime_int);
898}898}
899899
900test "extern union doesn't trigger field check at comptime" {900test "extern union doesn't trigger field check at comptime" {
...@@ -904,7 +904,7 @@ test "extern union doesn't trigger field check at comptime" {...@@ -904,7 +904,7 @@ test "extern union doesn't trigger field check at comptime" {
904 };904 };
905905
906 const x = U{ .x = 0x55AAAA55 };906 const x = U{ .x = 0x55AAAA55 };
907 try comptime expect(x.y == 0x55);907 comptime assert(x.y == 0x55);
908}908}
909909
910test "anonymous union literal syntax" {910test "anonymous union literal syntax" {
test/behavior/vector.zig+2-2
...@@ -904,9 +904,9 @@ test "vector @reduce comptime" {...@@ -904,9 +904,9 @@ test "vector @reduce comptime" {
904 const value = V{ 1, -1, 1, -1 };904 const value = V{ 1, -1, 1, -1 };
905 const result = value > @as(V, @splat(0));905 const result = value > @as(V, @splat(0));
906 // result is { true, false, true, false };906 // result is { true, false, true, false };
907 try comptime expect(@TypeOf(result) == @Vector(4, bool));907 comptime assert(@TypeOf(result) == @Vector(4, bool));
908 const is_all_true = @reduce(.And, result);908 const is_all_true = @reduce(.And, result);
909 try comptime expect(@TypeOf(is_all_true) == bool);909 comptime assert(@TypeOf(is_all_true) == bool);
910 try expect(is_all_true == false);910 try expect(is_all_true == false);
911}911}
912912