diff --git a/doc/langref.html.in b/doc/langref.html.in index 744d33f85c..e21b6274e1 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -358,7 +358,7 @@ test "comments" { //expect(false); const x = true; // another comment - expect(x); + try expect(x); } {#code_end#}
@@ -718,15 +718,15 @@ const mem = @import("std").mem; test "string literals" { const bytes = "hello"; - expect(@TypeOf(bytes) == *const [5:0]u8); - expect(bytes.len == 5); - expect(bytes[1] == 'e'); - expect(bytes[5] == 0); - expect('e' == '\x65'); - expect('\u{1f4a9}' == 128169); - expect('π―' == 128175); - expect(mem.eql(u8, "hello", "h\x65llo")); - expect("\xff"[0] == 0xff); // non-UTF-8 strings are possible with \xNN notation. + try expect(@TypeOf(bytes) == *const [5:0]u8); + try expect(bytes.len == 5); + try expect(bytes[1] == 'e'); + try expect(bytes[5] == 0); + try expect('e' == '\x65'); + try expect('\u{1f4a9}' == 128169); + try expect('π―' == 128175); + try expect(mem.eql(u8, "hello", "h\x65llo")); + try expect("\xff"[0] == 0xff); // non-UTF-8 strings are possible with \xNN notation. } {#code_end#} {#see_also|Arrays|Zig Test|Source Encoding#} @@ -826,7 +826,7 @@ test "var" { y += 1; - expect(y == 5679); + try expect(y == 5679); } {#code_end#}
Variables must be initialized:
@@ -845,7 +845,7 @@ const expect = @import("std").testing.expect; test "init with undefined" { var x: i32 = undefined; x = 1; - expect(x == 1); + try expect(x == 1); } {#code_end#}@@ -887,8 +887,8 @@ var y: i32 = add(10, x); const x: i32 = add(12, 34); test "global variables" { - expect(x == 46); - expect(y == 56); + try expect(x == 46); + try expect(y == 56); } fn add(a: i32, b: i32) i32 { @@ -906,8 +906,8 @@ const std = @import("std"); const expect = std.testing.expect; test "namespaced global variable" { - expect(foo() == 1235); - expect(foo() == 1236); + try expect(foo() == 1235); + try expect(foo() == 1236); } fn foo() i32 { @@ -985,8 +985,8 @@ test "comptime vars" { x += 1; y += 1; - expect(x == 2); - expect(y == 2); + try expect(x == 2); + try expect(y == 2); if (y != 2) { // This compile error never triggers because y is a comptime variable, @@ -1777,6 +1777,7 @@ orelse catch {#header_open|Arrays#} {#code_begin|test|arrays#} const expect = @import("std").testing.expect; +const assert = @import("std").debug.assert; const mem = @import("std").mem; // array literal @@ -1784,14 +1785,14 @@ const message = [_]u8{ 'h', 'e', 'l', 'l', 'o' }; // get the size of an array comptime { - expect(message.len == 5); + assert(message.len == 5); } // A string literal is a single-item pointer to an array literal. const same_message = "hello"; comptime { - expect(mem.eql(u8, &message, same_message)); + assert(mem.eql(u8, &message, same_message)); } test "iterate over an array" { @@ -1799,7 +1800,7 @@ test "iterate over an array" { for (message) |byte| { sum += byte; } - expect(sum == 'h' + 'e' + 'l' * 2 + 'o'); + try expect(sum == 'h' + 'e' + 'l' * 2 + 'o'); } // modifiable array @@ -1809,8 +1810,8 @@ test "modify an array" { for (some_integers) |*item, i| { item.* = @intCast(i32, i); } - expect(some_integers[10] == 10); - expect(some_integers[99] == 99); + try expect(some_integers[10] == 10); + try expect(some_integers[99] == 99); } // array concatenation works if the values are known @@ -1819,7 +1820,7 @@ const part_one = [_]i32{ 1, 2, 3, 4 }; const part_two = [_]i32{ 5, 6, 7, 8 }; const all_of_it = part_one ++ part_two; comptime { - expect(mem.eql(i32, &all_of_it, &[_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 })); + assert(mem.eql(i32, &all_of_it, &[_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 })); } // remember that string literals are arrays @@ -1827,21 +1828,21 @@ const hello = "hello"; const world = "world"; const hello_world = hello ++ " " ++ world; comptime { - expect(mem.eql(u8, hello_world, "hello world")); + assert(mem.eql(u8, hello_world, "hello world")); } // ** does repeating patterns const pattern = "ab" ** 3; comptime { - expect(mem.eql(u8, pattern, "ababab")); + assert(mem.eql(u8, pattern, "ababab")); } // initialize an array to zero const all_zero = [_]u16{0} ** 10; comptime { - expect(all_zero.len == 10); - expect(all_zero[5] == 0); + assert(all_zero.len == 10); + assert(all_zero[5] == 0); } // use compile-time code to initialize an array @@ -1861,8 +1862,8 @@ const Point = struct { }; test "compile-time array initialization" { - expect(fancy_array[4].x == 4); - expect(fancy_array[4].y == 8); + try expect(fancy_array[4].x == 4); + try expect(fancy_array[4].y == 8); } // call a function to initialize an array @@ -1874,9 +1875,9 @@ fn makePoint(x: i32) Point { }; } test "array initialization with function calls" { - expect(more_points[4].x == 3); - expect(more_points[4].y == 6); - expect(more_points.len == 10); + try expect(more_points[4].x == 3); + try expect(more_points[4].y == 6); + try expect(more_points.len == 10); } {#code_end#} {#see_also|for|Slices#} @@ -1890,10 +1891,10 @@ const expect = std.testing.expect; test "anonymous list literal syntax" { var array: [4]u8 = .{11, 22, 33, 44}; - expect(array[0] == 11); - expect(array[1] == 22); - expect(array[2] == 33); - expect(array[3] == 44); + try expect(array[0] == 11); + try expect(array[1] == 22); + try expect(array[2] == 33); + try expect(array[3] == 44); } {#code_end#}
@@ -1905,15 +1906,15 @@ const std = @import("std"); const expect = std.testing.expect; test "fully anonymous list literal" { - dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi"}); + try dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi"}); } -fn dump(args: anytype) void { - expect(args.@"0" == 1234); - expect(args.@"1" == 12.34); - expect(args.@"2"); - expect(args.@"3"[0] == 'h'); - expect(args.@"3"[1] == 'i'); +fn dump(args: anytype) !void { + try expect(args.@"0" == 1234); + try expect(args.@"1" == 12.34); + try expect(args.@"2"); + try expect(args.@"3"[0] == 'h'); + try expect(args.@"3"[1] == 'i'); } {#code_end#} {#header_close#} @@ -1934,13 +1935,13 @@ const mat4x4 = [4][4]f32{ }; test "multidimensional arrays" { // Access the 2D array by indexing the outer array, and then the inner array. - expect(mat4x4[1][1] == 1.0); + try expect(mat4x4[1][1] == 1.0); // Here we iterate with for loops. for (mat4x4) |row, row_index| { for (row) |cell, column_index| { if (row_index == column_index) { - expect(cell == 1.0); + try expect(cell == 1.0); } } } @@ -1960,9 +1961,9 @@ const expect = std.testing.expect; test "null terminated array" { const array = [_:0]u8 {1, 2, 3, 4}; - expect(@TypeOf(array) == [4:0]u8); - expect(array.len == 4); - expect(array[4] == 0); + try expect(@TypeOf(array) == [4:0]u8); + try expect(array.len == 4); + try expect(array[4] == 0); } {#code_end#} {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Slices#} @@ -2040,17 +2041,17 @@ test "address of syntax" { const x_ptr = &x; // Dereference a pointer: - expect(x_ptr.* == 1234); + try expect(x_ptr.* == 1234); // When you get the address of a const variable, you get a const single-item pointer. - expect(@TypeOf(x_ptr) == *const i32); + try expect(@TypeOf(x_ptr) == *const i32); // If you want to mutate the value, you'd need an address of a mutable variable: var y: i32 = 5678; const y_ptr = &y; - expect(@TypeOf(y_ptr) == *i32); + try expect(@TypeOf(y_ptr) == *i32); y_ptr.* += 1; - expect(y_ptr.* == 5679); + try expect(y_ptr.* == 5679); } test "pointer array access" { @@ -2059,11 +2060,11 @@ test "pointer array access" { // does not support pointer arithmetic. var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; const ptr = &array[2]; - expect(@TypeOf(ptr) == *u8); + try expect(@TypeOf(ptr) == *u8); - expect(array[2] == 3); + try expect(array[2] == 3); ptr.* += 1; - expect(array[2] == 4); + try expect(array[2] == 4); } {#code_end#}
@@ -2081,11 +2082,11 @@ const expect = @import("std").testing.expect; test "pointer slicing" { var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; const slice = array[2..4]; - expect(slice.len == 2); + try expect(slice.len == 2); - expect(array[3] == 4); + try expect(array[3] == 4); slice[1] += 1; - expect(array[3] == 5); + try expect(array[3] == 5); } {#code_end#}
Pointers work at compile-time too, as long as the code does not depend on @@ -2099,7 +2100,7 @@ test "comptime pointers" { const ptr = &x; ptr.* += 1; x += 1; - expect(ptr.* == 3); + try expect(ptr.* == 3); } } {#code_end#} @@ -2111,8 +2112,8 @@ const expect = @import("std").testing.expect; test "@ptrToInt and @intToPtr" { const ptr = @intToPtr(*i32, 0xdeadbee0); const addr = @ptrToInt(ptr); - expect(@TypeOf(addr) == usize); - expect(addr == 0xdeadbee0); + try expect(@TypeOf(addr) == usize); + try expect(addr == 0xdeadbee0); } {#code_end#}
Zig is able to preserve memory addresses in comptime code, as long as @@ -2126,8 +2127,8 @@ test "comptime @intToPtr" { // ptr is never dereferenced. const ptr = @intToPtr(*i32, 0xdeadbee0); const addr = @ptrToInt(ptr); - expect(@TypeOf(addr) == usize); - expect(addr == 0xdeadbee0); + try expect(@TypeOf(addr) == usize); + try expect(addr == 0xdeadbee0); } } {#code_end#} @@ -2142,7 +2143,7 @@ const expect = @import("std").testing.expect; test "volatile" { const mmio_ptr = @intToPtr(*volatile u8, 0x12345678); - expect(@TypeOf(mmio_ptr) == *volatile u8); + try expect(@TypeOf(mmio_ptr) == *volatile u8); } {#code_end#}
@@ -2163,20 +2164,20 @@ const expect = std.testing.expect; test "pointer casting" { const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 }; const u32_ptr = @ptrCast(*const u32, &bytes); - expect(u32_ptr.* == 0x12121212); + try expect(u32_ptr.* == 0x12121212); // Even this example is contrived - there are better ways to do the above than // pointer casting. For example, using a slice narrowing cast: const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0]; - expect(u32_value == 0x12121212); + try expect(u32_value == 0x12121212); // And even another way, the most straightforward way to do it: - expect(@bitCast(u32, bytes) == 0x12121212); + try expect(@bitCast(u32, bytes) == 0x12121212); } test "pointer child type" { // pointer types have a `child` field which tells you the type they point to. - expect(@typeInfo(*u32).Pointer.child == u32); + try expect(@typeInfo(*u32).Pointer.child == u32); } {#code_end#} {#header_open|Alignment#} @@ -2201,10 +2202,10 @@ const expect = std.testing.expect; test "variable alignment" { var x: i32 = 1234; const align_of_i32 = @alignOf(@TypeOf(x)); - expect(@TypeOf(&x) == *i32); - expect(*i32 == *align(align_of_i32) i32); + try expect(@TypeOf(&x) == *i32); + try expect(*i32 == *align(align_of_i32) i32); if (std.Target.current.cpu.arch == .x86_64) { - expect(@typeInfo(*i32).Pointer.alignment == 4); + try expect(@typeInfo(*i32).Pointer.alignment == 4); } } {#code_end#} @@ -2222,11 +2223,11 @@ const expect = @import("std").testing.expect; var foo: u8 align(4) = 100; test "global variable alignment" { - expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4); - expect(@TypeOf(&foo) == *align(4) u8); + try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4); + try expect(@TypeOf(&foo) == *align(4) u8); const as_pointer_to_array: *[1]u8 = &foo; const as_slice: []u8 = as_pointer_to_array; - expect(@TypeOf(as_slice) == []align(4) u8); + try expect(@TypeOf(as_slice) == []align(4) u8); } fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; } @@ -2234,9 +2235,9 @@ fn noop1() align(1) void {} fn noop4() align(4) void {} test "function alignment" { - expect(derp() == 1234); - expect(@TypeOf(noop1) == fn() align(1) void); - expect(@TypeOf(noop4) == fn() align(4) void); + try expect(derp() == 1234); + try expect(@TypeOf(noop1) == fn() align(1) void); + try expect(@TypeOf(noop4) == fn() align(4) void); noop1(); noop4(); } @@ -2253,7 +2254,7 @@ const std = @import("std"); test "pointer alignment safety" { var array align(4) = [_]u32{ 0x11111111, 0x11111111 }; const bytes = std.mem.sliceAsBytes(array[0..]); - std.testing.expect(foo(bytes) == 0x11111111); + try std.testing.expect(foo(bytes) == 0x11111111); } fn foo(bytes: []u8) u32 { const slice4 = bytes[1..5]; @@ -2279,7 +2280,7 @@ const expect = std.testing.expect; test "allowzero" { var zero: usize = 0; var ptr = @intToPtr(*allowzero i32, zero); - expect(@ptrToInt(ptr) == 0); + try expect(@ptrToInt(ptr) == 0); } {#code_end#} {#header_close#} @@ -2321,14 +2322,14 @@ test "basic slices" { // Both can be accessed with the `len` field. var known_at_runtime_zero: usize = 0; const slice = array[known_at_runtime_zero..array.len]; - expect(&slice[0] == &array[0]); - expect(slice.len == array.len); + try expect(&slice[0] == &array[0]); + try expect(slice.len == array.len); // Using the address-of operator on a slice gives a single-item pointer, // while using the `ptr` field gives a many-item pointer. - expect(@TypeOf(slice.ptr) == [*]i32); - expect(@TypeOf(&slice[0]) == *i32); - expect(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0])); + try expect(@TypeOf(slice.ptr) == [*]i32); + try expect(@TypeOf(&slice[0]) == *i32); + try expect(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0])); // Slices have array bounds checking. If you try to access something out // of bounds, you'll get a safety check failure: @@ -2362,7 +2363,7 @@ test "using slices for strings" { // Generally, you can use UTF-8 and not worry about whether something is a // string. If you don't need to deal with individual characters, no need // to decode. - expect(mem.eql(u8, hello_world, "hello δΈη")); + try expect(mem.eql(u8, hello_world, "hello δΈη")); } test "slice pointer" { @@ -2372,16 +2373,16 @@ test "slice pointer" { // You can use slicing syntax to convert a pointer into a slice: const slice = ptr[0..5]; slice[2] = 3; - expect(slice[2] == 3); + try expect(slice[2] == 3); // The slice is mutable because we sliced a mutable pointer. // Furthermore, it is actually a pointer to an array, since the start // and end indexes were both comptime-known. - expect(@TypeOf(slice) == *[5]u8); + try expect(@TypeOf(slice) == *[5]u8); // You can also slice a slice: const slice2 = slice[2..3]; - expect(slice2.len == 1); - expect(slice2[0] == 3); + try expect(slice2.len == 1); + try expect(slice2[0] == 3); } {#code_end#} {#see_also|Pointers|for|Arrays#} @@ -2400,8 +2401,8 @@ const expect = std.testing.expect; test "null terminated slice" { const slice: [:0]const u8 = "hello"; - expect(slice.len == 5); - expect(slice[5] == 0); + try expect(slice.len == 5); + try expect(slice[5] == 0); } {#code_end#} {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Arrays#} @@ -2463,12 +2464,12 @@ const expect = @import("std").testing.expect; test "dot product" { const v1 = Vec3.init(1.0, 0.0, 0.0); const v2 = Vec3.init(0.0, 1.0, 0.0); - expect(v1.dot(v2) == 0.0); + try expect(v1.dot(v2) == 0.0); // Other than being available to call with dot syntax, struct methods are // not special. You can reference them as any other declaration inside // the struct: - expect(Vec3.dot(v1, v2) == 0.0); + try expect(Vec3.dot(v1, v2) == 0.0); } // Structs can have global declarations. @@ -2477,8 +2478,8 @@ const Empty = struct { pub const PI = 3.14; }; test "struct namespaced variable" { - expect(Empty.PI == 3.14); - expect(@sizeOf(Empty) == 0); + try expect(Empty.PI == 3.14); + try expect(@sizeOf(Empty) == 0); // you can still instantiate an empty struct const does_nothing = Empty {}; @@ -2496,7 +2497,7 @@ test "field parent pointer" { .y = 0.5678, }; setYBasedOnX(&point.x, 0.9); - expect(point.y == 0.9); + try expect(point.y == 0.9); } // You can return a struct from a function. This is how we do generics @@ -2518,19 +2519,19 @@ fn LinkedList(comptime T: type) type { test "linked list" { // Functions called at compile-time are memoized. This means you can // do this: - expect(LinkedList(i32) == LinkedList(i32)); + try expect(LinkedList(i32) == LinkedList(i32)); var list = LinkedList(i32) { .first = null, .last = null, .len = 0, }; - expect(list.len == 0); + try expect(list.len == 0); // Since types are first class values you can instantiate the type // by assigning it to a variable: const ListOfInts = LinkedList(i32); - expect(ListOfInts == LinkedList(i32)); + try expect(ListOfInts == LinkedList(i32)); var node = ListOfInts.Node { .prev = null, @@ -2542,7 +2543,7 @@ test "linked list" { .last = &node, .len = 1, }; - expect(list2.first.?.data == 1234); + try expect(list2.first.?.data == 1234); } {#code_end#} @@ -2615,25 +2616,25 @@ const Divided = packed struct { }; test "@bitCast between packed structs" { - doTheTest(); - comptime doTheTest(); + try doTheTest(); + comptime try doTheTest(); } -fn doTheTest() void { - expect(@sizeOf(Full) == 2); - expect(@sizeOf(Divided) == 2); +fn doTheTest() !void { + try expect(@sizeOf(Full) == 2); + try expect(@sizeOf(Divided) == 2); var full = Full{ .number = 0x1234 }; var divided = @bitCast(Divided, full); switch (builtin.endian) { .Big => { - expect(divided.half1 == 0x12); - expect(divided.quarter3 == 0x3); - expect(divided.quarter4 == 0x4); + try expect(divided.half1 == 0x12); + try expect(divided.quarter3 == 0x3); + try expect(divided.quarter4 == 0x4); }, .Little => { - expect(divided.half1 == 0x34); - expect(divided.quarter3 == 0x2); - expect(divided.quarter4 == 0x1); + try expect(divided.half1 == 0x34); + try expect(divided.quarter3 == 0x2); + try expect(divided.quarter4 == 0x1); }, } } @@ -2659,7 +2660,7 @@ var foo = BitField{ test "pointer to non-byte-aligned field" { const ptr = &foo.b; - expect(ptr.* == 2); + try expect(ptr.* == 2); } {#code_end#}
@@ -2683,7 +2684,7 @@ var bit_field = BitField{ }; test "pointer to non-bit-aligned field" { - expect(bar(&bit_field.b) == 2); + try expect(bar(&bit_field.b) == 2); } fn bar(x: *const u3) u3 { @@ -2714,8 +2715,8 @@ var bit_field = BitField{ }; test "pointer to non-bit-aligned field" { - expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b)); - expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c)); + try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b)); + try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c)); } {#code_end#}
@@ -2733,13 +2734,13 @@ const BitField = packed struct { test "pointer to non-bit-aligned field" { comptime { - expect(@bitOffsetOf(BitField, "a") == 0); - expect(@bitOffsetOf(BitField, "b") == 3); - expect(@bitOffsetOf(BitField, "c") == 6); + try expect(@bitOffsetOf(BitField, "a") == 0); + try expect(@bitOffsetOf(BitField, "b") == 3); + try expect(@bitOffsetOf(BitField, "c") == 6); - expect(@byteOffsetOf(BitField, "a") == 0); - expect(@byteOffsetOf(BitField, "b") == 0); - expect(@byteOffsetOf(BitField, "c") == 0); + try expect(@byteOffsetOf(BitField, "a") == 0); + try expect(@byteOffsetOf(BitField, "b") == 0); + try expect(@byteOffsetOf(BitField, "c") == 0); } } {#code_end#} @@ -2776,9 +2777,9 @@ test "aligned struct fields" { }; var foo = S{ .a = 1, .b = 2 }; - expectEqual(64, @alignOf(S)); - expectEqual(*align(2) u32, @TypeOf(&foo.a)); - expectEqual(*align(64) u32, @TypeOf(&foo.b)); + try expectEqual(64, @alignOf(S)); + try expectEqual(*align(2) u32, @TypeOf(&foo.a)); + try expectEqual(*align(64) u32, @TypeOf(&foo.b)); } {#code_end#}
@@ -2834,8 +2835,8 @@ test "anonymous struct literal" { .x = 13, .y = 67, }; - expect(pt.x == 13); - expect(pt.y == 67); + try expect(pt.x == 13); + try expect(pt.y == 67); } {#code_end#}
@@ -2847,7 +2848,7 @@ const std = @import("std"); const expect = std.testing.expect; test "fully anonymous struct" { - dump(.{ + try dump(.{ .int = @as(u32, 1234), .float = @as(f64, 12.34), .b = true, @@ -2855,12 +2856,12 @@ test "fully anonymous struct" { }); } -fn dump(args: anytype) void { - expect(args.int == 1234); - expect(args.float == 12.34); - expect(args.b); - expect(args.s[0] == 'h'); - expect(args.s[1] == 'i'); +fn dump(args: anytype) !void { + try expect(args.int == 1234); + try expect(args.float == 12.34); + try expect(args.b); + try expect(args.s[0] == 'h'); + try expect(args.s[1] == 'i'); } {#code_end#}
@@ -2884,14 +2885,14 @@ test "tuple" { true, "hi", } ++ .{false} ** 2; - expect(values[0] == 1234); - expect(values[4] == false); + try expect(values[0] == 1234); + try expect(values[4] == false); inline for (values) |v, i| { if (i != 2) continue; - expect(v); + try expect(v); } - expect(values.len == 6); - expect(values.@"3"[0] == 'h'); + try expect(values.len == 6); + try expect(values.@"3"[0] == 'h'); } {#code_end#} {#header_close#} @@ -2922,9 +2923,9 @@ const Value = enum(u2) { // Now you can cast between u2 and Value. // The ordinal value starts from 0, counting up for each member. test "enum ordinal value" { - expect(@enumToInt(Value.zero) == 0); - expect(@enumToInt(Value.one) == 1); - expect(@enumToInt(Value.two) == 2); + try expect(@enumToInt(Value.zero) == 0); + try expect(@enumToInt(Value.one) == 1); + try expect(@enumToInt(Value.two) == 2); } // You can override the ordinal value for an enum. @@ -2934,9 +2935,9 @@ const Value2 = enum(u32) { million = 1000000, }; test "set enum ordinal value" { - expect(@enumToInt(Value2.hundred) == 100); - expect(@enumToInt(Value2.thousand) == 1000); - expect(@enumToInt(Value2.million) == 1000000); + try expect(@enumToInt(Value2.hundred) == 100); + try expect(@enumToInt(Value2.thousand) == 1000); + try expect(@enumToInt(Value2.million) == 1000000); } // Enums can have methods, the same as structs and unions. @@ -2954,7 +2955,7 @@ const Suit = enum { }; test "enum method" { const p = Suit.spades; - expect(!p.isClubs()); + try expect(!p.isClubs()); } // An enum variant of different types can be switched upon. @@ -2970,7 +2971,7 @@ test "enum variant switch" { Foo.number => "this is a number", Foo.none => "this is a none", }; - expect(mem.eql(u8, what_is_it, "this is a number")); + try expect(mem.eql(u8, what_is_it, "this is a number")); } // @typeInfo can be used to access the integer tag type of an enum. @@ -2981,18 +2982,18 @@ const Small = enum { four, }; test "std.meta.Tag" { - expect(@typeInfo(Small).Enum.tag_type == u2); + try expect(@typeInfo(Small).Enum.tag_type == u2); } // @typeInfo tells us the field count and the fields names: test "@typeInfo" { - expect(@typeInfo(Small).Enum.fields.len == 4); - expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two")); + try expect(@typeInfo(Small).Enum.fields.len == 4); + try expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two")); } // @tagName gives a []const u8 representation of an enum value: test "@tagName" { - expect(mem.eql(u8, @tagName(Small.three), "three")); + try expect(mem.eql(u8, @tagName(Small.three), "three")); } {#code_end#} {#see_also|@typeInfo|@tagName|@sizeOf#} @@ -3027,7 +3028,7 @@ test "packed enum" { two, three, }; - std.testing.expect(@sizeOf(Number) == @sizeOf(u8)); + try std.testing.expect(@sizeOf(Number) == @sizeOf(u8)); } {#code_end#}
This makes the enum eligible to be in a {#link|packed struct#}.
@@ -3050,7 +3051,7 @@ const Color = enum { test "enum literals" { const color1: Color = .auto; const color2 = Color.auto; - expect(color1 == color2); + try expect(color1 == color2); } test "switch using enum literals" { @@ -3060,7 +3061,7 @@ test "switch using enum literals" { .on => true, .off => false, }; - expect(result); + try expect(result); } {#code_end#} {#header_close#} @@ -3096,12 +3097,12 @@ test "switch on non-exhaustive enum" { .three => false, _ => false, }; - expect(result); + try expect(result); const is_one = switch (number) { .one => true, else => false, }; - expect(is_one); + try expect(is_one); } {#code_end#} {#header_close#} @@ -3141,9 +3142,9 @@ const Payload = union { }; test "simple union" { var payload = Payload{ .int = 1234 }; - expect(payload.int == 1234); + try expect(payload.int == 1234); payload = Payload{ .float = 12.34 }; - expect(payload.float == 12.34); + try expect(payload.float == 12.34); } {#code_end#}@@ -3174,24 +3175,24 @@ const ComplexType = union(ComplexTypeTag) { test "switch on tagged union" { const c = ComplexType{ .ok = 42 }; - expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); + try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); switch (c) { - ComplexTypeTag.ok => |value| expect(value == 42), + ComplexTypeTag.ok => |value| try expect(value == 42), ComplexTypeTag.not_ok => unreachable, } } test "get tag type" { - expect(std.meta.Tag(ComplexType) == ComplexTypeTag); + try expect(std.meta.Tag(ComplexType) == ComplexTypeTag); } test "coerce to enum" { const c1 = ComplexType{ .ok = 42 }; const c2 = ComplexType.not_ok; - expect(c1 == .ok); - expect(c2 == .not_ok); + try expect(c1 == .ok); + try expect(c2 == .not_ok); } {#code_end#}
In order to modify the payload of a tagged union in a switch expression, @@ -3212,14 +3213,14 @@ const ComplexType = union(ComplexTypeTag) { test "modify tagged union in switch" { var c = ComplexType{ .ok = 42 }; - expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); + try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); switch (c) { ComplexTypeTag.ok => |*value| value.* += 1, ComplexTypeTag.not_ok => unreachable, } - expect(c.ok == 43); + try expect(c.ok == 43); } {#code_end#}
@@ -3250,8 +3251,8 @@ test "union method" { var v1 = Variant{ .int = 1 }; var v2 = Variant{ .boolean = false }; - expect(v1.truthy()); - expect(!v2.truthy()); + try expect(v1.truthy()); + try expect(!v2.truthy()); } {#code_end#}
@@ -3268,7 +3269,7 @@ const Small2 = union(enum) { c: u8, }; test "@tagName" { - expect(std.mem.eql(u8, @tagName(Small2.a), "a")); + try expect(std.mem.eql(u8, @tagName(Small2.a), "a")); } {#code_end#} {#header_close#} @@ -3301,8 +3302,8 @@ const Number = union { test "anonymous union literal syntax" { var i: Number = .{.int = 42}; var f = makeNumber(); - expect(i.int == 42); - expect(f.float == 12.34); + try expect(i.int == 42); + try expect(f.float == 12.34); } fn makeNumber() Number { @@ -3364,8 +3365,8 @@ test "labeled break from labeled block expression" { y += 1; break :blk y; }; - expect(x == 124); - expect(y == 124); + try expect(x == 124); + try expect(y == 124); } {#code_end#}
Here, {#syntax#}blk{#endsyntax#} can be any name.
@@ -3443,7 +3444,7 @@ test "switch simple" { else => 9, }; - expect(b == 1); + try expect(b == 1); } // Switch expressions can be used outside a function: @@ -3506,8 +3507,8 @@ test "switch on tagged union" { Item.d => 8, }; - expect(b == 6); - expect(a.c.x == 2); + try expect(b == 6); + try expect(a.c.x == 2); } {#code_end#} {#see_also|comptime|enum|@compileError|Compile Variables#} @@ -3556,7 +3557,7 @@ test "enum literals with switch" { .on => false, .off => true, }; - expect(result); + try expect(result); } {#code_end#} {#header_close#} @@ -3575,7 +3576,7 @@ test "while basic" { while (i < 10) { i += 1; } - expect(i == 10); + try expect(i == 10); } {#code_end#}@@ -3591,7 +3592,7 @@ test "while break" { break; i += 1; } - expect(i == 10); + try expect(i == 10); } {#code_end#}
@@ -3608,7 +3609,7 @@ test "while continue" { continue; break; } - expect(i == 10); + try expect(i == 10); } {#code_end#}
@@ -3621,7 +3622,7 @@ const expect = @import("std").testing.expect; test "while loop continue expression" { var i: usize = 0; while (i < 10) : (i += 1) {} - expect(i == 10); + try expect(i == 10); } test "while loop continue expression, more complicated" { @@ -3629,7 +3630,7 @@ test "while loop continue expression, more complicated" { var j: usize = 1; while (i * j < 2000) : ({ i *= 2; j *= 3; }) { const my_ij = i * j; - expect(my_ij < 2000); + try expect(my_ij < 2000); } } {#code_end#} @@ -3648,8 +3649,8 @@ test "while loop continue expression, more complicated" { const expect = @import("std").testing.expect; test "while else" { - expect(rangeHasNumber(0, 10, 5)); - expect(!rangeHasNumber(0, 10, 15)); + try expect(rangeHasNumber(0, 10, 5)); + try expect(!rangeHasNumber(0, 10, 15)); } fn rangeHasNumber(begin: usize, end: usize, number: usize) bool { @@ -3706,14 +3707,14 @@ test "while null capture" { while (eventuallyNullSequence()) |value| { sum1 += value; } - expect(sum1 == 3); + try expect(sum1 == 3); var sum2: u32 = 0; numbers_left = 3; while (eventuallyNullSequence()) |value| { sum2 += value; } else { - expect(sum2 == 3); + try expect(sum2 == 3); } } @@ -3748,7 +3749,7 @@ test "while error union capture" { while (eventuallyErrorSequence()) |value| { sum1 += value; } else |err| { - expect(err == error.ReachedZero); + try expect(err == error.ReachedZero); } } @@ -3784,7 +3785,7 @@ test "inline while loop" { }; sum += typeNameLength(T); } - expect(sum == 9); + try expect(sum == 9); } fn typeNameLength(comptime T: type) usize { @@ -3819,22 +3820,22 @@ test "for basics" { } sum += value; } - expect(sum == 16); + try expect(sum == 16); // To iterate over a portion of a slice, reslice. for (items[0..1]) |value| { sum += value; } - expect(sum == 20); + try expect(sum == 20); // To access the index of iteration, specify a second capture value. // This is zero-indexed. var sum2: i32 = 0; for (items) |value, i| { - expect(@TypeOf(i) == usize); + try expect(@TypeOf(i) == usize); sum2 += @intCast(i32, i); } - expect(sum2 == 10); + try expect(sum2 == 10); } test "for reference" { @@ -3846,9 +3847,9 @@ test "for reference" { value.* += 1; } - expect(items[0] == 4); - expect(items[1] == 5); - expect(items[2] == 3); + try expect(items[0] == 4); + try expect(items[1] == 5); + try expect(items[2] == 3); } test "for else" { @@ -3863,10 +3864,10 @@ test "for else" { sum += value.?; } } else blk: { - expect(sum == 12); + try expect(sum == 12); break :blk sum; }; - expect(result == 12); + try expect(result == 12); } {#code_end#} {#header_open|Labeled for#} @@ -3884,7 +3885,7 @@ test "nested break" { break :outer; } } - expect(count == 1); + try expect(count == 1); } test "nested continue" { @@ -3896,7 +3897,7 @@ test "nested continue" { } } - expect(count == 8); + try expect(count == 8); } {#code_end#} {#header_close#} @@ -3923,7 +3924,7 @@ test "inline for loop" { }; sum += typeNameLength(T); } - expect(sum == 9); + try expect(sum == 9); } fn typeNameLength(comptime T: type) usize { @@ -3956,7 +3957,7 @@ test "if expression" { const a: u32 = 5; const b: u32 = 4; const result = if (a != b) 47 else 3089; - expect(result == 47); + try expect(result == 47); } test "if boolean" { @@ -3964,7 +3965,7 @@ test "if boolean" { const a: u32 = 5; const b: u32 = 4; if (a != b) { - expect(true); + try expect(true); } else if (a == 9) { unreachable; } else { @@ -3977,7 +3978,7 @@ test "if optional" { const a: ?u32 = 0; if (a) |value| { - expect(value == 0); + try expect(value == 0); } else { unreachable; } @@ -3986,17 +3987,17 @@ test "if optional" { if (b) |value| { unreachable; } else { - expect(true); + try expect(true); } // The else is not required. if (a) |value| { - expect(value == 0); + try expect(value == 0); } // To test against null only, use the binary equality operator. if (b == null) { - expect(true); + try expect(true); } // Access the value by reference using a pointer capture. @@ -4006,7 +4007,7 @@ test "if optional" { } if (c) |value| { - expect(value == 2); + try expect(value == 2); } else { unreachable; } @@ -4018,7 +4019,7 @@ test "if error union" { const a: anyerror!u32 = 0; if (a) |value| { - expect(value == 0); + try expect(value == 0); } else |err| { unreachable; } @@ -4027,17 +4028,17 @@ test "if error union" { if (b) |value| { unreachable; } else |err| { - expect(err == error.BadValue); + try expect(err == error.BadValue); } // The else and |err| capture is strictly required. if (a) |value| { - expect(value == 0); + try expect(value == 0); } else |_| {} // To check only the error value, use an empty block expression. if (b) |_| {} else |err| { - expect(err == error.BadValue); + try expect(err == error.BadValue); } // Access the value by reference using a pointer capture. @@ -4049,7 +4050,7 @@ test "if error union" { } if (c) |value| { - expect(value == 9); + try expect(value == 9); } else |err| { unreachable; } @@ -4061,14 +4062,14 @@ test "if error union with optional" { const a: anyerror!?u32 = 0; if (a) |optional_value| { - expect(optional_value.? == 0); + try expect(optional_value.? == 0); } else |err| { unreachable; } const b: anyerror!?u32 = null; if (b) |optional_value| { - expect(optional_value == null); + try expect(optional_value == null); } else |err| { unreachable; } @@ -4077,7 +4078,7 @@ test "if error union with optional" { if (c) |optional_value| { unreachable; } else |err| { - expect(err == error.BadValue); + try expect(err == error.BadValue); } // Access the value by reference by using a pointer capture each time. @@ -4091,7 +4092,7 @@ test "if error union with optional" { } if (d) |optional_value| { - expect(optional_value.? == 9); + try expect(optional_value.? == 9); } else |err| { unreachable; } @@ -4106,21 +4107,21 @@ const expect = std.testing.expect; const print = std.debug.print; // defer will execute an expression at the end of the current scope. -fn deferExample() usize { +fn deferExample() !usize { var a: usize = 1; { defer a = 2; a = 1; } - expect(a == 2); + try expect(a == 2); a = 5; return a; } test "defer basics" { - expect(deferExample() == 5); + try expect((try deferExample()) == 5); } // If multiple defer statements are specified, they will be executed in @@ -4258,7 +4259,7 @@ pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(if (@import("bu test "foo" { const value = bar() catch ExitProcess(1); - expect(value == 1234); + try expect(value == 1234); } fn bar() anyerror!u32 { @@ -4321,17 +4322,17 @@ fn do_op(fn_call: call2_op, op1: i8, op2: i8) i8 { } test "function" { - expect(do_op(add, 5, 6) == 11); - expect(do_op(sub2, 5, 6) == -1); + try expect(do_op(add, 5, 6) == 11); + try expect(do_op(sub2, 5, 6) == -1); } {#code_end#}
Function values are like pointers:
{#code_begin|obj#} -const expect = @import("std").testing.expect; +const assert = @import("std").debug.assert; comptime { - expect(@TypeOf(foo) == fn()void); - expect(@sizeOf(fn()void) == @sizeOf(?fn()void)); + assert(@TypeOf(foo) == fn()void); + assert(@sizeOf(fn()void) == @sizeOf(?fn()void)); } fn foo() void { } @@ -4366,7 +4367,7 @@ fn foo(point: Point) i32 { const expect = @import("std").testing.expect; test "pass struct to function" { - expect(foo(Point{ .x = 1, .y = 2 }) == 3); + try expect(foo(Point{ .x = 1, .y = 2 }) == 3); } {#code_end#}@@ -4387,11 +4388,11 @@ fn addFortyTwo(x: anytype) @TypeOf(x) { } test "fn type inference" { - expect(addFortyTwo(1) == 43); - expect(@TypeOf(addFortyTwo(1)) == comptime_int); + try expect(addFortyTwo(1) == 43); + try expect(@TypeOf(addFortyTwo(1)) == comptime_int); var y: i64 = 2; - expect(addFortyTwo(y) == 44); - expect(@TypeOf(addFortyTwo(y)) == i64); + try expect(addFortyTwo(y) == 44); + try expect(@TypeOf(addFortyTwo(y)) == i64); } {#code_end#} @@ -4401,8 +4402,8 @@ test "fn type inference" { const expect = @import("std").testing.expect; test "fn reflection" { - expect(@typeInfo(@TypeOf(expect)).Fn.return_type.? == void); - expect(@typeInfo(@TypeOf(expect)).Fn.is_var_args == false); + try expect(@typeInfo(@TypeOf(expect)).Fn.args[0].arg_type.? == bool); + try expect(@typeInfo(@TypeOf(expect)).Fn.is_var_args == false); } {#code_end#} {#header_close#} @@ -4437,7 +4438,7 @@ const AllocationError = error { test "coerce subset to superset" { const err = foo(AllocationError.OutOfMemory); - std.testing.expect(err == FileOpenError.OutOfMemory); + try std.testing.expect(err == FileOpenError.OutOfMemory); } fn foo(err: AllocationError) FileOpenError { @@ -4545,7 +4546,7 @@ fn charToDigit(c: u8) u8 { test "parse u64" { const result = try parseU64("1234", 10); - std.testing.expect(result == 1234); + try std.testing.expect(result == 1234); } {#code_end#}
@@ -4702,10 +4703,10 @@ test "error union" { foo = error.SomeError; // Use compile-time reflection to access the payload type of an error union: - comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.payload == i32); + comptime try expect(@typeInfo(@TypeOf(foo)).ErrorUnion.payload == i32); // Use compile-time reflection to access the error set type of an error union: - comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.error_set == anyerror); + comptime try expect(@typeInfo(@TypeOf(foo)).ErrorUnion.error_set == anyerror); } {#code_end#} {#header_open|Merging Error Sets#} @@ -5082,7 +5083,7 @@ test "optional type" { foo = 1234; // Use compile-time reflection to access the child type of the optional: - comptime expect(@typeInfo(@TypeOf(foo)).Optional.child == i32); + comptime try expect(@typeInfo(@TypeOf(foo)).Optional.child == i32); } {#code_end#} {#header_close#} @@ -5109,11 +5110,11 @@ test "optional pointers" { var x: i32 = 1; ptr = &x; - expect(ptr.?.* == 1); + try expect(ptr.?.* == 1); // Optional pointers are the same size as normal pointers, because pointer // value 0 is used as the null value. - expect(@sizeOf(?*i32) == @sizeOf(*i32)); + try expect(@sizeOf(?*i32) == @sizeOf(*i32)); } {#code_end#} {#header_close#} @@ -5186,7 +5187,7 @@ const mem = std.mem; test "cast *[1][*]const u8 to [*]const ?[*]const u8" { const window_name = [1][*]const u8{"window name"}; const x: [*]const ?[*]const u8 = &window_name; - expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name")); + try expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name")); } {#code_end#} {#header_close#} @@ -5207,13 +5208,13 @@ test "integer widening" { var d: u64 = c; var e: u64 = d; var f: u128 = e; - expect(f == a); + try expect(f == a); } test "implicit unsigned integer to signed integer" { var a: u8 = 250; var b: i16 = a; - expect(b == 250); + try expect(b == 250); } test "float widening" { @@ -5225,7 +5226,7 @@ test "float widening" { var b: f32 = a; var c: f64 = b; var d: f128 = c; - expect(d == a); + try expect(d == a); } {#code_end#} {#header_close#} @@ -5257,48 +5258,48 @@ const expect = std.testing.expect; test "[N]T to []const T" { var x1: []const u8 = "hello"; var x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; - expect(std.mem.eql(u8, x1, x2)); + try expect(std.mem.eql(u8, x1, x2)); var y: []const f32 = &[2]f32{ 1.2, 3.4 }; - expect(y[0] == 1.2); + try expect(y[0] == 1.2); } // Likewise, it works when the destination type is an error union. test "[N]T to E![]const T" { var x1: anyerror![]const u8 = "hello"; var x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; - expect(std.mem.eql(u8, try x1, try x2)); + try expect(std.mem.eql(u8, try x1, try x2)); var y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 }; - expect((try y)[0] == 1.2); + try expect((try y)[0] == 1.2); } // Likewise, it works when the destination type is an optional. test "[N]T to ?[]const T" { var x1: ?[]const u8 = "hello"; var x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; - expect(std.mem.eql(u8, x1.?, x2.?)); + try expect(std.mem.eql(u8, x1.?, x2.?)); var y: ?[]const f32 = &[2]f32{ 1.2, 3.4 }; - expect(y.?[0] == 1.2); + try expect(y.?[0] == 1.2); } // In this cast, the array length becomes the slice length. test "*[N]T to []T" { var buf: [5]u8 = "hello".*; const x: []u8 = &buf; - expect(std.mem.eql(u8, x, "hello")); + try expect(std.mem.eql(u8, x, "hello")); const buf2 = [2]f32{ 1.2, 3.4 }; const x2: []const f32 = &buf2; - expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 })); + try expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 })); } // Single-item pointers to arrays can be coerced to many-item pointers. test "*[N]T to [*]T" { var buf: [5]u8 = "hello".*; const x: [*]u8 = &buf; - expect(x[4] == 'o'); + try expect(x[4] == 'o'); // x[5] would be an uncaught out of bounds pointer dereference! } @@ -5306,7 +5307,7 @@ test "*[N]T to [*]T" { test "*[N]T to ?[*]T" { var buf: [5]u8 = "hello".*; const x: ?[*]u8 = &buf; - expect(x.?[4] == 'o'); + try expect(x.?[4] == 'o'); } // Single-item pointers can be cast to len-1 single-item arrays. @@ -5314,7 +5315,7 @@ test "*T to *[1]T" { var x: i32 = 1234; const y: *[1]i32 = &x; const z: [*]i32 = y; - expect(z[0] == 1234); + try expect(z[0] == 1234); } {#code_end#} {#see_also|C Pointers#} @@ -5331,8 +5332,8 @@ test "coerce to optionals" { const x: ?i32 = 1234; const y: ?i32 = null; - expect(x.? == 1234); - expect(y == null); + try expect(x.? == 1234); + try expect(y == null); } {#code_end#}
It works nested inside the {#link|Error Union Type#}, too:
@@ -5344,8 +5345,8 @@ test "coerce to optionals wrapped in error union" { const x: anyerror!?i32 = 1234; const y: anyerror!?i32 = null; - expect((try x).? == 1234); - expect((try y) == null); + try expect((try x).? == 1234); + try expect((try y) == null); } {#code_end#} {#header_close#} @@ -5361,8 +5362,8 @@ test "coercion to error unions" { const x: anyerror!i32 = 1234; const y: anyerror!i32 = error.Failure; - expect((try x) == 1234); - std.testing.expectError(error.Failure, y); + try expect((try x) == 1234); + try std.testing.expectError(error.Failure, y); } {#code_end#} {#header_close#} @@ -5377,7 +5378,7 @@ const expect = std.testing.expect; test "coercing large integer type to smaller one when value is comptime known to fit" { const x: u64 = 255; const y: u8 = x; - expect(y == 255); + try expect(y == 255); } {#code_end#} {#header_close#} @@ -5405,11 +5406,11 @@ const U = union(E) { test "coercion between unions and enums" { var u = U{ .two = 12.34 }; var e: E = u; - expect(e == E.two); + try expect(e == E.two); const three = E.three; var another_u: U = three; - expect(another_u == E.three); + try expect(another_u == E.three); } {#code_end#} {#see_also|union|enum#} @@ -5482,37 +5483,37 @@ test "peer resolve int widening" { var a: i8 = 12; var b: i16 = 34; var c = a + b; - expect(c == 46); - expect(@TypeOf(c) == i16); + try expect(c == 46); + try expect(@TypeOf(c) == i16); } test "peer resolve arrays of different size to const slice" { - expect(mem.eql(u8, boolToStr(true), "true")); - expect(mem.eql(u8, boolToStr(false), "false")); - comptime expect(mem.eql(u8, boolToStr(true), "true")); - comptime expect(mem.eql(u8, boolToStr(false), "false")); + try expect(mem.eql(u8, boolToStr(true), "true")); + try expect(mem.eql(u8, boolToStr(false), "false")); + comptime try expect(mem.eql(u8, boolToStr(true), "true")); + comptime try expect(mem.eql(u8, boolToStr(false), "false")); } fn boolToStr(b: bool) []const u8 { return if (b) "true" else "false"; } test "peer resolve array and const slice" { - testPeerResolveArrayConstSlice(true); - comptime testPeerResolveArrayConstSlice(true); + try testPeerResolveArrayConstSlice(true); + comptime try testPeerResolveArrayConstSlice(true); } -fn testPeerResolveArrayConstSlice(b: bool) void { +fn testPeerResolveArrayConstSlice(b: bool) !void { const value1 = if (b) "aoeu" else @as([]const u8, "zz"); const value2 = if (b) @as([]const u8, "zz") else "aoeu"; - expect(mem.eql(u8, value1, "aoeu")); - expect(mem.eql(u8, value2, "zz")); + try expect(mem.eql(u8, value1, "aoeu")); + try expect(mem.eql(u8, value2, "zz")); } test "peer type resolution: ?T and T" { - expect(peerTypeTAndOptionalT(true, false).? == 0); - expect(peerTypeTAndOptionalT(false, false).? == 3); + try expect(peerTypeTAndOptionalT(true, false).? == 0); + try expect(peerTypeTAndOptionalT(false, false).? == 3); comptime { - expect(peerTypeTAndOptionalT(true, false).? == 0); - expect(peerTypeTAndOptionalT(false, false).? == 3); + try expect(peerTypeTAndOptionalT(true, false).? == 0); + try expect(peerTypeTAndOptionalT(false, false).? == 3); } } fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { @@ -5524,11 +5525,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { } test "peer type resolution: *[0]u8 and []const u8" { - expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); - expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); + try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); + try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); comptime { - expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); - expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); + try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); + try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); } } fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 { @@ -5542,14 +5543,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" { { var data = "hi".*; const slice = data[0..]; - expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); - expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); + try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); + try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); } comptime { var data = "hi".*; const slice = data[0..]; - expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); - expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); + try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); + try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); } } fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { @@ -5563,8 +5564,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { test "peer type resolution: *const T and ?*T" { const a = @intToPtr(*const usize, 0x123456780); const b = @intToPtr(?*usize, 0x123456780); - expect(a == b); - expect(b == a); + try expect(a == b); + try expect(b == a); } {#code_end#} {#header_close#} @@ -5620,11 +5621,11 @@ test "turn HashMap into a set with void" { try map.put(1, {}); try map.put(2, {}); - expect(map.contains(2)); - expect(!map.contains(3)); + try expect(map.contains(2)); + try expect(!map.contains(3)); _ = map.remove(2); - expect(!map.contains(2)); + try expect(!map.contains(2)); } {#code_end#}Note that this is different from using a dummy value for the hash map value. @@ -5679,7 +5680,7 @@ test "pointer to empty struct" { var b = Empty{}; var ptr_a = &a; var ptr_b = &b; - comptime expect(ptr_a == ptr_b); + comptime try expect(ptr_a == ptr_b); } {#code_end#}
The type being pointed to can only ever be one value; therefore loads and stores are @@ -5714,7 +5715,7 @@ test "@intToPtr for pointer to zero bit type" { usingnamespace @import("std"); test "using std namespace" { - testing.expect(true); + try testing.expect(true); } {#code_end#}
@@ -5826,7 +5827,7 @@ fn max(comptime T: type, a: T, b: T) T { } } test "try to compare bools" { - @import("std").testing.expect(max(bool, false, true) == true); + try @import("std").testing.expect(max(bool, false, true) == true); } {#code_end#}
@@ -5894,9 +5895,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 { } test "perform fn" { - expect(performFn('t', 1) == 6); - expect(performFn('o', 0) == 1); - expect(performFn('w', 99) == 99); + try expect(performFn('t', 1) == 6); + try expect(performFn('o', 0) == 1); + try expect(performFn('w', 99) == 99); } {#code_end#}
@@ -5988,11 +5989,11 @@ fn fibonacci(index: u32) u32 { test "fibonacci" { // test fibonacci at run-time - expect(fibonacci(7) == 13); + try expect(fibonacci(7) == 13); // test fibonacci at compile-time comptime { - expect(fibonacci(7) == 13); + try expect(fibonacci(7) == 13); } } {#code_end#} @@ -6009,7 +6010,7 @@ fn fibonacci(index: u32) u32 { test "fibonacci" { comptime { - expect(fibonacci(7) == 13); + try expect(fibonacci(7) == 13); } } {#code_end#} @@ -6032,7 +6033,7 @@ fn fibonacci(index: i32) i32 { test "fibonacci" { comptime { - expect(fibonacci(7) == 13); + try expect(fibonacci(7) == 13); } } {#code_end#} @@ -6045,7 +6046,7 @@ test "fibonacci" {
What if we fix the base case, but put the wrong value in the {#syntax#}expect{#endsyntax#} line?
- {#code_begin|test_err|encountered @panic at compile-time#} + {#code_begin|test_err|test "fibonacci"... FAIL (TestUnexpectedResult)#} const expect = @import("std").testing.expect; fn fibonacci(index: i32) i32 { @@ -6055,7 +6056,7 @@ fn fibonacci(index: i32) i32 { test "fibonacci" { comptime { - expect(fibonacci(7) == 99999); + try expect(fibonacci(7) == 99999); } } {#code_end#} @@ -6105,7 +6106,7 @@ fn sum(numbers: []const i32) i32 { } test "variable values" { - @import("std").testing.expect(sum_of_first_25_primes == 1060); + try @import("std").testing.expect(sum_of_first_25_primes == 1060); } {#code_end#}@@ -6513,7 +6514,7 @@ comptime { extern fn my_func(a: i32, b: i32) i32; test "global assembly" { - expect(my_func(12, 34) == 46); + try expect(my_func(12, 34) == 46); } {#code_end#} {#header_close#} @@ -6554,7 +6555,7 @@ var x: i32 = 1; test "suspend with no resume" { var frame = async func(); - expect(x == 2); + try expect(x == 2); } fn func() void { @@ -6581,14 +6582,14 @@ var result = false; test "async function suspend with block" { _ = async testSuspendBlock(); - expect(!result); + try expect(!result); resume the_frame; - expect(result); + try expect(result); } fn testSuspendBlock() void { suspend { - comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)); + comptime try expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)); the_frame = @frame(); } result = true; @@ -6617,7 +6618,7 @@ const expect = std.testing.expect; test "resume from suspend" { var my_result: i32 = 1; _ = async testResumeFromSuspend(&my_result); - std.testing.expect(my_result == 2); + try std.testing.expect(my_result == 2); } fn testResumeFromSuspend(my_result: *i32) void { suspend { @@ -6653,7 +6654,7 @@ test "async and await" { fn amain() void { var frame = async func(); - comptime expect(@TypeOf(frame) == @Frame(func)); + comptime try expect(@TypeOf(frame) == @Frame(func)); const ptr: anyframe->void = &frame; const any_ptr: anyframe = ptr; @@ -6694,8 +6695,8 @@ test "async function await" { seq('f'); resume the_frame; seq('i'); - expect(final_result == 1234); - expect(std.mem.eql(u8, &seq_points, "abcdefghi")); + try expect(final_result == 1234); + try expect(std.mem.eql(u8, &seq_points, "abcdefghi")); } fn amain() void { seq('b'); @@ -6909,9 +6910,9 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { for the current target to match the C ABI. When the child type of a pointer has this alignment, the alignment can be omitted from the type.
-{#syntax#}const expect = @import("std").testing.expect;
+ {#syntax#}const expect = @import("std").debug.assert;
comptime {
- expect(*u32 == *align(@alignOf(u32)) u32);
+ assert(*u32 == *align(@alignOf(u32)) u32);
}{#endsyntax#}
The result is a target-specific compile time constant. It is guaranteed to be
@@ -6957,9 +6958,9 @@ test "async fn pointer in a struct field" {
var foo = Foo{ .bar = func };
var bytes: [64]u8 align(@alignOf(@Frame(func))) = undefined;
const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
- expect(data == 2);
+ try expect(data == 2);
resume f;
- expect(data == 4);
+ try expect(data == 4);
}
fn func(y: *i32) void {
@@ -7146,7 +7147,7 @@ fn func(y: *i32) void {
const expect = @import("std").testing.expect;
test "noinline function call" {
- expect(@call(.{}, add, .{3, 9}) == 12);
+ try expect(@call(.{}, add, .{3, 9}) == 12);
}
fn add(a: i32, b: i32) i32 {
@@ -7621,17 +7622,17 @@ test "field access by string" {
@field(p, "x") = 4;
@field(p, "y") = @field(p, "x") + 1;
- expect(@field(p, "x") == 4);
- expect(@field(p, "y") == 5);
+ try expect(@field(p, "x") == 4);
+ try expect(@field(p, "y") == 5);
}
test "decl access by string" {
const expect = std.testing.expect;
- expect(@field(Point, "z") == 1);
+ try expect(@field(Point, "z") == 1);
@field(Point, "z") = 2;
- expect(@field(Point, "z") == 2);
+ try expect(@field(Point, "z") == 2);
}
{#code_end#}
@@ -7747,16 +7748,16 @@ const Foo = struct {
};
test "@hasDecl" {
- expect(@hasDecl(Foo, "blah"));
+ try expect(@hasDecl(Foo, "blah"));
// Even though `hi` is private, @hasDecl returns true because this test is
// in the same file scope as Foo. It would return false if Foo was declared
// in a different file.
- expect(@hasDecl(Foo, "hi"));
+ try expect(@hasDecl(Foo, "hi"));
// @hasDecl is for declarations; not fields.
- expect(!@hasDecl(Foo, "nope"));
- expect(!@hasDecl(Foo, "nope1234"));
+ try expect(!@hasDecl(Foo, "nope"));
+ try expect(!@hasDecl(Foo, "nope1234"));
}
{#code_end#}
{#see_also|@hasField#}
@@ -7937,8 +7938,8 @@ test "@wasmMemoryGrow" {
if (builtin.arch != .wasm32) return error.SkipZigTest;
var prev = @wasmMemorySize(0);
- expect(prev == @wasmMemoryGrow(0, 1));
- expect(prev + 1 == @wasmMemorySize(0));
+ try expect(prev == @wasmMemoryGrow(0, 1));
+ try expect(prev + 1 == @wasmMemorySize(0));
}
{#code_end#}
{#see_also|@wasmMemorySize#}
@@ -8279,8 +8280,8 @@ const expect = std.testing.expect;
test "vector @splat" {
const scalar: u32 = 5;
const result = @splat(4, scalar);
- comptime expect(@TypeOf(result) == std.meta.Vector(4, u32));
- expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
+ comptime try expect(@TypeOf(result) == std.meta.Vector(4, u32));
+ try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
}
{#code_end#}
@@ -8322,10 +8323,10 @@ test "vector @reduce" {
const value: std.meta.Vector(4, i32) = [_]i32{ 1, -1, 1, -1 };
const result = value > @splat(4, @as(i32, 0));
// result is { true, false, true, false };
- comptime expect(@TypeOf(result) == std.meta.Vector(4, bool));
+ comptime try expect(@TypeOf(result) == std.meta.Vector(4, bool));
const is_all_true = @reduce(.And, result);
- comptime expect(@TypeOf(is_all_true) == bool);
- expect(is_all_true == false);
+ comptime try expect(@TypeOf(is_all_true) == bool);
+ try expect(is_all_true == false);
}
{#code_end#}
{#see_also|Vectors|@setFloatMode#}
@@ -8341,16 +8342,16 @@ const std = @import("std");
const expect = std.testing.expect;
test "@src" {
- doTheTest();
+ try doTheTest();
}
-fn doTheTest() void {
+fn doTheTest() !void {
const src = @src();
- expect(src.line == 9);
- expect(src.column == 17);
- expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
- expect(std.mem.endsWith(u8, src.file, "test.zig"));
+ try expect(src.line == 9);
+ try expect(src.column == 17);
+ try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
+ try expect(std.mem.endsWith(u8, src.file, "test.zig"));
}
{#code_end#}
{#header_close#}
@@ -8527,7 +8528,7 @@ const expect = std.testing.expect;
test "@This()" {
var items = [_]i32{ 1, 2, 3, 4 };
const list = List(i32){ .items = items[0..] };
- expect(list.length() == 4);
+ try expect(list.length() == 4);
}
fn List(comptime T: type) type {
@@ -8573,7 +8574,7 @@ const expect = std.testing.expect;
test "integer truncation" {
var a: u16 = 0xabcd;
var b: u8 = @truncate(u8, a);
- expect(b == 0xcd);
+ try expect(b == 0xcd);
}
{#code_end#}
@@ -8661,8 +8662,8 @@ const expect = std.testing.expect;
test "no runtime side effects" {
var data: i32 = 0;
const T = @TypeOf(foo(i32, &data));
- comptime expect(T == i32);
- expect(data == 0);
+ comptime try expect(T == i32);
+ try expect(data == 0);
}
fn foo(comptime T: type, ptr: *T) T {
@@ -8972,9 +8973,9 @@ const maxInt = std.math.maxInt;
test "wraparound addition and subtraction" {
const x: i32 = maxInt(i32);
const min_val = x +% 1;
- expect(min_val == minInt(i32));
+ try expect(min_val == minInt(i32));
const max_val = min_val -% 1;
- expect(max_val == maxInt(i32));
+ try expect(max_val == maxInt(i32));
}
{#code_end#}
{#header_close#}
@@ -9405,7 +9406,7 @@ test "using an allocator" {
var buffer: [100]u8 = undefined;
const allocator = &std.heap.FixedBufferAllocator.init(&buffer).allocator;
const result = try concat(allocator, "foo", "bar");
- expect(std.mem.eql(u8, "foobar", result));
+ try expect(std.mem.eql(u8, "foobar", result));
}
fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 {
@@ -9675,7 +9676,7 @@ const builtin = std.builtin;
const expect = std.testing.expect;
test "builtin.is_test" {
- expect(builtin.is_test);
+ try expect(builtin.is_test);
}
{#code_end#}
@@ -9720,13 +9721,13 @@ test "assert in release fast mode" {
Better practice for checking the output when testing is to use {#syntax#}std.testing.expect{#endsyntax#}:
- {#code_begin|test_err|test failure#}
+ {#code_begin|test_err|test "expect in release fast mode"... FAIL (TestUnexpectedResult)#}
{#code_release_fast#}
const std = @import("std");
const expect = std.testing.expect;
test "expect in release fast mode" {
- expect(false);
+ try expect(false);
}
{#code_end#}
See the rest of the {#syntax#}std.testing{#endsyntax#} namespace for more available functions.
diff --git a/lib/std/SemanticVersion.zig b/lib/std/SemanticVersion.zig
index 52c3ae59df..8e748184a8 100644
--- a/lib/std/SemanticVersion.zig
+++ b/lib/std/SemanticVersion.zig
@@ -249,13 +249,13 @@ test "SemanticVersion format" {
"+justmeta",
"9.8.7+meta+meta",
"9.8.7-whatever+meta+meta",
- }) |invalid| expectError(error.InvalidVersion, parse(invalid));
+ }) |invalid| try expectError(error.InvalidVersion, parse(invalid));
// Valid version string that may overflow.
const big_valid = "99999999999999999999999.999999999999999999.99999999999999999";
if (parse(big_valid)) |ver| {
try std.testing.expectFmt(big_valid, "{}", .{ver});
- } else |err| expect(err == error.Overflow);
+ } else |err| try expect(err == error.Overflow);
// Invalid version string that may overflow.
const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12";
@@ -264,22 +264,22 @@ test "SemanticVersion format" {
test "SemanticVersion precedence" {
// SemVer 2 spec 11.2 example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.
- expect(order(try parse("1.0.0"), try parse("2.0.0")) == .lt);
- expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt);
- expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt);
+ try expect(order(try parse("1.0.0"), try parse("2.0.0")) == .lt);
+ try expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt);
+ try expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt);
// SemVer 2 spec 11.3 example: 1.0.0-alpha < 1.0.0.
- expect(order(try parse("1.0.0-alpha"), try parse("1.0.0")) == .lt);
+ try expect(order(try parse("1.0.0-alpha"), try parse("1.0.0")) == .lt);
// SemVer 2 spec 11.4 example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta <
// 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
- expect(order(try parse("1.0.0-alpha"), try parse("1.0.0-alpha.1")) == .lt);
- expect(order(try parse("1.0.0-alpha.1"), try parse("1.0.0-alpha.beta")) == .lt);
- expect(order(try parse("1.0.0-alpha.beta"), try parse("1.0.0-beta")) == .lt);
- expect(order(try parse("1.0.0-beta"), try parse("1.0.0-beta.2")) == .lt);
- expect(order(try parse("1.0.0-beta.2"), try parse("1.0.0-beta.11")) == .lt);
- expect(order(try parse("1.0.0-beta.11"), try parse("1.0.0-rc.1")) == .lt);
- expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt);
+ try expect(order(try parse("1.0.0-alpha"), try parse("1.0.0-alpha.1")) == .lt);
+ try expect(order(try parse("1.0.0-alpha.1"), try parse("1.0.0-alpha.beta")) == .lt);
+ try expect(order(try parse("1.0.0-alpha.beta"), try parse("1.0.0-beta")) == .lt);
+ try expect(order(try parse("1.0.0-beta"), try parse("1.0.0-beta.2")) == .lt);
+ try expect(order(try parse("1.0.0-beta.2"), try parse("1.0.0-beta.11")) == .lt);
+ try expect(order(try parse("1.0.0-beta.11"), try parse("1.0.0-rc.1")) == .lt);
+ try expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt);
}
test "zig_version" {
diff --git a/lib/std/Thread/AutoResetEvent.zig b/lib/std/Thread/AutoResetEvent.zig
index 0726dc794a..63da2c9a30 100644
--- a/lib/std/Thread/AutoResetEvent.zig
+++ b/lib/std/Thread/AutoResetEvent.zig
@@ -176,7 +176,7 @@ test "basic usage" {
// test local code paths
{
var event = AutoResetEvent{};
- testing.expectError(error.TimedOut, event.timedWait(1));
+ try testing.expectError(error.TimedOut, event.timedWait(1));
event.set();
event.wait();
}
@@ -192,28 +192,28 @@ test "basic usage" {
const Self = @This();
- fn sender(self: *Self) void {
- testing.expect(self.value == 0);
+ fn sender(self: *Self) !void {
+ try testing.expect(self.value == 0);
self.value = 1;
self.out.set();
self.in.wait();
- testing.expect(self.value == 2);
+ try testing.expect(self.value == 2);
self.value = 3;
self.out.set();
self.in.wait();
- testing.expect(self.value == 4);
+ try testing.expect(self.value == 4);
}
- fn receiver(self: *Self) void {
+ fn receiver(self: *Self) !void {
self.out.wait();
- testing.expect(self.value == 1);
+ try testing.expect(self.value == 1);
self.value = 2;
self.in.set();
self.out.wait();
- testing.expect(self.value == 3);
+ try testing.expect(self.value == 3);
self.value = 4;
self.in.set();
}
diff --git a/lib/std/Thread/Mutex.zig b/lib/std/Thread/Mutex.zig
index e7d11954bf..cae4e282de 100644
--- a/lib/std/Thread/Mutex.zig
+++ b/lib/std/Thread/Mutex.zig
@@ -294,7 +294,7 @@ test "basic usage" {
if (builtin.single_threaded) {
worker(&context);
- testing.expect(context.data == TestContext.incr_count);
+ try testing.expect(context.data == TestContext.incr_count);
} else {
const thread_count = 10;
var threads: [thread_count]*std.Thread = undefined;
@@ -304,7 +304,7 @@ test "basic usage" {
for (threads) |t|
t.wait();
- testing.expect(context.data == thread_count * TestContext.incr_count);
+ try testing.expect(context.data == thread_count * TestContext.incr_count);
}
}
diff --git a/lib/std/Thread/ResetEvent.zig b/lib/std/Thread/ResetEvent.zig
index 439fb0db40..f161b46aa0 100644
--- a/lib/std/Thread/ResetEvent.zig
+++ b/lib/std/Thread/ResetEvent.zig
@@ -204,7 +204,7 @@ test "basic usage" {
event.reset();
event.set();
- testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
+ try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
// test cross-thread signaling
if (builtin.single_threaded)
@@ -233,25 +233,25 @@ test "basic usage" {
self.* = undefined;
}
- fn sender(self: *Self) void {
+ fn sender(self: *Self) !void {
// update value and signal input
- testing.expect(self.value == 0);
+ try testing.expect(self.value == 0);
self.value = 1;
self.in.set();
// wait for receiver to update value and signal output
self.out.wait();
- testing.expect(self.value == 2);
+ try testing.expect(self.value == 2);
// update value and signal final input
self.value = 3;
self.in.set();
}
- fn receiver(self: *Self) void {
+ fn receiver(self: *Self) !void {
// wait for sender to update value and signal input
self.in.wait();
- assert(self.value == 1);
+ try testing.expect(self.value == 1);
// update value and signal output
self.in.reset();
@@ -260,7 +260,7 @@ test "basic usage" {
// wait for sender to update value and signal final input
self.in.wait();
- assert(self.value == 3);
+ try testing.expect(self.value == 3);
}
fn sleeper(self: *Self) void {
@@ -272,9 +272,9 @@ test "basic usage" {
fn timedWaiter(self: *Self) !void {
self.in.wait();
- testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
+ try testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
try self.out.timedWait(time.ns_per_ms * 100);
- testing.expect(self.value == 5);
+ try testing.expect(self.value == 5);
}
};
@@ -283,7 +283,7 @@ test "basic usage" {
defer context.deinit();
const receiver = try std.Thread.spawn(Context.receiver, &context);
defer receiver.wait();
- context.sender();
+ try context.sender();
if (false) {
// I have now observed this fail on macOS, Windows, and Linux.
diff --git a/lib/std/Thread/StaticResetEvent.zig b/lib/std/Thread/StaticResetEvent.zig
index 07a8e50c16..96a5a765a2 100644
--- a/lib/std/Thread/StaticResetEvent.zig
+++ b/lib/std/Thread/StaticResetEvent.zig
@@ -320,7 +320,7 @@ test "basic usage" {
event.reset();
event.set();
- testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
+ try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
// test cross-thread signaling
if (std.builtin.single_threaded)
@@ -333,25 +333,25 @@ test "basic usage" {
in: StaticResetEvent = .{},
out: StaticResetEvent = .{},
- fn sender(self: *Self) void {
+ fn sender(self: *Self) !void {
// update value and signal input
- testing.expect(self.value == 0);
+ try testing.expect(self.value == 0);
self.value = 1;
self.in.set();
// wait for receiver to update value and signal output
self.out.wait();
- testing.expect(self.value == 2);
+ try testing.expect(self.value == 2);
// update value and signal final input
self.value = 3;
self.in.set();
}
- fn receiver(self: *Self) void {
+ fn receiver(self: *Self) !void {
// wait for sender to update value and signal input
self.in.wait();
- assert(self.value == 1);
+ try testing.expect(self.value == 1);
// update value and signal output
self.in.reset();
@@ -360,7 +360,7 @@ test "basic usage" {
// wait for sender to update value and signal final input
self.in.wait();
- assert(self.value == 3);
+ try testing.expect(self.value == 3);
}
fn sleeper(self: *Self) void {
@@ -372,16 +372,16 @@ test "basic usage" {
fn timedWaiter(self: *Self) !void {
self.in.wait();
- testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
+ try testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
try self.out.timedWait(time.ns_per_ms * 100);
- testing.expect(self.value == 5);
+ try testing.expect(self.value == 5);
}
};
var context = Context{};
const receiver = try std.Thread.spawn(Context.receiver, &context);
defer receiver.wait();
- context.sender();
+ try context.sender();
if (false) {
// I have now observed this fail on macOS, Windows, and Linux.
diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig
index 83a061dfef..25a1aead52 100644
--- a/lib/std/array_hash_map.zig
+++ b/lib/std/array_hash_map.zig
@@ -1064,63 +1064,63 @@ test "basic hash map usage" {
var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
defer map.deinit();
- testing.expect((try map.fetchPut(1, 11)) == null);
- testing.expect((try map.fetchPut(2, 22)) == null);
- testing.expect((try map.fetchPut(3, 33)) == null);
- testing.expect((try map.fetchPut(4, 44)) == null);
+ try testing.expect((try map.fetchPut(1, 11)) == null);
+ try testing.expect((try map.fetchPut(2, 22)) == null);
+ try testing.expect((try map.fetchPut(3, 33)) == null);
+ try testing.expect((try map.fetchPut(4, 44)) == null);
try map.putNoClobber(5, 55);
- testing.expect((try map.fetchPut(5, 66)).?.value == 55);
- testing.expect((try map.fetchPut(5, 55)).?.value == 66);
+ try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
+ try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
const gop1 = try map.getOrPut(5);
- testing.expect(gop1.found_existing == true);
- testing.expect(gop1.entry.value == 55);
- testing.expect(gop1.index == 4);
+ try testing.expect(gop1.found_existing == true);
+ try testing.expect(gop1.entry.value == 55);
+ try testing.expect(gop1.index == 4);
gop1.entry.value = 77;
- testing.expect(map.getEntry(5).?.value == 77);
+ try testing.expect(map.getEntry(5).?.value == 77);
const gop2 = try map.getOrPut(99);
- testing.expect(gop2.found_existing == false);
- testing.expect(gop2.index == 5);
+ try testing.expect(gop2.found_existing == false);
+ try testing.expect(gop2.index == 5);
gop2.entry.value = 42;
- testing.expect(map.getEntry(99).?.value == 42);
+ try testing.expect(map.getEntry(99).?.value == 42);
const gop3 = try map.getOrPutValue(5, 5);
- testing.expect(gop3.value == 77);
+ try testing.expect(gop3.value == 77);
const gop4 = try map.getOrPutValue(100, 41);
- testing.expect(gop4.value == 41);
+ try testing.expect(gop4.value == 41);
- testing.expect(map.contains(2));
- testing.expect(map.getEntry(2).?.value == 22);
- testing.expect(map.get(2).? == 22);
+ try testing.expect(map.contains(2));
+ try testing.expect(map.getEntry(2).?.value == 22);
+ try testing.expect(map.get(2).? == 22);
const rmv1 = map.swapRemove(2);
- testing.expect(rmv1.?.key == 2);
- testing.expect(rmv1.?.value == 22);
- testing.expect(map.swapRemove(2) == null);
- testing.expect(map.getEntry(2) == null);
- testing.expect(map.get(2) == null);
+ try testing.expect(rmv1.?.key == 2);
+ try testing.expect(rmv1.?.value == 22);
+ try testing.expect(map.swapRemove(2) == null);
+ try testing.expect(map.getEntry(2) == null);
+ try testing.expect(map.get(2) == null);
// Since we've used `swapRemove` above, the index of this entry should remain unchanged.
- testing.expect(map.getIndex(100).? == 1);
+ try testing.expect(map.getIndex(100).? == 1);
const gop5 = try map.getOrPut(5);
- testing.expect(gop5.found_existing == true);
- testing.expect(gop5.entry.value == 77);
- testing.expect(gop5.index == 4);
+ try testing.expect(gop5.found_existing == true);
+ try testing.expect(gop5.entry.value == 77);
+ try testing.expect(gop5.index == 4);
// Whereas, if we do an `orderedRemove`, it should move the index forward one spot.
const rmv2 = map.orderedRemove(100);
- testing.expect(rmv2.?.key == 100);
- testing.expect(rmv2.?.value == 41);
- testing.expect(map.orderedRemove(100) == null);
- testing.expect(map.getEntry(100) == null);
- testing.expect(map.get(100) == null);
+ try testing.expect(rmv2.?.key == 100);
+ try testing.expect(rmv2.?.value == 41);
+ try testing.expect(map.orderedRemove(100) == null);
+ try testing.expect(map.getEntry(100) == null);
+ try testing.expect(map.get(100) == null);
const gop6 = try map.getOrPut(5);
- testing.expect(gop6.found_existing == true);
- testing.expect(gop6.entry.value == 77);
- testing.expect(gop6.index == 3);
+ try testing.expect(gop6.found_existing == true);
+ try testing.expect(gop6.entry.value == 77);
+ try testing.expect(gop6.index == 3);
map.removeAssertDiscard(3);
}
@@ -1156,11 +1156,11 @@ test "iterator hash map" {
while (it.next()) |entry| : (count += 1) {
buffer[@intCast(usize, entry.key)] = entry.value;
}
- testing.expect(count == 3);
- testing.expect(it.next() == null);
+ try testing.expect(count == 3);
+ try testing.expect(it.next() == null);
for (buffer) |v, i| {
- testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
+ try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
}
it.reset();
@@ -1172,13 +1172,13 @@ test "iterator hash map" {
}
for (buffer[0..2]) |v, i| {
- testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
+ try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
}
it.reset();
var entry = it.next().?;
- testing.expect(entry.key == first_entry.key);
- testing.expect(entry.value == first_entry.value);
+ try testing.expect(entry.key == first_entry.key);
+ try testing.expect(entry.value == first_entry.value);
}
test "ensure capacity" {
@@ -1187,13 +1187,13 @@ test "ensure capacity" {
try map.ensureCapacity(20);
const initial_capacity = map.capacity();
- testing.expect(initial_capacity >= 20);
+ try testing.expect(initial_capacity >= 20);
var i: i32 = 0;
while (i < 20) : (i += 1) {
- testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
+ try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
}
// shouldn't resize from putAssumeCapacity
- testing.expect(initial_capacity == map.capacity());
+ try testing.expect(initial_capacity == map.capacity());
}
test "clone" {
@@ -1211,7 +1211,7 @@ test "clone" {
i = 0;
while (i < 10) : (i += 1) {
- testing.expect(copy.get(i).? == i * 10);
+ try testing.expect(copy.get(i).? == i * 10);
}
}
@@ -1223,35 +1223,35 @@ test "shrink" {
const num_entries = 20;
var i: i32 = 0;
while (i < num_entries) : (i += 1)
- testing.expect((try map.fetchPut(i, i * 10)) == null);
+ try testing.expect((try map.fetchPut(i, i * 10)) == null);
- testing.expect(map.unmanaged.index_header != null);
- testing.expect(map.count() == num_entries);
+ try testing.expect(map.unmanaged.index_header != null);
+ try testing.expect(map.count() == num_entries);
// Test `shrinkRetainingCapacity`.
map.shrinkRetainingCapacity(17);
- testing.expect(map.count() == 17);
- testing.expect(map.capacity() == 20);
+ try testing.expect(map.count() == 17);
+ try testing.expect(map.capacity() == 20);
i = 0;
while (i < num_entries) : (i += 1) {
const gop = try map.getOrPut(i);
if (i < 17) {
- testing.expect(gop.found_existing == true);
- testing.expect(gop.entry.value == i * 10);
- } else testing.expect(gop.found_existing == false);
+ try testing.expect(gop.found_existing == true);
+ try testing.expect(gop.entry.value == i * 10);
+ } else try testing.expect(gop.found_existing == false);
}
// Test `shrinkAndFree`.
map.shrinkAndFree(15);
- testing.expect(map.count() == 15);
- testing.expect(map.capacity() == 15);
+ try testing.expect(map.count() == 15);
+ try testing.expect(map.capacity() == 15);
i = 0;
while (i < num_entries) : (i += 1) {
const gop = try map.getOrPut(i);
if (i < 15) {
- testing.expect(gop.found_existing == true);
- testing.expect(gop.entry.value == i * 10);
- } else testing.expect(gop.found_existing == false);
+ try testing.expect(gop.found_existing == true);
+ try testing.expect(gop.entry.value == i * 10);
+ } else try testing.expect(gop.found_existing == false);
}
}
@@ -1264,12 +1264,12 @@ test "pop" {
var i: i32 = 0;
while (i < 9) : (i += 1) {
- testing.expect((try map.fetchPut(i, i)) == null);
+ try testing.expect((try map.fetchPut(i, i)) == null);
}
while (i > 0) : (i -= 1) {
const pop = map.pop();
- testing.expect(pop.key == i - 1 and pop.value == i - 1);
+ try testing.expect(pop.key == i - 1 and pop.value == i - 1);
}
}
@@ -1281,10 +1281,10 @@ test "reIndex" {
const num_indexed_entries = 20;
var i: i32 = 0;
while (i < num_indexed_entries) : (i += 1)
- testing.expect((try map.fetchPut(i, i * 10)) == null);
+ try testing.expect((try map.fetchPut(i, i * 10)) == null);
// Make sure we allocated an index header.
- testing.expect(map.unmanaged.index_header != null);
+ try testing.expect(map.unmanaged.index_header != null);
// Now write to the underlying array list directly.
const num_unindexed_entries = 20;
@@ -1303,9 +1303,9 @@ test "reIndex" {
i = 0;
while (i < num_indexed_entries + num_unindexed_entries) : (i += 1) {
const gop = try map.getOrPut(i);
- testing.expect(gop.found_existing == true);
- testing.expect(gop.entry.value == i * 10);
- testing.expect(gop.index == i);
+ try testing.expect(gop.found_existing == true);
+ try testing.expect(gop.entry.value == i * 10);
+ try testing.expect(gop.index == i);
}
}
@@ -1332,9 +1332,9 @@ test "fromOwnedArrayList" {
i = 0;
while (i < num_entries) : (i += 1) {
const gop = try map.getOrPut(i);
- testing.expect(gop.found_existing == true);
- testing.expect(gop.entry.value == i * 10);
- testing.expect(gop.index == i);
+ try testing.expect(gop.found_existing == true);
+ try testing.expect(gop.entry.value == i * 10);
+ try testing.expect(gop.index == i);
}
}
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index 7825d36ac3..94e99247c5 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -695,15 +695,15 @@ test "std.ArrayList/ArrayListUnmanaged.init" {
var list = ArrayList(i32).init(testing.allocator);
defer list.deinit();
- testing.expect(list.items.len == 0);
- testing.expect(list.capacity == 0);
+ try testing.expect(list.items.len == 0);
+ try testing.expect(list.capacity == 0);
}
{
var list = ArrayListUnmanaged(i32){};
- testing.expect(list.items.len == 0);
- testing.expect(list.capacity == 0);
+ try testing.expect(list.items.len == 0);
+ try testing.expect(list.capacity == 0);
}
}
@@ -712,14 +712,14 @@ test "std.ArrayList/ArrayListUnmanaged.initCapacity" {
{
var list = try ArrayList(i8).initCapacity(a, 200);
defer list.deinit();
- testing.expect(list.items.len == 0);
- testing.expect(list.capacity >= 200);
+ try testing.expect(list.items.len == 0);
+ try testing.expect(list.capacity >= 200);
}
{
var list = try ArrayListUnmanaged(i8).initCapacity(a, 200);
defer list.deinit(a);
- testing.expect(list.items.len == 0);
- testing.expect(list.capacity >= 200);
+ try testing.expect(list.items.len == 0);
+ try testing.expect(list.capacity >= 200);
}
}
@@ -739,33 +739,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
{
var i: usize = 0;
while (i < 10) : (i += 1) {
- testing.expect(list.items[i] == @intCast(i32, i + 1));
+ try testing.expect(list.items[i] == @intCast(i32, i + 1));
}
}
for (list.items) |v, i| {
- testing.expect(v == @intCast(i32, i + 1));
+ try testing.expect(v == @intCast(i32, i + 1));
}
- testing.expect(list.pop() == 10);
- testing.expect(list.items.len == 9);
+ try testing.expect(list.pop() == 10);
+ try testing.expect(list.items.len == 9);
list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;
- testing.expect(list.items.len == 12);
- testing.expect(list.pop() == 3);
- testing.expect(list.pop() == 2);
- testing.expect(list.pop() == 1);
- testing.expect(list.items.len == 9);
+ try testing.expect(list.items.len == 12);
+ try testing.expect(list.pop() == 3);
+ try testing.expect(list.pop() == 2);
+ try testing.expect(list.pop() == 1);
+ try testing.expect(list.items.len == 9);
list.appendSlice(&[_]i32{}) catch unreachable;
- testing.expect(list.items.len == 9);
+ try testing.expect(list.items.len == 9);
// can only set on indices < self.items.len
list.items[7] = 33;
list.items[8] = 42;
- testing.expect(list.pop() == 42);
- testing.expect(list.pop() == 33);
+ try testing.expect(list.pop() == 42);
+ try testing.expect(list.pop() == 33);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -781,33 +781,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
{
var i: usize = 0;
while (i < 10) : (i += 1) {
- testing.expect(list.items[i] == @intCast(i32, i + 1));
+ try testing.expect(list.items[i] == @intCast(i32, i + 1));
}
}
for (list.items) |v, i| {
- testing.expect(v == @intCast(i32, i + 1));
+ try testing.expect(v == @intCast(i32, i + 1));
}
- testing.expect(list.pop() == 10);
- testing.expect(list.items.len == 9);
+ try testing.expect(list.pop() == 10);
+ try testing.expect(list.items.len == 9);
list.appendSlice(a, &[_]i32{ 1, 2, 3 }) catch unreachable;
- testing.expect(list.items.len == 12);
- testing.expect(list.pop() == 3);
- testing.expect(list.pop() == 2);
- testing.expect(list.pop() == 1);
- testing.expect(list.items.len == 9);
+ try testing.expect(list.items.len == 12);
+ try testing.expect(list.pop() == 3);
+ try testing.expect(list.pop() == 2);
+ try testing.expect(list.pop() == 1);
+ try testing.expect(list.items.len == 9);
list.appendSlice(a, &[_]i32{}) catch unreachable;
- testing.expect(list.items.len == 9);
+ try testing.expect(list.items.len == 9);
// can only set on indices < self.items.len
list.items[7] = 33;
list.items[8] = 42;
- testing.expect(list.pop() == 42);
- testing.expect(list.pop() == 33);
+ try testing.expect(list.pop() == 42);
+ try testing.expect(list.pop() == 33);
}
}
@@ -818,9 +818,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
defer list.deinit();
try list.appendNTimes(2, 10);
- testing.expectEqual(@as(usize, 10), list.items.len);
+ try testing.expectEqual(@as(usize, 10), list.items.len);
for (list.items) |element| {
- testing.expectEqual(@as(i32, 2), element);
+ try testing.expectEqual(@as(i32, 2), element);
}
}
{
@@ -828,9 +828,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
defer list.deinit(a);
try list.appendNTimes(a, 2, 10);
- testing.expectEqual(@as(usize, 10), list.items.len);
+ try testing.expectEqual(@as(usize, 10), list.items.len);
for (list.items) |element| {
- testing.expectEqual(@as(i32, 2), element);
+ try testing.expectEqual(@as(i32, 2), element);
}
}
}
@@ -840,12 +840,12 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes with failing allocator" {
{
var list = ArrayList(i32).init(a);
defer list.deinit();
- testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));
+ try testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));
}
{
var list = ArrayListUnmanaged(i32){};
defer list.deinit(a);
- testing.expectError(error.OutOfMemory, list.appendNTimes(a, 2, 10));
+ try testing.expectError(error.OutOfMemory, list.appendNTimes(a, 2, 10));
}
}
@@ -864,18 +864,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
try list.append(7);
//remove from middle
- testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
- testing.expectEqual(@as(i32, 5), list.items[3]);
- testing.expectEqual(@as(usize, 6), list.items.len);
+ try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
+ try testing.expectEqual(@as(i32, 5), list.items[3]);
+ try testing.expectEqual(@as(usize, 6), list.items.len);
//remove from end
- testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
- testing.expectEqual(@as(usize, 5), list.items.len);
+ try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
+ try testing.expectEqual(@as(usize, 5), list.items.len);
//remove from front
- testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
- testing.expectEqual(@as(i32, 2), list.items[0]);
- testing.expectEqual(@as(usize, 4), list.items.len);
+ try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
+ try testing.expectEqual(@as(i32, 2), list.items[0]);
+ try testing.expectEqual(@as(usize, 4), list.items.len);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -890,18 +890,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
try list.append(a, 7);
//remove from middle
- testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
- testing.expectEqual(@as(i32, 5), list.items[3]);
- testing.expectEqual(@as(usize, 6), list.items.len);
+ try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
+ try testing.expectEqual(@as(i32, 5), list.items[3]);
+ try testing.expectEqual(@as(usize, 6), list.items.len);
//remove from end
- testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
- testing.expectEqual(@as(usize, 5), list.items.len);
+ try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
+ try testing.expectEqual(@as(usize, 5), list.items.len);
//remove from front
- testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
- testing.expectEqual(@as(i32, 2), list.items[0]);
- testing.expectEqual(@as(usize, 4), list.items.len);
+ try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
+ try testing.expectEqual(@as(i32, 2), list.items[0]);
+ try testing.expectEqual(@as(usize, 4), list.items.len);
}
}
@@ -920,18 +920,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
try list.append(7);
//remove from middle
- testing.expect(list.swapRemove(3) == 4);
- testing.expect(list.items[3] == 7);
- testing.expect(list.items.len == 6);
+ try testing.expect(list.swapRemove(3) == 4);
+ try testing.expect(list.items[3] == 7);
+ try testing.expect(list.items.len == 6);
//remove from end
- testing.expect(list.swapRemove(5) == 6);
- testing.expect(list.items.len == 5);
+ try testing.expect(list.swapRemove(5) == 6);
+ try testing.expect(list.items.len == 5);
//remove from front
- testing.expect(list.swapRemove(0) == 1);
- testing.expect(list.items[0] == 5);
- testing.expect(list.items.len == 4);
+ try testing.expect(list.swapRemove(0) == 1);
+ try testing.expect(list.items[0] == 5);
+ try testing.expect(list.items.len == 4);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -946,18 +946,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
try list.append(a, 7);
//remove from middle
- testing.expect(list.swapRemove(3) == 4);
- testing.expect(list.items[3] == 7);
- testing.expect(list.items.len == 6);
+ try testing.expect(list.swapRemove(3) == 4);
+ try testing.expect(list.items[3] == 7);
+ try testing.expect(list.items.len == 6);
//remove from end
- testing.expect(list.swapRemove(5) == 6);
- testing.expect(list.items.len == 5);
+ try testing.expect(list.swapRemove(5) == 6);
+ try testing.expect(list.items.len == 5);
//remove from front
- testing.expect(list.swapRemove(0) == 1);
- testing.expect(list.items[0] == 5);
- testing.expect(list.items.len == 4);
+ try testing.expect(list.swapRemove(0) == 1);
+ try testing.expect(list.items[0] == 5);
+ try testing.expect(list.items.len == 4);
}
}
@@ -971,10 +971,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
try list.append(2);
try list.append(3);
try list.insert(0, 5);
- testing.expect(list.items[0] == 5);
- testing.expect(list.items[1] == 1);
- testing.expect(list.items[2] == 2);
- testing.expect(list.items[3] == 3);
+ try testing.expect(list.items[0] == 5);
+ try testing.expect(list.items[1] == 1);
+ try testing.expect(list.items[2] == 2);
+ try testing.expect(list.items[3] == 3);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -984,10 +984,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
try list.append(a, 2);
try list.append(a, 3);
try list.insert(a, 0, 5);
- testing.expect(list.items[0] == 5);
- testing.expect(list.items[1] == 1);
- testing.expect(list.items[2] == 2);
- testing.expect(list.items[3] == 3);
+ try testing.expect(list.items[0] == 5);
+ try testing.expect(list.items[1] == 1);
+ try testing.expect(list.items[2] == 2);
+ try testing.expect(list.items[3] == 3);
}
}
@@ -1002,17 +1002,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
try list.append(3);
try list.append(4);
try list.insertSlice(1, &[_]i32{ 9, 8 });
- testing.expect(list.items[0] == 1);
- testing.expect(list.items[1] == 9);
- testing.expect(list.items[2] == 8);
- testing.expect(list.items[3] == 2);
- testing.expect(list.items[4] == 3);
- testing.expect(list.items[5] == 4);
+ try testing.expect(list.items[0] == 1);
+ try testing.expect(list.items[1] == 9);
+ try testing.expect(list.items[2] == 8);
+ try testing.expect(list.items[3] == 2);
+ try testing.expect(list.items[4] == 3);
+ try testing.expect(list.items[5] == 4);
const items = [_]i32{1};
try list.insertSlice(0, items[0..0]);
- testing.expect(list.items.len == 6);
- testing.expect(list.items[0] == 1);
+ try testing.expect(list.items.len == 6);
+ try testing.expect(list.items[0] == 1);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -1023,17 +1023,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
try list.append(a, 3);
try list.append(a, 4);
try list.insertSlice(a, 1, &[_]i32{ 9, 8 });
- testing.expect(list.items[0] == 1);
- testing.expect(list.items[1] == 9);
- testing.expect(list.items[2] == 8);
- testing.expect(list.items[3] == 2);
- testing.expect(list.items[4] == 3);
- testing.expect(list.items[5] == 4);
+ try testing.expect(list.items[0] == 1);
+ try testing.expect(list.items[1] == 9);
+ try testing.expect(list.items[2] == 8);
+ try testing.expect(list.items[3] == 2);
+ try testing.expect(list.items[4] == 3);
+ try testing.expect(list.items[5] == 4);
const items = [_]i32{1};
try list.insertSlice(a, 0, items[0..0]);
- testing.expect(list.items.len == 6);
- testing.expect(list.items[0] == 1);
+ try testing.expect(list.items.len == 6);
+ try testing.expect(list.items[0] == 1);
}
}
@@ -1066,13 +1066,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
try list_lt.replaceRange(1, 2, &new);
// after_range > new_items.len in function body
- testing.expect(1 + 4 > new.len);
+ try testing.expect(1 + 4 > new.len);
try list_gt.replaceRange(1, 4, &new);
- testing.expectEqualSlices(i32, list_zero.items, &result_zero);
- testing.expectEqualSlices(i32, list_eq.items, &result_eq);
- testing.expectEqualSlices(i32, list_lt.items, &result_le);
- testing.expectEqualSlices(i32, list_gt.items, &result_gt);
+ try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
+ try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
+ try testing.expectEqualSlices(i32, list_lt.items, &result_le);
+ try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
}
{
var list_zero = ArrayListUnmanaged(i32){};
@@ -1090,13 +1090,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
try list_lt.replaceRange(a, 1, 2, &new);
// after_range > new_items.len in function body
- testing.expect(1 + 4 > new.len);
+ try testing.expect(1 + 4 > new.len);
try list_gt.replaceRange(a, 1, 4, &new);
- testing.expectEqualSlices(i32, list_zero.items, &result_zero);
- testing.expectEqualSlices(i32, list_eq.items, &result_eq);
- testing.expectEqualSlices(i32, list_lt.items, &result_le);
- testing.expectEqualSlices(i32, list_gt.items, &result_gt);
+ try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
+ try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
+ try testing.expectEqualSlices(i32, list_lt.items, &result_le);
+ try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
}
}
@@ -1116,13 +1116,13 @@ test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" {
var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(a) };
defer root.sub_items.deinit();
try root.sub_items.append(Item{ .integer = 42, .sub_items = ArrayList(Item).init(a) });
- testing.expect(root.sub_items.items[0].integer == 42);
+ try testing.expect(root.sub_items.items[0].integer == 42);
}
{
var root = ItemUnmanaged{ .integer = 1, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} };
defer root.sub_items.deinit(a);
try root.sub_items.append(a, ItemUnmanaged{ .integer = 42, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} });
- testing.expect(root.sub_items.items[0].integer == 42);
+ try testing.expect(root.sub_items.items[0].integer == 42);
}
}
@@ -1137,7 +1137,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
const y: i32 = 1234;
try buffer.writer().print("x: {}\ny: {}\n", .{ x, y });
- testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items);
+ try testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items);
}
{
var list = ArrayListAligned(u8, 2).init(a);
@@ -1149,7 +1149,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
try writer.writeAll("d");
try writer.writeAll("efg");
- testing.expectEqualSlices(u8, list.items, "abcdefg");
+ try testing.expectEqualSlices(u8, list.items, "abcdefg");
}
}
@@ -1167,7 +1167,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
try list.append(3);
list.shrinkAndFree(1);
- testing.expect(list.items.len == 1);
+ try testing.expect(list.items.len == 1);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -1177,7 +1177,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
try list.append(a, 3);
list.shrinkAndFree(a, 1);
- testing.expect(list.items.len == 1);
+ try testing.expect(list.items.len == 1);
}
}
@@ -1191,7 +1191,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
try list.ensureCapacity(8);
list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
- testing.expectEqualSlices(u8, list.items, "aoeuasdf");
+ try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
}
{
var list = ArrayListUnmanaged(u8){};
@@ -1201,7 +1201,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
try list.ensureCapacity(a, 8);
list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
- testing.expectEqualSlices(u8, list.items, "aoeuasdf");
+ try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
}
}
@@ -1215,7 +1215,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
const result = try list.toOwnedSliceSentinel(0);
defer a.free(result);
- testing.expectEqualStrings(result, mem.spanZ(result.ptr));
+ try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
}
{
var list = ArrayListUnmanaged(u8){};
@@ -1225,7 +1225,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
const result = try list.toOwnedSliceSentinel(a, 0);
defer a.free(result);
- testing.expectEqualStrings(result, mem.spanZ(result.ptr));
+ try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
}
}
@@ -1239,7 +1239,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
try list.insertSlice(2, &.{ 4, 5, 6, 7 });
try list.replaceRange(1, 3, &.{ 8, 9 });
- testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
+ try testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
}
{
var list = std.ArrayListAlignedUnmanaged(u8, 8){};
@@ -1249,6 +1249,6 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
try list.insertSlice(a, 2, &.{ 4, 5, 6, 7 });
try list.replaceRange(a, 1, 3, &.{ 8, 9 });
- testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
+ try testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
}
}
diff --git a/lib/std/ascii.zig b/lib/std/ascii.zig
index 09ab1094fa..ea7b61aa9e 100644
--- a/lib/std/ascii.zig
+++ b/lib/std/ascii.zig
@@ -236,11 +236,11 @@ pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.F
test "spaces" {
const testing = std.testing;
- for (spaces) |space| testing.expect(isSpace(space));
+ for (spaces) |space| try testing.expect(isSpace(space));
var i: u8 = 0;
while (isASCII(i)) : (i += 1) {
- if (isSpace(i)) testing.expect(std.mem.indexOfScalar(u8, &spaces, i) != null);
+ if (isSpace(i)) try testing.expect(std.mem.indexOfScalar(u8, &spaces, i) != null);
}
}
@@ -279,13 +279,13 @@ pub fn toLower(c: u8) u8 {
test "ascii character classes" {
const testing = std.testing;
- testing.expect('C' == toUpper('c'));
- testing.expect(':' == toUpper(':'));
- testing.expect('\xab' == toUpper('\xab'));
- testing.expect('c' == toLower('C'));
- testing.expect(isAlpha('c'));
- testing.expect(!isAlpha('5'));
- testing.expect(isSpace(' '));
+ try testing.expect('C' == toUpper('c'));
+ try testing.expect(':' == toUpper(':'));
+ try testing.expect('\xab' == toUpper('\xab'));
+ try testing.expect('c' == toLower('C'));
+ try testing.expect(isAlpha('c'));
+ try testing.expect(!isAlpha('5'));
+ try testing.expect(isSpace(' '));
}
/// Allocates a lower case copy of `ascii_string`.
@@ -301,7 +301,7 @@ pub fn allocLowerString(allocator: *std.mem.Allocator, ascii_string: []const u8)
test "allocLowerString" {
const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+π©!");
defer std.testing.allocator.free(result);
- std.testing.expect(std.mem.eql(u8, "abcdefghijklmnopqrst0234+π©!", result));
+ try std.testing.expect(std.mem.eql(u8, "abcdefghijklmnopqrst0234+π©!", result));
}
/// Allocates an upper case copy of `ascii_string`.
@@ -317,7 +317,7 @@ pub fn allocUpperString(allocator: *std.mem.Allocator, ascii_string: []const u8)
test "allocUpperString" {
const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+π©!");
defer std.testing.allocator.free(result);
- std.testing.expect(std.mem.eql(u8, "ABCDEFGHIJKLMNOPQRST0234+π©!", result));
+ try std.testing.expect(std.mem.eql(u8, "ABCDEFGHIJKLMNOPQRST0234+π©!", result));
}
/// Compares strings `a` and `b` case insensitively and returns whether they are equal.
@@ -330,9 +330,9 @@ pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool {
}
test "eqlIgnoreCase" {
- std.testing.expect(eqlIgnoreCase("HElπ©Lo!", "helπ©lo!"));
- std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));
- std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
+ try std.testing.expect(eqlIgnoreCase("HElπ©Lo!", "helπ©lo!"));
+ try std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));
+ try std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
}
pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
@@ -340,8 +340,8 @@ pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
}
test "ascii.startsWithIgnoreCase" {
- std.testing.expect(startsWithIgnoreCase("boB", "Bo"));
- std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));
+ try std.testing.expect(startsWithIgnoreCase("boB", "Bo"));
+ try std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));
}
pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
@@ -349,8 +349,8 @@ pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
}
test "ascii.endsWithIgnoreCase" {
- std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));
- std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
+ try std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));
+ try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
}
/// Finds `substr` in `container`, ignoring case, starting at `start_index`.
@@ -372,12 +372,12 @@ pub fn indexOfIgnoreCase(container: []const u8, substr: []const u8) ?usize {
}
test "indexOfIgnoreCase" {
- std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
- std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
- std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);
- std.testing.expect(indexOfIgnoreCase("foo", "fool") == null);
+ try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
+ try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
+ try std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);
+ try std.testing.expect(indexOfIgnoreCase("foo", "fool") == null);
- std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0);
+ try std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0);
}
/// Compares two slices of numbers lexicographically. O(n).
diff --git a/lib/std/atomic/bool.zig b/lib/std/atomic/bool.zig
index 0cffb99d38..1c6ac8d046 100644
--- a/lib/std/atomic/bool.zig
+++ b/lib/std/atomic/bool.zig
@@ -47,9 +47,9 @@ pub const Bool = extern struct {
test "std.atomic.Bool" {
var a = Bool.init(false);
- testing.expectEqual(false, a.xchg(false, .SeqCst));
- testing.expectEqual(false, a.load(.SeqCst));
+ try testing.expectEqual(false, a.xchg(false, .SeqCst));
+ try testing.expectEqual(false, a.load(.SeqCst));
a.store(true, .SeqCst);
- testing.expectEqual(true, a.xchg(false, .SeqCst));
- testing.expectEqual(false, a.load(.SeqCst));
+ try testing.expectEqual(true, a.xchg(false, .SeqCst));
+ try testing.expectEqual(false, a.load(.SeqCst));
}
diff --git a/lib/std/atomic/int.zig b/lib/std/atomic/int.zig
index 2d1c5f80e9..3809541fe3 100644
--- a/lib/std/atomic/int.zig
+++ b/lib/std/atomic/int.zig
@@ -81,12 +81,12 @@ pub fn Int(comptime T: type) type {
test "std.atomic.Int" {
var a = Int(u8).init(0);
- testing.expectEqual(@as(u8, 0), a.incr());
- testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
+ try testing.expectEqual(@as(u8, 0), a.incr());
+ try testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
a.store(42, .SeqCst);
- testing.expectEqual(@as(u8, 42), a.decr());
- testing.expectEqual(@as(u8, 41), a.xchg(100));
- testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
- testing.expectEqual(@as(u8, 105), a.get());
+ try testing.expectEqual(@as(u8, 42), a.decr());
+ try testing.expectEqual(@as(u8, 41), a.xchg(100));
+ try testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
+ try testing.expectEqual(@as(u8, 105), a.get());
a.set(200);
}
diff --git a/lib/std/atomic/queue.zig b/lib/std/atomic/queue.zig
index 4e427a1669..24723c90f9 100644
--- a/lib/std/atomic/queue.zig
+++ b/lib/std/atomic/queue.zig
@@ -195,24 +195,24 @@ test "std.atomic.Queue" {
};
if (builtin.single_threaded) {
- expect(context.queue.isEmpty());
+ try expect(context.queue.isEmpty());
{
var i: usize = 0;
while (i < put_thread_count) : (i += 1) {
- expect(startPuts(&context) == 0);
+ try expect(startPuts(&context) == 0);
}
}
- expect(!context.queue.isEmpty());
+ try expect(!context.queue.isEmpty());
context.puts_done = true;
{
var i: usize = 0;
while (i < put_thread_count) : (i += 1) {
- expect(startGets(&context) == 0);
+ try expect(startGets(&context) == 0);
}
}
- expect(context.queue.isEmpty());
+ try expect(context.queue.isEmpty());
} else {
- expect(context.queue.isEmpty());
+ try expect(context.queue.isEmpty());
var putters: [put_thread_count]*std.Thread = undefined;
for (putters) |*t| {
@@ -229,7 +229,7 @@ test "std.atomic.Queue" {
for (getters) |t|
t.wait();
- expect(context.queue.isEmpty());
+ try expect(context.queue.isEmpty());
}
if (context.put_sum != context.get_sum) {
@@ -279,7 +279,7 @@ fn startGets(ctx: *Context) u8 {
test "std.atomic.Queue single-threaded" {
var queue = Queue(i32).init();
- expect(queue.isEmpty());
+ try expect(queue.isEmpty());
var node_0 = Queue(i32).Node{
.data = 0,
@@ -287,7 +287,7 @@ test "std.atomic.Queue single-threaded" {
.prev = undefined,
};
queue.put(&node_0);
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
var node_1 = Queue(i32).Node{
.data = 1,
@@ -295,10 +295,10 @@ test "std.atomic.Queue single-threaded" {
.prev = undefined,
};
queue.put(&node_1);
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
- expect(queue.get().?.data == 0);
- expect(!queue.isEmpty());
+ try expect(queue.get().?.data == 0);
+ try expect(!queue.isEmpty());
var node_2 = Queue(i32).Node{
.data = 2,
@@ -306,7 +306,7 @@ test "std.atomic.Queue single-threaded" {
.prev = undefined,
};
queue.put(&node_2);
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
var node_3 = Queue(i32).Node{
.data = 3,
@@ -314,13 +314,13 @@ test "std.atomic.Queue single-threaded" {
.prev = undefined,
};
queue.put(&node_3);
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
- expect(queue.get().?.data == 1);
- expect(!queue.isEmpty());
+ try expect(queue.get().?.data == 1);
+ try expect(!queue.isEmpty());
- expect(queue.get().?.data == 2);
- expect(!queue.isEmpty());
+ try expect(queue.get().?.data == 2);
+ try expect(!queue.isEmpty());
var node_4 = Queue(i32).Node{
.data = 4,
@@ -328,17 +328,17 @@ test "std.atomic.Queue single-threaded" {
.prev = undefined,
};
queue.put(&node_4);
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
- expect(queue.get().?.data == 3);
+ try expect(queue.get().?.data == 3);
node_3.next = null;
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
- expect(queue.get().?.data == 4);
- expect(queue.isEmpty());
+ try expect(queue.get().?.data == 4);
+ try expect(queue.isEmpty());
- expect(queue.get() == null);
- expect(queue.isEmpty());
+ try expect(queue.get() == null);
+ try expect(queue.isEmpty());
}
test "std.atomic.Queue dump" {
@@ -352,7 +352,7 @@ test "std.atomic.Queue dump" {
// Test empty stream
fbs.reset();
try queue.dumpToStream(fbs.writer());
- expect(mem.eql(u8, buffer[0..fbs.pos],
+ try expect(mem.eql(u8, buffer[0..fbs.pos],
\\head: (null)
\\tail: (null)
\\
@@ -376,7 +376,7 @@ test "std.atomic.Queue dump" {
\\ (null)
\\
, .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) });
- expect(mem.eql(u8, buffer[0..fbs.pos], expected));
+ try expect(mem.eql(u8, buffer[0..fbs.pos], expected));
// Test a stream with two elements
var node_1 = Queue(i32).Node{
@@ -397,5 +397,5 @@ test "std.atomic.Queue dump" {
\\ (null)
\\
, .{ @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail) });
- expect(mem.eql(u8, buffer[0..fbs.pos], expected));
+ try expect(mem.eql(u8, buffer[0..fbs.pos], expected));
}
diff --git a/lib/std/atomic/stack.zig b/lib/std/atomic/stack.zig
index 4096c27354..3a24e79d9d 100644
--- a/lib/std/atomic/stack.zig
+++ b/lib/std/atomic/stack.zig
@@ -110,14 +110,14 @@ test "std.atomic.stack" {
{
var i: usize = 0;
while (i < put_thread_count) : (i += 1) {
- expect(startPuts(&context) == 0);
+ try expect(startPuts(&context) == 0);
}
}
context.puts_done = true;
{
var i: usize = 0;
while (i < put_thread_count) : (i += 1) {
- expect(startGets(&context) == 0);
+ try expect(startGets(&context) == 0);
}
}
} else {
diff --git a/lib/std/base64.zig b/lib/std/base64.zig
index 4e7c9a696f..1f37f07a28 100644
--- a/lib/std/base64.zig
+++ b/lib/std/base64.zig
@@ -318,14 +318,14 @@ pub const Base64DecoderWithIgnore = struct {
test "base64" {
@setEvalBranchQuota(8000);
- testBase64() catch unreachable;
- comptime testAllApis(standard, "comptime", "Y29tcHRpbWU=") catch unreachable;
+ try testBase64();
+ comptime try testAllApis(standard, "comptime", "Y29tcHRpbWU=");
}
test "base64 url_safe_no_pad" {
@setEvalBranchQuota(8000);
- testBase64UrlSafeNoPad() catch unreachable;
- comptime testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU") catch unreachable;
+ try testBase64UrlSafeNoPad();
+ comptime try testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU");
}
fn testBase64() !void {
@@ -404,7 +404,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
{
var buffer: [0x100]u8 = undefined;
const encoded = codecs.Encoder.encode(&buffer, expected_decoded);
- testing.expectEqualSlices(u8, expected_encoded, encoded);
+ try testing.expectEqualSlices(u8, expected_encoded, encoded);
}
// Base64Decoder
@@ -412,7 +412,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
var buffer: [0x100]u8 = undefined;
var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];
try codecs.Decoder.decode(decoded, expected_encoded);
- testing.expectEqualSlices(u8, expected_decoded, decoded);
+ try testing.expectEqualSlices(u8, expected_decoded, decoded);
}
// Base64DecoderWithIgnore
@@ -421,8 +421,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
var buffer: [0x100]u8 = undefined;
var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
var written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
- testing.expect(written <= decoded.len);
- testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
+ try testing.expect(written <= decoded.len);
+ try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
}
}
@@ -431,7 +431,7 @@ fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded:
var buffer: [0x100]u8 = undefined;
var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
var written = try decoder_ignore_space.decode(decoded, encoded);
- testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
+ try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
}
fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void {
diff --git a/lib/std/bit_set.zig b/lib/std/bit_set.zig
index 80cdd5c79c..e6a99ce250 100644
--- a/lib/std/bit_set.zig
+++ b/lib/std/bit_set.zig
@@ -998,9 +998,9 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ
const testing = std.testing;
-fn testBitSet(a: anytype, b: anytype, len: usize) void {
- testing.expectEqual(len, a.capacity());
- testing.expectEqual(len, b.capacity());
+fn testBitSet(a: anytype, b: anytype, len: usize) !void {
+ try testing.expectEqual(len, a.capacity());
+ try testing.expectEqual(len, b.capacity());
{
var i: usize = 0;
@@ -1010,50 +1010,50 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
}
}
- testing.expectEqual((len + 1) / 2, a.count());
- testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());
+ try testing.expectEqual((len + 1) / 2, a.count());
+ try testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());
{
var iter = a.iterator(.{});
var i: usize = 0;
while (i < len) : (i += 2) {
- testing.expectEqual(@as(?usize, i), iter.next());
+ try testing.expectEqual(@as(?usize, i), iter.next());
}
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
}
a.toggleAll();
{
var iter = a.iterator(.{});
var i: usize = 1;
while (i < len) : (i += 2) {
- testing.expectEqual(@as(?usize, i), iter.next());
+ try testing.expectEqual(@as(?usize, i), iter.next());
}
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
}
{
var iter = b.iterator(.{ .kind = .unset });
var i: usize = 2;
while (i < len) : (i += 4) {
- testing.expectEqual(@as(?usize, i), iter.next());
+ try testing.expectEqual(@as(?usize, i), iter.next());
if (i + 1 < len) {
- testing.expectEqual(@as(?usize, i + 1), iter.next());
+ try testing.expectEqual(@as(?usize, i + 1), iter.next());
}
}
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
}
{
var i: usize = 0;
while (i < len) : (i += 1) {
- testing.expectEqual(i & 1 != 0, a.isSet(i));
- testing.expectEqual(i & 2 == 0, b.isSet(i));
+ try testing.expectEqual(i & 1 != 0, a.isSet(i));
+ try testing.expectEqual(i & 2 == 0, b.isSet(i));
}
}
@@ -1061,8 +1061,8 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
{
var i: usize = 0;
while (i < len) : (i += 1) {
- testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));
- testing.expectEqual(i & 2 == 0, b.isSet(i));
+ try testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));
+ try testing.expectEqual(i & 2 == 0, b.isSet(i));
}
i = len;
@@ -1071,27 +1071,27 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
while (i > 0) {
i -= 1;
if (i & 1 != 0 or i & 2 == 0) {
- testing.expectEqual(@as(?usize, i), set.next());
+ try testing.expectEqual(@as(?usize, i), set.next());
} else {
- testing.expectEqual(@as(?usize, i), unset.next());
+ try testing.expectEqual(@as(?usize, i), unset.next());
}
}
- testing.expectEqual(@as(?usize, null), set.next());
- testing.expectEqual(@as(?usize, null), set.next());
- testing.expectEqual(@as(?usize, null), set.next());
- testing.expectEqual(@as(?usize, null), unset.next());
- testing.expectEqual(@as(?usize, null), unset.next());
- testing.expectEqual(@as(?usize, null), unset.next());
+ try testing.expectEqual(@as(?usize, null), set.next());
+ try testing.expectEqual(@as(?usize, null), set.next());
+ try testing.expectEqual(@as(?usize, null), set.next());
+ try testing.expectEqual(@as(?usize, null), unset.next());
+ try testing.expectEqual(@as(?usize, null), unset.next());
+ try testing.expectEqual(@as(?usize, null), unset.next());
}
a.toggleSet(b.*);
{
- testing.expectEqual(len / 4, a.count());
+ try testing.expectEqual(len / 4, a.count());
var i: usize = 0;
while (i < len) : (i += 1) {
- testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));
- testing.expectEqual(i & 2 == 0, b.isSet(i));
+ try testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));
+ try testing.expectEqual(i & 2 == 0, b.isSet(i));
if (i & 1 == 0) {
a.set(i);
} else {
@@ -1102,29 +1102,29 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
a.setIntersection(b.*);
{
- testing.expectEqual((len + 3) / 4, a.count());
+ try testing.expectEqual((len + 3) / 4, a.count());
var i: usize = 0;
while (i < len) : (i += 1) {
- testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));
- testing.expectEqual(i & 2 == 0, b.isSet(i));
+ try testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));
+ try testing.expectEqual(i & 2 == 0, b.isSet(i));
}
}
a.toggleSet(a.*);
{
var iter = a.iterator(.{});
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(usize, 0), a.count());
}
{
var iter = a.iterator(.{ .direction = .reverse });
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(usize, 0), a.count());
}
const test_bits = [_]usize{
@@ -1139,51 +1139,51 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
for (test_bits) |i| {
if (i < a.capacity()) {
- testing.expectEqual(@as(?usize, i), a.findFirstSet());
- testing.expectEqual(@as(?usize, i), a.toggleFirstSet());
+ try testing.expectEqual(@as(?usize, i), a.findFirstSet());
+ try testing.expectEqual(@as(?usize, i), a.toggleFirstSet());
}
}
- testing.expectEqual(@as(?usize, null), a.findFirstSet());
- testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
- testing.expectEqual(@as(?usize, null), a.findFirstSet());
- testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(?usize, null), a.findFirstSet());
+ try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
+ try testing.expectEqual(@as(?usize, null), a.findFirstSet());
+ try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
+ try testing.expectEqual(@as(usize, 0), a.count());
}
-fn testStaticBitSet(comptime Set: type) void {
+fn testStaticBitSet(comptime Set: type) !void {
var a = Set.initEmpty();
var b = Set.initFull();
- testing.expectEqual(@as(usize, 0), a.count());
- testing.expectEqual(@as(usize, Set.bit_length), b.count());
+ try testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(usize, Set.bit_length), b.count());
- testBitSet(&a, &b, Set.bit_length);
+ try testBitSet(&a, &b, Set.bit_length);
}
test "IntegerBitSet" {
- testStaticBitSet(IntegerBitSet(0));
- testStaticBitSet(IntegerBitSet(1));
- testStaticBitSet(IntegerBitSet(2));
- testStaticBitSet(IntegerBitSet(5));
- testStaticBitSet(IntegerBitSet(8));
- testStaticBitSet(IntegerBitSet(32));
- testStaticBitSet(IntegerBitSet(64));
- testStaticBitSet(IntegerBitSet(127));
+ try testStaticBitSet(IntegerBitSet(0));
+ try testStaticBitSet(IntegerBitSet(1));
+ try testStaticBitSet(IntegerBitSet(2));
+ try testStaticBitSet(IntegerBitSet(5));
+ try testStaticBitSet(IntegerBitSet(8));
+ try testStaticBitSet(IntegerBitSet(32));
+ try testStaticBitSet(IntegerBitSet(64));
+ try testStaticBitSet(IntegerBitSet(127));
}
test "ArrayBitSet" {
inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| {
- testStaticBitSet(ArrayBitSet(u8, size));
- testStaticBitSet(ArrayBitSet(u16, size));
- testStaticBitSet(ArrayBitSet(u32, size));
- testStaticBitSet(ArrayBitSet(u64, size));
- testStaticBitSet(ArrayBitSet(u128, size));
+ try testStaticBitSet(ArrayBitSet(u8, size));
+ try testStaticBitSet(ArrayBitSet(u16, size));
+ try testStaticBitSet(ArrayBitSet(u32, size));
+ try testStaticBitSet(ArrayBitSet(u64, size));
+ try testStaticBitSet(ArrayBitSet(u128, size));
}
}
test "DynamicBitSetUnmanaged" {
const allocator = std.testing.allocator;
var a = try DynamicBitSetUnmanaged.initEmpty(300, allocator);
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(usize, 0), a.count());
a.deinit(allocator);
a = try DynamicBitSetUnmanaged.initEmpty(0, allocator);
@@ -1193,10 +1193,10 @@ test "DynamicBitSetUnmanaged" {
var tmp = try a.clone(allocator);
defer tmp.deinit(allocator);
- testing.expectEqual(old_len, tmp.capacity());
+ try testing.expectEqual(old_len, tmp.capacity());
var i: usize = 0;
while (i < old_len) : (i += 1) {
- testing.expectEqual(a.isSet(i), tmp.isSet(i));
+ try testing.expectEqual(a.isSet(i), tmp.isSet(i));
}
a.toggleSet(a); // zero a
@@ -1206,24 +1206,24 @@ test "DynamicBitSetUnmanaged" {
try tmp.resize(size, false, allocator);
if (size > old_len) {
- testing.expectEqual(size - old_len, a.count());
+ try testing.expectEqual(size - old_len, a.count());
} else {
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(usize, 0), a.count());
}
- testing.expectEqual(@as(usize, 0), tmp.count());
+ try testing.expectEqual(@as(usize, 0), tmp.count());
var b = try DynamicBitSetUnmanaged.initFull(size, allocator);
defer b.deinit(allocator);
- testing.expectEqual(@as(usize, size), b.count());
+ try testing.expectEqual(@as(usize, size), b.count());
- testBitSet(&a, &b, size);
+ try testBitSet(&a, &b, size);
}
}
test "DynamicBitSet" {
const allocator = std.testing.allocator;
var a = try DynamicBitSet.initEmpty(300, allocator);
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(usize, 0), a.count());
a.deinit();
a = try DynamicBitSet.initEmpty(0, allocator);
@@ -1233,10 +1233,10 @@ test "DynamicBitSet" {
var tmp = try a.clone(allocator);
defer tmp.deinit();
- testing.expectEqual(old_len, tmp.capacity());
+ try testing.expectEqual(old_len, tmp.capacity());
var i: usize = 0;
while (i < old_len) : (i += 1) {
- testing.expectEqual(a.isSet(i), tmp.isSet(i));
+ try testing.expectEqual(a.isSet(i), tmp.isSet(i));
}
a.toggleSet(a); // zero a
@@ -1246,24 +1246,24 @@ test "DynamicBitSet" {
try tmp.resize(size, false);
if (size > old_len) {
- testing.expectEqual(size - old_len, a.count());
+ try testing.expectEqual(size - old_len, a.count());
} else {
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(usize, 0), a.count());
}
- testing.expectEqual(@as(usize, 0), tmp.count());
+ try testing.expectEqual(@as(usize, 0), tmp.count());
var b = try DynamicBitSet.initFull(size, allocator);
defer b.deinit();
- testing.expectEqual(@as(usize, size), b.count());
+ try testing.expectEqual(@as(usize, size), b.count());
- testBitSet(&a, &b, size);
+ try testBitSet(&a, &b, size);
}
}
test "StaticBitSet" {
- testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));
- testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));
- testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));
- testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));
- testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));
+ try testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));
+ try testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));
+ try testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));
+ try testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));
+ try testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));
}
diff --git a/lib/std/buf_map.zig b/lib/std/buf_map.zig
index 29d1ac4876..4708b9c37b 100644
--- a/lib/std/buf_map.zig
+++ b/lib/std/buf_map.zig
@@ -94,19 +94,19 @@ test "BufMap" {
defer bufmap.deinit();
try bufmap.set("x", "1");
- testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
- testing.expect(1 == bufmap.count());
+ try testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
+ try testing.expect(1 == bufmap.count());
try bufmap.set("x", "2");
- testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
- testing.expect(1 == bufmap.count());
+ try testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
+ try testing.expect(1 == bufmap.count());
try bufmap.set("x", "3");
- testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
- testing.expect(1 == bufmap.count());
+ try testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
+ try testing.expect(1 == bufmap.count());
bufmap.delete("x");
- testing.expect(0 == bufmap.count());
+ try testing.expect(0 == bufmap.count());
try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v1"));
try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v2"));
diff --git a/lib/std/buf_set.zig b/lib/std/buf_set.zig
index e59dc9841b..5e09aa6bcb 100644
--- a/lib/std/buf_set.zig
+++ b/lib/std/buf_set.zig
@@ -73,9 +73,9 @@ test "BufSet" {
defer bufset.deinit();
try bufset.put("x");
- testing.expect(bufset.count() == 1);
+ try testing.expect(bufset.count() == 1);
bufset.delete("x");
- testing.expect(bufset.count() == 0);
+ try testing.expect(bufset.count() == 0);
try bufset.put("x");
try bufset.put("y");
diff --git a/lib/std/build.zig b/lib/std/build.zig
index 1811073279..1bdd97b253 100644
--- a/lib/std/build.zig
+++ b/lib/std/build.zig
@@ -3060,19 +3060,19 @@ test "Builder.dupePkg()" {
const dupe_deps = dupe.dependencies.?;
// probably the same top level package details
- std.testing.expectEqualStrings(pkg_top.name, dupe.name);
+ try std.testing.expectEqualStrings(pkg_top.name, dupe.name);
// probably the same dependencies
- std.testing.expectEqual(original_deps.len, dupe_deps.len);
- std.testing.expectEqual(original_deps[0].name, pkg_dep.name);
+ try std.testing.expectEqual(original_deps.len, dupe_deps.len);
+ try std.testing.expectEqual(original_deps[0].name, pkg_dep.name);
// could segfault otherwise if pointers in duplicated package's fields are
// the same as those in stack allocated package's fields
- std.testing.expect(dupe_deps.ptr != original_deps.ptr);
- std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);
- std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);
- std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr);
- std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
+ try std.testing.expect(dupe_deps.ptr != original_deps.ptr);
+ try std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);
+ try std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);
+ try std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr);
+ try std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
}
test "LibExeObjStep.addBuildOption" {
@@ -3096,7 +3096,7 @@ test "LibExeObjStep.addBuildOption" {
exe.addBuildOption(?[]const u8, "optional_string", null);
exe.addBuildOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
- std.testing.expectEqualStrings(
+ try std.testing.expectEqualStrings(
\\pub const option1: usize = 1;
\\pub const option2: ?usize = null;
\\pub const string: []const u8 = "zigisthebest";
@@ -3140,10 +3140,10 @@ test "LibExeObjStep.addPackage" {
var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");
exe.addPackage(pkg_top);
- std.testing.expectEqual(@as(usize, 1), exe.packages.items.len);
+ try std.testing.expectEqual(@as(usize, 1), exe.packages.items.len);
const dupe = exe.packages.items[0];
- std.testing.expectEqualStrings(pkg_top.name, dupe.name);
+ try std.testing.expectEqualStrings(pkg_top.name, dupe.name);
}
test {
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig
index 53c27f0bf5..c623719108 100644
--- a/lib/std/builtin.zig
+++ b/lib/std/builtin.zig
@@ -546,7 +546,7 @@ pub fn testVersionParse() !void {
const f = struct {
fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void {
const v = try Version.parse(text);
- std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3);
+ try std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3);
}
fn err(text: []const u8, expected_err: anyerror) !void {
diff --git a/lib/std/c/tokenizer.zig b/lib/std/c/tokenizer.zig
index 4399d3dc6c..0d4c646c39 100644
--- a/lib/std/c/tokenizer.zig
+++ b/lib/std/c/tokenizer.zig
@@ -1310,7 +1310,7 @@ pub const Tokenizer = struct {
};
test "operators" {
- expectTokens(
+ try expectTokens(
\\ ! != | || |= = ==
\\ ( ) { } [ ] . .. ...
\\ ^ ^= + ++ += - -- -=
@@ -1379,7 +1379,7 @@ test "operators" {
}
test "keywords" {
- expectTokens(
+ try expectTokens(
\\auto break case char const continue default do
\\double else enum extern float for goto if int
\\long register return short signed sizeof static
@@ -1442,7 +1442,7 @@ test "keywords" {
}
test "preprocessor keywords" {
- expectTokens(
+ try expectTokens(
\\#include
\\#define #include <1
\\#ifdef
@@ -1478,7 +1478,7 @@ test "preprocessor keywords" {
}
test "line continuation" {
- expectTokens(
+ try expectTokens(
\\#define foo \
\\ bar
\\"foo\
@@ -1509,7 +1509,7 @@ test "line continuation" {
}
test "string prefix" {
- expectTokens(
+ try expectTokens(
\\"foo"
\\u"foo"
\\u8"foo"
@@ -1543,7 +1543,7 @@ test "string prefix" {
}
test "num suffixes" {
- expectTokens(
+ try expectTokens(
\\ 1.0f 1.0L 1.0 .0 1.
\\ 0l 0lu 0ll 0llu 0
\\ 1u 1ul 1ull 1
@@ -1573,7 +1573,7 @@ test "num suffixes" {
});
}
-fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
+fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) !void {
var tokenizer = Tokenizer{
.buffer = source,
};
@@ -1584,5 +1584,5 @@ fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
}
}
const last_token = tokenizer.next();
- std.testing.expect(last_token.id == .Eof);
+ try std.testing.expect(last_token.id == .Eof);
}
diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig
index 01db179bbe..17a79d1bf9 100644
--- a/lib/std/child_process.zig
+++ b/lib/std/child_process.zig
@@ -1005,7 +1005,7 @@ test "createNullDelimitedEnvMap" {
defer arena.deinit();
const environ = try createNullDelimitedEnvMap(&arena.allocator, &envmap);
- testing.expectEqual(@as(usize, 5), environ.len);
+ try testing.expectEqual(@as(usize, 5), environ.len);
inline for (.{
"HOME=/home/ifreund",
@@ -1017,7 +1017,7 @@ test "createNullDelimitedEnvMap" {
for (environ) |variable| {
if (mem.eql(u8, mem.span(variable orelse continue), target)) break;
} else {
- testing.expect(false); // Environment variable not found
+ try testing.expect(false); // Environment variable not found
}
}
}
diff --git a/lib/std/compress/deflate.zig b/lib/std/compress/deflate.zig
index 88b9ec8672..45ffb64b4f 100644
--- a/lib/std/compress/deflate.zig
+++ b/lib/std/compress/deflate.zig
@@ -669,5 +669,5 @@ test "lengths overflow" {
var inflate = inflateStream(reader, &window);
var buf: [1]u8 = undefined;
- std.testing.expectError(error.InvalidLength, inflate.read(&buf));
+ try std.testing.expectError(error.InvalidLength, inflate.read(&buf));
}
diff --git a/lib/std/compress/gzip.zig b/lib/std/compress/gzip.zig
index 89aa12207b..387b64f59a 100644
--- a/lib/std/compress/gzip.zig
+++ b/lib/std/compress/gzip.zig
@@ -172,17 +172,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
var hash: [32]u8 = undefined;
std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
- assertEqual(expected, &hash);
+ try assertEqual(expected, &hash);
}
// Assert `expected` == `input` where `input` is a bytestring.
-pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
+pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void {
var expected_bytes: [expected.len / 2]u8 = undefined;
for (expected_bytes) |*r, i| {
r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
}
- testing.expectEqualSlices(u8, &expected_bytes, input);
+ try testing.expectEqualSlices(u8, &expected_bytes, input);
}
// All the test cases are obtained by compressing the RFC1952 text
@@ -198,12 +198,12 @@ test "compressed data" {
test "sanity checks" {
// Truncated header
- testing.expectError(
+ try testing.expectError(
error.EndOfStream,
testReader(&[_]u8{ 0x1f, 0x8B }, ""),
);
// Wrong CM
- testing.expectError(
+ try testing.expectError(
error.InvalidCompression,
testReader(&[_]u8{
0x1f, 0x8b, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -211,7 +211,7 @@ test "sanity checks" {
}, ""),
);
// Wrong checksum
- testing.expectError(
+ try testing.expectError(
error.WrongChecksum,
testReader(&[_]u8{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -220,7 +220,7 @@ test "sanity checks" {
}, ""),
);
// Truncated checksum
- testing.expectError(
+ try testing.expectError(
error.EndOfStream,
testReader(&[_]u8{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -228,7 +228,7 @@ test "sanity checks" {
}, ""),
);
// Wrong initial size
- testing.expectError(
+ try testing.expectError(
error.CorruptedData,
testReader(&[_]u8{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -237,7 +237,7 @@ test "sanity checks" {
}, ""),
);
// Truncated initial size field
- testing.expectError(
+ try testing.expectError(
error.EndOfStream,
testReader(&[_]u8{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
diff --git a/lib/std/compress/zlib.zig b/lib/std/compress/zlib.zig
index 7ef644ef6d..0ee154bf22 100644
--- a/lib/std/compress/zlib.zig
+++ b/lib/std/compress/zlib.zig
@@ -109,17 +109,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
var hash: [32]u8 = undefined;
std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
- assertEqual(expected, &hash);
+ try assertEqual(expected, &hash);
}
// Assert `expected` == `input` where `input` is a bytestring.
-pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
+pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void {
var expected_bytes: [expected.len / 2]u8 = undefined;
for (expected_bytes) |*r, i| {
r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
}
- testing.expectEqualSlices(u8, &expected_bytes, input);
+ try testing.expectEqualSlices(u8, &expected_bytes, input);
}
// All the test cases are obtained by compressing the RFC1950 text
@@ -159,32 +159,32 @@ test "don't read past deflate stream's end" {
test "sanity checks" {
// Truncated header
- testing.expectError(
+ try testing.expectError(
error.EndOfStream,
testReader(&[_]u8{0x78}, ""),
);
// Failed FCHECK check
- testing.expectError(
+ try testing.expectError(
error.BadHeader,
testReader(&[_]u8{ 0x78, 0x9D }, ""),
);
// Wrong CM
- testing.expectError(
+ try testing.expectError(
error.InvalidCompression,
testReader(&[_]u8{ 0x79, 0x94 }, ""),
);
// Wrong CINFO
- testing.expectError(
+ try testing.expectError(
error.InvalidWindowSize,
testReader(&[_]u8{ 0x88, 0x98 }, ""),
);
// Wrong checksum
- testing.expectError(
+ try testing.expectError(
error.WrongChecksum,
testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, ""),
);
// Truncated checksum
- testing.expectError(
+ try testing.expectError(
error.EndOfStream,
testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00 }, ""),
);
diff --git a/lib/std/comptime_string_map.zig b/lib/std/comptime_string_map.zig
index 4882924ae5..1dca59e997 100644
--- a/lib/std/comptime_string_map.zig
+++ b/lib/std/comptime_string_map.zig
@@ -95,7 +95,7 @@ test "ComptimeStringMap list literal of list literals" {
.{ "samelen", .E },
});
- testMap(map);
+ try testMap(map);
}
test "ComptimeStringMap array of structs" {
@@ -111,7 +111,7 @@ test "ComptimeStringMap array of structs" {
.{ .@"0" = "samelen", .@"1" = .E },
});
- testMap(map);
+ try testMap(map);
}
test "ComptimeStringMap slice of structs" {
@@ -128,18 +128,18 @@ test "ComptimeStringMap slice of structs" {
};
const map = ComptimeStringMap(TestEnum, slice);
- testMap(map);
+ try testMap(map);
}
-fn testMap(comptime map: anytype) void {
- std.testing.expectEqual(TestEnum.A, map.get("have").?);
- std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
- std.testing.expect(null == map.get("missing"));
- std.testing.expectEqual(TestEnum.D, map.get("these").?);
- std.testing.expectEqual(TestEnum.E, map.get("samelen").?);
+fn testMap(comptime map: anytype) !void {
+ try std.testing.expectEqual(TestEnum.A, map.get("have").?);
+ try std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
+ try std.testing.expect(null == map.get("missing"));
+ try std.testing.expectEqual(TestEnum.D, map.get("these").?);
+ try std.testing.expectEqual(TestEnum.E, map.get("samelen").?);
- std.testing.expect(!map.has("missing"));
- std.testing.expect(map.has("these"));
+ try std.testing.expect(!map.has("missing"));
+ try std.testing.expect(map.has("these"));
}
test "ComptimeStringMap void value type, slice of structs" {
@@ -155,7 +155,7 @@ test "ComptimeStringMap void value type, slice of structs" {
};
const map = ComptimeStringMap(void, slice);
- testSet(map);
+ try testSet(map);
}
test "ComptimeStringMap void value type, list literal of list literals" {
@@ -167,16 +167,16 @@ test "ComptimeStringMap void value type, list literal of list literals" {
.{"samelen"},
});
- testSet(map);
+ try testSet(map);
}
-fn testSet(comptime map: anytype) void {
- std.testing.expectEqual({}, map.get("have").?);
- std.testing.expectEqual({}, map.get("nothing").?);
- std.testing.expect(null == map.get("missing"));
- std.testing.expectEqual({}, map.get("these").?);
- std.testing.expectEqual({}, map.get("samelen").?);
+fn testSet(comptime map: anytype) !void {
+ try std.testing.expectEqual({}, map.get("have").?);
+ try std.testing.expectEqual({}, map.get("nothing").?);
+ try std.testing.expect(null == map.get("missing"));
+ try std.testing.expectEqual({}, map.get("these").?);
+ try std.testing.expectEqual({}, map.get("samelen").?);
- std.testing.expect(!map.has("missing"));
- std.testing.expect(map.has("these"));
+ try std.testing.expect(!map.has("missing"));
+ try std.testing.expect(map.has("these"));
}
diff --git a/lib/std/crypto.zig b/lib/std/crypto.zig
index af23af9460..42ded1f2ea 100644
--- a/lib/std/crypto.zig
+++ b/lib/std/crypto.zig
@@ -188,7 +188,7 @@ test "CSPRNG" {
const a = random.int(u64);
const b = random.int(u64);
const c = random.int(u64);
- std.testing.expect(a ^ b ^ c != 0);
+ try std.testing.expect(a ^ b ^ c != 0);
}
test "issue #4532: no index out of bounds" {
@@ -226,6 +226,6 @@ test "issue #4532: no index out of bounds" {
h.update(block[1..]);
h.final(&out2);
- std.testing.expectEqual(out1, out2);
+ try std.testing.expectEqual(out1, out2);
}
}
diff --git a/lib/std/crypto/25519/curve25519.zig b/lib/std/crypto/25519/curve25519.zig
index 90b0e10c4f..6ebc8548c2 100644
--- a/lib/std/crypto/25519/curve25519.zig
+++ b/lib/std/crypto/25519/curve25519.zig
@@ -120,13 +120,13 @@ test "curve25519" {
const p = try Curve25519.basePoint.clampedMul(s);
try p.rejectIdentity();
var buf: [128]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");
const q = try p.clampedMul(s);
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");
try Curve25519.rejectNonCanonical(s);
s[31] |= 0x80;
- std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));
+ try std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));
}
test "curve25519 small order check" {
@@ -155,13 +155,13 @@ test "curve25519 small order check" {
},
};
for (small_order_ss) |small_order_s| {
- std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(small_order_s).mul(s));
+ try std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(small_order_s).mul(s));
var extra = small_order_s;
extra[31] ^= 0x80;
- std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(extra).mul(s));
+ try std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(extra).mul(s));
var valid = small_order_s;
valid[31] = 0x40;
s[0] = 0;
- std.testing.expectError(error.IdentityElement, Curve25519.fromBytes(valid).mul(s));
+ try std.testing.expectError(error.IdentityElement, Curve25519.fromBytes(valid).mul(s));
}
}
diff --git a/lib/std/crypto/25519/ed25519.zig b/lib/std/crypto/25519/ed25519.zig
index b48cc24b4b..b6321e8d8c 100644
--- a/lib/std/crypto/25519/ed25519.zig
+++ b/lib/std/crypto/25519/ed25519.zig
@@ -219,8 +219,8 @@ test "ed25519 key pair creation" {
_ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
const key_pair = try Ed25519.KeyPair.create(seed);
var buf: [256]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
}
test "ed25519 signature" {
@@ -230,9 +230,9 @@ test "ed25519 signature" {
const sig = try Ed25519.sign("test", key_pair, null);
var buf: [128]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&sig)}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&sig)}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");
try Ed25519.verify(sig, "test", key_pair.public_key);
- std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verify(sig, "TEST", key_pair.public_key));
+ try std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verify(sig, "TEST", key_pair.public_key));
}
test "ed25519 batch verification" {
@@ -260,7 +260,7 @@ test "ed25519 batch verification" {
try Ed25519.verifyBatch(2, signature_batch);
signature_batch[1].sig = sig1;
- std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verifyBatch(signature_batch.len, signature_batch));
+ try std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verifyBatch(signature_batch.len, signature_batch));
}
}
@@ -354,7 +354,7 @@ test "ed25519 test vectors" {
var sig: [64]u8 = undefined;
_ = try fmt.hexToBytes(&sig, entry.sig_hex);
if (entry.expected) |error_type| {
- std.testing.expectError(error_type, Ed25519.verify(sig, &msg, public_key));
+ try std.testing.expectError(error_type, Ed25519.verify(sig, &msg, public_key));
} else {
try Ed25519.verify(sig, &msg, public_key);
}
diff --git a/lib/std/crypto/25519/edwards25519.zig b/lib/std/crypto/25519/edwards25519.zig
index 4e3d156007..e6fa9b2534 100644
--- a/lib/std/crypto/25519/edwards25519.zig
+++ b/lib/std/crypto/25519/edwards25519.zig
@@ -491,7 +491,7 @@ test "edwards25519 packing/unpacking" {
var b = Edwards25519.basePoint;
const pk = try b.mul(s);
var buf: [128]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&pk.toBytes())}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&pk.toBytes())}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");
const small_order_ss: [7][32]u8 = .{
.{
@@ -518,7 +518,7 @@ test "edwards25519 packing/unpacking" {
};
for (small_order_ss) |small_order_s| {
const small_p = try Edwards25519.fromBytes(small_order_s);
- std.testing.expectError(error.WeakPublicKey, small_p.mul(s));
+ try std.testing.expectError(error.WeakPublicKey, small_p.mul(s));
}
}
@@ -531,26 +531,26 @@ test "edwards25519 point addition/substraction" {
const q = try Edwards25519.basePoint.clampedMul(s2);
const r = p.add(q).add(q).sub(q).sub(q);
try r.rejectIdentity();
- std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());
- std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());
- std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());
+ try std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());
+ try std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());
+ try std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());
}
test "edwards25519 uniform-to-point" {
var r = [32]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
var p = Edwards25519.fromUniform(r);
- htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);
+ try htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);
r[31] = 0xff;
p = Edwards25519.fromUniform(r);
- htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);
+ try htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);
}
// Test vectors from draft-irtf-cfrg-hash-to-curve-10
test "edwards25519 hash-to-curve operation" {
var p = Edwards25519.fromString(true, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_RO_", "abc");
- htest.assertEqual("31558a26887f23fb8218f143e69d5f0af2e7831130bd5b432ef23883b895831a", p.toBytes()[0..]);
+ try htest.assertEqual("31558a26887f23fb8218f143e69d5f0af2e7831130bd5b432ef23883b895831a", p.toBytes()[0..]);
p = Edwards25519.fromString(false, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_NU_", "abc");
- htest.assertEqual("42fa27c8f5a1ae0aa38bb59d5938e5145622ba5dedd11d11736fa2f9502d73e7", p.toBytes()[0..]);
+ try htest.assertEqual("42fa27c8f5a1ae0aa38bb59d5938e5145622ba5dedd11d11736fa2f9502d73e7", p.toBytes()[0..]);
}
diff --git a/lib/std/crypto/25519/ristretto255.zig b/lib/std/crypto/25519/ristretto255.zig
index 50f1580a80..c17461e40a 100644
--- a/lib/std/crypto/25519/ristretto255.zig
+++ b/lib/std/crypto/25519/ristretto255.zig
@@ -175,21 +175,21 @@ pub const Ristretto255 = struct {
test "ristretto255" {
const p = Ristretto255.basePoint;
var buf: [256]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");
var r: [Ristretto255.encoded_length]u8 = undefined;
_ = try fmt.hexToBytes(r[0..], "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919");
var q = try Ristretto255.fromBytes(r);
q = q.dbl().add(p);
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
const s = [_]u8{15} ++ [_]u8{0} ** 31;
const w = try p.mul(s);
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&w.toBytes())}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&w.toBytes())}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
- std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p)));
+ try std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p)));
const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32;
const ph = Ristretto255.fromUniform(h);
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&ph.toBytes())}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&ph.toBytes())}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
}
diff --git a/lib/std/crypto/25519/scalar.zig b/lib/std/crypto/25519/scalar.zig
index e8564ff577..e89c6d6f2a 100644
--- a/lib/std/crypto/25519/scalar.zig
+++ b/lib/std/crypto/25519/scalar.zig
@@ -773,15 +773,15 @@ test "scalar25519" {
var y = x.toBytes();
try rejectNonCanonical(y);
var buf: [128]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&y)}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&y)}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");
const reduced = reduce(field_size);
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&reduced)}), "0000000000000000000000000000000000000000000000000000000000000000");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&reduced)}), "0000000000000000000000000000000000000000000000000000000000000000");
}
test "non-canonical scalar25519" {
const too_targe: [32]u8 = .{ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
- std.testing.expectError(error.NonCanonical, rejectNonCanonical(too_targe));
+ try std.testing.expectError(error.NonCanonical, rejectNonCanonical(too_targe));
}
test "mulAdd overflow check" {
@@ -790,5 +790,5 @@ test "mulAdd overflow check" {
const c: [32]u8 = [_]u8{0xff} ** 32;
const x = mulAdd(a, b, c);
var buf: [128]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&x)}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&x)}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
}
diff --git a/lib/std/crypto/25519/x25519.zig b/lib/std/crypto/25519/x25519.zig
index 07b1dc7a86..5109fd7c2a 100644
--- a/lib/std/crypto/25519/x25519.zig
+++ b/lib/std/crypto/25519/x25519.zig
@@ -92,7 +92,7 @@ test "x25519 public key calculation from secret key" {
_ = try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
_ = try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
const pk_calculated = try X25519.recoverPublicKey(sk);
- std.testing.expectEqual(pk_calculated, pk_expected);
+ try std.testing.expectEqual(pk_calculated, pk_expected);
}
test "x25519 rfc7748 vector1" {
@@ -102,7 +102,7 @@ test "x25519 rfc7748 vector1" {
const expected_output = [32]u8{ 0xc3, 0xda, 0x55, 0x37, 0x9d, 0xe9, 0xc6, 0x90, 0x8e, 0x94, 0xea, 0x4d, 0xf2, 0x8d, 0x08, 0x4f, 0x32, 0xec, 0xcf, 0x03, 0x49, 0x1c, 0x71, 0xf7, 0x54, 0xb4, 0x07, 0x55, 0x77, 0xa2, 0x85, 0x52 };
const output = try X25519.scalarmult(secret_key, public_key);
- std.testing.expectEqual(output, expected_output);
+ try std.testing.expectEqual(output, expected_output);
}
test "x25519 rfc7748 vector2" {
@@ -112,7 +112,7 @@ test "x25519 rfc7748 vector2" {
const expected_output = [32]u8{ 0x95, 0xcb, 0xde, 0x94, 0x76, 0xe8, 0x90, 0x7d, 0x7a, 0xad, 0xe4, 0x5c, 0xb4, 0xb8, 0x73, 0xf8, 0x8b, 0x59, 0x5a, 0x68, 0x79, 0x9f, 0xa1, 0x52, 0xe6, 0xf8, 0xf7, 0x64, 0x7a, 0xac, 0x79, 0x57 };
const output = try X25519.scalarmult(secret_key, public_key);
- std.testing.expectEqual(output, expected_output);
+ try std.testing.expectEqual(output, expected_output);
}
test "x25519 rfc7748 one iteration" {
@@ -129,7 +129,7 @@ test "x25519 rfc7748 one iteration" {
mem.copy(u8, k[0..], output[0..]);
}
- std.testing.expectEqual(k, expected_output);
+ try std.testing.expectEqual(k, expected_output);
}
test "x25519 rfc7748 1,000 iterations" {
@@ -151,7 +151,7 @@ test "x25519 rfc7748 1,000 iterations" {
mem.copy(u8, k[0..], output[0..]);
}
- std.testing.expectEqual(k, expected_output);
+ try std.testing.expectEqual(k, expected_output);
}
test "x25519 rfc7748 1,000,000 iterations" {
@@ -172,12 +172,12 @@ test "x25519 rfc7748 1,000,000 iterations" {
mem.copy(u8, k[0..], output[0..]);
}
- std.testing.expectEqual(k[0..], expected_output);
+ try std.testing.expectEqual(k[0..], expected_output);
}
test "edwards25519 -> curve25519 map" {
const ed_kp = try crypto.sign.Ed25519.KeyPair.create([_]u8{0x42} ** 32);
const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp);
- htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);
- htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);
+ try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);
+ try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);
}
diff --git a/lib/std/crypto/aegis.zig b/lib/std/crypto/aegis.zig
index 59dcf04dac..a9418c6ca6 100644
--- a/lib/std/crypto/aegis.zig
+++ b/lib/std/crypto/aegis.zig
@@ -352,16 +352,16 @@ test "Aegis128L test vector 1" {
Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c);
- htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);
+ try htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c);
+ try htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);
c[0] +%= 1;
- testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
+ try testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
c[0] -%= 1;
tag[0] +%= 1;
- testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
+ try testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
}
test "Aegis128L test vector 2" {
@@ -375,10 +375,10 @@ test "Aegis128L test vector 2" {
Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c);
- htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
+ try htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c);
+ try htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
}
test "Aegis128L test vector 3" {
@@ -392,9 +392,9 @@ test "Aegis128L test vector 3" {
Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("83cc600dc4e3e7e62d4055826174f149", &tag);
+ try htest.assertEqual("83cc600dc4e3e7e62d4055826174f149", &tag);
}
test "Aegis256 test vector 1" {
@@ -408,16 +408,16 @@ test "Aegis256 test vector 1" {
Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c);
- htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);
+ try htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c);
+ try htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);
c[0] +%= 1;
- testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
+ try testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
c[0] -%= 1;
tag[0] +%= 1;
- testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
+ try testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
}
test "Aegis256 test vector 2" {
@@ -431,10 +431,10 @@ test "Aegis256 test vector 2" {
Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);
- htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
+ try htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);
+ try htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
}
test "Aegis256 test vector 3" {
@@ -448,7 +448,7 @@ test "Aegis256 test vector 3" {
Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("f7a0878f68bd083e8065354071fc27c3", &tag);
+ try htest.assertEqual("f7a0878f68bd083e8065354071fc27c3", &tag);
}
diff --git a/lib/std/crypto/aes.zig b/lib/std/crypto/aes.zig
index 2a81492c8a..b24a3bf921 100644
--- a/lib/std/crypto/aes.zig
+++ b/lib/std/crypto/aes.zig
@@ -48,7 +48,7 @@ test "ctr" {
var out: [exp_out.len]u8 = undefined;
var ctx = Aes128.initEnc(key);
ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, builtin.Endian.Big);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
test "encrypt" {
@@ -61,7 +61,7 @@ test "encrypt" {
var out: [exp_out.len]u8 = undefined;
var ctx = Aes128.initEnc(key);
ctx.encrypt(out[0..], in[0..]);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
// Appendix C.3
@@ -76,7 +76,7 @@ test "encrypt" {
var out: [exp_out.len]u8 = undefined;
var ctx = Aes256.initEnc(key);
ctx.encrypt(out[0..], in[0..]);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
}
@@ -90,7 +90,7 @@ test "decrypt" {
var out: [exp_out.len]u8 = undefined;
var ctx = Aes128.initDec(key);
ctx.decrypt(out[0..], in[0..]);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
// Appendix C.3
@@ -105,7 +105,7 @@ test "decrypt" {
var out: [exp_out.len]u8 = undefined;
var ctx = Aes256.initDec(key);
ctx.decrypt(out[0..], in[0..]);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
}
@@ -123,11 +123,11 @@ test "expand 128-bit key" {
for (enc.key_schedule.round_keys) |round_key, i| {
_ = try std.fmt.hexToBytes(&exp, exp_enc[i]);
- testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
+ try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
}
for (enc.key_schedule.round_keys) |round_key, i| {
_ = try std.fmt.hexToBytes(&exp, exp_dec[i]);
- testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
+ try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
}
}
@@ -145,10 +145,10 @@ test "expand 256-bit key" {
for (enc.key_schedule.round_keys) |round_key, i| {
_ = try std.fmt.hexToBytes(&exp, exp_enc[i]);
- testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
+ try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
}
for (dec.key_schedule.round_keys) |round_key, i| {
_ = try std.fmt.hexToBytes(&exp, exp_dec[i]);
- testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
+ try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
}
}
diff --git a/lib/std/crypto/aes_gcm.zig b/lib/std/crypto/aes_gcm.zig
index 70746af073..cc2a423f70 100644
--- a/lib/std/crypto/aes_gcm.zig
+++ b/lib/std/crypto/aes_gcm.zig
@@ -118,7 +118,7 @@ test "Aes256Gcm - Empty message and no associated data" {
var tag: [Aes256Gcm.tag_length]u8 = undefined;
Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
- htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);
+ try htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);
}
test "Aes256Gcm - Associated data only" {
@@ -130,7 +130,7 @@ test "Aes256Gcm - Associated data only" {
var tag: [Aes256Gcm.tag_length]u8 = undefined;
Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
- htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);
+ try htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);
}
test "Aes256Gcm - Message only" {
@@ -144,10 +144,10 @@ test "Aes256Gcm - Message only" {
Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);
- testing.expectEqualSlices(u8, m[0..], m2[0..]);
+ try testing.expectEqualSlices(u8, m[0..], m2[0..]);
- htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c);
- htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);
+ try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c);
+ try htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);
}
test "Aes256Gcm - Message and associated data" {
@@ -161,8 +161,8 @@ test "Aes256Gcm - Message and associated data" {
Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);
- testing.expectEqualSlices(u8, m[0..], m2[0..]);
+ try testing.expectEqualSlices(u8, m[0..], m2[0..]);
- htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c);
- htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);
+ try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c);
+ try htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);
}
diff --git a/lib/std/crypto/bcrypt.zig b/lib/std/crypto/bcrypt.zig
index 51fb144b2f..c1ad239e90 100644
--- a/lib/std/crypto/bcrypt.zig
+++ b/lib/std/crypto/bcrypt.zig
@@ -281,13 +281,13 @@ test "bcrypt codec" {
Codec.encode(salt_str[0..], salt[0..]);
var salt2: [salt_length]u8 = undefined;
try Codec.decode(salt2[0..], salt_str[0..]);
- testing.expectEqualSlices(u8, salt[0..], salt2[0..]);
+ try testing.expectEqualSlices(u8, salt[0..], salt2[0..]);
}
test "bcrypt" {
const s = try strHash("password", 5);
try strVerify(s, "password");
- testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));
+ try testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));
const long_s = try strHash("password" ** 100, 5);
try strVerify(long_s, "password" ** 100);
diff --git a/lib/std/crypto/blake2.zig b/lib/std/crypto/blake2.zig
index 4203a99459..e0b9eff5b9 100644
--- a/lib/std/crypto/blake2.zig
+++ b/lib/std/crypto/blake2.zig
@@ -194,16 +194,16 @@ pub fn Blake2s(comptime out_bits: usize) type {
test "blake2s160 single" {
const h1 = "354c9c33f735962418bdacb9479873429c34916f";
- htest.assertEqualHash(Blake2s160, h1, "");
+ try htest.assertEqualHash(Blake2s160, h1, "");
const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
- htest.assertEqualHash(Blake2s160, h2, "abc");
+ try htest.assertEqualHash(Blake2s160, h2, "abc");
const h3 = "5a604fec9713c369e84b0ed68daed7d7504ef240";
- htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
- htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);
+ try htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);
}
test "blake2s160 streaming" {
@@ -213,21 +213,21 @@ test "blake2s160 streaming" {
const h1 = "354c9c33f735962418bdacb9479873429c34916f";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
h = Blake2s160.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2s160.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
@@ -235,12 +235,12 @@ test "blake2s160 streaming" {
h.update("a" ** 32);
h.update("b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2s160.init(.{});
h.update("a" ** 32 ++ "b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68";
@@ -248,12 +248,12 @@ test "blake2s160 streaming" {
h.update("a" ** 32);
h.update("b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
h.update("a" ** 32 ++ "b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
}
test "comptime blake2s160" {
@@ -265,28 +265,28 @@ test "comptime blake2s160" {
const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f";
- htest.assertEqualHash(Blake2s160, h1, block[0..]);
+ try htest.assertEqualHash(Blake2s160, h1, block[0..]);
var h = Blake2s160.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
test "blake2s224 single" {
const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
- htest.assertEqualHash(Blake2s224, h1, "");
+ try htest.assertEqualHash(Blake2s224, h1, "");
const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
- htest.assertEqualHash(Blake2s224, h2, "abc");
+ try htest.assertEqualHash(Blake2s224, h2, "abc");
const h3 = "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912";
- htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
- htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);
+ try htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);
}
test "blake2s224 streaming" {
@@ -296,21 +296,21 @@ test "blake2s224 streaming" {
const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
h = Blake2s224.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2s224.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
@@ -318,12 +318,12 @@ test "blake2s224 streaming" {
h.update("a" ** 32);
h.update("b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2s224.init(.{});
h.update("a" ** 32 ++ "b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3";
@@ -331,12 +331,12 @@ test "blake2s224 streaming" {
h.update("a" ** 32);
h.update("b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
h.update("a" ** 32 ++ "b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
}
test "comptime blake2s224" {
@@ -347,28 +347,28 @@ test "comptime blake2s224" {
const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576";
- htest.assertEqualHash(Blake2s224, h1, block[0..]);
+ try htest.assertEqualHash(Blake2s224, h1, block[0..]);
var h = Blake2s224.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
test "blake2s256 single" {
const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
- htest.assertEqualHash(Blake2s256, h1, "");
+ try htest.assertEqualHash(Blake2s256, h1, "");
const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
- htest.assertEqualHash(Blake2s256, h2, "abc");
+ try htest.assertEqualHash(Blake2s256, h2, "abc");
const h3 = "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812";
- htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
- htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);
+ try htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);
}
test "blake2s256 streaming" {
@@ -378,21 +378,21 @@ test "blake2s256 streaming" {
const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
h = Blake2s256.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2s256.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
@@ -400,12 +400,12 @@ test "blake2s256 streaming" {
h.update("a" ** 32);
h.update("b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2s256.init(.{});
h.update("a" ** 32 ++ "b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
}
test "blake2s256 keyed" {
@@ -415,20 +415,20 @@ test "blake2s256 keyed" {
const key = "secret_key";
Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
var h = Blake2s256.init(.{ .key = key });
h.update("a" ** 64 ++ "b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
h = Blake2s256.init(.{ .key = key });
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
test "comptime blake2s256" {
@@ -439,13 +439,13 @@ test "comptime blake2s256" {
const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3";
- htest.assertEqualHash(Blake2s256, h1, block[0..]);
+ try htest.assertEqualHash(Blake2s256, h1, block[0..]);
var h = Blake2s256.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
@@ -617,16 +617,16 @@ pub fn Blake2b(comptime out_bits: usize) type {
test "blake2b160 single" {
const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
- htest.assertEqualHash(Blake2b160, h1, "");
+ try htest.assertEqualHash(Blake2b160, h1, "");
const h2 = "384264f676f39536840523f284921cdc68b6846b";
- htest.assertEqualHash(Blake2b160, h2, "abc");
+ try htest.assertEqualHash(Blake2b160, h2, "abc");
const h3 = "3c523ed102ab45a37d54f5610d5a983162fde84f";
- htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
- htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);
+ try htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);
}
test "blake2b160 streaming" {
@@ -636,40 +636,40 @@ test "blake2b160 streaming" {
const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "384264f676f39536840523f284921cdc68b6846b";
h = Blake2b160.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2b160.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
h = Blake2b160.init(.{});
h.update("a" ** 64 ++ "b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2b160.init(.{});
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2b160.init(.{});
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc";
@@ -677,13 +677,13 @@ test "blake2b160 streaming" {
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
}
test "comptime blake2b160" {
@@ -694,28 +694,28 @@ test "comptime blake2b160" {
const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9";
- htest.assertEqualHash(Blake2b160, h1, block[0..]);
+ try htest.assertEqualHash(Blake2b160, h1, block[0..]);
var h = Blake2b160.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
test "blake2b384 single" {
const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
- htest.assertEqualHash(Blake2b384, h1, "");
+ try htest.assertEqualHash(Blake2b384, h1, "");
const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
- htest.assertEqualHash(Blake2b384, h2, "abc");
+ try htest.assertEqualHash(Blake2b384, h2, "abc");
const h3 = "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d";
- htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
- htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);
+ try htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);
}
test "blake2b384 streaming" {
@@ -725,40 +725,40 @@ test "blake2b384 streaming" {
const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
h = Blake2b384.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2b384.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
h = Blake2b384.init(.{});
h.update("a" ** 64 ++ "b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2b384.init(.{});
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2b384.init(.{});
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c";
@@ -766,13 +766,13 @@ test "blake2b384 streaming" {
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
}
test "comptime blake2b384" {
@@ -783,28 +783,28 @@ test "comptime blake2b384" {
const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d";
- htest.assertEqualHash(Blake2b384, h1, block[0..]);
+ try htest.assertEqualHash(Blake2b384, h1, block[0..]);
var h = Blake2b384.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
test "blake2b512 single" {
const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
- htest.assertEqualHash(Blake2b512, h1, "");
+ try htest.assertEqualHash(Blake2b512, h1, "");
const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
- htest.assertEqualHash(Blake2b512, h2, "abc");
+ try htest.assertEqualHash(Blake2b512, h2, "abc");
const h3 = "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918";
- htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
- htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);
+ try htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);
}
test "blake2b512 streaming" {
@@ -814,34 +814,34 @@ test "blake2b512 streaming" {
const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
h = Blake2b512.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2b512.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
h = Blake2b512.init(.{});
h.update("a" ** 64 ++ "b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2b512.init(.{});
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
}
test "blake2b512 keyed" {
@@ -851,20 +851,20 @@ test "blake2b512 keyed" {
const key = "secret_key";
Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
var h = Blake2b512.init(.{ .key = key });
h.update("a" ** 64 ++ "b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
h = Blake2b512.init(.{ .key = key });
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
test "comptime blake2b512" {
@@ -875,12 +875,12 @@ test "comptime blake2b512" {
const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41";
- htest.assertEqualHash(Blake2b512, h1, block[0..]);
+ try htest.assertEqualHash(Blake2b512, h1, block[0..]);
var h = Blake2b512.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
diff --git a/lib/std/crypto/blake3.zig b/lib/std/crypto/blake3.zig
index a10c50b074..e6b5e42f47 100644
--- a/lib/std/crypto/blake3.zig
+++ b/lib/std/crypto/blake3.zig
@@ -641,7 +641,7 @@ const reference_test = ReferenceTest{
},
};
-fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {
+fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) !void {
// Save initial state
const initial_state = hasher.*;
@@ -664,7 +664,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {
// Compare to expected value
var expected_bytes: [expected_hex.len / 2]u8 = undefined;
_ = fmt.hexToBytes(expected_bytes[0..], expected_hex[0..]) catch unreachable;
- testing.expectEqual(actual_bytes, expected_bytes);
+ try testing.expectEqual(actual_bytes, expected_bytes);
// Restore initial state
hasher.* = initial_state;
@@ -676,8 +676,8 @@ test "BLAKE3 reference test cases" {
var derive_key = &Blake3.initKdf(reference_test.context_string, .{});
for (reference_test.cases) |t| {
- testBlake3(hash, t.input_len, t.hash.*);
- testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);
- testBlake3(derive_key, t.input_len, t.derive_key.*);
+ try testBlake3(hash, t.input_len, t.hash.*);
+ try testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);
+ try testBlake3(derive_key, t.input_len, t.derive_key.*);
}
}
diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig
index ea9eafd356..b007d52353 100644
--- a/lib/std/crypto/chacha20.zig
+++ b/lib/std/crypto/chacha20.zig
@@ -604,9 +604,9 @@ test "chacha20 AEAD API" {
aead.encrypt(c[0..], tag[0..], m, ad, nonce, key);
try aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key);
- testing.expectEqualSlices(u8, out[0..], m);
+ try testing.expectEqualSlices(u8, out[0..], m);
c[0] += 1;
- testing.expectError(error.AuthenticationFailed, aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key));
+ try testing.expectError(error.AuthenticationFailed, aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key));
}
}
@@ -644,11 +644,11 @@ test "crypto.chacha20 test vector sunscreen" {
};
ChaCha20IETF.xor(result[0..], m[0..], 1, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
var m2: [114]u8 = undefined;
ChaCha20IETF.xor(m2[0..], result[0..], 1, key, nonce);
- testing.expect(mem.order(u8, m, &m2) == .eq);
+ try testing.expect(mem.order(u8, m, &m2) == .eq);
}
// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
@@ -683,7 +683,7 @@ test "crypto.chacha20 test vector 1" {
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 2" {
@@ -717,7 +717,7 @@ test "crypto.chacha20 test vector 2" {
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 3" {
@@ -751,7 +751,7 @@ test "crypto.chacha20 test vector 3" {
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 4" {
@@ -785,7 +785,7 @@ test "crypto.chacha20 test vector 4" {
const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 5" {
@@ -857,7 +857,7 @@ test "crypto.chacha20 test vector 5" {
};
ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
}
test "seal" {
@@ -873,7 +873,7 @@ test "seal" {
var out: [exp_out.len]u8 = undefined;
ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m, ad, nonce, key);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
{
const m = [_]u8{
@@ -906,7 +906,7 @@ test "seal" {
var out: [exp_out.len]u8 = undefined;
ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m[0..], ad[0..], nonce, key);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
}
@@ -923,7 +923,7 @@ test "open" {
var out: [exp_out.len]u8 = undefined;
try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
{
const c = [_]u8{
@@ -956,21 +956,21 @@ test "open" {
var out: [exp_out.len]u8 = undefined;
try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
// corrupting the ciphertext, data, key, or nonce should cause a failure
var bad_c = c;
bad_c[0] ^= 1;
- testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], bad_c[0..out.len], bad_c[out.len..].*, ad[0..], nonce, key));
+ try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], bad_c[0..out.len], bad_c[out.len..].*, ad[0..], nonce, key));
var bad_ad = ad;
bad_ad[0] ^= 1;
- testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, bad_ad[0..], nonce, key));
+ try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, bad_ad[0..], nonce, key));
var bad_key = key;
bad_key[0] ^= 1;
- testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], nonce, bad_key));
+ try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], nonce, bad_key));
var bad_nonce = nonce;
bad_nonce[0] ^= 1;
- testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], bad_nonce, key));
+ try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], bad_nonce, key));
}
}
@@ -982,7 +982,7 @@ test "crypto.xchacha20" {
var c: [m.len]u8 = undefined;
XChaCha20IETF.xor(c[0..], m[0..], 0, key, nonce);
var buf: [2 * c.len]u8 = undefined;
- testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");
+ try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");
}
{
const ad = "Additional data";
@@ -991,9 +991,9 @@ test "crypto.xchacha20" {
var out: [m.len]u8 = undefined;
try XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key);
var buf: [2 * c.len]u8 = undefined;
- testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
- testing.expectEqualSlices(u8, out[0..], m);
+ try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
+ try testing.expectEqualSlices(u8, out[0..], m);
c[0] += 1;
- testing.expectError(error.AuthenticationFailed, XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key));
+ try testing.expectError(error.AuthenticationFailed, XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key));
}
}
diff --git a/lib/std/crypto/ghash.zig b/lib/std/crypto/ghash.zig
index ffc9ef41ae..e5eb3fc496 100644
--- a/lib/std/crypto/ghash.zig
+++ b/lib/std/crypto/ghash.zig
@@ -326,11 +326,11 @@ test "ghash" {
st.update(&m);
var out: [16]u8 = undefined;
st.final(&out);
- htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
+ try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
st = Ghash.init(&key);
st.update(m[0..100]);
st.update(m[100..]);
st.final(&out);
- htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
+ try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
}
diff --git a/lib/std/crypto/gimli.zig b/lib/std/crypto/gimli.zig
index fb67c25343..0485769193 100644
--- a/lib/std/crypto/gimli.zig
+++ b/lib/std/crypto/gimli.zig
@@ -205,7 +205,7 @@ test "permute" {
while (i < 12) : (i += 1) {
mem.writeIntLittle(u32, expected_output[i * 4 ..][0..4], tv_output[i / 4][i % 4]);
}
- testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);
+ try testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);
}
pub const Hash = struct {
@@ -274,7 +274,7 @@ test "hash" {
_ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
var md: [32]u8 = undefined;
hash(&md, &msg, .{});
- htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
+ try htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
}
test "hash test vector 17" {
@@ -282,7 +282,7 @@ test "hash test vector 17" {
_ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F");
var md: [32]u8 = undefined;
hash(&md, &msg, .{});
- htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);
+ try htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);
}
test "hash test vector 33" {
@@ -290,7 +290,7 @@ test "hash test vector 33" {
_ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
var md: [32]u8 = undefined;
hash(&md, &msg, .{});
- htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);
+ try htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);
}
pub const Aead = struct {
@@ -447,12 +447,12 @@ test "cipher" {
var ct: [pt.len]u8 = undefined;
var tag: [16]u8 = undefined;
Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
- htest.assertEqual("", &ct);
- htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);
+ try htest.assertEqual("", &ct);
+ try htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);
var pt2: [pt.len]u8 = undefined;
try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &pt, &pt2);
+ try testing.expectEqualSlices(u8, &pt, &pt2);
}
{ // test vector (34) from NIST KAT submission.
const ad: [0]u8 = undefined;
@@ -462,12 +462,12 @@ test "cipher" {
var ct: [pt.len]u8 = undefined;
var tag: [16]u8 = undefined;
Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
- htest.assertEqual("7F", &ct);
- htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);
+ try htest.assertEqual("7F", &ct);
+ try htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);
var pt2: [pt.len]u8 = undefined;
try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &pt, &pt2);
+ try testing.expectEqualSlices(u8, &pt, &pt2);
}
{ // test vector (106) from NIST KAT submission.
var ad: [12 / 2]u8 = undefined;
@@ -478,12 +478,12 @@ test "cipher" {
var ct: [pt.len]u8 = undefined;
var tag: [16]u8 = undefined;
Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
- htest.assertEqual("484D35", &ct);
- htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);
+ try htest.assertEqual("484D35", &ct);
+ try htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);
var pt2: [pt.len]u8 = undefined;
try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &pt, &pt2);
+ try testing.expectEqualSlices(u8, &pt, &pt2);
}
{ // test vector (790) from NIST KAT submission.
var ad: [60 / 2]u8 = undefined;
@@ -494,12 +494,12 @@ test "cipher" {
var ct: [pt.len]u8 = undefined;
var tag: [16]u8 = undefined;
Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
- htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);
- htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);
+ try htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);
+ try htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);
var pt2: [pt.len]u8 = undefined;
try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &pt, &pt2);
+ try testing.expectEqualSlices(u8, &pt, &pt2);
}
{ // test vector (1057) from NIST KAT submission.
const ad: [0]u8 = undefined;
@@ -509,11 +509,11 @@ test "cipher" {
var ct: [pt.len]u8 = undefined;
var tag: [16]u8 = undefined;
Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
- htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);
- htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);
+ try htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);
+ try htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);
var pt2: [pt.len]u8 = undefined;
try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &pt, &pt2);
+ try testing.expectEqualSlices(u8, &pt, &pt2);
}
}
diff --git a/lib/std/crypto/hkdf.zig b/lib/std/crypto/hkdf.zig
index c0f919ef82..81c541231d 100644
--- a/lib/std/crypto/hkdf.zig
+++ b/lib/std/crypto/hkdf.zig
@@ -65,8 +65,8 @@ test "Hkdf" {
const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
const kdf = HkdfSha256;
const prk = kdf.extract(&salt, &ikm);
- htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);
+ try htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);
var out: [42]u8 = undefined;
kdf.expand(&out, &context, prk);
- htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);
+ try htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);
}
diff --git a/lib/std/crypto/hmac.zig b/lib/std/crypto/hmac.zig
index 7f29c62941..12c4a53e0f 100644
--- a/lib/std/crypto/hmac.zig
+++ b/lib/std/crypto/hmac.zig
@@ -84,26 +84,26 @@ const htest = @import("test.zig");
test "hmac md5" {
var out: [HmacMd5.mac_length]u8 = undefined;
HmacMd5.create(out[0..], "", "");
- htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);
+ try htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);
HmacMd5.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
- htest.assertEqual("80070713463e7749b90c2dc24911e275", out[0..]);
+ try htest.assertEqual("80070713463e7749b90c2dc24911e275", out[0..]);
}
test "hmac sha1" {
var out: [HmacSha1.mac_length]u8 = undefined;
HmacSha1.create(out[0..], "", "");
- htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);
+ try htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);
HmacSha1.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
- htest.assertEqual("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9", out[0..]);
+ try htest.assertEqual("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9", out[0..]);
}
test "hmac sha256" {
var out: [sha2.HmacSha256.mac_length]u8 = undefined;
sha2.HmacSha256.create(out[0..], "", "");
- htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);
+ try htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);
sha2.HmacSha256.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
- htest.assertEqual("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8", out[0..]);
+ try htest.assertEqual("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8", out[0..]);
}
diff --git a/lib/std/crypto/isap.zig b/lib/std/crypto/isap.zig
index 6deb4977bb..c7706df1df 100644
--- a/lib/std/crypto/isap.zig
+++ b/lib/std/crypto/isap.zig
@@ -240,8 +240,8 @@ test "ISAP" {
var msg = "test";
var c: [msg.len]u8 = undefined;
IsapA128A.encrypt(c[0..], &tag, msg[0..], ad, n, k);
- testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[0..]));
- testing.expect(mem.eql(u8, &[_]u8{ 0x6c, 0x25, 0xe8, 0xe2, 0xe1, 0x1f, 0x38, 0xe9, 0x80, 0x75, 0xde, 0xd5, 0x2d, 0xb2, 0x31, 0x82 }, tag[0..]));
+ try testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[0..]));
+ try testing.expect(mem.eql(u8, &[_]u8{ 0x6c, 0x25, 0xe8, 0xe2, 0xe1, 0x1f, 0x38, 0xe9, 0x80, 0x75, 0xde, 0xd5, 0x2d, 0xb2, 0x31, 0x82 }, tag[0..]));
try IsapA128A.decrypt(c[0..], c[0..], tag, ad, n, k);
- testing.expect(mem.eql(u8, msg, c[0..]));
+ try testing.expect(mem.eql(u8, msg, c[0..]));
}
diff --git a/lib/std/crypto/md5.zig b/lib/std/crypto/md5.zig
index 78454ce3c1..d4109eed8a 100644
--- a/lib/std/crypto/md5.zig
+++ b/lib/std/crypto/md5.zig
@@ -241,13 +241,13 @@ pub const Md5 = struct {
const htest = @import("test.zig");
test "md5 single" {
- htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");
- htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");
- htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");
- htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");
- htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");
- htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
- htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
+ try htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");
+ try htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");
+ try htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");
+ try htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");
+ try htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");
+ try htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
+ try htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
}
test "md5 streaming" {
@@ -255,12 +255,12 @@ test "md5 streaming" {
var out: [16]u8 = undefined;
h.final(out[0..]);
- htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);
+ try htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);
h = Md5.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
+ try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
h = Md5.init(.{});
h.update("a");
@@ -268,7 +268,7 @@ test "md5 streaming" {
h.update("c");
h.final(out[0..]);
- htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
+ try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
}
test "md5 aligned final" {
diff --git a/lib/std/crypto/pbkdf2.zig b/lib/std/crypto/pbkdf2.zig
index f93a5235af..b3e2a32bf3 100644
--- a/lib/std/crypto/pbkdf2.zig
+++ b/lib/std/crypto/pbkdf2.zig
@@ -168,7 +168,7 @@ test "RFC 6070 one iteration" {
const expected = "0c60c80f961f0e71f3a9b524af6012062fe037a6";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "RFC 6070 two iterations" {
@@ -183,7 +183,7 @@ test "RFC 6070 two iterations" {
const expected = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "RFC 6070 4096 iterations" {
@@ -198,7 +198,7 @@ test "RFC 6070 4096 iterations" {
const expected = "4b007901b765489abead49d926f721d065a429c1";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "RFC 6070 16,777,216 iterations" {
@@ -218,7 +218,7 @@ test "RFC 6070 16,777,216 iterations" {
const expected = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "RFC 6070 multi-block salt and password" {
@@ -233,7 +233,7 @@ test "RFC 6070 multi-block salt and password" {
const expected = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "RFC 6070 embedded NUL" {
@@ -248,7 +248,7 @@ test "RFC 6070 embedded NUL" {
const expected = "56fa6aa75548099dcc37d7f03425e0c3";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "Very large dk_len" {
diff --git a/lib/std/crypto/pcurves/tests.zig b/lib/std/crypto/pcurves/tests.zig
index 4e8e08a7fe..6d9682abf1 100644
--- a/lib/std/crypto/pcurves/tests.zig
+++ b/lib/std/crypto/pcurves/tests.zig
@@ -17,7 +17,7 @@ test "p256 ECDH key exchange" {
const dhB = try P256.basePoint.mul(dhb, .Little);
const shareda = try dhA.mul(dhb, .Little);
const sharedb = try dhB.mul(dha, .Little);
- testing.expect(shareda.equivalent(sharedb));
+ try testing.expect(shareda.equivalent(sharedb));
}
test "p256 point from affine coordinates" {
@@ -28,7 +28,7 @@ test "p256 point from affine coordinates" {
var ys: [32]u8 = undefined;
_ = try fmt.hexToBytes(&ys, yh);
var p = try P256.fromSerializedAffineCoordinates(xs, ys, .Big);
- testing.expect(p.equivalent(P256.basePoint));
+ try testing.expect(p.equivalent(P256.basePoint));
}
test "p256 test vectors" {
@@ -50,7 +50,7 @@ test "p256 test vectors" {
p = p.add(P256.basePoint);
var xs: [32]u8 = undefined;
_ = try fmt.hexToBytes(&xs, xh);
- testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
+ try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
}
}
@@ -67,7 +67,7 @@ test "p256 test vectors - doubling" {
p = p.dbl();
var xs: [32]u8 = undefined;
_ = try fmt.hexToBytes(&xs, xh);
- testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
+ try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
}
}
@@ -75,29 +75,29 @@ test "p256 compressed sec1 encoding/decoding" {
const p = P256.random();
const s = p.toCompressedSec1();
const q = try P256.fromSec1(&s);
- testing.expect(p.equivalent(q));
+ try testing.expect(p.equivalent(q));
}
test "p256 uncompressed sec1 encoding/decoding" {
const p = P256.random();
const s = p.toUncompressedSec1();
const q = try P256.fromSec1(&s);
- testing.expect(p.equivalent(q));
+ try testing.expect(p.equivalent(q));
}
test "p256 public key is the neutral element" {
const n = P256.scalar.Scalar.zero.toBytes(.Little);
const p = P256.random();
- testing.expectError(error.IdentityElement, p.mul(n, .Little));
+ try testing.expectError(error.IdentityElement, p.mul(n, .Little));
}
test "p256 public key is the neutral element (public verification)" {
const n = P256.scalar.Scalar.zero.toBytes(.Little);
const p = P256.random();
- testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
+ try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
}
test "p256 field element non-canonical encoding" {
const s = [_]u8{0xff} ** 32;
- testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .Little));
+ try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .Little));
}
diff --git a/lib/std/crypto/poly1305.zig b/lib/std/crypto/poly1305.zig
index 375cf0a3cb..e93afac859 100644
--- a/lib/std/crypto/poly1305.zig
+++ b/lib/std/crypto/poly1305.zig
@@ -216,5 +216,5 @@ test "poly1305 rfc7439 vector1" {
var mac: [16]u8 = undefined;
Poly1305.create(mac[0..], msg, key);
- std.testing.expectEqualSlices(u8, expected_mac, &mac);
+ try std.testing.expectEqualSlices(u8, expected_mac, &mac);
}
diff --git a/lib/std/crypto/salsa20.zig b/lib/std/crypto/salsa20.zig
index 2a06944adc..8a800c8a40 100644
--- a/lib/std/crypto/salsa20.zig
+++ b/lib/std/crypto/salsa20.zig
@@ -561,11 +561,11 @@ test "(x)salsa20" {
var c: [msg.len]u8 = undefined;
Salsa20.xor(&c, msg[0..], 0, key, nonce);
- htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);
+ try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);
const extended_nonce = [_]u8{0x42} ** 24;
XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce);
- htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);
+ try htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);
}
test "xsalsa20poly1305" {
@@ -628,5 +628,5 @@ test "secretbox twoblocks" {
const msg = [_]u8{'a'} ** 97;
var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined;
SecretBox.seal(&ciphertext, &msg, nonce, key);
- htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
+ try htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
}
diff --git a/lib/std/crypto/sha1.zig b/lib/std/crypto/sha1.zig
index ac699f0ef1..6bf6b469e2 100644
--- a/lib/std/crypto/sha1.zig
+++ b/lib/std/crypto/sha1.zig
@@ -265,9 +265,9 @@ pub const Sha1 = struct {
const htest = @import("test.zig");
test "sha1 single" {
- htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");
- htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");
- htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");
+ try htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");
+ try htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha1 streaming" {
@@ -275,19 +275,19 @@ test "sha1 streaming" {
var out: [20]u8 = undefined;
h.final(&out);
- htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);
+ try htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);
h = Sha1.init(.{});
h.update("abc");
h.final(&out);
- htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
+ try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
h = Sha1.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(&out);
- htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
+ try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
}
test "sha1 aligned final" {
diff --git a/lib/std/crypto/sha2.zig b/lib/std/crypto/sha2.zig
index 5a37004e8c..ece2a3abfb 100644
--- a/lib/std/crypto/sha2.zig
+++ b/lib/std/crypto/sha2.zig
@@ -285,9 +285,9 @@ fn Sha2x32(comptime params: Sha2Params32) type {
}
test "sha224 single" {
- htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");
- htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");
- htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");
+ try htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");
+ try htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha224 streaming" {
@@ -295,25 +295,25 @@ test "sha224 streaming" {
var out: [28]u8 = undefined;
h.final(out[0..]);
- htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);
+ try htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);
h = Sha224.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
+ try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
h = Sha224.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
+ try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
}
test "sha256 single" {
- htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");
- htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");
- htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");
+ try htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");
+ try htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha256 streaming" {
@@ -321,19 +321,19 @@ test "sha256 streaming" {
var out: [32]u8 = undefined;
h.final(out[0..]);
- htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);
+ try htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);
h = Sha256.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
+ try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
h = Sha256.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
+ try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
}
test "sha256 aligned final" {
@@ -675,13 +675,13 @@ fn Sha2x64(comptime params: Sha2Params64) type {
test "sha384 single" {
const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
- htest.assertEqualHash(Sha384, h1, "");
+ try htest.assertEqualHash(Sha384, h1, "");
const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
- htest.assertEqualHash(Sha384, h2, "abc");
+ try htest.assertEqualHash(Sha384, h2, "abc");
const h3 = "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039";
- htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha384 streaming" {
@@ -690,32 +690,32 @@ test "sha384 streaming" {
const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
h = Sha384.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Sha384.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
}
test "sha512 single" {
const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
- htest.assertEqualHash(Sha512, h1, "");
+ try htest.assertEqualHash(Sha512, h1, "");
const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
- htest.assertEqualHash(Sha512, h2, "abc");
+ try htest.assertEqualHash(Sha512, h2, "abc");
const h3 = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909";
- htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha512 streaming" {
@@ -724,21 +724,21 @@ test "sha512 streaming" {
const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
h = Sha512.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Sha512.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
}
test "sha512 aligned final" {
diff --git a/lib/std/crypto/sha3.zig b/lib/std/crypto/sha3.zig
index d68821133e..d642d631e0 100644
--- a/lib/std/crypto/sha3.zig
+++ b/lib/std/crypto/sha3.zig
@@ -169,9 +169,9 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void {
}
test "sha3-224 single" {
- htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");
- htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");
- htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");
+ try htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");
+ try htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha3-224 streaming" {
@@ -179,25 +179,25 @@ test "sha3-224 streaming" {
var out: [28]u8 = undefined;
h.final(out[0..]);
- htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);
+ try htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);
h = Sha3_224.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
+ try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
h = Sha3_224.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
+ try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
}
test "sha3-256 single" {
- htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");
- htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");
- htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");
+ try htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");
+ try htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha3-256 streaming" {
@@ -205,19 +205,19 @@ test "sha3-256 streaming" {
var out: [32]u8 = undefined;
h.final(out[0..]);
- htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);
+ try htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);
h = Sha3_256.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
+ try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
h = Sha3_256.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
+ try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
}
test "sha3-256 aligned final" {
@@ -231,11 +231,11 @@ test "sha3-256 aligned final" {
test "sha3-384 single" {
const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
- htest.assertEqualHash(Sha3_384, h1, "");
+ try htest.assertEqualHash(Sha3_384, h1, "");
const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
- htest.assertEqualHash(Sha3_384, h2, "abc");
+ try htest.assertEqualHash(Sha3_384, h2, "abc");
const h3 = "79407d3b5916b59c3e30b09822974791c313fb9ecc849e406f23592d04f625dc8c709b98b43b3852b337216179aa7fc7";
- htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha3-384 streaming" {
@@ -244,29 +244,29 @@ test "sha3-384 streaming" {
const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
h = Sha3_384.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Sha3_384.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
}
test "sha3-512 single" {
const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
- htest.assertEqualHash(Sha3_512, h1, "");
+ try htest.assertEqualHash(Sha3_512, h1, "");
const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
- htest.assertEqualHash(Sha3_512, h2, "abc");
+ try htest.assertEqualHash(Sha3_512, h2, "abc");
const h3 = "afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185";
- htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha3-512 streaming" {
@@ -275,20 +275,20 @@ test "sha3-512 streaming" {
const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
h = Sha3_512.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Sha3_512.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
}
test "sha3-512 aligned final" {
@@ -301,13 +301,13 @@ test "sha3-512 aligned final" {
}
test "keccak-256 single" {
- htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");
- htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");
- htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");
+ try htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");
+ try htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "keccak-512 single" {
- htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");
- htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");
- htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");
+ try htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");
+ try htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
diff --git a/lib/std/crypto/siphash.zig b/lib/std/crypto/siphash.zig
index 67bb2a329a..3bed5d1086 100644
--- a/lib/std/crypto/siphash.zig
+++ b/lib/std/crypto/siphash.zig
@@ -319,7 +319,7 @@ test "siphash64-2-4 sanity" {
var out: [siphash.mac_length]u8 = undefined;
siphash.create(&out, buffer[0..i], test_key);
- testing.expectEqual(out, vector);
+ try testing.expectEqual(out, vector);
}
}
@@ -399,7 +399,7 @@ test "siphash128-2-4 sanity" {
var out: [siphash.mac_length]u8 = undefined;
siphash.create(&out, buffer[0..i], test_key[0..]);
- testing.expectEqual(out, vector);
+ try testing.expectEqual(out, vector);
}
}
@@ -423,6 +423,6 @@ test "iterative non-divisible update" {
}
const iterative_hash = siphash.finalInt();
- std.testing.expectEqual(iterative_hash, non_iterative_hash);
+ try std.testing.expectEqual(iterative_hash, non_iterative_hash);
}
}
diff --git a/lib/std/crypto/test.zig b/lib/std/crypto/test.zig
index cab07c50ec..b517fbecb1 100644
--- a/lib/std/crypto/test.zig
+++ b/lib/std/crypto/test.zig
@@ -8,19 +8,19 @@ const testing = std.testing;
const fmt = std.fmt;
// Hash using the specified hasher `H` asserting `expected == H(input)`.
-pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) void {
+pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) !void {
var h: [Hasher.digest_length]u8 = undefined;
Hasher.hash(input, &h, .{});
- assertEqual(expected_hex, &h);
+ try assertEqual(expected_hex, &h);
}
// Assert `expected` == hex(`input`) where `input` is a bytestring
-pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) void {
+pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) !void {
var expected_bytes: [expected_hex.len / 2]u8 = undefined;
for (expected_bytes) |*r, i| {
r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable;
}
- testing.expectEqualSlices(u8, &expected_bytes, input);
+ try testing.expectEqualSlices(u8, &expected_bytes, input);
}
diff --git a/lib/std/crypto/utils.zig b/lib/std/crypto/utils.zig
index ca86601bf9..4c2a44b967 100644
--- a/lib/std/crypto/utils.zig
+++ b/lib/std/crypto/utils.zig
@@ -92,9 +92,9 @@ test "crypto.utils.timingSafeEql" {
var b: [100]u8 = undefined;
std.crypto.random.bytes(a[0..]);
std.crypto.random.bytes(b[0..]);
- testing.expect(!timingSafeEql([100]u8, a, b));
+ try testing.expect(!timingSafeEql([100]u8, a, b));
mem.copy(u8, a[0..], b[0..]);
- testing.expect(timingSafeEql([100]u8, a, b));
+ try testing.expect(timingSafeEql([100]u8, a, b));
}
test "crypto.utils.timingSafeEql (vectors)" {
@@ -104,22 +104,22 @@ test "crypto.utils.timingSafeEql (vectors)" {
std.crypto.random.bytes(b[0..]);
const v1: std.meta.Vector(100, u8) = a;
const v2: std.meta.Vector(100, u8) = b;
- testing.expect(!timingSafeEql(std.meta.Vector(100, u8), v1, v2));
+ try testing.expect(!timingSafeEql(std.meta.Vector(100, u8), v1, v2));
const v3: std.meta.Vector(100, u8) = a;
- testing.expect(timingSafeEql(std.meta.Vector(100, u8), v1, v3));
+ try testing.expect(timingSafeEql(std.meta.Vector(100, u8), v1, v3));
}
test "crypto.utils.timingSafeCompare" {
var a = [_]u8{10} ** 32;
var b = [_]u8{10} ** 32;
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);
a[31] = 1;
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
a[0] = 20;
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
}
test "crypto.utils.secureZero" {
@@ -129,5 +129,5 @@ test "crypto.utils.secureZero" {
mem.set(u8, a[0..], 0);
secureZero(u8, b[0..]);
- testing.expectEqualSlices(u8, a[0..], b[0..]);
+ try testing.expectEqualSlices(u8, a[0..], b[0..]);
}
diff --git a/lib/std/cstr.zig b/lib/std/cstr.zig
index 33f32ae892..d8b8cf455b 100644
--- a/lib/std/cstr.zig
+++ b/lib/std/cstr.zig
@@ -27,13 +27,13 @@ pub fn cmp(a: [*:0]const u8, b: [*:0]const u8) i8 {
}
test "cstr fns" {
- comptime testCStrFnsImpl();
- testCStrFnsImpl();
+ comptime try testCStrFnsImpl();
+ try testCStrFnsImpl();
}
-fn testCStrFnsImpl() void {
- testing.expect(cmp("aoeu", "aoez") == -1);
- testing.expect(mem.len("123456789") == 9);
+fn testCStrFnsImpl() !void {
+ try testing.expect(cmp("aoeu", "aoez") == -1);
+ try testing.expect(mem.len("123456789") == 9);
}
/// Returns a mutable, null-terminated slice with the same length as `slice`.
@@ -48,8 +48,8 @@ pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![:0]u8 {
test "addNullByte" {
const slice = try addNullByte(std.testing.allocator, "hello"[0..4]);
defer std.testing.allocator.free(slice);
- testing.expect(slice.len == 4);
- testing.expect(slice[4] == 0);
+ try testing.expect(slice.len == 4);
+ try testing.expect(slice[4] == 0);
}
pub const NullTerminated2DArray = struct {
diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig
index 98c59d4105..d39b367a02 100644
--- a/lib/std/dynamic_library.zig
+++ b/lib/std/dynamic_library.zig
@@ -408,7 +408,7 @@ test "dynamic_library" {
};
const dynlib = DynLib.open(libname) catch |err| {
- testing.expect(err == error.FileNotFound);
+ try testing.expect(err == error.FileNotFound);
return;
};
}
diff --git a/lib/std/elf.zig b/lib/std/elf.zig
index 36382ecc42..6a17f7228d 100644
--- a/lib/std/elf.zig
+++ b/lib/std/elf.zig
@@ -565,7 +565,7 @@ test "bswapAllFields" {
.ch_addralign = 0x12124242,
};
bswapAllFields(Elf32_Chdr, &s);
- std.testing.expectEqual(Elf32_Chdr{
+ try std.testing.expectEqual(Elf32_Chdr{
.ch_type = 0x34123412,
.ch_size = 0x78567856,
.ch_addralign = 0x42421212,
diff --git a/lib/std/enums.zig b/lib/std/enums.zig
index a868bdeb26..f0131f4c8a 100644
--- a/lib/std/enums.zig
+++ b/lib/std/enums.zig
@@ -56,10 +56,10 @@ test "std.enums.valuesFromFields" {
.{ .name = "a", .value = undefined },
.{ .name = "d", .value = undefined },
});
- testing.expectEqual(E.b, fields[0]);
- testing.expectEqual(E.a, fields[1]);
- testing.expectEqual(E.d, fields[2]); // a == d
- testing.expectEqual(E.d, fields[3]);
+ try testing.expectEqual(E.b, fields[0]);
+ try testing.expectEqual(E.a, fields[1]);
+ try testing.expectEqual(E.d, fields[2]); // a == d
+ try testing.expectEqual(E.d, fields[3]);
}
/// Returns the set of all named values in the given enum, in
@@ -70,7 +70,7 @@ pub fn values(comptime E: type) []const E {
test "std.enum.values" {
const E = extern enum { a, b, c, d = 0 };
- testing.expectEqualSlices(E, &.{ .a, .b, .c, .d }, values(E));
+ try testing.expectEqualSlices(E, &.{ .a, .b, .c, .d }, values(E));
}
/// Returns the set of all unique named values in the given enum, in
@@ -82,10 +82,10 @@ pub fn uniqueValues(comptime E: type) []const E {
test "std.enum.uniqueValues" {
const E = extern enum { a, b, c, d = 0, e, f = 3 };
- testing.expectEqualSlices(E, &.{ .a, .b, .c, .f }, uniqueValues(E));
+ try testing.expectEqualSlices(E, &.{ .a, .b, .c, .f }, uniqueValues(E));
const F = enum { a, b, c };
- testing.expectEqualSlices(F, &.{ .a, .b, .c }, uniqueValues(F));
+ try testing.expectEqualSlices(F, &.{ .a, .b, .c }, uniqueValues(F));
}
/// Returns the set of all unique field values in the given enum, in
@@ -179,10 +179,10 @@ test "std.enums.directEnumArray" {
.c = true,
});
- testing.expectEqual([7]bool, @TypeOf(array));
- testing.expectEqual(true, array[4]);
- testing.expectEqual(false, array[6]);
- testing.expectEqual(true, array[2]);
+ try testing.expectEqual([7]bool, @TypeOf(array));
+ try testing.expectEqual(true, array[4]);
+ try testing.expectEqual(false, array[6]);
+ try testing.expectEqual(true, array[2]);
}
/// Initializes an array of Data which can be indexed by
@@ -220,10 +220,10 @@ test "std.enums.directEnumArrayDefault" {
.b = runtime_false,
});
- testing.expectEqual([7]bool, @TypeOf(array));
- testing.expectEqual(true, array[4]);
- testing.expectEqual(false, array[6]);
- testing.expectEqual(false, array[2]);
+ try testing.expectEqual([7]bool, @TypeOf(array));
+ try testing.expectEqual(true, array[4]);
+ try testing.expectEqual(false, array[6]);
+ try testing.expectEqual(false, array[2]);
}
/// Cast an enum literal, value, or string to the enum value of type E
@@ -250,23 +250,23 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
test "std.enums.nameCast" {
const A = enum { a = 0, b = 1 };
const B = enum { a = 1, b = 0 };
- testing.expectEqual(A.a, nameCast(A, .a));
- testing.expectEqual(A.a, nameCast(A, A.a));
- testing.expectEqual(A.a, nameCast(A, B.a));
- testing.expectEqual(A.a, nameCast(A, "a"));
- testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
- testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
- testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
+ try testing.expectEqual(A.a, nameCast(A, .a));
+ try testing.expectEqual(A.a, nameCast(A, A.a));
+ try testing.expectEqual(A.a, nameCast(A, B.a));
+ try testing.expectEqual(A.a, nameCast(A, "a"));
+ try testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
+ try testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
+ try testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
- testing.expectEqual(B.a, nameCast(B, .a));
- testing.expectEqual(B.a, nameCast(B, A.a));
- testing.expectEqual(B.a, nameCast(B, B.a));
- testing.expectEqual(B.a, nameCast(B, "a"));
+ try testing.expectEqual(B.a, nameCast(B, .a));
+ try testing.expectEqual(B.a, nameCast(B, A.a));
+ try testing.expectEqual(B.a, nameCast(B, B.a));
+ try testing.expectEqual(B.a, nameCast(B, "a"));
- testing.expectEqual(B.b, nameCast(B, .b));
- testing.expectEqual(B.b, nameCast(B, A.b));
- testing.expectEqual(B.b, nameCast(B, B.b));
- testing.expectEqual(B.b, nameCast(B, "b"));
+ try testing.expectEqual(B.b, nameCast(B, .b));
+ try testing.expectEqual(B.b, nameCast(B, A.b));
+ try testing.expectEqual(B.b, nameCast(B, B.b));
+ try testing.expectEqual(B.b, nameCast(B, "b"));
}
/// A set of enum elements, backed by a bitfield. If the enum
@@ -851,202 +851,202 @@ test "std.enums.EnumIndexer dense zeroed" {
const E = enum { b = 1, a = 0, c = 2 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
- testing.expectEqual(E, Indexer.Key);
- testing.expectEqual(@as(usize, 3), Indexer.count);
+ try testing.expectEqual(E, Indexer.Key);
+ try testing.expectEqual(@as(usize, 3), Indexer.count);
- testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
- testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
- testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
+ try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
+ try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
+ try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
- testing.expectEqual(E.a, Indexer.keyForIndex(0));
- testing.expectEqual(E.b, Indexer.keyForIndex(1));
- testing.expectEqual(E.c, Indexer.keyForIndex(2));
+ try testing.expectEqual(E.a, Indexer.keyForIndex(0));
+ try testing.expectEqual(E.b, Indexer.keyForIndex(1));
+ try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumIndexer dense positive" {
const E = enum(u4) { c = 6, a = 4, b = 5 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
- testing.expectEqual(E, Indexer.Key);
- testing.expectEqual(@as(usize, 3), Indexer.count);
+ try testing.expectEqual(E, Indexer.Key);
+ try testing.expectEqual(@as(usize, 3), Indexer.count);
- testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
- testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
- testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
+ try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
+ try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
+ try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
- testing.expectEqual(E.a, Indexer.keyForIndex(0));
- testing.expectEqual(E.b, Indexer.keyForIndex(1));
- testing.expectEqual(E.c, Indexer.keyForIndex(2));
+ try testing.expectEqual(E.a, Indexer.keyForIndex(0));
+ try testing.expectEqual(E.b, Indexer.keyForIndex(1));
+ try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumIndexer dense negative" {
const E = enum(i4) { a = -6, c = -4, b = -5 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
- testing.expectEqual(E, Indexer.Key);
- testing.expectEqual(@as(usize, 3), Indexer.count);
+ try testing.expectEqual(E, Indexer.Key);
+ try testing.expectEqual(@as(usize, 3), Indexer.count);
- testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
- testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
- testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
+ try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
+ try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
+ try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
- testing.expectEqual(E.a, Indexer.keyForIndex(0));
- testing.expectEqual(E.b, Indexer.keyForIndex(1));
- testing.expectEqual(E.c, Indexer.keyForIndex(2));
+ try testing.expectEqual(E.a, Indexer.keyForIndex(0));
+ try testing.expectEqual(E.b, Indexer.keyForIndex(1));
+ try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumIndexer sparse" {
const E = enum(i4) { a = -2, c = 6, b = 4 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
- testing.expectEqual(E, Indexer.Key);
- testing.expectEqual(@as(usize, 3), Indexer.count);
+ try testing.expectEqual(E, Indexer.Key);
+ try testing.expectEqual(@as(usize, 3), Indexer.count);
- testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
- testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
- testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
+ try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
+ try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
+ try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
- testing.expectEqual(E.a, Indexer.keyForIndex(0));
- testing.expectEqual(E.b, Indexer.keyForIndex(1));
- testing.expectEqual(E.c, Indexer.keyForIndex(2));
+ try testing.expectEqual(E.a, Indexer.keyForIndex(0));
+ try testing.expectEqual(E.b, Indexer.keyForIndex(1));
+ try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumIndexer repeats" {
const E = extern enum { a = -2, c = 6, b = 4, b2 = 4 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
- testing.expectEqual(E, Indexer.Key);
- testing.expectEqual(@as(usize, 3), Indexer.count);
+ try testing.expectEqual(E, Indexer.Key);
+ try testing.expectEqual(@as(usize, 3), Indexer.count);
- testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
- testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
- testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
+ try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
+ try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
+ try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
- testing.expectEqual(E.a, Indexer.keyForIndex(0));
- testing.expectEqual(E.b, Indexer.keyForIndex(1));
- testing.expectEqual(E.c, Indexer.keyForIndex(2));
+ try testing.expectEqual(E.a, Indexer.keyForIndex(0));
+ try testing.expectEqual(E.b, Indexer.keyForIndex(1));
+ try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumSet" {
const E = extern enum { a, b, c, d, e = 0 };
const Set = EnumSet(E);
- testing.expectEqual(E, Set.Key);
- testing.expectEqual(EnumIndexer(E), Set.Indexer);
- testing.expectEqual(@as(usize, 4), Set.len);
+ try testing.expectEqual(E, Set.Key);
+ try testing.expectEqual(EnumIndexer(E), Set.Indexer);
+ try testing.expectEqual(@as(usize, 4), Set.len);
// Empty sets
const empty = Set{};
- comptime testing.expect(empty.count() == 0);
+ comptime try testing.expect(empty.count() == 0);
var empty_b = Set.init(.{});
- testing.expect(empty_b.count() == 0);
+ try testing.expect(empty_b.count() == 0);
const empty_c = comptime Set.init(.{});
- comptime testing.expect(empty_c.count() == 0);
+ comptime try testing.expect(empty_c.count() == 0);
const full = Set.initFull();
- testing.expect(full.count() == Set.len);
+ try testing.expect(full.count() == Set.len);
const full_b = comptime Set.initFull();
- comptime testing.expect(full_b.count() == Set.len);
+ comptime try testing.expect(full_b.count() == Set.len);
- testing.expectEqual(false, empty.contains(.a));
- testing.expectEqual(false, empty.contains(.b));
- testing.expectEqual(false, empty.contains(.c));
- testing.expectEqual(false, empty.contains(.d));
- testing.expectEqual(false, empty.contains(.e));
+ try testing.expectEqual(false, empty.contains(.a));
+ try testing.expectEqual(false, empty.contains(.b));
+ try testing.expectEqual(false, empty.contains(.c));
+ try testing.expectEqual(false, empty.contains(.d));
+ try testing.expectEqual(false, empty.contains(.e));
{
var iter = empty_b.iterator();
- testing.expectEqual(@as(?E, null), iter.next());
+ try testing.expectEqual(@as(?E, null), iter.next());
}
var mut = Set.init(.{
.a = true,
.c = true,
});
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(false, mut.contains(.b));
- testing.expectEqual(true, mut.contains(.c));
- testing.expectEqual(false, mut.contains(.d));
- testing.expectEqual(true, mut.contains(.e)); // aliases a
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(false, mut.contains(.b));
+ try testing.expectEqual(true, mut.contains(.c));
+ try testing.expectEqual(false, mut.contains(.d));
+ try testing.expectEqual(true, mut.contains(.e)); // aliases a
{
var it = mut.iterator();
- testing.expectEqual(@as(?E, .a), it.next());
- testing.expectEqual(@as(?E, .c), it.next());
- testing.expectEqual(@as(?E, null), it.next());
+ try testing.expectEqual(@as(?E, .a), it.next());
+ try testing.expectEqual(@as(?E, .c), it.next());
+ try testing.expectEqual(@as(?E, null), it.next());
}
mut.toggleAll();
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(false, mut.contains(.a));
- testing.expectEqual(true, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(true, mut.contains(.d));
- testing.expectEqual(false, mut.contains(.e)); // aliases a
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(false, mut.contains(.a));
+ try testing.expectEqual(true, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(true, mut.contains(.d));
+ try testing.expectEqual(false, mut.contains(.e)); // aliases a
{
var it = mut.iterator();
- testing.expectEqual(@as(?E, .b), it.next());
- testing.expectEqual(@as(?E, .d), it.next());
- testing.expectEqual(@as(?E, null), it.next());
+ try testing.expectEqual(@as(?E, .b), it.next());
+ try testing.expectEqual(@as(?E, .d), it.next());
+ try testing.expectEqual(@as(?E, null), it.next());
}
mut.toggleSet(Set.init(.{ .a = true, .b = true }));
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(false, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(true, mut.contains(.d));
- testing.expectEqual(true, mut.contains(.e)); // aliases a
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(false, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(true, mut.contains(.d));
+ try testing.expectEqual(true, mut.contains(.e)); // aliases a
mut.setUnion(Set.init(.{ .a = true, .b = true }));
- testing.expectEqual(@as(usize, 3), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(true, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(true, mut.contains(.d));
+ try testing.expectEqual(@as(usize, 3), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(true, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(true, mut.contains(.d));
mut.remove(.c);
mut.remove(.b);
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(false, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(true, mut.contains(.d));
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(false, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(true, mut.contains(.d));
mut.setIntersection(Set.init(.{ .a = true, .b = true }));
- testing.expectEqual(@as(usize, 1), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(false, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(false, mut.contains(.d));
+ try testing.expectEqual(@as(usize, 1), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(false, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(false, mut.contains(.d));
mut.insert(.a);
mut.insert(.b);
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(true, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(false, mut.contains(.d));
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(true, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(false, mut.contains(.d));
mut.setPresent(.a, false);
mut.toggle(.b);
mut.toggle(.c);
mut.setPresent(.d, true);
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(false, mut.contains(.a));
- testing.expectEqual(false, mut.contains(.b));
- testing.expectEqual(true, mut.contains(.c));
- testing.expectEqual(true, mut.contains(.d));
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(false, mut.contains(.a));
+ try testing.expectEqual(false, mut.contains(.b));
+ try testing.expectEqual(true, mut.contains(.c));
+ try testing.expectEqual(true, mut.contains(.d));
}
test "std.enums.EnumArray void" {
const E = extern enum { a, b, c, d, e = 0 };
const ArrayVoid = EnumArray(E, void);
- testing.expectEqual(E, ArrayVoid.Key);
- testing.expectEqual(EnumIndexer(E), ArrayVoid.Indexer);
- testing.expectEqual(void, ArrayVoid.Value);
- testing.expectEqual(@as(usize, 4), ArrayVoid.len);
+ try testing.expectEqual(E, ArrayVoid.Key);
+ try testing.expectEqual(EnumIndexer(E), ArrayVoid.Indexer);
+ try testing.expectEqual(void, ArrayVoid.Value);
+ try testing.expectEqual(@as(usize, 4), ArrayVoid.len);
const undef = ArrayVoid.initUndefined();
var inst = ArrayVoid.initFill({});
@@ -1059,113 +1059,113 @@ test "std.enums.EnumArray void" {
inst.set(.a, {});
var it = inst.iterator();
- testing.expectEqual(E.a, it.next().?.key);
- testing.expectEqual(E.b, it.next().?.key);
- testing.expectEqual(E.c, it.next().?.key);
- testing.expectEqual(E.d, it.next().?.key);
- testing.expect(it.next() == null);
+ try testing.expectEqual(E.a, it.next().?.key);
+ try testing.expectEqual(E.b, it.next().?.key);
+ try testing.expectEqual(E.c, it.next().?.key);
+ try testing.expectEqual(E.d, it.next().?.key);
+ try testing.expect(it.next() == null);
}
test "std.enums.EnumArray sized" {
const E = extern enum { a, b, c, d, e = 0 };
const Array = EnumArray(E, usize);
- testing.expectEqual(E, Array.Key);
- testing.expectEqual(EnumIndexer(E), Array.Indexer);
- testing.expectEqual(usize, Array.Value);
- testing.expectEqual(@as(usize, 4), Array.len);
+ try testing.expectEqual(E, Array.Key);
+ try testing.expectEqual(EnumIndexer(E), Array.Indexer);
+ try testing.expectEqual(usize, Array.Value);
+ try testing.expectEqual(@as(usize, 4), Array.len);
const undef = Array.initUndefined();
var inst = Array.initFill(5);
const inst2 = Array.init(.{ .a = 1, .b = 2, .c = 3, .d = 4 });
const inst3 = Array.initDefault(6, .{ .b = 4, .c = 2 });
- testing.expectEqual(@as(usize, 5), inst.get(.a));
- testing.expectEqual(@as(usize, 5), inst.get(.b));
- testing.expectEqual(@as(usize, 5), inst.get(.c));
- testing.expectEqual(@as(usize, 5), inst.get(.d));
+ try testing.expectEqual(@as(usize, 5), inst.get(.a));
+ try testing.expectEqual(@as(usize, 5), inst.get(.b));
+ try testing.expectEqual(@as(usize, 5), inst.get(.c));
+ try testing.expectEqual(@as(usize, 5), inst.get(.d));
- testing.expectEqual(@as(usize, 1), inst2.get(.a));
- testing.expectEqual(@as(usize, 2), inst2.get(.b));
- testing.expectEqual(@as(usize, 3), inst2.get(.c));
- testing.expectEqual(@as(usize, 4), inst2.get(.d));
+ try testing.expectEqual(@as(usize, 1), inst2.get(.a));
+ try testing.expectEqual(@as(usize, 2), inst2.get(.b));
+ try testing.expectEqual(@as(usize, 3), inst2.get(.c));
+ try testing.expectEqual(@as(usize, 4), inst2.get(.d));
- testing.expectEqual(@as(usize, 6), inst3.get(.a));
- testing.expectEqual(@as(usize, 4), inst3.get(.b));
- testing.expectEqual(@as(usize, 2), inst3.get(.c));
- testing.expectEqual(@as(usize, 6), inst3.get(.d));
+ try testing.expectEqual(@as(usize, 6), inst3.get(.a));
+ try testing.expectEqual(@as(usize, 4), inst3.get(.b));
+ try testing.expectEqual(@as(usize, 2), inst3.get(.c));
+ try testing.expectEqual(@as(usize, 6), inst3.get(.d));
- testing.expectEqual(&inst.values[0], inst.getPtr(.a));
- testing.expectEqual(&inst.values[1], inst.getPtr(.b));
- testing.expectEqual(&inst.values[2], inst.getPtr(.c));
- testing.expectEqual(&inst.values[3], inst.getPtr(.d));
+ try testing.expectEqual(&inst.values[0], inst.getPtr(.a));
+ try testing.expectEqual(&inst.values[1], inst.getPtr(.b));
+ try testing.expectEqual(&inst.values[2], inst.getPtr(.c));
+ try testing.expectEqual(&inst.values[3], inst.getPtr(.d));
- testing.expectEqual(@as(*const usize, &inst.values[0]), inst.getPtrConst(.a));
- testing.expectEqual(@as(*const usize, &inst.values[1]), inst.getPtrConst(.b));
- testing.expectEqual(@as(*const usize, &inst.values[2]), inst.getPtrConst(.c));
- testing.expectEqual(@as(*const usize, &inst.values[3]), inst.getPtrConst(.d));
+ try testing.expectEqual(@as(*const usize, &inst.values[0]), inst.getPtrConst(.a));
+ try testing.expectEqual(@as(*const usize, &inst.values[1]), inst.getPtrConst(.b));
+ try testing.expectEqual(@as(*const usize, &inst.values[2]), inst.getPtrConst(.c));
+ try testing.expectEqual(@as(*const usize, &inst.values[3]), inst.getPtrConst(.d));
inst.set(.c, 8);
- testing.expectEqual(@as(usize, 5), inst.get(.a));
- testing.expectEqual(@as(usize, 5), inst.get(.b));
- testing.expectEqual(@as(usize, 8), inst.get(.c));
- testing.expectEqual(@as(usize, 5), inst.get(.d));
+ try testing.expectEqual(@as(usize, 5), inst.get(.a));
+ try testing.expectEqual(@as(usize, 5), inst.get(.b));
+ try testing.expectEqual(@as(usize, 8), inst.get(.c));
+ try testing.expectEqual(@as(usize, 5), inst.get(.d));
var it = inst.iterator();
const Entry = Array.Entry;
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .a,
.value = &inst.values[0],
}), it.next());
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .b,
.value = &inst.values[1],
}), it.next());
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .c,
.value = &inst.values[2],
}), it.next());
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .d,
.value = &inst.values[3],
}), it.next());
- testing.expectEqual(@as(?Entry, null), it.next());
+ try testing.expectEqual(@as(?Entry, null), it.next());
}
test "std.enums.EnumMap void" {
const E = extern enum { a, b, c, d, e = 0 };
const Map = EnumMap(E, void);
- testing.expectEqual(E, Map.Key);
- testing.expectEqual(EnumIndexer(E), Map.Indexer);
- testing.expectEqual(void, Map.Value);
- testing.expectEqual(@as(usize, 4), Map.len);
+ try testing.expectEqual(E, Map.Key);
+ try testing.expectEqual(EnumIndexer(E), Map.Indexer);
+ try testing.expectEqual(void, Map.Value);
+ try testing.expectEqual(@as(usize, 4), Map.len);
const b = Map.initFull({});
- testing.expectEqual(@as(usize, 4), b.count());
+ try testing.expectEqual(@as(usize, 4), b.count());
const c = Map.initFullWith(.{ .a = {}, .b = {}, .c = {}, .d = {} });
- testing.expectEqual(@as(usize, 4), c.count());
+ try testing.expectEqual(@as(usize, 4), c.count());
const d = Map.initFullWithDefault({}, .{ .b = {} });
- testing.expectEqual(@as(usize, 4), d.count());
+ try testing.expectEqual(@as(usize, 4), d.count());
var a = Map.init(.{ .b = {}, .d = {} });
- testing.expectEqual(@as(usize, 2), a.count());
- testing.expectEqual(false, a.contains(.a));
- testing.expectEqual(true, a.contains(.b));
- testing.expectEqual(false, a.contains(.c));
- testing.expectEqual(true, a.contains(.d));
- testing.expect(a.get(.a) == null);
- testing.expect(a.get(.b) != null);
- testing.expect(a.get(.c) == null);
- testing.expect(a.get(.d) != null);
- testing.expect(a.getPtr(.a) == null);
- testing.expect(a.getPtr(.b) != null);
- testing.expect(a.getPtr(.c) == null);
- testing.expect(a.getPtr(.d) != null);
- testing.expect(a.getPtrConst(.a) == null);
- testing.expect(a.getPtrConst(.b) != null);
- testing.expect(a.getPtrConst(.c) == null);
- testing.expect(a.getPtrConst(.d) != null);
+ try testing.expectEqual(@as(usize, 2), a.count());
+ try testing.expectEqual(false, a.contains(.a));
+ try testing.expectEqual(true, a.contains(.b));
+ try testing.expectEqual(false, a.contains(.c));
+ try testing.expectEqual(true, a.contains(.d));
+ try testing.expect(a.get(.a) == null);
+ try testing.expect(a.get(.b) != null);
+ try testing.expect(a.get(.c) == null);
+ try testing.expect(a.get(.d) != null);
+ try testing.expect(a.getPtr(.a) == null);
+ try testing.expect(a.getPtr(.b) != null);
+ try testing.expect(a.getPtr(.c) == null);
+ try testing.expect(a.getPtr(.d) != null);
+ try testing.expect(a.getPtrConst(.a) == null);
+ try testing.expect(a.getPtrConst(.b) != null);
+ try testing.expect(a.getPtrConst(.c) == null);
+ try testing.expect(a.getPtrConst(.d) != null);
_ = a.getPtrAssertContains(.b);
_ = a.getAssertContains(.d);
@@ -1174,115 +1174,115 @@ test "std.enums.EnumMap void" {
a.putUninitialized(.c).* = {};
a.putUninitialized(.c).* = {};
- testing.expectEqual(@as(usize, 4), a.count());
- testing.expect(a.get(.a) != null);
- testing.expect(a.get(.b) != null);
- testing.expect(a.get(.c) != null);
- testing.expect(a.get(.d) != null);
+ try testing.expectEqual(@as(usize, 4), a.count());
+ try testing.expect(a.get(.a) != null);
+ try testing.expect(a.get(.b) != null);
+ try testing.expect(a.get(.c) != null);
+ try testing.expect(a.get(.d) != null);
a.remove(.a);
_ = a.fetchRemove(.c);
var iter = a.iterator();
const Entry = Map.Entry;
- testing.expectEqual(E.b, iter.next().?.key);
- testing.expectEqual(E.d, iter.next().?.key);
- testing.expect(iter.next() == null);
+ try testing.expectEqual(E.b, iter.next().?.key);
+ try testing.expectEqual(E.d, iter.next().?.key);
+ try testing.expect(iter.next() == null);
}
test "std.enums.EnumMap sized" {
const E = extern enum { a, b, c, d, e = 0 };
const Map = EnumMap(E, usize);
- testing.expectEqual(E, Map.Key);
- testing.expectEqual(EnumIndexer(E), Map.Indexer);
- testing.expectEqual(usize, Map.Value);
- testing.expectEqual(@as(usize, 4), Map.len);
+ try testing.expectEqual(E, Map.Key);
+ try testing.expectEqual(EnumIndexer(E), Map.Indexer);
+ try testing.expectEqual(usize, Map.Value);
+ try testing.expectEqual(@as(usize, 4), Map.len);
const b = Map.initFull(5);
- testing.expectEqual(@as(usize, 4), b.count());
- testing.expect(b.contains(.a));
- testing.expect(b.contains(.b));
- testing.expect(b.contains(.c));
- testing.expect(b.contains(.d));
- testing.expectEqual(@as(?usize, 5), b.get(.a));
- testing.expectEqual(@as(?usize, 5), b.get(.b));
- testing.expectEqual(@as(?usize, 5), b.get(.c));
- testing.expectEqual(@as(?usize, 5), b.get(.d));
+ try testing.expectEqual(@as(usize, 4), b.count());
+ try testing.expect(b.contains(.a));
+ try testing.expect(b.contains(.b));
+ try testing.expect(b.contains(.c));
+ try testing.expect(b.contains(.d));
+ try testing.expectEqual(@as(?usize, 5), b.get(.a));
+ try testing.expectEqual(@as(?usize, 5), b.get(.b));
+ try testing.expectEqual(@as(?usize, 5), b.get(.c));
+ try testing.expectEqual(@as(?usize, 5), b.get(.d));
const c = Map.initFullWith(.{ .a = 1, .b = 2, .c = 3, .d = 4 });
- testing.expectEqual(@as(usize, 4), c.count());
- testing.expect(c.contains(.a));
- testing.expect(c.contains(.b));
- testing.expect(c.contains(.c));
- testing.expect(c.contains(.d));
- testing.expectEqual(@as(?usize, 1), c.get(.a));
- testing.expectEqual(@as(?usize, 2), c.get(.b));
- testing.expectEqual(@as(?usize, 3), c.get(.c));
- testing.expectEqual(@as(?usize, 4), c.get(.d));
+ try testing.expectEqual(@as(usize, 4), c.count());
+ try testing.expect(c.contains(.a));
+ try testing.expect(c.contains(.b));
+ try testing.expect(c.contains(.c));
+ try testing.expect(c.contains(.d));
+ try testing.expectEqual(@as(?usize, 1), c.get(.a));
+ try testing.expectEqual(@as(?usize, 2), c.get(.b));
+ try testing.expectEqual(@as(?usize, 3), c.get(.c));
+ try testing.expectEqual(@as(?usize, 4), c.get(.d));
const d = Map.initFullWithDefault(6, .{ .b = 2, .c = 4 });
- testing.expectEqual(@as(usize, 4), d.count());
- testing.expect(d.contains(.a));
- testing.expect(d.contains(.b));
- testing.expect(d.contains(.c));
- testing.expect(d.contains(.d));
- testing.expectEqual(@as(?usize, 6), d.get(.a));
- testing.expectEqual(@as(?usize, 2), d.get(.b));
- testing.expectEqual(@as(?usize, 4), d.get(.c));
- testing.expectEqual(@as(?usize, 6), d.get(.d));
+ try testing.expectEqual(@as(usize, 4), d.count());
+ try testing.expect(d.contains(.a));
+ try testing.expect(d.contains(.b));
+ try testing.expect(d.contains(.c));
+ try testing.expect(d.contains(.d));
+ try testing.expectEqual(@as(?usize, 6), d.get(.a));
+ try testing.expectEqual(@as(?usize, 2), d.get(.b));
+ try testing.expectEqual(@as(?usize, 4), d.get(.c));
+ try testing.expectEqual(@as(?usize, 6), d.get(.d));
var a = Map.init(.{ .b = 2, .d = 4 });
- testing.expectEqual(@as(usize, 2), a.count());
- testing.expectEqual(false, a.contains(.a));
- testing.expectEqual(true, a.contains(.b));
- testing.expectEqual(false, a.contains(.c));
- testing.expectEqual(true, a.contains(.d));
+ try testing.expectEqual(@as(usize, 2), a.count());
+ try testing.expectEqual(false, a.contains(.a));
+ try testing.expectEqual(true, a.contains(.b));
+ try testing.expectEqual(false, a.contains(.c));
+ try testing.expectEqual(true, a.contains(.d));
- testing.expectEqual(@as(?usize, null), a.get(.a));
- testing.expectEqual(@as(?usize, 2), a.get(.b));
- testing.expectEqual(@as(?usize, null), a.get(.c));
- testing.expectEqual(@as(?usize, 4), a.get(.d));
+ try testing.expectEqual(@as(?usize, null), a.get(.a));
+ try testing.expectEqual(@as(?usize, 2), a.get(.b));
+ try testing.expectEqual(@as(?usize, null), a.get(.c));
+ try testing.expectEqual(@as(?usize, 4), a.get(.d));
- testing.expectEqual(@as(?*usize, null), a.getPtr(.a));
- testing.expectEqual(@as(?*usize, &a.values[1]), a.getPtr(.b));
- testing.expectEqual(@as(?*usize, null), a.getPtr(.c));
- testing.expectEqual(@as(?*usize, &a.values[3]), a.getPtr(.d));
+ try testing.expectEqual(@as(?*usize, null), a.getPtr(.a));
+ try testing.expectEqual(@as(?*usize, &a.values[1]), a.getPtr(.b));
+ try testing.expectEqual(@as(?*usize, null), a.getPtr(.c));
+ try testing.expectEqual(@as(?*usize, &a.values[3]), a.getPtr(.d));
- testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.a));
- testing.expectEqual(@as(?*const usize, &a.values[1]), a.getPtrConst(.b));
- testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.c));
- testing.expectEqual(@as(?*const usize, &a.values[3]), a.getPtrConst(.d));
+ try testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.a));
+ try testing.expectEqual(@as(?*const usize, &a.values[1]), a.getPtrConst(.b));
+ try testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.c));
+ try testing.expectEqual(@as(?*const usize, &a.values[3]), a.getPtrConst(.d));
- testing.expectEqual(@as(*const usize, &a.values[1]), a.getPtrAssertContains(.b));
- testing.expectEqual(@as(*const usize, &a.values[3]), a.getPtrAssertContains(.d));
- testing.expectEqual(@as(usize, 2), a.getAssertContains(.b));
- testing.expectEqual(@as(usize, 4), a.getAssertContains(.d));
+ try testing.expectEqual(@as(*const usize, &a.values[1]), a.getPtrAssertContains(.b));
+ try testing.expectEqual(@as(*const usize, &a.values[3]), a.getPtrAssertContains(.d));
+ try testing.expectEqual(@as(usize, 2), a.getAssertContains(.b));
+ try testing.expectEqual(@as(usize, 4), a.getAssertContains(.d));
a.put(.a, 3);
a.put(.a, 5);
a.putUninitialized(.c).* = 7;
a.putUninitialized(.c).* = 9;
- testing.expectEqual(@as(usize, 4), a.count());
- testing.expectEqual(@as(?usize, 5), a.get(.a));
- testing.expectEqual(@as(?usize, 2), a.get(.b));
- testing.expectEqual(@as(?usize, 9), a.get(.c));
- testing.expectEqual(@as(?usize, 4), a.get(.d));
+ try testing.expectEqual(@as(usize, 4), a.count());
+ try testing.expectEqual(@as(?usize, 5), a.get(.a));
+ try testing.expectEqual(@as(?usize, 2), a.get(.b));
+ try testing.expectEqual(@as(?usize, 9), a.get(.c));
+ try testing.expectEqual(@as(?usize, 4), a.get(.d));
a.remove(.a);
- testing.expectEqual(@as(?usize, null), a.fetchRemove(.a));
- testing.expectEqual(@as(?usize, 9), a.fetchRemove(.c));
+ try testing.expectEqual(@as(?usize, null), a.fetchRemove(.a));
+ try testing.expectEqual(@as(?usize, 9), a.fetchRemove(.c));
a.remove(.c);
var iter = a.iterator();
const Entry = Map.Entry;
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .b,
.value = &a.values[1],
}), iter.next());
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .d,
.value = &a.values[3],
}), iter.next());
- testing.expectEqual(@as(?Entry, null), iter.next());
+ try testing.expectEqual(@as(?Entry, null), iter.next());
}
diff --git a/lib/std/event/batch.zig b/lib/std/event/batch.zig
index 5368c5336d..af7f293cff 100644
--- a/lib/std/event/batch.zig
+++ b/lib/std/event/batch.zig
@@ -119,12 +119,12 @@ test "std.event.Batch" {
batch.add(&async sleepALittle(&count));
batch.add(&async increaseByTen(&count));
batch.wait();
- testing.expect(count == 11);
+ try testing.expect(count == 11);
var another = Batch(anyerror!void, 2, .auto_async).init();
another.add(&async somethingElse());
another.add(&async doSomethingThatFails());
- testing.expectError(error.ItBroke, another.wait());
+ try testing.expectError(error.ItBroke, another.wait());
}
fn sleepALittle(count: *usize) void {
diff --git a/lib/std/event/channel.zig b/lib/std/event/channel.zig
index 2711488705..a069985aeb 100644
--- a/lib/std/event/channel.zig
+++ b/lib/std/event/channel.zig
@@ -310,25 +310,25 @@ test "std.event.Channel wraparound" {
// the buffer wraps around, make sure it doesn't crash.
var result: i32 = undefined;
channel.put(5);
- testing.expectEqual(@as(i32, 5), channel.get());
+ try testing.expectEqual(@as(i32, 5), channel.get());
channel.put(6);
- testing.expectEqual(@as(i32, 6), channel.get());
+ try testing.expectEqual(@as(i32, 6), channel.get());
channel.put(7);
- testing.expectEqual(@as(i32, 7), channel.get());
+ try testing.expectEqual(@as(i32, 7), channel.get());
}
fn testChannelGetter(channel: *Channel(i32)) callconv(.Async) void {
const value1 = channel.get();
- testing.expect(value1 == 1234);
+ try testing.expect(value1 == 1234);
const value2 = channel.get();
- testing.expect(value2 == 4567);
+ try testing.expect(value2 == 4567);
const value3 = channel.getOrNull();
- testing.expect(value3 == null);
+ try testing.expect(value3 == null);
var last_put = async testPut(channel, 4444);
const value4 = channel.getOrNull();
- testing.expect(value4.? == 4444);
+ try testing.expect(value4.? == 4444);
await last_put;
}
fn testChannelPutter(channel: *Channel(i32)) callconv(.Async) void {
diff --git a/lib/std/event/future.zig b/lib/std/event/future.zig
index 30a2e46ec5..a081ec0c0f 100644
--- a/lib/std/event/future.zig
+++ b/lib/std/event/future.zig
@@ -107,7 +107,7 @@ fn testFuture() void {
const result = (await a) + (await b);
- testing.expect(result == 12);
+ try testing.expect(result == 12);
}
fn waitOnFuture(future: *Future(i32)) i32 {
diff --git a/lib/std/event/group.zig b/lib/std/event/group.zig
index b052c15704..e6e608ac57 100644
--- a/lib/std/event/group.zig
+++ b/lib/std/event/group.zig
@@ -140,14 +140,14 @@ fn testGroup(allocator: *Allocator) callconv(.Async) void {
var increase_by_ten_frame = async increaseByTen(&count);
group.add(&increase_by_ten_frame) catch @panic("memory");
group.wait();
- testing.expect(count == 11);
+ try testing.expect(count == 11);
var another = Group(anyerror!void).init(allocator);
var something_else_frame = async somethingElse();
another.add(&something_else_frame) catch @panic("memory");
var something_that_fails_frame = async doSomethingThatFails();
another.add(&something_that_fails_frame) catch @panic("memory");
- testing.expectError(error.ItBroke, another.wait());
+ try testing.expectError(error.ItBroke, another.wait());
}
fn sleepALittle(count: *usize) callconv(.Async) void {
std.time.sleep(1 * std.time.ns_per_ms);
diff --git a/lib/std/event/lock.zig b/lib/std/event/lock.zig
index d48c6c1520..fd59bd49c4 100644
--- a/lib/std/event/lock.zig
+++ b/lib/std/event/lock.zig
@@ -136,7 +136,7 @@ test "std.event.Lock" {
testLock(&lock);
const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
- testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
+ try testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
}
fn testLock(lock: *Lock) void {
var handle1 = async lockRunner(lock);
diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig
index 878cea4aa6..279d26490e 100644
--- a/lib/std/event/loop.zig
+++ b/lib/std/event/loop.zig
@@ -1655,7 +1655,7 @@ fn testEventLoop() i32 {
fn testEventLoop2(h: anyframe->i32, did_it: *bool) void {
const value = await h;
- testing.expect(value == 1234);
+ try testing.expect(value == 1234);
did_it.* = true;
}
@@ -1682,7 +1682,7 @@ test "std.event.Loop - runDetached" {
// with the previous runDetached.
loop.run();
- testing.expect(testRunDetachedData == 1);
+ try testing.expect(testRunDetachedData == 1);
}
fn testRunDetached() void {
@@ -1705,7 +1705,7 @@ test "std.event.Loop - sleep" {
for (frames) |*frame|
await frame;
- testing.expect(sleep_count == frames.len);
+ try testing.expect(sleep_count == frames.len);
}
fn testSleep(wait_ns: u64, sleep_count: *usize) void {
diff --git a/lib/std/event/rwlock.zig b/lib/std/event/rwlock.zig
index 04b45ee308..46e14472bf 100644
--- a/lib/std/event/rwlock.zig
+++ b/lib/std/event/rwlock.zig
@@ -228,7 +228,7 @@ test "std.event.RwLock" {
const handle = testLock(std.heap.page_allocator, &lock);
const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
- testing.expectEqualSlices(i32, expected_result, shared_test_data);
+ try testing.expectEqualSlices(i32, expected_result, shared_test_data);
}
fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void {
var read_nodes: [100]Loop.NextTickNode = undefined;
@@ -290,7 +290,7 @@ fn readRunner(lock: *RwLock) callconv(.Async) void {
const handle = await lock_promise;
defer handle.release();
- testing.expect(shared_test_index == 0);
- testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
+ try testing.expect(shared_test_index == 0);
+ try testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
}
}
diff --git a/lib/std/fifo.zig b/lib/std/fifo.zig
index b0771bba16..8377fd13b5 100644
--- a/lib/std/fifo.zig
+++ b/lib/std/fifo.zig
@@ -402,59 +402,59 @@ test "LinearFifo(u8, .Dynamic)" {
defer fifo.deinit();
try fifo.write("HELLO");
- testing.expectEqual(@as(usize, 5), fifo.readableLength());
- testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
+ try testing.expectEqual(@as(usize, 5), fifo.readableLength());
+ try testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
{
var i: usize = 0;
while (i < 5) : (i += 1) {
try fifo.write(&[_]u8{fifo.peekItem(i)});
}
- testing.expectEqual(@as(usize, 10), fifo.readableLength());
- testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
+ try testing.expectEqual(@as(usize, 10), fifo.readableLength());
+ try testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
}
{
- testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);
- testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);
- testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
- testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
- testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);
+ try testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);
+ try testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);
+ try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
+ try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
+ try testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);
}
- testing.expectEqual(@as(usize, 5), fifo.readableLength());
+ try testing.expectEqual(@as(usize, 5), fifo.readableLength());
{ // Writes that wrap around
- testing.expectEqual(@as(usize, 11), fifo.writableLength());
- testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
+ try testing.expectEqual(@as(usize, 11), fifo.writableLength());
+ try testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
fifo.writeAssumeCapacity("6 file_size
const buf2 = try file.readToEndAlloc(testing.allocator, 1024);
defer testing.allocator.free(buf2);
- testing.expectEqual(write_buf.len, buf2.len);
- testing.expect(std.mem.eql(u8, write_buf, buf2));
+ try testing.expectEqual(write_buf.len, buf2.len);
+ try testing.expect(std.mem.eql(u8, write_buf, buf2));
try file.seekTo(0);
// max_bytes == file_size
const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len);
defer testing.allocator.free(buf3);
- testing.expectEqual(write_buf.len, buf3.len);
- testing.expect(std.mem.eql(u8, write_buf, buf3));
+ try testing.expectEqual(write_buf.len, buf3.len);
+ try testing.expect(std.mem.eql(u8, write_buf, buf3));
try file.seekTo(0);
// max_bytes < file_size
- testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1));
+ try testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1));
}
test "directory operations on files" {
@@ -257,22 +257,22 @@ test "directory operations on files" {
var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true });
file.close();
- testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));
- testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));
- testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));
+ try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));
+ try testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));
+ try testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));
if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_file_name);
defer testing.allocator.free(absolute_path);
- testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));
- testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));
+ try testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));
+ try testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));
}
// ensure the file still exists and is a file as a sanity check
file = try tmp_dir.dir.openFile(test_file_name, .{});
const stat = try file.stat();
- testing.expect(stat.kind == .File);
+ try testing.expect(stat.kind == .File);
file.close();
}
@@ -287,23 +287,23 @@ test "file operations on directories" {
try tmp_dir.dir.makeDir(test_dir_name);
- testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));
- testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));
+ try testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));
+ try testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));
// Currently, WASI will return error.Unexpected (via ENOTCAPABLE) when attempting fd_read on a directory handle.
// TODO: Re-enable on WASI once https://github.com/bytecodealliance/wasmtime/issues/1935 is resolved.
if (builtin.os.tag != .wasi) {
- testing.expectError(error.IsDir, tmp_dir.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize)));
+ try testing.expectError(error.IsDir, tmp_dir.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize)));
}
// Note: The `.write = true` is necessary to ensure the error occurs on all platforms.
// TODO: Add a read-only test as well, see https://github.com/ziglang/zig/issues/5732
- testing.expectError(error.IsDir, tmp_dir.dir.openFile(test_dir_name, .{ .write = true }));
+ try testing.expectError(error.IsDir, tmp_dir.dir.openFile(test_dir_name, .{ .write = true }));
if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_dir_name);
defer testing.allocator.free(absolute_path);
- testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));
- testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));
+ try testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));
+ try testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));
}
// ensure the directory still exists as a sanity check
@@ -316,7 +316,7 @@ test "deleteDir" {
defer tmp_dir.cleanup();
// deleting a non-existent directory
- testing.expectError(error.FileNotFound, tmp_dir.dir.deleteDir("test_dir"));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.deleteDir("test_dir"));
var dir = try tmp_dir.dir.makeOpenPath("test_dir", .{});
var file = try dir.createFile("test_file", .{});
@@ -326,7 +326,7 @@ test "deleteDir" {
// deleting a non-empty directory
// TODO: Re-enable this check on Windows, see https://github.com/ziglang/zig/issues/5537
if (builtin.os.tag != .windows) {
- testing.expectError(error.DirNotEmpty, tmp_dir.dir.deleteDir("test_dir"));
+ try testing.expectError(error.DirNotEmpty, tmp_dir.dir.deleteDir("test_dir"));
}
dir = try tmp_dir.dir.openDir("test_dir", .{});
@@ -341,7 +341,7 @@ test "Dir.rename files" {
var tmp_dir = tmpDir(.{});
defer tmp_dir.cleanup();
- testing.expectError(error.FileNotFound, tmp_dir.dir.rename("missing_file_name", "something_else"));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.rename("missing_file_name", "something_else"));
// Renaming files
const test_file_name = "test_file";
@@ -351,7 +351,7 @@ test "Dir.rename files" {
try tmp_dir.dir.rename(test_file_name, renamed_test_file_name);
// Ensure the file was renamed
- testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
file.close();
@@ -363,7 +363,7 @@ test "Dir.rename files" {
existing_file.close();
try tmp_dir.dir.rename(renamed_test_file_name, "existing_file");
- testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(renamed_test_file_name, .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(renamed_test_file_name, .{}));
file = try tmp_dir.dir.openFile("existing_file", .{});
file.close();
}
@@ -380,7 +380,7 @@ test "Dir.rename directories" {
try tmp_dir.dir.rename("test_dir", "test_dir_renamed");
// Ensure the directory was renamed
- testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir", .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir", .{}));
var dir = try tmp_dir.dir.openDir("test_dir_renamed", .{});
// Put a file in the directory
@@ -391,7 +391,7 @@ test "Dir.rename directories" {
try tmp_dir.dir.rename("test_dir_renamed", "test_dir_renamed_again");
// Ensure the directory was renamed and the file still exists in it
- testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir_renamed", .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir_renamed", .{}));
dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
file = try dir.openFile("test_file", .{});
file.close();
@@ -402,7 +402,7 @@ test "Dir.rename directories" {
file = try target_dir.createFile("filler", .{ .read = true });
file.close();
- testing.expectError(error.PathAlreadyExists, tmp_dir.dir.rename("test_dir_renamed_again", "non_empty_target_dir"));
+ try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.rename("test_dir_renamed_again", "non_empty_target_dir"));
// Ensure the directory was not renamed
dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
@@ -421,8 +421,8 @@ test "Dir.rename file <-> dir" {
var file = try tmp_dir.dir.createFile("test_file", .{ .read = true });
file.close();
try tmp_dir.dir.makeDir("test_dir");
- testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir"));
- testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file"));
+ try testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir"));
+ try testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file"));
}
test "rename" {
@@ -440,7 +440,7 @@ test "rename" {
try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);
// ensure the file was renamed
- testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(test_file_name, .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(test_file_name, .{}));
file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{});
file.close();
}
@@ -461,7 +461,7 @@ test "renameAbsolute" {
break :blk try fs.realpathAlloc(&arena.allocator, relative_path);
};
- testing.expectError(error.FileNotFound, fs.renameAbsolute(
+ try testing.expectError(error.FileNotFound, fs.renameAbsolute(
try fs.path.join(allocator, &[_][]const u8{ base_path, "missing_file_name" }),
try fs.path.join(allocator, &[_][]const u8{ base_path, "something_else" }),
));
@@ -477,10 +477,10 @@ test "renameAbsolute" {
);
// ensure the file was renamed
- testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
const stat = try file.stat();
- testing.expect(stat.kind == .File);
+ try testing.expect(stat.kind == .File);
file.close();
// Renaming directories
@@ -493,7 +493,7 @@ test "renameAbsolute" {
);
// ensure the directory was renamed
- testing.expectError(error.FileNotFound, tmp_dir.dir.openDir(test_dir_name, .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir(test_dir_name, .{}));
var dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{});
dir.close();
}
@@ -516,7 +516,7 @@ test "makePath, put some files in it, deleteTree" {
if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {
@panic("expected error");
} else |err| {
- testing.expect(err == error.FileNotFound);
+ try testing.expect(err == error.FileNotFound);
}
}
@@ -530,7 +530,7 @@ test "access file" {
if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| {
@panic("expected error");
} else |err| {
- testing.expect(err == error.FileNotFound);
+ try testing.expect(err == error.FileNotFound);
}
try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
@@ -600,7 +600,7 @@ test "sendfile" {
.header_count = 2,
});
const amt = try dest_file.preadAll(&written_buf, 0);
- testing.expect(mem.eql(u8, written_buf[0..amt], "header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n"));
+ try testing.expect(mem.eql(u8, written_buf[0..amt], "header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n"));
}
test "copyRangeAll" {
@@ -626,7 +626,7 @@ test "copyRangeAll" {
_ = try src_file.copyRangeAll(0, dest_file, 0, data.len);
const amt = try dest_file.preadAll(&written_buf, 0);
- testing.expect(mem.eql(u8, written_buf[0..amt], data));
+ try testing.expect(mem.eql(u8, written_buf[0..amt], data));
}
test "fs.copyFile" {
@@ -655,7 +655,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void {
const contents = try dir.readFileAlloc(testing.allocator, file_path, 1000);
defer testing.allocator.free(contents);
- testing.expectEqualSlices(u8, data, contents);
+ try testing.expectEqualSlices(u8, data, contents);
}
test "AtomicFile" {
@@ -676,7 +676,7 @@ test "AtomicFile" {
}
const content = try tmp.dir.readFileAlloc(testing.allocator, test_out_file, 9999);
defer testing.allocator.free(content);
- testing.expect(mem.eql(u8, content, test_content));
+ try testing.expect(mem.eql(u8, content, test_content));
try tmp.dir.deleteFile(test_out_file);
}
@@ -685,7 +685,7 @@ test "realpath" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
- testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf));
+ try testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf));
}
test "open file with exclusive nonblocking lock twice" {
@@ -700,7 +700,7 @@ test "open file with exclusive nonblocking lock twice" {
defer file1.close();
const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
- testing.expectError(error.WouldBlock, file2);
+ try testing.expectError(error.WouldBlock, file2);
}
test "open file with shared and exclusive nonblocking lock" {
@@ -715,7 +715,7 @@ test "open file with shared and exclusive nonblocking lock" {
defer file1.close();
const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
- testing.expectError(error.WouldBlock, file2);
+ try testing.expectError(error.WouldBlock, file2);
}
test "open file with exclusive and shared nonblocking lock" {
@@ -730,7 +730,7 @@ test "open file with exclusive and shared nonblocking lock" {
defer file1.close();
const file2 = tmp.dir.createFile(filename, .{ .lock = .Shared, .lock_nonblocking = true });
- testing.expectError(error.WouldBlock, file2);
+ try testing.expectError(error.WouldBlock, file2);
}
test "open file with exclusive lock twice, make sure it waits" {
@@ -790,7 +790,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
file1.close();
- testing.expectError(error.WouldBlock, file2);
+ try testing.expectError(error.WouldBlock, file2);
try fs.deleteFileAbsolute(filename);
}
@@ -830,6 +830,6 @@ test "walker" {
try fs.path.join(allocator, &[_][]const u8{ expected_dir_name, name });
var entry = (try walker.next()).?;
- testing.expectEqualStrings(expected_dir_name, try fs.path.relative(allocator, tmp_path, entry.path));
+ try testing.expectEqualStrings(expected_dir_name, try fs.path.relative(allocator, tmp_path, entry.path));
}
}
diff --git a/lib/std/fs/wasi.zig b/lib/std/fs/wasi.zig
index cf5431f994..17208a0245 100644
--- a/lib/std/fs/wasi.zig
+++ b/lib/std/fs/wasi.zig
@@ -174,8 +174,8 @@ test "extracting WASI preopens" {
try preopens.populate();
- std.testing.expectEqual(@as(usize, 1), preopens.asSlice().len);
+ try std.testing.expectEqual(@as(usize, 1), preopens.asSlice().len);
const preopen = preopens.find(PreopenType{ .Dir = "." }) orelse unreachable;
- std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));
- std.testing.expectEqual(@as(usize, 3), preopen.fd);
+ try std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));
+ try std.testing.expectEqual(@as(usize, 3), preopen.fd);
}
diff --git a/lib/std/fs/watch.zig b/lib/std/fs/watch.zig
index 1c7cb68b32..09bd21ab33 100644
--- a/lib/std/fs/watch.zig
+++ b/lib/std/fs/watch.zig
@@ -662,13 +662,13 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
const read_contents = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
defer allocator.free(read_contents);
- testing.expectEqualSlices(u8, contents, read_contents);
+ try testing.expectEqualSlices(u8, contents, read_contents);
// now watch the file
var watch = try Watch(void).init(allocator, 0);
defer watch.deinit();
- testing.expect((try watch.addFile(file_path, {})) == null);
+ try testing.expect((try watch.addFile(file_path, {})) == null);
var ev = async watch.channel.get();
var ev_consumed = false;
@@ -698,7 +698,7 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
const contents_updated = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
defer allocator.free(contents_updated);
- testing.expectEqualSlices(u8,
+ try testing.expectEqualSlices(u8,
\\line 1
\\lorem ipsum
, contents_updated);
diff --git a/lib/std/hash/adler.zig b/lib/std/hash/adler.zig
index 9cd85ba7cf..61408e82ee 100644
--- a/lib/std/hash/adler.zig
+++ b/lib/std/hash/adler.zig
@@ -99,21 +99,21 @@ pub const Adler32 = struct {
};
test "adler32 sanity" {
- testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));
- testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));
+ try testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));
+ try testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));
}
test "adler32 long" {
const long1 = [_]u8{1} ** 1024;
- testing.expectEqual(@as(u32, 0x06780401), Adler32.hash(long1[0..]));
+ try testing.expectEqual(@as(u32, 0x06780401), Adler32.hash(long1[0..]));
const long2 = [_]u8{1} ** 1025;
- testing.expectEqual(@as(u32, 0x0a7a0402), Adler32.hash(long2[0..]));
+ try testing.expectEqual(@as(u32, 0x0a7a0402), Adler32.hash(long2[0..]));
}
test "adler32 very long" {
const long = [_]u8{1} ** 5553;
- testing.expectEqual(@as(u32, 0x707f15b2), Adler32.hash(long[0..]));
+ try testing.expectEqual(@as(u32, 0x707f15b2), Adler32.hash(long[0..]));
}
test "adler32 very long with variation" {
@@ -129,5 +129,5 @@ test "adler32 very long with variation" {
break :blk result;
};
- testing.expectEqual(@as(u32, 0x5af38d6e), std.hash.Adler32.hash(long[0..]));
+ try testing.expectEqual(@as(u32, 0x5af38d6e), std.hash.Adler32.hash(long[0..]));
}
diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig
index e053e87efb..efe02fb8ff 100644
--- a/lib/std/hash/auto_hash.zig
+++ b/lib/std/hash/auto_hash.zig
@@ -239,18 +239,18 @@ fn testHashDeepRecursive(key: anytype) u64 {
test "typeContainsSlice" {
comptime {
- testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo)));
+ try testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo)));
- testing.expect(typeContainsSlice([]const u8));
- testing.expect(!typeContainsSlice(u8));
+ try testing.expect(typeContainsSlice([]const u8));
+ try testing.expect(!typeContainsSlice(u8));
const A = struct { x: []const u8 };
const B = struct { a: A };
const C = struct { b: B };
const D = struct { x: u8 };
- testing.expect(typeContainsSlice(A));
- testing.expect(typeContainsSlice(B));
- testing.expect(typeContainsSlice(C));
- testing.expect(!typeContainsSlice(D));
+ try testing.expect(typeContainsSlice(A));
+ try testing.expect(typeContainsSlice(B));
+ try testing.expect(typeContainsSlice(C));
+ try testing.expect(!typeContainsSlice(D));
}
}
@@ -261,17 +261,17 @@ test "hash pointer" {
const c = &array[2];
const d = a;
- testing.expect(testHashShallow(a) == testHashShallow(d));
- testing.expect(testHashShallow(a) != testHashShallow(c));
- testing.expect(testHashShallow(a) != testHashShallow(b));
+ try testing.expect(testHashShallow(a) == testHashShallow(d));
+ try testing.expect(testHashShallow(a) != testHashShallow(c));
+ try testing.expect(testHashShallow(a) != testHashShallow(b));
- testing.expect(testHashDeep(a) == testHashDeep(a));
- testing.expect(testHashDeep(a) == testHashDeep(c));
- testing.expect(testHashDeep(a) == testHashDeep(b));
+ try testing.expect(testHashDeep(a) == testHashDeep(a));
+ try testing.expect(testHashDeep(a) == testHashDeep(c));
+ try testing.expect(testHashDeep(a) == testHashDeep(b));
- testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));
- testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));
- testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));
+ try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));
+ try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));
+ try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));
}
test "hash slice shallow" {
@@ -286,10 +286,10 @@ test "hash slice shallow" {
const a = array1[runtime_zero..];
const b = array2[runtime_zero..];
const c = array1[runtime_zero..3];
- testing.expect(testHashShallow(a) == testHashShallow(a));
- testing.expect(testHashShallow(a) != testHashShallow(array1));
- testing.expect(testHashShallow(a) != testHashShallow(b));
- testing.expect(testHashShallow(a) != testHashShallow(c));
+ try testing.expect(testHashShallow(a) == testHashShallow(a));
+ try testing.expect(testHashShallow(a) != testHashShallow(array1));
+ try testing.expect(testHashShallow(a) != testHashShallow(b));
+ try testing.expect(testHashShallow(a) != testHashShallow(c));
}
test "hash slice deep" {
@@ -302,10 +302,10 @@ test "hash slice deep" {
const a = array1[0..];
const b = array2[0..];
const c = array1[0..3];
- testing.expect(testHashDeep(a) == testHashDeep(a));
- testing.expect(testHashDeep(a) == testHashDeep(array1));
- testing.expect(testHashDeep(a) == testHashDeep(b));
- testing.expect(testHashDeep(a) != testHashDeep(c));
+ try testing.expect(testHashDeep(a) == testHashDeep(a));
+ try testing.expect(testHashDeep(a) == testHashDeep(array1));
+ try testing.expect(testHashDeep(a) == testHashDeep(b));
+ try testing.expect(testHashDeep(a) != testHashDeep(c));
}
test "hash struct deep" {
@@ -331,28 +331,28 @@ test "hash struct deep" {
defer allocator.destroy(bar.c);
defer allocator.destroy(baz.c);
- testing.expect(testHashDeep(foo) == testHashDeep(bar));
- testing.expect(testHashDeep(foo) != testHashDeep(baz));
- testing.expect(testHashDeep(bar) != testHashDeep(baz));
+ try testing.expect(testHashDeep(foo) == testHashDeep(bar));
+ try testing.expect(testHashDeep(foo) != testHashDeep(baz));
+ try testing.expect(testHashDeep(bar) != testHashDeep(baz));
var hasher = Wyhash.init(0);
const h = testHashDeep(foo);
autoHash(&hasher, foo.a);
autoHash(&hasher, foo.b);
autoHash(&hasher, foo.c.*);
- testing.expectEqual(h, hasher.final());
+ try testing.expectEqual(h, hasher.final());
const h2 = testHashDeepRecursive(&foo);
- testing.expect(h2 != testHashDeep(&foo));
- testing.expect(h2 == testHashDeep(foo));
+ try testing.expect(h2 != testHashDeep(&foo));
+ try testing.expect(h2 == testHashDeep(foo));
}
test "testHash optional" {
const a: ?u32 = 123;
const b: ?u32 = null;
- testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
- testing.expect(testHash(a) != testHash(b));
- testing.expectEqual(testHash(b), 0);
+ try testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
+ try testing.expect(testHash(a) != testHash(b));
+ try testing.expectEqual(testHash(b), 0);
}
test "testHash array" {
@@ -362,7 +362,7 @@ test "testHash array" {
autoHash(&hasher, @as(u32, 1));
autoHash(&hasher, @as(u32, 2));
autoHash(&hasher, @as(u32, 3));
- testing.expectEqual(h, hasher.final());
+ try testing.expectEqual(h, hasher.final());
}
test "testHash struct" {
@@ -377,7 +377,7 @@ test "testHash struct" {
autoHash(&hasher, @as(u32, 1));
autoHash(&hasher, @as(u32, 2));
autoHash(&hasher, @as(u32, 3));
- testing.expectEqual(h, hasher.final());
+ try testing.expectEqual(h, hasher.final());
}
test "testHash union" {
@@ -390,12 +390,12 @@ test "testHash union" {
const a = Foo{ .A = 18 };
var b = Foo{ .B = true };
const c = Foo{ .C = 18 };
- testing.expect(testHash(a) == testHash(a));
- testing.expect(testHash(a) != testHash(b));
- testing.expect(testHash(a) != testHash(c));
+ try testing.expect(testHash(a) == testHash(a));
+ try testing.expect(testHash(a) != testHash(b));
+ try testing.expect(testHash(a) != testHash(c));
b = Foo{ .A = 18 };
- testing.expect(testHash(a) == testHash(b));
+ try testing.expect(testHash(a) == testHash(b));
}
test "testHash vector" {
@@ -404,13 +404,13 @@ test "testHash vector" {
const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };
- testing.expect(testHash(a) == testHash(a));
- testing.expect(testHash(a) != testHash(b));
+ try testing.expect(testHash(a) == testHash(a));
+ try testing.expect(testHash(a) != testHash(b));
const c: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };
const d: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 5 };
- testing.expect(testHash(c) == testHash(c));
- testing.expect(testHash(c) != testHash(d));
+ try testing.expect(testHash(c) == testHash(c));
+ try testing.expect(testHash(c) != testHash(d));
}
test "testHash error union" {
@@ -422,7 +422,7 @@ test "testHash error union" {
};
const f = Foo{};
const g: Errors!Foo = Errors.Test;
- testing.expect(testHash(f) != testHash(g));
- testing.expect(testHash(f) == testHash(Foo{}));
- testing.expect(testHash(g) == testHash(Errors.Test));
+ try testing.expect(testHash(f) != testHash(g));
+ try testing.expect(testHash(f) == testHash(Foo{}));
+ try testing.expect(testHash(g) == testHash(Errors.Test));
}
diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig
index d7f2f1a9eb..9767800e7b 100644
--- a/lib/std/hash/cityhash.zig
+++ b/lib/std/hash/cityhash.zig
@@ -381,14 +381,14 @@ fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
test "cityhash32" {
const Test = struct {
- fn doTest() void {
+ fn doTest() !void {
// Note: SMHasher doesn't provide a 32bit version of the algorithm.
// Note: The implementation was verified against the Google Abseil version.
- std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
- std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
+ try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
+ try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
}
};
- Test.doTest();
+ try Test.doTest();
// TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
// case once we ship stage2.
//@setEvalBranchQuota(50000);
@@ -397,13 +397,13 @@ test "cityhash32" {
test "cityhash64" {
const Test = struct {
- fn doTest() void {
+ fn doTest() !void {
// Note: This is not compliant with the SMHasher implementation of CityHash64!
// Note: The implementation was verified against the Google Abseil version.
- std.testing.expectEqual(SMHasherTest(CityHash64.hashWithSeed), 0x5FABC5C5);
+ try std.testing.expectEqual(SMHasherTest(CityHash64.hashWithSeed), 0x5FABC5C5);
}
};
- Test.doTest();
+ try Test.doTest();
// TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
// case once we ship stage2.
//@setEvalBranchQuota(50000);
diff --git a/lib/std/hash/crc.zig b/lib/std/hash/crc.zig
index a2d6ed429c..391438f463 100644
--- a/lib/std/hash/crc.zig
+++ b/lib/std/hash/crc.zig
@@ -109,9 +109,9 @@ test "crc32 ieee" {
const Crc32Ieee = Crc32WithPoly(.IEEE);
- testing.expect(Crc32Ieee.hash("") == 0x00000000);
- testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
- testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
+ try testing.expect(Crc32Ieee.hash("") == 0x00000000);
+ try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
+ try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
}
test "crc32 castagnoli" {
@@ -119,9 +119,9 @@ test "crc32 castagnoli" {
const Crc32Castagnoli = Crc32WithPoly(.Castagnoli);
- testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
- testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
- testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
+ try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
+ try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
+ try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
}
// half-byte lookup table implementation.
@@ -177,9 +177,9 @@ test "small crc32 ieee" {
const Crc32Ieee = Crc32SmallWithPoly(.IEEE);
- testing.expect(Crc32Ieee.hash("") == 0x00000000);
- testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
- testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
+ try testing.expect(Crc32Ieee.hash("") == 0x00000000);
+ try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
+ try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
}
test "small crc32 castagnoli" {
@@ -187,7 +187,7 @@ test "small crc32 castagnoli" {
const Crc32Castagnoli = Crc32SmallWithPoly(.Castagnoli);
- testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
- testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
- testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
+ try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
+ try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
+ try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
}
diff --git a/lib/std/hash/fnv.zig b/lib/std/hash/fnv.zig
index 99e3bd482d..7dadf5488f 100644
--- a/lib/std/hash/fnv.zig
+++ b/lib/std/hash/fnv.zig
@@ -46,18 +46,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
}
test "fnv1a-32" {
- testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
- testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
- testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
+ try testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
+ try testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
+ try testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
}
test "fnv1a-64" {
- testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
- testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
- testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
+ try testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
+ try testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
+ try testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
}
test "fnv1a-128" {
- testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
- testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
+ try testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
+ try testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
}
diff --git a/lib/std/hash/murmur.zig b/lib/std/hash/murmur.zig
index 65dd523396..61e4791387 100644
--- a/lib/std/hash/murmur.zig
+++ b/lib/std/hash/murmur.zig
@@ -308,7 +308,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
}
test "murmur2_32" {
- testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);
+ try testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);
var v0: u32 = 0x12345678;
var v1: u64 = 0x1234567812345678;
var v0le: u32 = v0;
@@ -317,12 +317,12 @@ test "murmur2_32" {
v0le = @byteSwap(u32, v0le);
v1le = @byteSwap(u64, v1le);
}
- testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));
- testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));
+ try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));
+ try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));
}
test "murmur2_64" {
- std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);
+ try std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);
var v0: u32 = 0x12345678;
var v1: u64 = 0x1234567812345678;
var v0le: u32 = v0;
@@ -331,12 +331,12 @@ test "murmur2_64" {
v0le = @byteSwap(u32, v0le);
v1le = @byteSwap(u64, v1le);
}
- testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));
- testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));
+ try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));
+ try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));
}
test "murmur3_32" {
- std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);
+ try std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);
var v0: u32 = 0x12345678;
var v1: u64 = 0x1234567812345678;
var v0le: u32 = v0;
@@ -345,6 +345,6 @@ test "murmur3_32" {
v0le = @byteSwap(u32, v0le);
v1le = @byteSwap(u64, v1le);
}
- testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));
- testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));
+ try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));
+ try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));
}
diff --git a/lib/std/hash/wyhash.zig b/lib/std/hash/wyhash.zig
index 45530eccff..4b9afe6355 100644
--- a/lib/std/hash/wyhash.zig
+++ b/lib/std/hash/wyhash.zig
@@ -183,13 +183,13 @@ const expectEqual = std.testing.expectEqual;
test "test vectors" {
const hash = Wyhash.hash;
- expectEqual(hash(0, ""), 0x0);
- expectEqual(hash(1, "a"), 0xbed235177f41d328);
- expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
- expectEqual(hash(3, "message digest"), 0x37320f657213a290);
- expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
- expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
- expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
+ try expectEqual(hash(0, ""), 0x0);
+ try expectEqual(hash(1, "a"), 0xbed235177f41d328);
+ try expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
+ try expectEqual(hash(3, "message digest"), 0x37320f657213a290);
+ try expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
+ try expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
+ try expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
}
test "test vectors streaming" {
@@ -197,19 +197,19 @@ test "test vectors streaming" {
for ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |e| {
wh.update(mem.asBytes(&e));
}
- expectEqual(wh.final(), 0x602a1894d3bbfe7f);
+ try expectEqual(wh.final(), 0x602a1894d3bbfe7f);
const pattern = "1234567890";
const count = 8;
const result = 0x829e9c148b75970e;
- expectEqual(Wyhash.hash(6, pattern ** 8), result);
+ try expectEqual(Wyhash.hash(6, pattern ** 8), result);
wh = Wyhash.init(6);
var i: u32 = 0;
while (i < count) : (i += 1) {
wh.update(pattern);
}
- expectEqual(wh.final(), result);
+ try expectEqual(wh.final(), result);
}
test "iterative non-divisible update" {
@@ -231,6 +231,6 @@ test "iterative non-divisible update" {
}
const iterative_hash = wy.final();
- std.testing.expectEqual(iterative_hash, non_iterative_hash);
+ try std.testing.expectEqual(iterative_hash, non_iterative_hash);
}
}
diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig
index b74144d08b..0523ad7376 100644
--- a/lib/std/hash_map.zig
+++ b/lib/std/hash_map.zig
@@ -824,15 +824,15 @@ test "std.hash_map basic usage" {
while (it.next()) |kv| {
sum += kv.key;
}
- expect(sum == total);
+ try expect(sum == total);
i = 0;
sum = 0;
while (i < count) : (i += 1) {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
sum += map.get(i).?;
}
- expectEqual(total, sum);
+ try expectEqual(total, sum);
}
test "std.hash_map ensureCapacity" {
@@ -841,13 +841,13 @@ test "std.hash_map ensureCapacity" {
try map.ensureCapacity(20);
const initial_capacity = map.capacity();
- testing.expect(initial_capacity >= 20);
+ try testing.expect(initial_capacity >= 20);
var i: i32 = 0;
while (i < 20) : (i += 1) {
- testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
+ try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
}
// shouldn't resize from putAssumeCapacity
- testing.expect(initial_capacity == map.capacity());
+ try testing.expect(initial_capacity == map.capacity());
}
test "std.hash_map ensureCapacity with tombstones" {
@@ -870,22 +870,22 @@ test "std.hash_map clearRetainingCapacity" {
map.clearRetainingCapacity();
try map.put(1, 1);
- expectEqual(map.get(1).?, 1);
- expectEqual(map.count(), 1);
+ try expectEqual(map.get(1).?, 1);
+ try expectEqual(map.count(), 1);
map.clearRetainingCapacity();
map.putAssumeCapacity(1, 1);
- expectEqual(map.get(1).?, 1);
- expectEqual(map.count(), 1);
+ try expectEqual(map.get(1).?, 1);
+ try expectEqual(map.count(), 1);
const cap = map.capacity();
- expect(cap > 0);
+ try expect(cap > 0);
map.clearRetainingCapacity();
map.clearRetainingCapacity();
- expectEqual(map.count(), 0);
- expectEqual(map.capacity(), cap);
- expect(!map.contains(1));
+ try expectEqual(map.count(), 0);
+ try expectEqual(map.capacity(), cap);
+ try expect(!map.contains(1));
}
test "std.hash_map grow" {
@@ -898,19 +898,19 @@ test "std.hash_map grow" {
while (i < growTo) : (i += 1) {
try map.put(i, i);
}
- expectEqual(map.count(), growTo);
+ try expectEqual(map.count(), growTo);
i = 0;
var it = map.iterator();
while (it.next()) |kv| {
- expectEqual(kv.key, kv.value);
+ try expectEqual(kv.key, kv.value);
i += 1;
}
- expectEqual(i, growTo);
+ try expectEqual(i, growTo);
i = 0;
while (i < growTo) : (i += 1) {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
}
}
@@ -921,7 +921,7 @@ test "std.hash_map clone" {
var a = try map.clone();
defer a.deinit();
- expectEqual(a.count(), 0);
+ try expectEqual(a.count(), 0);
try a.put(1, 1);
try a.put(2, 2);
@@ -930,10 +930,10 @@ test "std.hash_map clone" {
var b = try a.clone();
defer b.deinit();
- expectEqual(b.count(), 3);
- expectEqual(b.get(1), 1);
- expectEqual(b.get(2), 2);
- expectEqual(b.get(3), 3);
+ try expectEqual(b.count(), 3);
+ try expectEqual(b.get(1), 1);
+ try expectEqual(b.get(2), 2);
+ try expectEqual(b.get(3), 3);
}
test "std.hash_map ensureCapacity with existing elements" {
@@ -941,12 +941,12 @@ test "std.hash_map ensureCapacity with existing elements" {
defer map.deinit();
try map.put(0, 0);
- expectEqual(map.count(), 1);
- expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);
+ try expectEqual(map.count(), 1);
+ try expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);
try map.ensureCapacity(65);
- expectEqual(map.count(), 1);
- expectEqual(map.capacity(), 128);
+ try expectEqual(map.count(), 1);
+ try expectEqual(map.capacity(), 128);
}
test "std.hash_map ensureCapacity satisfies max load factor" {
@@ -954,7 +954,7 @@ test "std.hash_map ensureCapacity satisfies max load factor" {
defer map.deinit();
try map.ensureCapacity(127);
- expectEqual(map.capacity(), 256);
+ try expectEqual(map.capacity(), 256);
}
test "std.hash_map remove" {
@@ -972,19 +972,19 @@ test "std.hash_map remove" {
_ = map.remove(i);
}
}
- expectEqual(map.count(), 10);
+ try expectEqual(map.count(), 10);
var it = map.iterator();
while (it.next()) |kv| {
- expectEqual(kv.key, kv.value);
- expect(kv.key % 3 != 0);
+ try expectEqual(kv.key, kv.value);
+ try expect(kv.key % 3 != 0);
}
i = 0;
while (i < 16) : (i += 1) {
if (i % 3 == 0) {
- expect(!map.contains(i));
+ try expect(!map.contains(i));
} else {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
}
}
}
@@ -1001,14 +1001,14 @@ test "std.hash_map reverse removes" {
i = 16;
while (i > 0) : (i -= 1) {
_ = map.remove(i - 1);
- expect(!map.contains(i - 1));
+ try expect(!map.contains(i - 1));
var j: u32 = 0;
while (j < i - 1) : (j += 1) {
- expectEqual(map.get(j).?, j);
+ try expectEqual(map.get(j).?, j);
}
}
- expectEqual(map.count(), 0);
+ try expectEqual(map.count(), 0);
}
test "std.hash_map multiple removes on same metadata" {
@@ -1024,17 +1024,17 @@ test "std.hash_map multiple removes on same metadata" {
_ = map.remove(15);
_ = map.remove(14);
_ = map.remove(13);
- expect(!map.contains(7));
- expect(!map.contains(15));
- expect(!map.contains(14));
- expect(!map.contains(13));
+ try expect(!map.contains(7));
+ try expect(!map.contains(15));
+ try expect(!map.contains(14));
+ try expect(!map.contains(13));
i = 0;
while (i < 13) : (i += 1) {
if (i == 7) {
- expect(!map.contains(i));
+ try expect(!map.contains(i));
} else {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
}
}
@@ -1044,7 +1044,7 @@ test "std.hash_map multiple removes on same metadata" {
try map.put(7, 7);
i = 0;
while (i < 16) : (i += 1) {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
}
}
@@ -1070,12 +1070,12 @@ test "std.hash_map put and remove loop in random order" {
for (keys.items) |key| {
try map.put(key, key);
}
- expectEqual(map.count(), size);
+ try expectEqual(map.count(), size);
for (keys.items) |key| {
_ = map.remove(key);
}
- expectEqual(map.count(), 0);
+ try expectEqual(map.count(), 0);
}
}
@@ -1119,7 +1119,7 @@ test "std.hash_map put" {
i = 0;
while (i < 16) : (i += 1) {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
}
i = 0;
@@ -1129,7 +1129,7 @@ test "std.hash_map put" {
i = 0;
while (i < 16) : (i += 1) {
- expectEqual(map.get(i).?, i * 16 + 1);
+ try expectEqual(map.get(i).?, i * 16 + 1);
}
}
@@ -1148,7 +1148,7 @@ test "std.hash_map putAssumeCapacity" {
while (i < 20) : (i += 1) {
sum += map.get(i).?;
}
- expectEqual(sum, 190);
+ try expectEqual(sum, 190);
i = 0;
while (i < 20) : (i += 1) {
@@ -1160,7 +1160,7 @@ test "std.hash_map putAssumeCapacity" {
while (i < 20) : (i += 1) {
sum += map.get(i).?;
}
- expectEqual(sum, 20);
+ try expectEqual(sum, 20);
}
test "std.hash_map getOrPut" {
@@ -1183,49 +1183,49 @@ test "std.hash_map getOrPut" {
sum += map.get(i).?;
}
- expectEqual(sum, 30);
+ try expectEqual(sum, 30);
}
test "std.hash_map basic hash map usage" {
var map = AutoHashMap(i32, i32).init(std.testing.allocator);
defer map.deinit();
- testing.expect((try map.fetchPut(1, 11)) == null);
- testing.expect((try map.fetchPut(2, 22)) == null);
- testing.expect((try map.fetchPut(3, 33)) == null);
- testing.expect((try map.fetchPut(4, 44)) == null);
+ try testing.expect((try map.fetchPut(1, 11)) == null);
+ try testing.expect((try map.fetchPut(2, 22)) == null);
+ try testing.expect((try map.fetchPut(3, 33)) == null);
+ try testing.expect((try map.fetchPut(4, 44)) == null);
try map.putNoClobber(5, 55);
- testing.expect((try map.fetchPut(5, 66)).?.value == 55);
- testing.expect((try map.fetchPut(5, 55)).?.value == 66);
+ try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
+ try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
const gop1 = try map.getOrPut(5);
- testing.expect(gop1.found_existing == true);
- testing.expect(gop1.entry.value == 55);
+ try testing.expect(gop1.found_existing == true);
+ try testing.expect(gop1.entry.value == 55);
gop1.entry.value = 77;
- testing.expect(map.getEntry(5).?.value == 77);
+ try testing.expect(map.getEntry(5).?.value == 77);
const gop2 = try map.getOrPut(99);
- testing.expect(gop2.found_existing == false);
+ try testing.expect(gop2.found_existing == false);
gop2.entry.value = 42;
- testing.expect(map.getEntry(99).?.value == 42);
+ try testing.expect(map.getEntry(99).?.value == 42);
const gop3 = try map.getOrPutValue(5, 5);
- testing.expect(gop3.value == 77);
+ try testing.expect(gop3.value == 77);
const gop4 = try map.getOrPutValue(100, 41);
- testing.expect(gop4.value == 41);
+ try testing.expect(gop4.value == 41);
- testing.expect(map.contains(2));
- testing.expect(map.getEntry(2).?.value == 22);
- testing.expect(map.get(2).? == 22);
+ try testing.expect(map.contains(2));
+ try testing.expect(map.getEntry(2).?.value == 22);
+ try testing.expect(map.get(2).? == 22);
const rmv1 = map.remove(2);
- testing.expect(rmv1.?.key == 2);
- testing.expect(rmv1.?.value == 22);
- testing.expect(map.remove(2) == null);
- testing.expect(map.getEntry(2) == null);
- testing.expect(map.get(2) == null);
+ try testing.expect(rmv1.?.key == 2);
+ try testing.expect(rmv1.?.value == 22);
+ try testing.expect(map.remove(2) == null);
+ try testing.expect(map.getEntry(2) == null);
+ try testing.expect(map.get(2) == null);
map.removeAssertDiscard(3);
}
@@ -1244,6 +1244,6 @@ test "std.hash_map clone" {
i = 0;
while (i < 10) : (i += 1) {
- testing.expect(copy.get(i).? == i * 10);
+ try testing.expect(copy.get(i).? == i * 10);
}
}
diff --git a/lib/std/heap.zig b/lib/std/heap.zig
index 3e1a24beea..9e86c78f69 100644
--- a/lib/std/heap.zig
+++ b/lib/std/heap.zig
@@ -858,16 +858,16 @@ test "WasmPageAllocator internals" {
if (comptime std.Target.current.isWasm()) {
const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;
const initial = try page_allocator.alloc(u8, mem.page_size);
- testing.expect(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.
+ try testing.expect(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.
var inplace = try page_allocator.realloc(initial, 1);
- testing.expectEqual(initial.ptr, inplace.ptr);
+ try testing.expectEqual(initial.ptr, inplace.ptr);
inplace = try page_allocator.realloc(inplace, 4);
- testing.expectEqual(initial.ptr, inplace.ptr);
+ try testing.expectEqual(initial.ptr, inplace.ptr);
page_allocator.free(inplace);
const reuse = try page_allocator.alloc(u8, 1);
- testing.expectEqual(initial.ptr, reuse.ptr);
+ try testing.expectEqual(initial.ptr, reuse.ptr);
page_allocator.free(reuse);
// This segment may span conventional and extended which has really complex rules so we're just ignoring it for now.
@@ -875,18 +875,18 @@ test "WasmPageAllocator internals" {
page_allocator.free(padding);
const extended = try page_allocator.alloc(u8, conventional_memsize);
- testing.expect(@ptrToInt(extended.ptr) >= conventional_memsize);
+ try testing.expect(@ptrToInt(extended.ptr) >= conventional_memsize);
const use_small = try page_allocator.alloc(u8, 1);
- testing.expectEqual(initial.ptr, use_small.ptr);
+ try testing.expectEqual(initial.ptr, use_small.ptr);
page_allocator.free(use_small);
inplace = try page_allocator.realloc(extended, 1);
- testing.expectEqual(extended.ptr, inplace.ptr);
+ try testing.expectEqual(extended.ptr, inplace.ptr);
page_allocator.free(inplace);
const reuse_extended = try page_allocator.alloc(u8, conventional_memsize);
- testing.expectEqual(extended.ptr, reuse_extended.ptr);
+ try testing.expectEqual(extended.ptr, reuse_extended.ptr);
page_allocator.free(reuse_extended);
}
}
@@ -959,15 +959,15 @@ test "FixedBufferAllocator.reset" {
var x = try fba.allocator.create(u64);
x.* = X;
- testing.expectError(error.OutOfMemory, fba.allocator.create(u64));
+ try testing.expectError(error.OutOfMemory, fba.allocator.create(u64));
fba.reset();
var y = try fba.allocator.create(u64);
y.* = Y;
// we expect Y to have overwritten X.
- testing.expect(x.* == y.*);
- testing.expect(y.* == Y);
+ try testing.expect(x.* == y.*);
+ try testing.expect(y.* == Y);
}
test "StackFallbackAllocator" {
@@ -987,11 +987,11 @@ test "FixedBufferAllocator Reuse memory on realloc" {
var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);
var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5);
- testing.expect(slice0.len == 5);
+ try testing.expect(slice0.len == 5);
var slice1 = try fixed_buffer_allocator.allocator.realloc(slice0, 10);
- testing.expect(slice1.ptr == slice0.ptr);
- testing.expect(slice1.len == 10);
- testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));
+ try testing.expect(slice1.ptr == slice0.ptr);
+ try testing.expect(slice1.len == 10);
+ try testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));
}
// check that we don't re-use the memory if it's not the most recent block
{
@@ -1002,10 +1002,10 @@ test "FixedBufferAllocator Reuse memory on realloc" {
slice0[1] = 2;
var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2);
var slice2 = try fixed_buffer_allocator.allocator.realloc(slice0, 4);
- testing.expect(slice0.ptr != slice2.ptr);
- testing.expect(slice1.ptr != slice2.ptr);
- testing.expect(slice2[0] == 1);
- testing.expect(slice2[1] == 2);
+ try testing.expect(slice0.ptr != slice2.ptr);
+ try testing.expect(slice1.ptr != slice2.ptr);
+ try testing.expect(slice2[0] == 1);
+ try testing.expect(slice2[1] == 2);
}
}
@@ -1024,28 +1024,28 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
const allocator = &validationAllocator.allocator;
var slice = try allocator.alloc(*i32, 100);
- testing.expect(slice.len == 100);
+ try testing.expect(slice.len == 100);
for (slice) |*item, i| {
item.* = try allocator.create(i32);
item.*.* = @intCast(i32, i);
}
slice = try allocator.realloc(slice, 20000);
- testing.expect(slice.len == 20000);
+ try testing.expect(slice.len == 20000);
for (slice[0..100]) |item, i| {
- testing.expect(item.* == @intCast(i32, i));
+ try testing.expect(item.* == @intCast(i32, i));
allocator.destroy(item);
}
slice = allocator.shrink(slice, 50);
- testing.expect(slice.len == 50);
+ try testing.expect(slice.len == 50);
slice = allocator.shrink(slice, 25);
- testing.expect(slice.len == 25);
+ try testing.expect(slice.len == 25);
slice = allocator.shrink(slice, 0);
- testing.expect(slice.len == 0);
+ try testing.expect(slice.len == 0);
slice = try allocator.realloc(slice, 10);
- testing.expect(slice.len == 10);
+ try testing.expect(slice.len == 10);
allocator.free(slice);
@@ -1058,7 +1058,7 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
allocator.destroy(zero_bit_ptr);
const oversize = try allocator.allocAdvanced(u32, null, 5, .at_least);
- testing.expect(oversize.len >= 5);
+ try testing.expect(oversize.len >= 5);
for (oversize) |*item| {
item.* = 0xDEADBEEF;
}
@@ -1073,29 +1073,29 @@ pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void {
inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| {
// initial
var slice = try allocator.alignedAlloc(u8, alignment, 10);
- testing.expect(slice.len == 10);
+ try testing.expect(slice.len == 10);
// grow
slice = try allocator.realloc(slice, 100);
- testing.expect(slice.len == 100);
+ try testing.expect(slice.len == 100);
// shrink
slice = allocator.shrink(slice, 10);
- testing.expect(slice.len == 10);
+ try testing.expect(slice.len == 10);
// go to zero
slice = allocator.shrink(slice, 0);
- testing.expect(slice.len == 0);
+ try testing.expect(slice.len == 0);
// realloc from zero
slice = try allocator.realloc(slice, 100);
- testing.expect(slice.len == 100);
+ try testing.expect(slice.len == 100);
// shrink with shrink
slice = allocator.shrink(slice, 10);
- testing.expect(slice.len == 10);
+ try testing.expect(slice.len == 10);
// shrink to zero
slice = allocator.shrink(slice, 0);
- testing.expect(slice.len == 0);
+ try testing.expect(slice.len == 0);
}
}
-pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator.Error!void {
+pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) !void {
var validationAllocator = mem.validationWrap(base_allocator);
const allocator = &validationAllocator.allocator;
@@ -1110,24 +1110,24 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator
_ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);
var slice = try allocator.alignedAlloc(u8, large_align, 500);
- testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
+ try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
slice = allocator.shrink(slice, 100);
- testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
+ try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
slice = try allocator.realloc(slice, 5000);
- testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
+ try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
slice = allocator.shrink(slice, 10);
- testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
+ try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
slice = try allocator.realloc(slice, 20000);
- testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
+ try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
allocator.free(slice);
}
-pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.Error!void {
+pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) !void {
var validationAllocator = mem.validationWrap(base_allocator);
const allocator = &validationAllocator.allocator;
@@ -1155,8 +1155,8 @@ pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.
// realloc to a smaller size but with a larger alignment
slice = try allocator.reallocAdvanced(slice, mem.page_size * 32, alloc_size / 2, .exact);
- testing.expect(slice[0] == 0x12);
- testing.expect(slice[60] == 0x34);
+ try testing.expect(slice[0] == 0x12);
+ try testing.expect(slice[60] == 0x34);
}
test "heap" {
diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig
index c731f22d66..b2980aae9f 100644
--- a/lib/std/heap/general_purpose_allocator.zig
+++ b/lib/std/heap/general_purpose_allocator.zig
@@ -692,7 +692,7 @@ const test_config = Config{};
test "small allocations - free in same order" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var list = std.ArrayList(*u64).init(std.testing.allocator);
@@ -711,7 +711,7 @@ test "small allocations - free in same order" {
test "small allocations - free in reverse order" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var list = std.ArrayList(*u64).init(std.testing.allocator);
@@ -730,7 +730,7 @@ test "small allocations - free in reverse order" {
test "large allocations" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
const ptr1 = try allocator.alloc(u64, 42768);
@@ -743,7 +743,7 @@ test "large allocations" {
test "realloc" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1);
@@ -753,19 +753,19 @@ test "realloc" {
// This reallocation should keep its pointer address.
const old_slice = slice;
slice = try allocator.realloc(slice, 2);
- std.testing.expect(old_slice.ptr == slice.ptr);
- std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(old_slice.ptr == slice.ptr);
+ try std.testing.expect(slice[0] == 0x12);
slice[1] = 0x34;
// This requires upgrading to a larger size class
slice = try allocator.realloc(slice, 17);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[1] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[1] == 0x34);
}
test "shrink" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alloc(u8, 20);
@@ -776,19 +776,19 @@ test "shrink" {
slice = allocator.shrink(slice, 17);
for (slice) |b| {
- std.testing.expect(b == 0x11);
+ try std.testing.expect(b == 0x11);
}
slice = allocator.shrink(slice, 16);
for (slice) |b| {
- std.testing.expect(b == 0x11);
+ try std.testing.expect(b == 0x11);
}
}
test "large object - grow" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice1 = try allocator.alloc(u8, page_size * 2 - 20);
@@ -796,17 +796,17 @@ test "large object - grow" {
const old = slice1;
slice1 = try allocator.realloc(slice1, page_size * 2 - 10);
- std.testing.expect(slice1.ptr == old.ptr);
+ try std.testing.expect(slice1.ptr == old.ptr);
slice1 = try allocator.realloc(slice1, page_size * 2);
- std.testing.expect(slice1.ptr == old.ptr);
+ try std.testing.expect(slice1.ptr == old.ptr);
slice1 = try allocator.realloc(slice1, page_size * 2 + 1);
}
test "realloc small object to large object" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alloc(u8, 70);
@@ -817,13 +817,13 @@ test "realloc small object to large object" {
// This requires upgrading to a large object
const large_object_size = page_size * 2 + 50;
slice = try allocator.realloc(slice, large_object_size);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[60] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[60] == 0x34);
}
test "shrink large object to large object" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alloc(u8, page_size * 2 + 50);
@@ -832,21 +832,21 @@ test "shrink large object to large object" {
slice[60] = 0x34;
slice = try allocator.resize(slice, page_size * 2 + 1);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[60] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[60] == 0x34);
slice = allocator.shrink(slice, page_size * 2 + 1);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[60] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[60] == 0x34);
slice = try allocator.realloc(slice, page_size * 2);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[60] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[60] == 0x34);
}
test "shrink large object to large object with larger alignment" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var debug_buffer: [1000]u8 = undefined;
@@ -875,13 +875,13 @@ test "shrink large object to large object with larger alignment" {
slice[60] = 0x34;
slice = try allocator.reallocAdvanced(slice, big_alignment, alloc_size / 2, .exact);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[60] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[60] == 0x34);
}
test "realloc large object to small object" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alloc(u8, page_size * 2 + 50);
@@ -890,8 +890,8 @@ test "realloc large object to small object" {
slice[16] = 0x34;
slice = try allocator.realloc(slice, 19);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[16] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[16] == 0x34);
}
test "overrideable mutexes" {
@@ -899,7 +899,7 @@ test "overrideable mutexes" {
.backing_allocator = std.testing.allocator,
.mutex = std.Thread.Mutex{},
};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
const ptr = try allocator.create(i32);
@@ -908,7 +908,7 @@ test "overrideable mutexes" {
test "non-page-allocator backing allocator" {
var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = std.testing.allocator };
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
const ptr = try allocator.create(i32);
@@ -917,7 +917,7 @@ test "non-page-allocator backing allocator" {
test "realloc large object to larger alignment" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var debug_buffer: [1000]u8 = undefined;
@@ -943,22 +943,22 @@ test "realloc large object to larger alignment" {
slice[16] = 0x34;
slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 100, .exact);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[16] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[16] == 0x34);
slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 25, .exact);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[16] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[16] == 0x34);
slice = try allocator.reallocAdvanced(slice, big_alignment, page_size * 2 + 100, .exact);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[16] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[16] == 0x34);
}
test "large object shrinks to small but allocation fails during shrink" {
var failing_allocator = std.testing.FailingAllocator.init(std.heap.page_allocator, 3);
var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = &failing_allocator.allocator };
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alloc(u8, page_size * 2 + 50);
@@ -969,13 +969,13 @@ test "large object shrinks to small but allocation fails during shrink" {
// Next allocation will fail in the backing allocator of the GeneralPurposeAllocator
slice = allocator.shrink(slice, 4);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[3] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[3] == 0x34);
}
test "objects of size 1024 and 2048" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
const slice = try allocator.alloc(u8, 1025);
@@ -987,26 +987,26 @@ test "objects of size 1024 and 2048" {
test "setting a memory cap" {
var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
gpa.setRequestedMemoryLimit(1010);
const small = try allocator.create(i32);
- std.testing.expect(gpa.total_requested_bytes == 4);
+ try std.testing.expect(gpa.total_requested_bytes == 4);
const big = try allocator.alloc(u8, 1000);
- std.testing.expect(gpa.total_requested_bytes == 1004);
+ try std.testing.expect(gpa.total_requested_bytes == 1004);
- std.testing.expectError(error.OutOfMemory, allocator.create(u64));
+ try std.testing.expectError(error.OutOfMemory, allocator.create(u64));
allocator.destroy(small);
- std.testing.expect(gpa.total_requested_bytes == 1000);
+ try std.testing.expect(gpa.total_requested_bytes == 1000);
allocator.free(big);
- std.testing.expect(gpa.total_requested_bytes == 0);
+ try std.testing.expect(gpa.total_requested_bytes == 0);
const exact = try allocator.alloc(u8, 1010);
- std.testing.expect(gpa.total_requested_bytes == 1010);
+ try std.testing.expect(gpa.total_requested_bytes == 1010);
allocator.free(exact);
}
diff --git a/lib/std/heap/logging_allocator.zig b/lib/std/heap/logging_allocator.zig
index 7885571ab3..ac301425bb 100644
--- a/lib/std/heap/logging_allocator.zig
+++ b/lib/std/heap/logging_allocator.zig
@@ -93,11 +93,11 @@ test "LoggingAllocator" {
var a = try allocator.alloc(u8, 10);
a = allocator.shrink(a, 5);
- std.testing.expect(a.len == 5);
- std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
+ try std.testing.expect(a.len == 5);
+ try std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
allocator.free(a);
- std.testing.expectEqualSlices(u8,
+ try std.testing.expectEqualSlices(u8,
\\alloc : 10 success!
\\shrink: 10 to 5
\\expand: 5 to 20 failure!
diff --git a/lib/std/io/bit_reader.zig b/lib/std/io/bit_reader.zig
index 213cd2b503..6d3f47fe95 100644
--- a/lib/std/io/bit_reader.zig
+++ b/lib/std/io/bit_reader.zig
@@ -185,64 +185,64 @@ test "api coverage" {
const expect = testing.expect;
const expectError = testing.expectError;
- expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
- expect(out_bits == 1);
- expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
- expect(out_bits == 2);
- expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
- expect(out_bits == 3);
- expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
- expect(out_bits == 4);
- expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
- expect(out_bits == 5);
- expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
- expect(out_bits == 1);
+ try expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
+ try expect(out_bits == 1);
+ try expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
+ try expect(out_bits == 2);
+ try expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
+ try expect(out_bits == 3);
+ try expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
+ try expect(out_bits == 4);
+ try expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
+ try expect(out_bits == 5);
+ try expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
+ try expect(out_bits == 1);
mem_in_be.pos = 0;
bit_stream_be.bit_count = 0;
- expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
- expect(out_bits == 15);
+ try expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
+ try expect(out_bits == 15);
mem_in_be.pos = 0;
bit_stream_be.bit_count = 0;
- expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
- expect(out_bits == 16);
+ try expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
+ try expect(out_bits == 16);
_ = try bit_stream_be.readBits(u0, 0, &out_bits);
- expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
- expect(out_bits == 0);
- expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
+ try expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
+ try expect(out_bits == 0);
+ try expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
var mem_in_le = io.fixedBufferStream(&mem_le);
var bit_stream_le = bitReader(.Little, mem_in_le.reader());
- expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
- expect(out_bits == 1);
- expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
- expect(out_bits == 2);
- expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
- expect(out_bits == 3);
- expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
- expect(out_bits == 4);
- expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
- expect(out_bits == 5);
- expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
- expect(out_bits == 1);
+ try expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
+ try expect(out_bits == 1);
+ try expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
+ try expect(out_bits == 2);
+ try expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
+ try expect(out_bits == 3);
+ try expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
+ try expect(out_bits == 4);
+ try expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
+ try expect(out_bits == 5);
+ try expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
+ try expect(out_bits == 1);
mem_in_le.pos = 0;
bit_stream_le.bit_count = 0;
- expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
- expect(out_bits == 15);
+ try expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
+ try expect(out_bits == 15);
mem_in_le.pos = 0;
bit_stream_le.bit_count = 0;
- expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
- expect(out_bits == 16);
+ try expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
+ try expect(out_bits == 16);
_ = try bit_stream_le.readBits(u0, 0, &out_bits);
- expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
- expect(out_bits == 0);
- expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
+ try expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
+ try expect(out_bits == 0);
+ try expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
}
diff --git a/lib/std/io/bit_writer.zig b/lib/std/io/bit_writer.zig
index 3ad2b75efb..67e72ef3dc 100644
--- a/lib/std/io/bit_writer.zig
+++ b/lib/std/io/bit_writer.zig
@@ -163,17 +163,17 @@ test "api coverage" {
try bit_stream_be.writeBits(@as(u9, 5), 5);
try bit_stream_be.writeBits(@as(u1, 1), 1);
- testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
+ try testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
mem_out_be.pos = 0;
try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);
try bit_stream_be.flushBits();
- testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
+ try testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
mem_out_be.pos = 0;
try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16);
- testing.expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
+ try testing.expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
try bit_stream_be.writeBits(@as(u0, 0), 0);
@@ -187,16 +187,16 @@ test "api coverage" {
try bit_stream_le.writeBits(@as(u9, 5), 5);
try bit_stream_le.writeBits(@as(u1, 1), 1);
- testing.expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
+ try testing.expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
mem_out_le.pos = 0;
try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);
try bit_stream_le.flushBits();
- testing.expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
+ try testing.expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
mem_out_le.pos = 0;
try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16);
- testing.expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
+ try testing.expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
try bit_stream_le.writeBits(@as(u0, 0), 0);
}
diff --git a/lib/std/io/buffered_reader.zig b/lib/std/io/buffered_reader.zig
index 5fda7f2741..16e6480037 100644
--- a/lib/std/io/buffered_reader.zig
+++ b/lib/std/io/buffered_reader.zig
@@ -87,5 +87,5 @@ test "io.BufferedReader" {
const res = try stream.readAllAlloc(testing.allocator, str.len + 1);
defer testing.allocator.free(res);
- testing.expectEqualSlices(u8, str, res);
+ try testing.expectEqualSlices(u8, str, res);
}
diff --git a/lib/std/io/counting_reader.zig b/lib/std/io/counting_reader.zig
index 1369155a73..3b06555deb 100644
--- a/lib/std/io/counting_reader.zig
+++ b/lib/std/io/counting_reader.zig
@@ -41,8 +41,8 @@ test "io.CountingReader" {
//read and discard all bytes
while (stream.readByte()) |_| {} else |err| {
- testing.expect(err == error.EndOfStream);
+ try testing.expect(err == error.EndOfStream);
}
- testing.expect(counting_stream.bytes_read == bytes.len);
+ try testing.expect(counting_stream.bytes_read == bytes.len);
}
diff --git a/lib/std/io/counting_writer.zig b/lib/std/io/counting_writer.zig
index f68c257486..28eddc1303 100644
--- a/lib/std/io/counting_writer.zig
+++ b/lib/std/io/counting_writer.zig
@@ -40,5 +40,5 @@ test "io.CountingWriter" {
const bytes = "yay" ** 100;
stream.writeAll(bytes) catch unreachable;
- testing.expect(counting_stream.bytes_written == bytes.len);
+ try testing.expect(counting_stream.bytes_written == bytes.len);
}
diff --git a/lib/std/io/fixed_buffer_stream.zig b/lib/std/io/fixed_buffer_stream.zig
index f86fd5a8d8..c154c221bf 100644
--- a/lib/std/io/fixed_buffer_stream.zig
+++ b/lib/std/io/fixed_buffer_stream.zig
@@ -134,7 +134,7 @@ test "FixedBufferStream output" {
const stream = fbs.writer();
try stream.print("{s}{s}!", .{ "Hello", "World" });
- testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
+ try testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
}
test "FixedBufferStream output 2" {
@@ -142,19 +142,19 @@ test "FixedBufferStream output 2" {
var fbs = fixedBufferStream(&buffer);
try fbs.writer().writeAll("Hello");
- testing.expect(mem.eql(u8, fbs.getWritten(), "Hello"));
+ try testing.expect(mem.eql(u8, fbs.getWritten(), "Hello"));
try fbs.writer().writeAll("world");
- testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
+ try testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
- testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!"));
- testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
+ try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!"));
+ try testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
fbs.reset();
- testing.expect(fbs.getWritten().len == 0);
+ try testing.expect(fbs.getWritten().len == 0);
- testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!"));
- testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));
+ try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!"));
+ try testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));
}
test "FixedBufferStream input" {
@@ -164,13 +164,13 @@ test "FixedBufferStream input" {
var dest: [4]u8 = undefined;
var read = try fbs.reader().read(dest[0..4]);
- testing.expect(read == 4);
- testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));
+ try testing.expect(read == 4);
+ try testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));
read = try fbs.reader().read(dest[0..4]);
- testing.expect(read == 3);
- testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));
+ try testing.expect(read == 3);
+ try testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));
read = try fbs.reader().read(dest[0..4]);
- testing.expect(read == 0);
+ try testing.expect(read == 0);
}
diff --git a/lib/std/io/limited_reader.zig b/lib/std/io/limited_reader.zig
index 734558b1e6..1647d5aac3 100644
--- a/lib/std/io/limited_reader.zig
+++ b/lib/std/io/limited_reader.zig
@@ -43,8 +43,8 @@ test "basic usage" {
var early_stream = limitedReader(fbs.reader(), 3);
var buf: [5]u8 = undefined;
- testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));
- testing.expectEqualSlices(u8, data[0..3], buf[0..3]);
- testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));
- testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));
+ try testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));
+ try testing.expectEqualSlices(u8, data[0..3], buf[0..3]);
+ try testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));
+ try testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));
}
diff --git a/lib/std/io/multi_writer.zig b/lib/std/io/multi_writer.zig
index 639dd3cd18..9676212bbd 100644
--- a/lib/std/io/multi_writer.zig
+++ b/lib/std/io/multi_writer.zig
@@ -52,6 +52,6 @@ test "MultiWriter" {
var fbs2 = io.fixedBufferStream(&buf2);
var stream = multiWriter(.{ fbs1.writer(), fbs2.writer() });
try stream.writer().print("HI", .{});
- testing.expectEqualSlices(u8, "HI", fbs1.getWritten());
- testing.expectEqualSlices(u8, "HI", fbs2.getWritten());
+ try testing.expectEqualSlices(u8, "HI", fbs1.getWritten());
+ try testing.expectEqualSlices(u8, "HI", fbs2.getWritten());
}
diff --git a/lib/std/io/peek_stream.zig b/lib/std/io/peek_stream.zig
index b431b0184d..f3b8ba6645 100644
--- a/lib/std/io/peek_stream.zig
+++ b/lib/std/io/peek_stream.zig
@@ -94,24 +94,24 @@ test "PeekStream" {
try ps.putBackByte(10);
var read = try ps.reader().read(dest[0..4]);
- testing.expect(read == 4);
- testing.expect(dest[0] == 10);
- testing.expect(dest[1] == 9);
- testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));
+ try testing.expect(read == 4);
+ try testing.expect(dest[0] == 10);
+ try testing.expect(dest[1] == 9);
+ try testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));
read = try ps.reader().read(dest[0..4]);
- testing.expect(read == 4);
- testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));
+ try testing.expect(read == 4);
+ try testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));
read = try ps.reader().read(dest[0..4]);
- testing.expect(read == 2);
- testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));
+ try testing.expect(read == 2);
+ try testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));
try ps.putBackByte(11);
try ps.putBackByte(12);
read = try ps.reader().read(dest[0..4]);
- testing.expect(read == 2);
- testing.expect(dest[0] == 12);
- testing.expect(dest[1] == 11);
+ try testing.expect(read == 2);
+ try testing.expect(dest[0] == 12);
+ try testing.expect(dest[1] == 11);
}
diff --git a/lib/std/io/reader.zig b/lib/std/io/reader.zig
index 916e2155fa..920b82e420 100644
--- a/lib/std/io/reader.zig
+++ b/lib/std/io/reader.zig
@@ -329,26 +329,26 @@ pub fn Reader(
test "Reader" {
var buf = "a\x02".*;
const reader = std.io.fixedBufferStream(&buf).reader();
- testing.expect((try reader.readByte()) == 'a');
- testing.expect((try reader.readEnum(enum(u8) {
+ try testing.expect((try reader.readByte()) == 'a');
+ try testing.expect((try reader.readEnum(enum(u8) {
a = 0,
b = 99,
c = 2,
d = 3,
}, undefined)) == .c);
- testing.expectError(error.EndOfStream, reader.readByte());
+ try testing.expectError(error.EndOfStream, reader.readByte());
}
test "Reader.isBytes" {
const reader = std.io.fixedBufferStream("foobar").reader();
- testing.expectEqual(true, try reader.isBytes("foo"));
- testing.expectEqual(false, try reader.isBytes("qux"));
+ try testing.expectEqual(true, try reader.isBytes("foo"));
+ try testing.expectEqual(false, try reader.isBytes("qux"));
}
test "Reader.skipBytes" {
const reader = std.io.fixedBufferStream("foobar").reader();
try reader.skipBytes(3, .{});
- testing.expect(try reader.isBytes("bar"));
+ try testing.expect(try reader.isBytes("bar"));
try reader.skipBytes(0, .{});
- testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));
+ try testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));
}
diff --git a/lib/std/io/test.zig b/lib/std/io/test.zig
index 9fdef0de1d..5d204767b3 100644
--- a/lib/std/io/test.zig
+++ b/lib/std/io/test.zig
@@ -40,7 +40,7 @@ test "write a file, read it, then delete it" {
{
// Make sure the exclusive flag is honored.
- expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true }));
+ try expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true }));
}
{
@@ -49,16 +49,16 @@ test "write a file, read it, then delete it" {
const file_size = try file.getEndPos();
const expected_file_size: u64 = "begin".len + data.len + "end".len;
- expectEqual(expected_file_size, file_size);
+ try expectEqual(expected_file_size, file_size);
var buf_stream = io.bufferedReader(file.reader());
const st = buf_stream.reader();
const contents = try st.readAllAlloc(std.testing.allocator, 2 * 1024);
defer std.testing.allocator.free(contents);
- expect(mem.eql(u8, contents[0.."begin".len], "begin"));
- expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
- expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
+ try expect(mem.eql(u8, contents[0.."begin".len], "begin"));
+ try expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
+ try expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
}
try tmp.dir.deleteFile(tmp_file_name);
}
@@ -90,20 +90,20 @@ test "BitStreams with File Stream" {
var out_bits: usize = undefined;
- expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
- expect(out_bits == 1);
- expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
- expect(out_bits == 2);
- expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
- expect(out_bits == 3);
- expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
- expect(out_bits == 4);
- expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
- expect(out_bits == 5);
- expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
- expect(out_bits == 1);
+ try expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
+ try expect(out_bits == 1);
+ try expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
+ try expect(out_bits == 2);
+ try expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
+ try expect(out_bits == 3);
+ try expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
+ try expect(out_bits == 4);
+ try expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
+ try expect(out_bits == 5);
+ try expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
+ try expect(out_bits == 1);
- expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
+ try expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
}
try tmp.dir.deleteFile(tmp_file_name);
}
@@ -123,16 +123,16 @@ test "File seek ops" {
// Seek to the end
try file.seekFromEnd(0);
- expect((try file.getPos()) == try file.getEndPos());
+ try expect((try file.getPos()) == try file.getEndPos());
// Negative delta
try file.seekBy(-4096);
- expect((try file.getPos()) == 4096);
+ try expect((try file.getPos()) == 4096);
// Positive delta
try file.seekBy(10);
- expect((try file.getPos()) == 4106);
+ try expect((try file.getPos()) == 4106);
// Absolute position
try file.seekTo(1234);
- expect((try file.getPos()) == 1234);
+ try expect((try file.getPos()) == 1234);
}
test "setEndPos" {
@@ -147,18 +147,18 @@ test "setEndPos" {
}
// Verify that the file size changes and the file offset is not moved
- std.testing.expect((try file.getEndPos()) == 0);
- std.testing.expect((try file.getPos()) == 0);
+ try std.testing.expect((try file.getEndPos()) == 0);
+ try std.testing.expect((try file.getPos()) == 0);
try file.setEndPos(8192);
- std.testing.expect((try file.getEndPos()) == 8192);
- std.testing.expect((try file.getPos()) == 0);
+ try std.testing.expect((try file.getEndPos()) == 8192);
+ try std.testing.expect((try file.getPos()) == 0);
try file.seekTo(100);
try file.setEndPos(4096);
- std.testing.expect((try file.getEndPos()) == 4096);
- std.testing.expect((try file.getPos()) == 100);
+ try std.testing.expect((try file.getEndPos()) == 4096);
+ try std.testing.expect((try file.getPos()) == 100);
try file.setEndPos(0);
- std.testing.expect((try file.getEndPos()) == 0);
- std.testing.expect((try file.getPos()) == 100);
+ try std.testing.expect((try file.getEndPos()) == 0);
+ try std.testing.expect((try file.getPos()) == 100);
}
test "updateTimes" {
@@ -178,6 +178,6 @@ test "updateTimes" {
stat_old.mtime - 5 * std.time.ns_per_s,
);
var stat_new = try file.stat();
- expect(stat_new.atime < stat_old.atime);
- expect(stat_new.mtime < stat_old.mtime);
+ try expect(stat_new.atime < stat_old.atime);
+ try expect(stat_new.mtime < stat_old.mtime);
}
diff --git a/lib/std/json.zig b/lib/std/json.zig
index 7596631ea2..665992c2f8 100644
--- a/lib/std/json.zig
+++ b/lib/std/json.zig
@@ -79,18 +79,18 @@ fn encodesTo(decoded: []const u8, encoded: []const u8) bool {
test "encodesTo" {
// same
- testing.expectEqual(true, encodesTo("false", "false"));
+ try testing.expectEqual(true, encodesTo("false", "false"));
// totally different
- testing.expectEqual(false, encodesTo("false", "true"));
+ try testing.expectEqual(false, encodesTo("false", "true"));
// different lengths
- testing.expectEqual(false, encodesTo("false", "other"));
+ try testing.expectEqual(false, encodesTo("false", "other"));
// with escape
- testing.expectEqual(true, encodesTo("\\", "\\\\"));
- testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));
+ try testing.expectEqual(true, encodesTo("\\", "\\\\"));
+ try testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));
// with unicode
- testing.expectEqual(true, encodesTo("Δ
", "\\u0105"));
- testing.expectEqual(true, encodesTo("π", "\\ud83d\\ude02"));
- testing.expectEqual(true, encodesTo("withΔ
unicodeπ", "with\\u0105unicode\\ud83d\\ude02"));
+ try testing.expectEqual(true, encodesTo("Δ
", "\\u0105"));
+ try testing.expectEqual(true, encodesTo("π", "\\ud83d\\ude02"));
+ try testing.expectEqual(true, encodesTo("withΔ
unicodeπ", "with\\u0105unicode\\ud83d\\ude02"));
}
/// A single token slice into the parent string.
@@ -1138,9 +1138,9 @@ pub const TokenStream = struct {
}
};
-fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) void {
+fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) !void {
const token = (p.next() catch unreachable).?;
- debug.assert(std.meta.activeTag(token) == id);
+ try testing.expect(std.meta.activeTag(token) == id);
}
test "json.token" {
@@ -1163,46 +1163,46 @@ test "json.token" {
var p = TokenStream.init(s);
- checkNext(&p, .ObjectBegin);
- checkNext(&p, .String); // Image
- checkNext(&p, .ObjectBegin);
- checkNext(&p, .String); // Width
- checkNext(&p, .Number);
- checkNext(&p, .String); // Height
- checkNext(&p, .Number);
- checkNext(&p, .String); // Title
- checkNext(&p, .String);
- checkNext(&p, .String); // Thumbnail
- checkNext(&p, .ObjectBegin);
- checkNext(&p, .String); // Url
- checkNext(&p, .String);
- checkNext(&p, .String); // Height
- checkNext(&p, .Number);
- checkNext(&p, .String); // Width
- checkNext(&p, .Number);
- checkNext(&p, .ObjectEnd);
- checkNext(&p, .String); // Animated
- checkNext(&p, .False);
- checkNext(&p, .String); // IDs
- checkNext(&p, .ArrayBegin);
- checkNext(&p, .Number);
- checkNext(&p, .Number);
- checkNext(&p, .Number);
- checkNext(&p, .Number);
- checkNext(&p, .ArrayEnd);
- checkNext(&p, .ObjectEnd);
- checkNext(&p, .ObjectEnd);
+ try checkNext(&p, .ObjectBegin);
+ try checkNext(&p, .String); // Image
+ try checkNext(&p, .ObjectBegin);
+ try checkNext(&p, .String); // Width
+ try checkNext(&p, .Number);
+ try checkNext(&p, .String); // Height
+ try checkNext(&p, .Number);
+ try checkNext(&p, .String); // Title
+ try checkNext(&p, .String);
+ try checkNext(&p, .String); // Thumbnail
+ try checkNext(&p, .ObjectBegin);
+ try checkNext(&p, .String); // Url
+ try checkNext(&p, .String);
+ try checkNext(&p, .String); // Height
+ try checkNext(&p, .Number);
+ try checkNext(&p, .String); // Width
+ try checkNext(&p, .Number);
+ try checkNext(&p, .ObjectEnd);
+ try checkNext(&p, .String); // Animated
+ try checkNext(&p, .False);
+ try checkNext(&p, .String); // IDs
+ try checkNext(&p, .ArrayBegin);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .ArrayEnd);
+ try checkNext(&p, .ObjectEnd);
+ try checkNext(&p, .ObjectEnd);
- testing.expect((try p.next()) == null);
+ try testing.expect((try p.next()) == null);
}
test "json.token mismatched close" {
var p = TokenStream.init("[102, 111, 111 }");
- checkNext(&p, .ArrayBegin);
- checkNext(&p, .Number);
- checkNext(&p, .Number);
- checkNext(&p, .Number);
- testing.expectError(error.UnexpectedClosingBrace, p.next());
+ try checkNext(&p, .ArrayBegin);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .Number);
+ try testing.expectError(error.UnexpectedClosingBrace, p.next());
}
/// Validate a JSON string. This does not limit number precision so a decoder may not necessarily
@@ -1223,12 +1223,12 @@ pub fn validate(s: []const u8) bool {
}
test "json.validate" {
- testing.expectEqual(true, validate("{}"));
- testing.expectEqual(true, validate("[]"));
- testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));
- testing.expectEqual(false, validate("{]"));
- testing.expectEqual(false, validate("[}"));
- testing.expectEqual(false, validate("{{{{[]}}}]"));
+ try testing.expectEqual(true, validate("{}"));
+ try testing.expectEqual(true, validate("[]"));
+ try testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));
+ try testing.expectEqual(false, validate("{]"));
+ try testing.expectEqual(false, validate("[}"));
+ try testing.expectEqual(false, validate("{{{{[]}}}]"));
}
const Allocator = std.mem.Allocator;
@@ -1326,37 +1326,37 @@ test "Value.jsonStringify" {
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try @as(Value, .Null).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "null");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "null");
}
{
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try (Value{ .Bool = true }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "true");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "true");
}
{
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "42");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "42");
}
{
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try (Value{ .NumberString = "43" }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "43");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "43");
}
{
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try (Value{ .Float = 42 }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "4.2e+01");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "4.2e+01");
}
{
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");
}
{
var buffer: [10]u8 = undefined;
@@ -1369,7 +1369,7 @@ test "Value.jsonStringify" {
try (Value{
.Array = Array.fromOwnedSlice(undefined, &vals),
}).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");
}
{
var buffer: [10]u8 = undefined;
@@ -1378,7 +1378,7 @@ test "Value.jsonStringify" {
defer obj.deinit();
try obj.putNoClobber("a", .{ .String = "b" });
try (Value{ .Object = obj }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");
}
}
@@ -1751,17 +1751,17 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {
}
test "parse" {
- testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));
- testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));
- testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));
- testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));
- testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{}));
- testing.expectEqual(@as(f64, 42), try parse(f64, &TokenStream.init("42.0"), ParseOptions{}));
- testing.expectEqual(@as(?bool, null), try parse(?bool, &TokenStream.init("null"), ParseOptions{}));
- testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{}));
+ try testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));
+ try testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));
+ try testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));
+ try testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));
+ try testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{}));
+ try testing.expectEqual(@as(f64, 42), try parse(f64, &TokenStream.init("42.0"), ParseOptions{}));
+ try testing.expectEqual(@as(?bool, null), try parse(?bool, &TokenStream.init("null"), ParseOptions{}));
+ try testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{}));
- testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
- testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{}));
+ try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
+ try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{}));
}
test "parse into enum" {
@@ -1770,31 +1770,31 @@ test "parse into enum" {
Bar,
@"with\\escape",
};
- testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{}));
- testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("42"), ParseOptions{}));
- testing.expectEqual(@as(T, .@"with\\escape"), try parse(T, &TokenStream.init("\"with\\\\escape\""), ParseOptions{}));
- testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{}));
- testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));
+ try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{}));
+ try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("42"), ParseOptions{}));
+ try testing.expectEqual(@as(T, .@"with\\escape"), try parse(T, &TokenStream.init("\"with\\\\escape\""), ParseOptions{}));
+ try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{}));
+ try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));
}
test "parse into that allocates a slice" {
- testing.expectError(error.AllocatorRequired, parse([]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
+ try testing.expectError(error.AllocatorRequired, parse([]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
const options = ParseOptions{ .allocator = testing.allocator };
{
const r = try parse([]u8, &TokenStream.init("\"foo\""), options);
defer parseFree([]u8, r, options);
- testing.expectEqualSlices(u8, "foo", r);
+ try testing.expectEqualSlices(u8, "foo", r);
}
{
const r = try parse([]u8, &TokenStream.init("[102, 111, 111]"), options);
defer parseFree([]u8, r, options);
- testing.expectEqualSlices(u8, "foo", r);
+ try testing.expectEqualSlices(u8, "foo", r);
}
{
const r = try parse([]u8, &TokenStream.init("\"with\\\\escape\""), options);
defer parseFree([]u8, r, options);
- testing.expectEqualSlices(u8, "with\\escape", r);
+ try testing.expectEqualSlices(u8, "with\\escape", r);
}
}
@@ -1805,7 +1805,7 @@ test "parse into tagged union" {
float: f64,
string: []const u8,
};
- testing.expectEqual(T{ .float = 1.5 }, try parse(T, &TokenStream.init("1.5"), ParseOptions{}));
+ try testing.expectEqual(T{ .float = 1.5 }, try parse(T, &TokenStream.init("1.5"), ParseOptions{}));
}
{ // failing allocations should be bubbled up instantly without trying next member
@@ -1816,7 +1816,7 @@ test "parse into tagged union" {
string: []const u8,
array: [3]u8,
};
- testing.expectError(error.OutOfMemory, parse(T, &TokenStream.init("[1,2,3]"), options));
+ try testing.expectError(error.OutOfMemory, parse(T, &TokenStream.init("[1,2,3]"), options));
}
{
@@ -1825,7 +1825,7 @@ test "parse into tagged union" {
x: u8,
y: u8,
};
- testing.expectEqual(T{ .x = 42 }, try parse(T, &TokenStream.init("42"), ParseOptions{}));
+ try testing.expectEqual(T{ .x = 42 }, try parse(T, &TokenStream.init("42"), ParseOptions{}));
}
{ // needs to back out when first union member doesn't match
@@ -1833,7 +1833,7 @@ test "parse into tagged union" {
A: struct { x: u32 },
B: struct { y: u32 },
};
- testing.expectEqual(T{ .B = .{ .y = 42 } }, try parse(T, &TokenStream.init("{\"y\":42}"), ParseOptions{}));
+ try testing.expectEqual(T{ .B = .{ .y = 42 } }, try parse(T, &TokenStream.init("{\"y\":42}"), ParseOptions{}));
}
}
@@ -1843,7 +1843,7 @@ test "parse union bubbles up AllocatorRequired" {
string: []const u8,
int: i32,
};
- testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));
+ try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));
}
{ // string member not first in union (and matching)
@@ -1852,7 +1852,7 @@ test "parse union bubbles up AllocatorRequired" {
float: f64,
string: []const u8,
};
- testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));
+ try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));
}
}
@@ -1866,11 +1866,11 @@ test "parseFree descends into tagged union" {
};
// use a string with unicode escape so we know result can't be a reference to global constant
const r = try parse(T, &TokenStream.init("\"with\\u0105unicode\""), options);
- testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));
- testing.expectEqualSlices(u8, "withΔ
unicode", r.string);
- testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);
+ try testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));
+ try testing.expectEqualSlices(u8, "withΔ
unicode", r.string);
+ try testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);
parseFree(T, r, options);
- testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);
+ try testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);
}
test "parse with comptime field" {
@@ -1879,7 +1879,7 @@ test "parse with comptime field" {
comptime a: i32 = 0,
b: bool,
};
- testing.expectEqual(T{ .a = 0, .b = true }, try parse(T, &TokenStream.init(
+ try testing.expectEqual(T{ .a = 0, .b = true }, try parse(T, &TokenStream.init(
\\{
\\ "a": 0,
\\ "b": true
@@ -1912,7 +1912,7 @@ test "parse with comptime field" {
test "parse into struct with no fields" {
const T = struct {};
- testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));
+ try testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));
}
test "parse into struct with misc fields" {
@@ -1968,24 +1968,24 @@ test "parse into struct with misc fields" {
\\}
), options);
defer parseFree(T, r, options);
- testing.expectEqual(@as(i64, 420), r.int);
- testing.expectEqual(@as(f64, 3.14), r.float);
- testing.expectEqual(true, r.@"with\\escape");
- testing.expectEqual(false, r.@"withΔ
unicodeπ");
- testing.expectEqualSlices(u8, "zig", r.language);
- testing.expectEqual(@as(?bool, null), r.optional);
- testing.expectEqual(@as(i32, 42), r.default_field);
- testing.expectEqual(@as(f64, 66.6), r.static_array[0]);
- testing.expectEqual(@as(f64, 420.420), r.static_array[1]);
- testing.expectEqual(@as(f64, 69.69), r.static_array[2]);
- testing.expectEqual(@as(usize, 3), r.dynamic_array.len);
- testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);
- testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);
- testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);
- testing.expectEqualSlices(u8, r.complex.nested, "zig");
- testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);
- testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);
- testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);
+ try testing.expectEqual(@as(i64, 420), r.int);
+ try testing.expectEqual(@as(f64, 3.14), r.float);
+ try testing.expectEqual(true, r.@"with\\escape");
+ try testing.expectEqual(false, r.@"withΔ
unicodeπ");
+ try testing.expectEqualSlices(u8, "zig", r.language);
+ try testing.expectEqual(@as(?bool, null), r.optional);
+ try testing.expectEqual(@as(i32, 42), r.default_field);
+ try testing.expectEqual(@as(f64, 66.6), r.static_array[0]);
+ try testing.expectEqual(@as(f64, 420.420), r.static_array[1]);
+ try testing.expectEqual(@as(f64, 69.69), r.static_array[2]);
+ try testing.expectEqual(@as(usize, 3), r.dynamic_array.len);
+ try testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);
+ try testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);
+ try testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);
+ try testing.expectEqualSlices(u8, r.complex.nested, "zig");
+ try testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);
+ try testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);
+ try testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);
}
/// A non-stream JSON parser which constructs a tree of Value's.
@@ -2320,28 +2320,28 @@ test "json.parser.dynamic" {
var image = root.Object.get("Image").?;
const width = image.Object.get("Width").?;
- testing.expect(width.Integer == 800);
+ try testing.expect(width.Integer == 800);
const height = image.Object.get("Height").?;
- testing.expect(height.Integer == 600);
+ try testing.expect(height.Integer == 600);
const title = image.Object.get("Title").?;
- testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));
+ try testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));
const animated = image.Object.get("Animated").?;
- testing.expect(animated.Bool == false);
+ try testing.expect(animated.Bool == false);
const array_of_object = image.Object.get("ArrayOfObject").?;
- testing.expect(array_of_object.Array.items.len == 1);
+ try testing.expect(array_of_object.Array.items.len == 1);
const obj0 = array_of_object.Array.items[0].Object.get("n").?;
- testing.expect(mem.eql(u8, obj0.String, "m"));
+ try testing.expect(mem.eql(u8, obj0.String, "m"));
const double = image.Object.get("double").?;
- testing.expect(double.Float == 1.3412);
+ try testing.expect(double.Float == 1.3412);
const large_int = image.Object.get("LargeInt").?;
- testing.expect(mem.eql(u8, large_int.NumberString, "18446744073709551615"));
+ try testing.expect(mem.eql(u8, large_int.NumberString, "18446744073709551615"));
}
test "import more json tests" {
@@ -2388,12 +2388,12 @@ test "write json then parse it" {
var tree = try parser.parse(fixed_buffer_stream.getWritten());
defer tree.deinit();
- testing.expect(tree.root.Object.get("f").?.Bool == false);
- testing.expect(tree.root.Object.get("t").?.Bool == true);
- testing.expect(tree.root.Object.get("int").?.Integer == 1234);
- testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});
- testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34);
- testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
+ try testing.expect(tree.root.Object.get("f").?.Bool == false);
+ try testing.expect(tree.root.Object.get("t").?.Bool == true);
+ try testing.expect(tree.root.Object.get("int").?.Integer == 1234);
+ try testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});
+ try testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34);
+ try testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
}
fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value {
@@ -2404,7 +2404,7 @@ fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value
test "parsing empty string gives appropriate error" {
var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena_allocator.deinit();
- testing.expectError(error.UnexpectedEndOfJson, test_parse(&arena_allocator.allocator, ""));
+ try testing.expectError(error.UnexpectedEndOfJson, test_parse(&arena_allocator.allocator, ""));
}
test "integer after float has proper type" {
@@ -2416,7 +2416,7 @@ test "integer after float has proper type" {
\\ "ints": [1, 2, 3]
\\}
);
- std.testing.expect(json.Object.get("ints").?.Array.items[0] == .Integer);
+ try std.testing.expect(json.Object.get("ints").?.Array.items[0] == .Integer);
}
test "escaped characters" {
@@ -2439,16 +2439,16 @@ test "escaped characters" {
const obj = (try test_parse(&arena_allocator.allocator, input)).Object;
- testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
- testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
- testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
- testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
- testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
- testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
- testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
- testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
- testing.expectEqualSlices(u8, obj.get("unicode").?.String, "Δ
");
- testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "π");
+ try testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
+ try testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
+ try testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
+ try testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
+ try testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
+ try testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
+ try testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
+ try testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
+ try testing.expectEqualSlices(u8, obj.get("unicode").?.String, "Δ
");
+ try testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "π");
}
test "string copy option" {
@@ -2471,7 +2471,7 @@ test "string copy option" {
const obj_copy = tree_copy.root.Object;
for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| {
- testing.expectEqualSlices(u8, obj_nocopy.get(field_name).?.String, obj_copy.get(field_name).?.String);
+ try testing.expectEqualSlices(u8, obj_nocopy.get(field_name).?.String, obj_copy.get(field_name).?.String);
}
const nocopy_addr = &obj_nocopy.get("noescape").?.String[0];
@@ -2479,12 +2479,12 @@ test "string copy option" {
var found_nocopy = false;
for (input) |_, index| {
- testing.expect(copy_addr != &input[index]);
+ try testing.expect(copy_addr != &input[index]);
if (nocopy_addr == &input[index]) {
found_nocopy = true;
}
}
- testing.expect(found_nocopy);
+ try testing.expect(found_nocopy);
}
pub const StringifyOptions = struct {
diff --git a/lib/std/json/test.zig b/lib/std/json/test.zig
index b0d873c910..e37ba72113 100644
--- a/lib/std/json/test.zig
+++ b/lib/std/json/test.zig
@@ -21,37 +21,37 @@ fn testNonStreaming(s: []const u8) !void {
}
fn ok(s: []const u8) !void {
- testing.expect(json.validate(s));
+ try testing.expect(json.validate(s));
try testNonStreaming(s);
}
-fn err(s: []const u8) void {
- testing.expect(!json.validate(s));
+fn err(s: []const u8) !void {
+ try testing.expect(!json.validate(s));
- testing.expect(std.meta.isError(testNonStreaming(s)));
+ try testing.expect(std.meta.isError(testNonStreaming(s)));
}
-fn utf8Error(s: []const u8) void {
- testing.expect(!json.validate(s));
+fn utf8Error(s: []const u8) !void {
+ try testing.expect(!json.validate(s));
- testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
+ try testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
}
-fn any(s: []const u8) void {
+fn any(s: []const u8) !void {
_ = json.validate(s);
testNonStreaming(s) catch {};
}
-fn anyStreamingErrNonStreaming(s: []const u8) void {
+fn anyStreamingErrNonStreaming(s: []const u8) !void {
_ = json.validate(s);
- testing.expect(std.meta.isError(testNonStreaming(s)));
+ try testing.expect(std.meta.isError(testNonStreaming(s)));
}
fn roundTrip(s: []const u8) !void {
- testing.expect(json.validate(s));
+ try testing.expect(json.validate(s));
var p = json.Parser.init(testing.allocator, false);
defer p.deinit();
@@ -63,7 +63,7 @@ fn roundTrip(s: []const u8) !void {
var fbs = std.io.fixedBufferStream(&buf);
try tree.root.jsonStringify(.{}, fbs.writer());
- testing.expectEqualStrings(s, fbs.getWritten());
+ try testing.expectEqualStrings(s, fbs.getWritten());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -642,109 +642,109 @@ test "y_structure_whitespace_array" {
////////////////////////////////////////////////////////////////////////////////////////////////////
test "n_array_1_true_without_comma" {
- err(
+ try err(
\\[1 true]
);
}
test "n_array_a_invalid_utf8" {
- err(
+ try err(
\\[aΓ₯]
);
}
test "n_array_colon_instead_of_comma" {
- err(
+ try err(
\\["": 1]
);
}
test "n_array_comma_after_close" {
- err(
+ try err(
\\[""],
);
}
test "n_array_comma_and_number" {
- err(
+ try err(
\\[,1]
);
}
test "n_array_double_comma" {
- err(
+ try err(
\\[1,,2]
);
}
test "n_array_double_extra_comma" {
- err(
+ try err(
\\["x",,]
);
}
test "n_array_extra_close" {
- err(
+ try err(
\\["x"]]
);
}
test "n_array_extra_comma" {
- err(
+ try err(
\\["",]
);
}
test "n_array_incomplete_invalid_value" {
- err(
+ try err(
\\[x
);
}
test "n_array_incomplete" {
- err(
+ try err(
\\["x"
);
}
test "n_array_inner_array_no_comma" {
- err(
+ try err(
\\[3[4]]
);
}
test "n_array_invalid_utf8" {
- err(
+ try err(
\\[ΓΏ]
);
}
test "n_array_items_separated_by_semicolon" {
- err(
+ try err(
\\[1:2]
);
}
test "n_array_just_comma" {
- err(
+ try err(
\\[,]
);
}
test "n_array_just_minus" {
- err(
+ try err(
\\[-]
);
}
test "n_array_missing_value" {
- err(
+ try err(
\\[ , ""]
);
}
test "n_array_newlines_unclosed" {
- err(
+ try err(
\\["a",
\\4
\\,1,
@@ -752,41 +752,41 @@ test "n_array_newlines_unclosed" {
}
test "n_array_number_and_comma" {
- err(
+ try err(
\\[1,]
);
}
test "n_array_number_and_several_commas" {
- err(
+ try err(
\\[1,,]
);
}
test "n_array_spaces_vertical_tab_formfeed" {
- err("[\"\x0aa\"\\f]");
+ try err("[\"\x0aa\"\\f]");
}
test "n_array_star_inside" {
- err(
+ try err(
\\[*]
);
}
test "n_array_unclosed" {
- err(
+ try err(
\\[""
);
}
test "n_array_unclosed_trailing_comma" {
- err(
+ try err(
\\[1,
);
}
test "n_array_unclosed_with_new_lines" {
- err(
+ try err(
\\[1,
\\1
\\,1
@@ -794,956 +794,956 @@ test "n_array_unclosed_with_new_lines" {
}
test "n_array_unclosed_with_object_inside" {
- err(
+ try err(
\\[{}
);
}
test "n_incomplete_false" {
- err(
+ try err(
\\[fals]
);
}
test "n_incomplete_null" {
- err(
+ try err(
\\[nul]
);
}
test "n_incomplete_true" {
- err(
+ try err(
\\[tru]
);
}
test "n_multidigit_number_then_00" {
- err("123\x00");
+ try err("123\x00");
}
test "n_number_0.1.2" {
- err(
+ try err(
\\[0.1.2]
);
}
test "n_number_-01" {
- err(
+ try err(
\\[-01]
);
}
test "n_number_0.3e" {
- err(
+ try err(
\\[0.3e]
);
}
test "n_number_0.3e+" {
- err(
+ try err(
\\[0.3e+]
);
}
test "n_number_0_capital_E" {
- err(
+ try err(
\\[0E]
);
}
test "n_number_0_capital_E+" {
- err(
+ try err(
\\[0E+]
);
}
test "n_number_0.e1" {
- err(
+ try err(
\\[0.e1]
);
}
test "n_number_0e" {
- err(
+ try err(
\\[0e]
);
}
test "n_number_0e+" {
- err(
+ try err(
\\[0e+]
);
}
test "n_number_1_000" {
- err(
+ try err(
\\[1 000.0]
);
}
test "n_number_1.0e-" {
- err(
+ try err(
\\[1.0e-]
);
}
test "n_number_1.0e" {
- err(
+ try err(
\\[1.0e]
);
}
test "n_number_1.0e+" {
- err(
+ try err(
\\[1.0e+]
);
}
test "n_number_-1.0." {
- err(
+ try err(
\\[-1.0.]
);
}
test "n_number_1eE2" {
- err(
+ try err(
\\[1eE2]
);
}
test "n_number_.-1" {
- err(
+ try err(
\\[.-1]
);
}
test "n_number_+1" {
- err(
+ try err(
\\[+1]
);
}
test "n_number_.2e-3" {
- err(
+ try err(
\\[.2e-3]
);
}
test "n_number_2.e-3" {
- err(
+ try err(
\\[2.e-3]
);
}
test "n_number_2.e+3" {
- err(
+ try err(
\\[2.e+3]
);
}
test "n_number_2.e3" {
- err(
+ try err(
\\[2.e3]
);
}
test "n_number_-2." {
- err(
+ try err(
\\[-2.]
);
}
test "n_number_9.e+" {
- err(
+ try err(
\\[9.e+]
);
}
test "n_number_expression" {
- err(
+ try err(
\\[1+2]
);
}
test "n_number_hex_1_digit" {
- err(
+ try err(
\\[0x1]
);
}
test "n_number_hex_2_digits" {
- err(
+ try err(
\\[0x42]
);
}
test "n_number_infinity" {
- err(
+ try err(
\\[Infinity]
);
}
test "n_number_+Inf" {
- err(
+ try err(
\\[+Inf]
);
}
test "n_number_Inf" {
- err(
+ try err(
\\[Inf]
);
}
test "n_number_invalid+-" {
- err(
+ try err(
\\[0e+-1]
);
}
test "n_number_invalid-negative-real" {
- err(
+ try err(
\\[-123.123foo]
);
}
test "n_number_invalid-utf-8-in-bigger-int" {
- err(
+ try err(
\\[123Γ₯]
);
}
test "n_number_invalid-utf-8-in-exponent" {
- err(
+ try err(
\\[1e1Γ₯]
);
}
test "n_number_invalid-utf-8-in-int" {
- err(
+ try err(
\\[0Γ₯]
);
}
test "n_number_++" {
- err(
+ try err(
\\[++1234]
);
}
test "n_number_minus_infinity" {
- err(
+ try err(
\\[-Infinity]
);
}
test "n_number_minus_sign_with_trailing_garbage" {
- err(
+ try err(
\\[-foo]
);
}
test "n_number_minus_space_1" {
- err(
+ try err(
\\[- 1]
);
}
test "n_number_-NaN" {
- err(
+ try err(
\\[-NaN]
);
}
test "n_number_NaN" {
- err(
+ try err(
\\[NaN]
);
}
test "n_number_neg_int_starting_with_zero" {
- err(
+ try err(
\\[-012]
);
}
test "n_number_neg_real_without_int_part" {
- err(
+ try err(
\\[-.123]
);
}
test "n_number_neg_with_garbage_at_end" {
- err(
+ try err(
\\[-1x]
);
}
test "n_number_real_garbage_after_e" {
- err(
+ try err(
\\[1ea]
);
}
test "n_number_real_with_invalid_utf8_after_e" {
- err(
+ try err(
\\[1eΓ₯]
);
}
test "n_number_real_without_fractional_part" {
- err(
+ try err(
\\[1.]
);
}
test "n_number_starting_with_dot" {
- err(
+ try err(
\\[.123]
);
}
test "n_number_U+FF11_fullwidth_digit_one" {
- err(
+ try err(
\\[Γ―ΒΌΒ]
);
}
test "n_number_with_alpha_char" {
- err(
+ try err(
\\[1.8011670033376514H-308]
);
}
test "n_number_with_alpha" {
- err(
+ try err(
\\[1.2a-3]
);
}
test "n_number_with_leading_zero" {
- err(
+ try err(
\\[012]
);
}
test "n_object_bad_value" {
- err(
+ try err(
\\["x", truth]
);
}
test "n_object_bracket_key" {
- err(
+ try err(
\\{[: "x"}
);
}
test "n_object_comma_instead_of_colon" {
- err(
+ try err(
\\{"x", null}
);
}
test "n_object_double_colon" {
- err(
+ try err(
\\{"x"::"b"}
);
}
test "n_object_emoji" {
- err(
+ try err(
\\{Γ°ΒΒ¨ðΒΒΒ}
);
}
test "n_object_garbage_at_end" {
- err(
+ try err(
\\{"a":"a" 123}
);
}
test "n_object_key_with_single_quotes" {
- err(
+ try err(
\\{key: 'value'}
);
}
test "n_object_lone_continuation_byte_in_key_and_trailing_comma" {
- err(
+ try err(
\\{"ΒΉ":"0",}
);
}
test "n_object_missing_colon" {
- err(
+ try err(
\\{"a" b}
);
}
test "n_object_missing_key" {
- err(
+ try err(
\\{:"b"}
);
}
test "n_object_missing_semicolon" {
- err(
+ try err(
\\{"a" "b"}
);
}
test "n_object_missing_value" {
- err(
+ try err(
\\{"a":
);
}
test "n_object_no-colon" {
- err(
+ try err(
\\{"a"
);
}
test "n_object_non_string_key_but_huge_number_instead" {
- err(
+ try err(
\\{9999E9999:1}
);
}
test "n_object_non_string_key" {
- err(
+ try err(
\\{1:1}
);
}
test "n_object_repeated_null_null" {
- err(
+ try err(
\\{null:null,null:null}
);
}
test "n_object_several_trailing_commas" {
- err(
+ try err(
\\{"id":0,,,,,}
);
}
test "n_object_single_quote" {
- err(
+ try err(
\\{'a':0}
);
}
test "n_object_trailing_comma" {
- err(
+ try err(
\\{"id":0,}
);
}
test "n_object_trailing_comment" {
- err(
+ try err(
\\{"a":"b"}/**/
);
}
test "n_object_trailing_comment_open" {
- err(
+ try err(
\\{"a":"b"}/**//
);
}
test "n_object_trailing_comment_slash_open_incomplete" {
- err(
+ try err(
\\{"a":"b"}/
);
}
test "n_object_trailing_comment_slash_open" {
- err(
+ try err(
\\{"a":"b"}//
);
}
test "n_object_two_commas_in_a_row" {
- err(
+ try err(
\\{"a":"b",,"c":"d"}
);
}
test "n_object_unquoted_key" {
- err(
+ try err(
\\{a: "b"}
);
}
test "n_object_unterminated-value" {
- err(
+ try err(
\\{"a":"a
);
}
test "n_object_with_single_string" {
- err(
+ try err(
\\{ "foo" : "bar", "a" }
);
}
test "n_object_with_trailing_garbage" {
- err(
+ try err(
\\{"a":"b"}#
);
}
test "n_single_space" {
- err(" ");
+ try err(" ");
}
test "n_string_1_surrogate_then_escape" {
- err(
+ try err(
\\["\uD800\"]
);
}
test "n_string_1_surrogate_then_escape_u1" {
- err(
+ try err(
\\["\uD800\u1"]
);
}
test "n_string_1_surrogate_then_escape_u1x" {
- err(
+ try err(
\\["\uD800\u1x"]
);
}
test "n_string_1_surrogate_then_escape_u" {
- err(
+ try err(
\\["\uD800\u"]
);
}
test "n_string_accentuated_char_no_quotes" {
- err(
+ try err(
\\[ΓΒ©]
);
}
test "n_string_backslash_00" {
- err("[\"\x00\"]");
+ try err("[\"\x00\"]");
}
test "n_string_escaped_backslash_bad" {
- err(
+ try err(
\\["\\\"]
);
}
test "n_string_escaped_ctrl_char_tab" {
- err("\x5b\x22\x5c\x09\x22\x5d");
+ try err("\x5b\x22\x5c\x09\x22\x5d");
}
test "n_string_escaped_emoji" {
- err("[\"\x5c\xc3\xb0\xc2\x9f\xc2\x8c\xc2\x80\"]");
+ try err("[\"\x5c\xc3\xb0\xc2\x9f\xc2\x8c\xc2\x80\"]");
}
test "n_string_escape_x" {
- err(
+ try err(
\\["\x00"]
);
}
test "n_string_incomplete_escaped_character" {
- err(
+ try err(
\\["\u00A"]
);
}
test "n_string_incomplete_escape" {
- err(
+ try err(
\\["\"]
);
}
test "n_string_incomplete_surrogate_escape_invalid" {
- err(
+ try err(
\\["\uD800\uD800\x"]
);
}
test "n_string_incomplete_surrogate" {
- err(
+ try err(
\\["\uD834\uDd"]
);
}
test "n_string_invalid_backslash_esc" {
- err(
+ try err(
\\["\a"]
);
}
test "n_string_invalid_unicode_escape" {
- err(
+ try err(
\\["\uqqqq"]
);
}
test "n_string_invalid_utf8_after_escape" {
- err("[\"\\\x75\xc3\xa5\"]");
+ try err("[\"\\\x75\xc3\xa5\"]");
}
test "n_string_invalid-utf-8-in-escape" {
- err(
+ try err(
\\["\uΓ₯"]
);
}
test "n_string_leading_uescaped_thinspace" {
- err(
+ try err(
\\[\u0020"asd"]
);
}
test "n_string_no_quotes_with_bad_escape" {
- err(
+ try err(
\\[\n]
);
}
test "n_string_single_doublequote" {
- err(
+ try err(
\\"
);
}
test "n_string_single_quote" {
- err(
+ try err(
\\['single quote']
);
}
test "n_string_single_string_no_double_quotes" {
- err(
+ try err(
\\abc
);
}
test "n_string_start_escape_unclosed" {
- err(
+ try err(
\\["\
);
}
test "n_string_unescaped_crtl_char" {
- err("[\"a\x00a\"]");
+ try err("[\"a\x00a\"]");
}
test "n_string_unescaped_newline" {
- err(
+ try err(
\\["new
\\line"]
);
}
test "n_string_unescaped_tab" {
- err("[\"\t\"]");
+ try err("[\"\t\"]");
}
test "n_string_unicode_CapitalU" {
- err(
+ try err(
\\"\UA66D"
);
}
test "n_string_with_trailing_garbage" {
- err(
+ try err(
\\""x
);
}
test "n_structure_100000_opening_arrays" {
- err("[" ** 100000);
+ try err("[" ** 100000);
}
test "n_structure_angle_bracket_." {
- err(
+ try err(
\\<.>
);
}
test "n_structure_angle_bracket_null" {
- err(
+ try err(
\\[]
);
}
test "n_structure_array_trailing_garbage" {
- err(
+ try err(
\\[1]x
);
}
test "n_structure_array_with_extra_array_close" {
- err(
+ try err(
\\[1]]
);
}
test "n_structure_array_with_unclosed_string" {
- err(
+ try err(
\\["asd]
);
}
test "n_structure_ascii-unicode-identifier" {
- err(
+ try err(
\\aΓΒ₯
);
}
test "n_structure_capitalized_True" {
- err(
+ try err(
\\[True]
);
}
test "n_structure_close_unopened_array" {
- err(
+ try err(
\\1]
);
}
test "n_structure_comma_instead_of_closing_brace" {
- err(
+ try err(
\\{"x": true,
);
}
test "n_structure_double_array" {
- err(
+ try err(
\\[][]
);
}
test "n_structure_end_array" {
- err(
+ try err(
\\]
);
}
test "n_structure_incomplete_UTF8_BOM" {
- err(
+ try err(
\\Γ―Β»{}
);
}
test "n_structure_lone-invalid-utf-8" {
- err(
+ try err(
\\Γ₯
);
}
test "n_structure_lone-open-bracket" {
- err(
+ try err(
\\[
);
}
test "n_structure_no_data" {
- err(
+ try err(
\\
);
}
test "n_structure_null-byte-outside-string" {
- err("[\x00]");
+ try err("[\x00]");
}
test "n_structure_number_with_trailing_garbage" {
- err(
+ try err(
\\2@
);
}
test "n_structure_object_followed_by_closing_object" {
- err(
+ try err(
\\{}}
);
}
test "n_structure_object_unclosed_no_value" {
- err(
+ try err(
\\{"":
);
}
test "n_structure_object_with_comment" {
- err(
+ try err(
\\{"a":/*comment*/"b"}
);
}
test "n_structure_object_with_trailing_garbage" {
- err(
+ try err(
\\{"a": true} "x"
);
}
test "n_structure_open_array_apostrophe" {
- err(
+ try err(
\\['
);
}
test "n_structure_open_array_comma" {
- err(
+ try err(
\\[,
);
}
test "n_structure_open_array_object" {
- err("[{\"\":" ** 50000);
+ try err("[{\"\":" ** 50000);
}
test "n_structure_open_array_open_object" {
- err(
+ try err(
\\[{
);
}
test "n_structure_open_array_open_string" {
- err(
+ try err(
\\["a
);
}
test "n_structure_open_array_string" {
- err(
+ try err(
\\["a"
);
}
test "n_structure_open_object_close_array" {
- err(
+ try err(
\\{]
);
}
test "n_structure_open_object_comma" {
- err(
+ try err(
\\{,
);
}
test "n_structure_open_object" {
- err(
+ try err(
\\{
);
}
test "n_structure_open_object_open_array" {
- err(
+ try err(
\\{[
);
}
test "n_structure_open_object_open_string" {
- err(
+ try err(
\\{"a
);
}
test "n_structure_open_object_string_with_apostrophes" {
- err(
+ try err(
\\{'a'
);
}
test "n_structure_open_open" {
- err(
+ try err(
\\["\{["\{["\{["\{
);
}
test "n_structure_single_eacute" {
- err(
+ try err(
\\Γ©
);
}
test "n_structure_single_star" {
- err(
+ try err(
\\*
);
}
test "n_structure_trailing_#" {
- err(
+ try err(
\\{"a":"b"}#{}
);
}
test "n_structure_U+2060_word_joined" {
- err(
+ try err(
\\[Γ’ΒΒ ]
);
}
test "n_structure_uescaped_LF_before_string" {
- err(
+ try err(
\\[\u000A""]
);
}
test "n_structure_unclosed_array" {
- err(
+ try err(
\\[1
);
}
test "n_structure_unclosed_array_partial_null" {
- err(
+ try err(
\\[ false, nul
);
}
test "n_structure_unclosed_array_unfinished_false" {
- err(
+ try err(
\\[ true, fals
);
}
test "n_structure_unclosed_array_unfinished_true" {
- err(
+ try err(
\\[ false, tru
);
}
test "n_structure_unclosed_object" {
- err(
+ try err(
\\{"asd":"asd"
);
}
test "n_structure_unicode-identifier" {
- err(
+ try err(
\\ΓΒ₯
);
}
test "n_structure_UTF8_BOM_no_data" {
- err(
+ try err(
\\
);
}
test "n_structure_whitespace_formfeed" {
- err("[\x0c]");
+ try err("[\x0c]");
}
test "n_structure_whitespace_U+2060_word_joiner" {
- err(
+ try err(
\\[Γ’ΒΒ ]
);
}
@@ -1751,255 +1751,255 @@ test "n_structure_whitespace_U+2060_word_joiner" {
////////////////////////////////////////////////////////////////////////////////////////////////////
test "i_number_double_huge_neg_exp" {
- any(
+ try any(
\\[123.456e-789]
);
}
test "i_number_huge_exp" {
- any(
+ try any(
\\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
);
}
test "i_number_neg_int_huge_exp" {
- any(
+ try any(
\\[-1e+9999]
);
}
test "i_number_pos_double_huge_exp" {
- any(
+ try any(
\\[1.5e+9999]
);
}
test "i_number_real_neg_overflow" {
- any(
+ try any(
\\[-123123e100000]
);
}
test "i_number_real_pos_overflow" {
- any(
+ try any(
\\[123123e100000]
);
}
test "i_number_real_underflow" {
- any(
+ try any(
\\[123e-10000000]
);
}
test "i_number_too_big_neg_int" {
- any(
+ try any(
\\[-123123123123123123123123123123]
);
}
test "i_number_too_big_pos_int" {
- any(
+ try any(
\\[100000000000000000000]
);
}
test "i_number_very_big_negative_int" {
- any(
+ try any(
\\[-237462374673276894279832749832423479823246327846]
);
}
test "i_object_key_lone_2nd_surrogate" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\{"\uDFAA":0}
);
}
test "i_string_1st_surrogate_but_2nd_missing" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uDADA"]
);
}
test "i_string_1st_valid_surrogate_2nd_invalid" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uD888\u1234"]
);
}
test "i_string_incomplete_surrogate_and_escape_valid" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uD800\n"]
);
}
test "i_string_incomplete_surrogate_pair" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uDd1ea"]
);
}
test "i_string_incomplete_surrogates_escape_valid" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uD800\uD800\n"]
);
}
test "i_string_invalid_lonely_surrogate" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\ud800"]
);
}
test "i_string_invalid_surrogate" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\ud800abc"]
);
}
test "i_string_invalid_utf-8" {
- any(
+ try any(
\\["ΓΏ"]
);
}
test "i_string_inverted_surrogates_U+1D11E" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uDd1e\uD834"]
);
}
test "i_string_iso_latin_1" {
- any(
+ try any(
\\["Γ©"]
);
}
test "i_string_lone_second_surrogate" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uDFAA"]
);
}
test "i_string_lone_utf8_continuation_byte" {
- any(
+ try any(
\\["Β"]
);
}
test "i_string_not_in_unicode_range" {
- any(
+ try any(
\\["ô¿¿¿"]
);
}
test "i_string_overlong_sequence_2_bytes" {
- any(
+ try any(
\\["ΓΒ―"]
);
}
test "i_string_overlong_sequence_6_bytes" {
- any(
+ try any(
\\["ΓΌΒΒΏΒΏΒΏΒΏ"]
);
}
test "i_string_overlong_sequence_6_bytes_null" {
- any(
+ try any(
\\["ΓΌΒΒΒΒΒ"]
);
}
test "i_string_truncated-utf-8" {
- any(
+ try any(
\\["Γ ΓΏ"]
);
}
test "i_string_utf16BE_no_BOM" {
- any("\x00\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d");
+ try any("\x00\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d");
}
test "i_string_utf16LE_no_BOM" {
- any("\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
+ try any("\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
}
test "i_string_UTF-16LE_with_BOM" {
- any("\xc3\xbf\xc3\xbe\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
+ try any("\xc3\xbf\xc3\xbe\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
}
test "i_string_UTF-8_invalid_sequence" {
- any(
+ try any(
\\["Γ¦ΒΒ₯ΓΒΓΊ"]
);
}
test "i_string_UTF8_surrogate_U+D800" {
- any(
+ try any(
\\["ΓΒ Β"]
);
}
test "i_structure_500_nested_arrays" {
- any(("[" ** 500) ++ ("]" ** 500));
+ try any(("[" ** 500) ++ ("]" ** 500));
}
test "i_structure_UTF-8_BOM_empty_object" {
- any(
+ try any(
\\{}
);
}
test "truncated UTF-8 sequence" {
- utf8Error("\"\xc2\"");
- utf8Error("\"\xdf\"");
- utf8Error("\"\xed\xa0\"");
- utf8Error("\"\xf0\x80\"");
- utf8Error("\"\xf0\x80\x80\"");
+ try utf8Error("\"\xc2\"");
+ try utf8Error("\"\xdf\"");
+ try utf8Error("\"\xed\xa0\"");
+ try utf8Error("\"\xf0\x80\"");
+ try utf8Error("\"\xf0\x80\x80\"");
}
test "invalid continuation byte" {
- utf8Error("\"\xc2\x00\"");
- utf8Error("\"\xc2\x7f\"");
- utf8Error("\"\xc2\xc0\"");
- utf8Error("\"\xc3\xc1\"");
- utf8Error("\"\xc4\xf5\"");
- utf8Error("\"\xc5\xff\"");
- utf8Error("\"\xe4\x80\x00\"");
- utf8Error("\"\xe5\x80\x10\"");
- utf8Error("\"\xe6\x80\xc0\"");
- utf8Error("\"\xe7\x80\xf5\"");
- utf8Error("\"\xe8\x00\x80\"");
- utf8Error("\"\xf2\x00\x80\x80\"");
- utf8Error("\"\xf0\x80\x00\x80\"");
- utf8Error("\"\xf1\x80\xc0\x80\"");
- utf8Error("\"\xf2\x80\x80\x00\"");
- utf8Error("\"\xf3\x80\x80\xc0\"");
- utf8Error("\"\xf4\x80\x80\xf5\"");
+ try utf8Error("\"\xc2\x00\"");
+ try utf8Error("\"\xc2\x7f\"");
+ try utf8Error("\"\xc2\xc0\"");
+ try utf8Error("\"\xc3\xc1\"");
+ try utf8Error("\"\xc4\xf5\"");
+ try utf8Error("\"\xc5\xff\"");
+ try utf8Error("\"\xe4\x80\x00\"");
+ try utf8Error("\"\xe5\x80\x10\"");
+ try utf8Error("\"\xe6\x80\xc0\"");
+ try utf8Error("\"\xe7\x80\xf5\"");
+ try utf8Error("\"\xe8\x00\x80\"");
+ try utf8Error("\"\xf2\x00\x80\x80\"");
+ try utf8Error("\"\xf0\x80\x00\x80\"");
+ try utf8Error("\"\xf1\x80\xc0\x80\"");
+ try utf8Error("\"\xf2\x80\x80\x00\"");
+ try utf8Error("\"\xf3\x80\x80\xc0\"");
+ try utf8Error("\"\xf4\x80\x80\xf5\"");
}
test "disallowed overlong form" {
- utf8Error("\"\xc0\x80\"");
- utf8Error("\"\xc0\x90\"");
- utf8Error("\"\xc1\x80\"");
- utf8Error("\"\xc1\x90\"");
- utf8Error("\"\xe0\x80\x80\"");
- utf8Error("\"\xf0\x80\x80\x80\"");
+ try utf8Error("\"\xc0\x80\"");
+ try utf8Error("\"\xc0\x90\"");
+ try utf8Error("\"\xc1\x80\"");
+ try utf8Error("\"\xc1\x90\"");
+ try utf8Error("\"\xe0\x80\x80\"");
+ try utf8Error("\"\xf0\x80\x80\x80\"");
}
test "out of UTF-16 range" {
- utf8Error("\"\xf4\x90\x80\x80\"");
- utf8Error("\"\xf5\x80\x80\x80\"");
- utf8Error("\"\xf6\x80\x80\x80\"");
- utf8Error("\"\xf7\x80\x80\x80\"");
- utf8Error("\"\xf8\x80\x80\x80\"");
- utf8Error("\"\xf9\x80\x80\x80\"");
- utf8Error("\"\xfa\x80\x80\x80\"");
- utf8Error("\"\xfb\x80\x80\x80\"");
- utf8Error("\"\xfc\x80\x80\x80\"");
- utf8Error("\"\xfd\x80\x80\x80\"");
- utf8Error("\"\xfe\x80\x80\x80\"");
- utf8Error("\"\xff\x80\x80\x80\"");
+ try utf8Error("\"\xf4\x90\x80\x80\"");
+ try utf8Error("\"\xf5\x80\x80\x80\"");
+ try utf8Error("\"\xf6\x80\x80\x80\"");
+ try utf8Error("\"\xf7\x80\x80\x80\"");
+ try utf8Error("\"\xf8\x80\x80\x80\"");
+ try utf8Error("\"\xf9\x80\x80\x80\"");
+ try utf8Error("\"\xfa\x80\x80\x80\"");
+ try utf8Error("\"\xfb\x80\x80\x80\"");
+ try utf8Error("\"\xfc\x80\x80\x80\"");
+ try utf8Error("\"\xfd\x80\x80\x80\"");
+ try utf8Error("\"\xfe\x80\x80\x80\"");
+ try utf8Error("\"\xff\x80\x80\x80\"");
}
diff --git a/lib/std/json/write_stream.zig b/lib/std/json/write_stream.zig
index 1cff0ed2b7..c9169be755 100644
--- a/lib/std/json/write_stream.zig
+++ b/lib/std/json/write_stream.zig
@@ -288,7 +288,7 @@ test "json write stream" {
\\ "float": 3.5e+00
\\}
;
- std.testing.expect(std.mem.eql(u8, expected, result));
+ try std.testing.expect(std.mem.eql(u8, expected, result));
}
fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value {
diff --git a/lib/std/leb128.zig b/lib/std/leb128.zig
index 90a329545f..b1f56e21ab 100644
--- a/lib/std/leb128.zig
+++ b/lib/std/leb128.zig
@@ -152,22 +152,22 @@ test "writeUnsignedFixed" {
{
var buf: [4]u8 = undefined;
writeUnsignedFixed(4, &buf, 0);
- testing.expect((try test_read_uleb128(u64, &buf)) == 0);
+ try testing.expect((try test_read_uleb128(u64, &buf)) == 0);
}
{
var buf: [4]u8 = undefined;
writeUnsignedFixed(4, &buf, 1);
- testing.expect((try test_read_uleb128(u64, &buf)) == 1);
+ try testing.expect((try test_read_uleb128(u64, &buf)) == 1);
}
{
var buf: [4]u8 = undefined;
writeUnsignedFixed(4, &buf, 1000);
- testing.expect((try test_read_uleb128(u64, &buf)) == 1000);
+ try testing.expect((try test_read_uleb128(u64, &buf)) == 1000);
}
{
var buf: [4]u8 = undefined;
writeUnsignedFixed(4, &buf, 10000000);
- testing.expect((try test_read_uleb128(u64, &buf)) == 10000000);
+ try testing.expect((try test_read_uleb128(u64, &buf)) == 10000000);
}
}
@@ -212,44 +212,44 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u
test "deserialize signed LEB128" {
// Truncated
- testing.expectError(error.EndOfStream, test_read_stream_ileb128(i64, "\x80"));
+ try testing.expectError(error.EndOfStream, test_read_stream_ileb128(i64, "\x80"));
// Overflow
- testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));
+ try testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));
// Decode SLEB128
- testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
- testing.expect((try test_read_ileb128(i64, "\x01")) == 1);
- testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);
- testing.expect((try test_read_ileb128(i64, "\x40")) == -64);
- testing.expect((try test_read_ileb128(i64, "\x41")) == -63);
- testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);
- testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);
- testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);
- testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);
- testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);
- testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);
- testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);
- testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);
- testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
- testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
- testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
- testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000);
- testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == @bitCast(i64, @intCast(u64, 0x8000000000000000)));
- testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
- testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
+ try testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
+ try testing.expect((try test_read_ileb128(i64, "\x01")) == 1);
+ try testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);
+ try testing.expect((try test_read_ileb128(i64, "\x40")) == -64);
+ try testing.expect((try test_read_ileb128(i64, "\x41")) == -63);
+ try testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);
+ try testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);
+ try testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);
+ try testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);
+ try testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);
+ try testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);
+ try testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
+ try testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
+ try testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
+ try testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == @bitCast(i64, @intCast(u64, 0x8000000000000000)));
+ try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
// Decode unnormalized SLEB128 with extra padding bytes.
- testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);
- testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);
- testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);
- testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);
- testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);
- testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);
+ try testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);
+ try testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);
// Decode sequence of SLEB128 values
try test_read_ileb128_seq(i64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
@@ -257,39 +257,39 @@ test "deserialize signed LEB128" {
test "deserialize unsigned LEB128" {
// Truncated
- testing.expectError(error.EndOfStream, test_read_stream_uleb128(u64, "\x80"));
+ try testing.expectError(error.EndOfStream, test_read_stream_uleb128(u64, "\x80"));
// Overflow
- testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));
- testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));
- testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90"));
- testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
// Decode ULEB128
- testing.expect((try test_read_uleb128(u64, "\x00")) == 0);
- testing.expect((try test_read_uleb128(u64, "\x01")) == 1);
- testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);
- testing.expect((try test_read_uleb128(u64, "\x40")) == 64);
- testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);
- testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);
- testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);
- testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);
- testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);
- testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);
- testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);
- testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);
- testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);
+ try testing.expect((try test_read_uleb128(u64, "\x00")) == 0);
+ try testing.expect((try test_read_uleb128(u64, "\x01")) == 1);
+ try testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);
+ try testing.expect((try test_read_uleb128(u64, "\x40")) == 64);
+ try testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);
+ try testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);
+ try testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);
+ try testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);
+ try testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);
+ try testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);
// Decode ULEB128 with extra padding bytes
- testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);
- testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);
- testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);
- testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);
- testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);
- testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);
+ try testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);
+ try testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);
// Decode sequence of ULEB128 values
try test_read_uleb128_seq(u64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
@@ -326,19 +326,19 @@ fn test_write_leb128(value: anytype) !void {
// stream write
try writeStream(fbs.writer(), value);
const w1_pos = fbs.pos;
- testing.expect(w1_pos == bytes_needed);
+ try testing.expect(w1_pos == bytes_needed);
// stream read
fbs.pos = 0;
const sr = try readStream(T, fbs.reader());
- testing.expect(fbs.pos == w1_pos);
- testing.expect(sr == value);
+ try testing.expect(fbs.pos == w1_pos);
+ try testing.expect(sr == value);
// bigger type stream read
fbs.pos = 0;
const bsr = try readStream(B, fbs.reader());
- testing.expect(fbs.pos == w1_pos);
- testing.expect(bsr == value);
+ try testing.expect(fbs.pos == w1_pos);
+ try testing.expect(bsr == value);
}
test "serialize unsigned LEB128" {
diff --git a/lib/std/linked_list.zig b/lib/std/linked_list.zig
index 2a6b58c8c9..49006343c5 100644
--- a/lib/std/linked_list.zig
+++ b/lib/std/linked_list.zig
@@ -123,7 +123,7 @@ test "basic SinglyLinkedList test" {
const L = SinglyLinkedList(u32);
var list = L{};
- testing.expect(list.len() == 0);
+ try testing.expect(list.len() == 0);
var one = L.Node{ .data = 1 };
var two = L.Node{ .data = 2 };
@@ -137,14 +137,14 @@ test "basic SinglyLinkedList test" {
two.insertAfter(&three); // {1, 2, 3, 5}
three.insertAfter(&four); // {1, 2, 3, 4, 5}
- testing.expect(list.len() == 5);
+ try testing.expect(list.len() == 5);
// Traverse forwards.
{
var it = list.first;
var index: u32 = 1;
while (it) |node| : (it = node.next) {
- testing.expect(node.data == index);
+ try testing.expect(node.data == index);
index += 1;
}
}
@@ -153,9 +153,9 @@ test "basic SinglyLinkedList test" {
_ = list.remove(&five); // {2, 3, 4}
_ = two.removeNext(); // {2, 4}
- testing.expect(list.first.?.data == 2);
- testing.expect(list.first.?.next.?.data == 4);
- testing.expect(list.first.?.next.?.next == null);
+ try testing.expect(list.first.?.data == 2);
+ try testing.expect(list.first.?.next.?.data == 4);
+ try testing.expect(list.first.?.next.?.next == null);
}
/// A tail queue is headed by a pair of pointers, one to the head of the
@@ -344,7 +344,7 @@ test "basic TailQueue test" {
var it = list.first;
var index: u32 = 1;
while (it) |node| : (it = node.next) {
- testing.expect(node.data == index);
+ try testing.expect(node.data == index);
index += 1;
}
}
@@ -354,7 +354,7 @@ test "basic TailQueue test" {
var it = list.last;
var index: u32 = 1;
while (it) |node| : (it = node.prev) {
- testing.expect(node.data == (6 - index));
+ try testing.expect(node.data == (6 - index));
index += 1;
}
}
@@ -363,9 +363,9 @@ test "basic TailQueue test" {
var last = list.pop(); // {2, 3, 4}
list.remove(&three); // {2, 4}
- testing.expect(list.first.?.data == 2);
- testing.expect(list.last.?.data == 4);
- testing.expect(list.len == 2);
+ try testing.expect(list.first.?.data == 2);
+ try testing.expect(list.last.?.data == 4);
+ try testing.expect(list.len == 2);
}
test "TailQueue concatenation" {
@@ -387,18 +387,18 @@ test "TailQueue concatenation" {
list1.concatByMoving(&list2);
- testing.expect(list1.last == &five);
- testing.expect(list1.len == 5);
- testing.expect(list2.first == null);
- testing.expect(list2.last == null);
- testing.expect(list2.len == 0);
+ try testing.expect(list1.last == &five);
+ try testing.expect(list1.len == 5);
+ try testing.expect(list2.first == null);
+ try testing.expect(list2.last == null);
+ try testing.expect(list2.len == 0);
// Traverse forwards.
{
var it = list1.first;
var index: u32 = 1;
while (it) |node| : (it = node.next) {
- testing.expect(node.data == index);
+ try testing.expect(node.data == index);
index += 1;
}
}
@@ -408,7 +408,7 @@ test "TailQueue concatenation" {
var it = list1.last;
var index: u32 = 1;
while (it) |node| : (it = node.prev) {
- testing.expect(node.data == (6 - index));
+ try testing.expect(node.data == (6 - index));
index += 1;
}
}
@@ -421,7 +421,7 @@ test "TailQueue concatenation" {
var it = list2.first;
var index: u32 = 1;
while (it) |node| : (it = node.next) {
- testing.expect(node.data == index);
+ try testing.expect(node.data == index);
index += 1;
}
}
@@ -431,7 +431,7 @@ test "TailQueue concatenation" {
var it = list2.last;
var index: u32 = 1;
while (it) |node| : (it = node.prev) {
- testing.expect(node.data == (6 - index));
+ try testing.expect(node.data == (6 - index));
index += 1;
}
}
diff --git a/lib/std/math.zig b/lib/std/math.zig
index 558f541c00..c0881c92ae 100644
--- a/lib/std/math.zig
+++ b/lib/std/math.zig
@@ -177,20 +177,20 @@ test "approxEqAbs and approxEqRel" {
else => unreachable,
};
- testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));
- testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));
- testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));
- testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));
- testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value));
- testing.expect(!approxEqAbs(T, 1.0 + 2 * epsilon(T), 1.0, eps_value));
- testing.expect(approxEqAbs(T, 1.0 + 1 * epsilon(T), 1.0, eps_value));
- testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value));
- testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));
- testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));
- testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));
- testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value));
- testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));
- testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));
+ try testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));
+ try testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));
+ try testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));
+ try testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));
+ try testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value));
+ try testing.expect(!approxEqAbs(T, 1.0 + 2 * epsilon(T), 1.0, eps_value));
+ try testing.expect(approxEqAbs(T, 1.0 + 1 * epsilon(T), 1.0, eps_value));
+ try testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value));
+ try testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));
+ try testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));
+ try testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));
+ try testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value));
+ try testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));
+ try testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));
}
}
@@ -349,34 +349,34 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) {
}
test "math.min" {
- testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
+ try testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
{
var a: u16 = 999;
var b: u32 = 10;
var result = min(a, b);
- testing.expect(@TypeOf(result) == u16);
- testing.expect(result == 10);
+ try testing.expect(@TypeOf(result) == u16);
+ try testing.expect(result == 10);
}
{
var a: f64 = 10.34;
var b: f32 = 999.12;
var result = min(a, b);
- testing.expect(@TypeOf(result) == f64);
- testing.expect(result == 10.34);
+ try testing.expect(@TypeOf(result) == f64);
+ try testing.expect(result == 10.34);
}
{
var a: i8 = -127;
var b: i16 = -200;
var result = min(a, b);
- testing.expect(@TypeOf(result) == i16);
- testing.expect(result == -200);
+ try testing.expect(@TypeOf(result) == i16);
+ try testing.expect(result == -200);
}
{
const a = 10.34;
var b: f32 = 999.12;
var result = min(a, b);
- testing.expect(@TypeOf(result) == f32);
- testing.expect(result == 10.34);
+ try testing.expect(@TypeOf(result) == f32);
+ try testing.expect(result == 10.34);
}
}
@@ -385,7 +385,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) {
}
test "math.max" {
- testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
+ try testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
}
pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper) {
@@ -394,19 +394,19 @@ pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, u
}
test "math.clamp" {
// Within range
- testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1);
+ try testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1);
// Below
- testing.expect(std.math.clamp(@as(i32, -5), @as(i32, -4), @as(i32, 7)) == -4);
+ try testing.expect(std.math.clamp(@as(i32, -5), @as(i32, -4), @as(i32, 7)) == -4);
// Above
- testing.expect(std.math.clamp(@as(i32, 8), @as(i32, -4), @as(i32, 7)) == 7);
+ try testing.expect(std.math.clamp(@as(i32, 8), @as(i32, -4), @as(i32, 7)) == 7);
// Floating point
- testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0);
- testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5);
+ try testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0);
+ try testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5);
// Mix of comptime and non-comptime
var i: i32 = 1;
- testing.expect(std.math.clamp(i, 0, 1) == 1);
+ try testing.expect(std.math.clamp(i, 0, 1) == 1);
}
pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) {
@@ -461,17 +461,17 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
}
test "math.shl" {
- testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
- testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
- testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
- testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
- testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
- testing.expect(shl(u8, 0b11111111, 8) == 0);
- testing.expect(shl(u8, 0b11111111, 9) == 0);
- testing.expect(shl(u8, 0b11111111, -2) == 0b00111111);
- testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) << 1);
- testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) >> 1);
- testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
+ try testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
+ try testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
+ try testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
+ try testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
+ try testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
+ try testing.expect(shl(u8, 0b11111111, 8) == 0);
+ try testing.expect(shl(u8, 0b11111111, 9) == 0);
+ try testing.expect(shl(u8, 0b11111111, -2) == 0b00111111);
+ try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) << 1);
+ try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) >> 1);
+ try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
}
/// Shifts right. Overflowed bits are truncated.
@@ -501,17 +501,17 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
}
test "math.shr" {
- testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
- testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
- testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
- testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
- testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
- testing.expect(shr(u8, 0b11111111, 8) == 0);
- testing.expect(shr(u8, 0b11111111, 9) == 0);
- testing.expect(shr(u8, 0b11111111, -2) == 0b11111100);
- testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) >> 1);
- testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) << 1);
- testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
+ try testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
+ try testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
+ try testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
+ try testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
+ try testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
+ try testing.expect(shr(u8, 0b11111111, 8) == 0);
+ try testing.expect(shr(u8, 0b11111111, 9) == 0);
+ try testing.expect(shr(u8, 0b11111111, -2) == 0b11111100);
+ try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) >> 1);
+ try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) << 1);
+ try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
}
/// Rotates right. Only unsigned values can be rotated.
@@ -533,13 +533,13 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
}
test "math.rotr" {
- testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
- testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
- testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
- testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
- testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
- testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(usize, 1))[0] == @as(u32, 1) << 31);
- testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);
+ try testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
+ try testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
+ try testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
+ try testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
+ try testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
+ try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(usize, 1))[0] == @as(u32, 1) << 31);
+ try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);
}
/// Rotates left. Only unsigned values can be rotated.
@@ -561,13 +561,13 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
}
test "math.rotl" {
- testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
- testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
- testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
- testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
- testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
- testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1);
- testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);
+ try testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
+ try testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
+ try testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
+ try testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
+ try testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
+ try testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1);
+ try testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);
}
pub fn Log2Int(comptime T: type) type {
@@ -598,62 +598,62 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
}
test "math.IntFittingRange" {
- testing.expect(IntFittingRange(0, 0) == u0);
- testing.expect(IntFittingRange(0, 1) == u1);
- testing.expect(IntFittingRange(0, 2) == u2);
- testing.expect(IntFittingRange(0, 3) == u2);
- testing.expect(IntFittingRange(0, 4) == u3);
- testing.expect(IntFittingRange(0, 7) == u3);
- testing.expect(IntFittingRange(0, 8) == u4);
- testing.expect(IntFittingRange(0, 9) == u4);
- testing.expect(IntFittingRange(0, 15) == u4);
- testing.expect(IntFittingRange(0, 16) == u5);
- testing.expect(IntFittingRange(0, 17) == u5);
- testing.expect(IntFittingRange(0, 4095) == u12);
- testing.expect(IntFittingRange(2000, 4095) == u12);
- testing.expect(IntFittingRange(0, 4096) == u13);
- testing.expect(IntFittingRange(2000, 4096) == u13);
- testing.expect(IntFittingRange(0, 4097) == u13);
- testing.expect(IntFittingRange(2000, 4097) == u13);
- testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
- testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
+ try testing.expect(IntFittingRange(0, 0) == u0);
+ try testing.expect(IntFittingRange(0, 1) == u1);
+ try testing.expect(IntFittingRange(0, 2) == u2);
+ try testing.expect(IntFittingRange(0, 3) == u2);
+ try testing.expect(IntFittingRange(0, 4) == u3);
+ try testing.expect(IntFittingRange(0, 7) == u3);
+ try testing.expect(IntFittingRange(0, 8) == u4);
+ try testing.expect(IntFittingRange(0, 9) == u4);
+ try testing.expect(IntFittingRange(0, 15) == u4);
+ try testing.expect(IntFittingRange(0, 16) == u5);
+ try testing.expect(IntFittingRange(0, 17) == u5);
+ try testing.expect(IntFittingRange(0, 4095) == u12);
+ try testing.expect(IntFittingRange(2000, 4095) == u12);
+ try testing.expect(IntFittingRange(0, 4096) == u13);
+ try testing.expect(IntFittingRange(2000, 4096) == u13);
+ try testing.expect(IntFittingRange(0, 4097) == u13);
+ try testing.expect(IntFittingRange(2000, 4097) == u13);
+ try testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
+ try testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
- testing.expect(IntFittingRange(-1, -1) == i1);
- testing.expect(IntFittingRange(-1, 0) == i1);
- testing.expect(IntFittingRange(-1, 1) == i2);
- testing.expect(IntFittingRange(-2, -2) == i2);
- testing.expect(IntFittingRange(-2, -1) == i2);
- testing.expect(IntFittingRange(-2, 0) == i2);
- testing.expect(IntFittingRange(-2, 1) == i2);
- testing.expect(IntFittingRange(-2, 2) == i3);
- testing.expect(IntFittingRange(-1, 2) == i3);
- testing.expect(IntFittingRange(-1, 3) == i3);
- testing.expect(IntFittingRange(-1, 4) == i4);
- testing.expect(IntFittingRange(-1, 7) == i4);
- testing.expect(IntFittingRange(-1, 8) == i5);
- testing.expect(IntFittingRange(-1, 9) == i5);
- testing.expect(IntFittingRange(-1, 15) == i5);
- testing.expect(IntFittingRange(-1, 16) == i6);
- testing.expect(IntFittingRange(-1, 17) == i6);
- testing.expect(IntFittingRange(-1, 4095) == i13);
- testing.expect(IntFittingRange(-4096, 4095) == i13);
- testing.expect(IntFittingRange(-1, 4096) == i14);
- testing.expect(IntFittingRange(-4097, 4095) == i14);
- testing.expect(IntFittingRange(-1, 4097) == i14);
- testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
- testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
+ try testing.expect(IntFittingRange(-1, -1) == i1);
+ try testing.expect(IntFittingRange(-1, 0) == i1);
+ try testing.expect(IntFittingRange(-1, 1) == i2);
+ try testing.expect(IntFittingRange(-2, -2) == i2);
+ try testing.expect(IntFittingRange(-2, -1) == i2);
+ try testing.expect(IntFittingRange(-2, 0) == i2);
+ try testing.expect(IntFittingRange(-2, 1) == i2);
+ try testing.expect(IntFittingRange(-2, 2) == i3);
+ try testing.expect(IntFittingRange(-1, 2) == i3);
+ try testing.expect(IntFittingRange(-1, 3) == i3);
+ try testing.expect(IntFittingRange(-1, 4) == i4);
+ try testing.expect(IntFittingRange(-1, 7) == i4);
+ try testing.expect(IntFittingRange(-1, 8) == i5);
+ try testing.expect(IntFittingRange(-1, 9) == i5);
+ try testing.expect(IntFittingRange(-1, 15) == i5);
+ try testing.expect(IntFittingRange(-1, 16) == i6);
+ try testing.expect(IntFittingRange(-1, 17) == i6);
+ try testing.expect(IntFittingRange(-1, 4095) == i13);
+ try testing.expect(IntFittingRange(-4096, 4095) == i13);
+ try testing.expect(IntFittingRange(-1, 4096) == i14);
+ try testing.expect(IntFittingRange(-4097, 4095) == i14);
+ try testing.expect(IntFittingRange(-1, 4097) == i14);
+ try testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
+ try testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
}
test "math overflow functions" {
- testOverflow();
- comptime testOverflow();
+ try testOverflow();
+ comptime try testOverflow();
}
-fn testOverflow() void {
- testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
- testing.expect((add(i32, 3, 4) catch unreachable) == 7);
- testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
- testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
+fn testOverflow() !void {
+ try testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
+ try testing.expect((add(i32, 3, 4) catch unreachable) == 7);
+ try testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
+ try testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
}
pub fn absInt(x: anytype) !@TypeOf(x) {
@@ -670,23 +670,23 @@ pub fn absInt(x: anytype) !@TypeOf(x) {
}
test "math.absInt" {
- testAbsInt();
- comptime testAbsInt();
+ try testAbsInt();
+ comptime try testAbsInt();
}
-fn testAbsInt() void {
- testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
- testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
+fn testAbsInt() !void {
+ try testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
+ try testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
}
pub const absFloat = fabs;
test "math.absFloat" {
- testAbsFloat();
- comptime testAbsFloat();
+ try testAbsFloat();
+ comptime try testAbsFloat();
}
-fn testAbsFloat() void {
- testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
- testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
+fn testAbsFloat() !void {
+ try testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
+ try testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
}
pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
@@ -697,17 +697,17 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.divTrunc" {
- testDivTrunc();
- comptime testDivTrunc();
+ try testDivTrunc();
+ comptime try testDivTrunc();
}
-fn testDivTrunc() void {
- testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
- testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
- testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
- testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
+fn testDivTrunc() !void {
+ try testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
+ try testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
+ try testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
+ try testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
- testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
- testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
+ try testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
+ try testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
}
pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
@@ -718,17 +718,17 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.divFloor" {
- testDivFloor();
- comptime testDivFloor();
+ try testDivFloor();
+ comptime try testDivFloor();
}
-fn testDivFloor() void {
- testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
- testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
- testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
- testing.expectError(error.Overflow, divFloor(i8, -128, -1));
+fn testDivFloor() !void {
+ try testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
+ try testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
+ try testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
+ try testing.expectError(error.Overflow, divFloor(i8, -128, -1));
- testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
- testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
+ try testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
+ try testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
}
pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
@@ -752,36 +752,36 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.divCeil" {
- testDivCeil();
- comptime testDivCeil();
+ try testDivCeil();
+ comptime try testDivCeil();
}
-fn testDivCeil() void {
- testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);
- testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable);
- testing.expectEqual(@as(i32, -1), divCeil(i32, 5, -3) catch unreachable);
- testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);
- testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);
- testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);
- testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));
- testing.expectError(error.Overflow, divCeil(i8, -128, -1));
+fn testDivCeil() !void {
+ try testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);
+ try testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable);
+ try testing.expectEqual(@as(i32, -1), divCeil(i32, 5, -3) catch unreachable);
+ try testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);
+ try testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);
+ try testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);
+ try testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));
+ try testing.expectError(error.Overflow, divCeil(i8, -128, -1));
- testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable);
- testing.expectEqual(@as(f32, 2.0), divCeil(f32, 5.0, 3.0) catch unreachable);
- testing.expectEqual(@as(f32, -1.0), divCeil(f32, -5.0, 3.0) catch unreachable);
- testing.expectEqual(@as(f32, -1.0), divCeil(f32, 5.0, -3.0) catch unreachable);
- testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable);
+ try testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable);
+ try testing.expectEqual(@as(f32, 2.0), divCeil(f32, 5.0, 3.0) catch unreachable);
+ try testing.expectEqual(@as(f32, -1.0), divCeil(f32, -5.0, 3.0) catch unreachable);
+ try testing.expectEqual(@as(f32, -1.0), divCeil(f32, 5.0, -3.0) catch unreachable);
+ try testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable);
- testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);
- testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);
- testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);
- testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);
- testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));
+ try testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);
+ try testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);
+ try testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);
+ try testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);
+ try testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));
- testing.expectEqual(6.0, divCeil(comptime_float, 23.0, 4.0) catch unreachable);
- testing.expectEqual(-5.0, divCeil(comptime_float, -23.0, 4.0) catch unreachable);
- testing.expectEqual(-5.0, divCeil(comptime_float, 23.0, -4.0) catch unreachable);
- testing.expectEqual(6.0, divCeil(comptime_float, -23.0, -4.0) catch unreachable);
- testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0));
+ try testing.expectEqual(6.0, divCeil(comptime_float, 23.0, 4.0) catch unreachable);
+ try testing.expectEqual(-5.0, divCeil(comptime_float, -23.0, 4.0) catch unreachable);
+ try testing.expectEqual(-5.0, divCeil(comptime_float, 23.0, -4.0) catch unreachable);
+ try testing.expectEqual(6.0, divCeil(comptime_float, -23.0, -4.0) catch unreachable);
+ try testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0));
}
pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
@@ -794,19 +794,19 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.divExact" {
- testDivExact();
- comptime testDivExact();
+ try testDivExact();
+ comptime try testDivExact();
}
-fn testDivExact() void {
- testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
- testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
- testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
- testing.expectError(error.Overflow, divExact(i8, -128, -1));
- testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
+fn testDivExact() !void {
+ try testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
+ try testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
+ try testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
+ try testing.expectError(error.Overflow, divExact(i8, -128, -1));
+ try testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
- testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
- testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
- testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
+ try testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
+ try testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
+ try testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
}
pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
@@ -817,19 +817,19 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.mod" {
- testMod();
- comptime testMod();
+ try testMod();
+ comptime try testMod();
}
-fn testMod() void {
- testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
- testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
- testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
- testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
+fn testMod() !void {
+ try testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
+ try testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
+ try testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
+ try testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
- testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
- testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
- testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
- testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
+ try testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
+ try testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
+ try testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
+ try testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
}
pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
@@ -840,19 +840,19 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.rem" {
- testRem();
- comptime testRem();
+ try testRem();
+ comptime try testRem();
}
-fn testRem() void {
- testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
- testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
- testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
- testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
+fn testRem() !void {
+ try testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
+ try testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
+ try testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
+ try testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
- testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
- testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
- testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
- testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
+ try testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
+ try testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
+ try testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
+ try testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
}
/// Returns the absolute value of the integer parameter.
@@ -883,11 +883,11 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
}
test "math.absCast" {
- testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));
- testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));
- testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));
- testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));
- testing.expectEqual(999, absCast(-999));
+ try testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));
+ try testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));
+ try testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));
+ try testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));
+ try testing.expectEqual(999, absCast(-999));
}
/// Returns the negation of the integer parameter.
@@ -904,13 +904,13 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x
}
test "math.negateCast" {
- testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
- testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
+ try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
+ try testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
- testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
- testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
+ try testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
+ try testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
- testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
+ try testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
}
/// Cast an integer to a different integer type. If the value doesn't fit,
@@ -929,13 +929,13 @@ pub fn cast(comptime T: type, x: anytype) (error{Overflow}!T) {
}
test "math.cast" {
- testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
- testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
- testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
- testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
+ try testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
+ try testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
+ try testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
+ try testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
- testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
- testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
+ try testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
+ try testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
}
pub const AlignCastError = error{UnalignedMemory};
@@ -966,17 +966,17 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {
}
test "math.floorPowerOfTwo" {
- testFloorPowerOfTwo();
- comptime testFloorPowerOfTwo();
+ try testFloorPowerOfTwo();
+ comptime try testFloorPowerOfTwo();
}
-fn testFloorPowerOfTwo() void {
- testing.expect(floorPowerOfTwo(u32, 63) == 32);
- testing.expect(floorPowerOfTwo(u32, 64) == 64);
- testing.expect(floorPowerOfTwo(u32, 65) == 64);
- testing.expect(floorPowerOfTwo(u4, 7) == 4);
- testing.expect(floorPowerOfTwo(u4, 8) == 8);
- testing.expect(floorPowerOfTwo(u4, 9) == 8);
+fn testFloorPowerOfTwo() !void {
+ try testing.expect(floorPowerOfTwo(u32, 63) == 32);
+ try testing.expect(floorPowerOfTwo(u32, 64) == 64);
+ try testing.expect(floorPowerOfTwo(u32, 65) == 64);
+ try testing.expect(floorPowerOfTwo(u4, 7) == 4);
+ try testing.expect(floorPowerOfTwo(u4, 8) == 8);
+ try testing.expect(floorPowerOfTwo(u4, 9) == 8);
}
/// Returns the next power of two (if the value is not already a power of two).
@@ -1012,20 +1012,20 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T {
}
test "math.ceilPowerOfTwoPromote" {
- testCeilPowerOfTwoPromote();
- comptime testCeilPowerOfTwoPromote();
+ try testCeilPowerOfTwoPromote();
+ comptime try testCeilPowerOfTwoPromote();
}
-fn testCeilPowerOfTwoPromote() void {
- testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
- testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
- testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
- testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
- testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
- testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
- testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
- testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
- testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
+fn testCeilPowerOfTwoPromote() !void {
+ try testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
+ try testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
+ try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
+ try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
+ try testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
+ try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
+ try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
+ try testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
+ try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
}
test "math.ceilPowerOfTwo" {
@@ -1034,15 +1034,15 @@ test "math.ceilPowerOfTwo" {
}
fn testCeilPowerOfTwo() !void {
- testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
- testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
- testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
- testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
- testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
- testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
- testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
- testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
- testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
+ try testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
+ try testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
+ try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
+ try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
+ try testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
+ try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
+ try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
+ try testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
+ try testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
}
pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
@@ -1059,16 +1059,16 @@ pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
}
test "std.math.log2_int_ceil" {
- testing.expect(log2_int_ceil(u32, 1) == 0);
- testing.expect(log2_int_ceil(u32, 2) == 1);
- testing.expect(log2_int_ceil(u32, 3) == 2);
- testing.expect(log2_int_ceil(u32, 4) == 2);
- testing.expect(log2_int_ceil(u32, 5) == 3);
- testing.expect(log2_int_ceil(u32, 6) == 3);
- testing.expect(log2_int_ceil(u32, 7) == 3);
- testing.expect(log2_int_ceil(u32, 8) == 3);
- testing.expect(log2_int_ceil(u32, 9) == 4);
- testing.expect(log2_int_ceil(u32, 10) == 4);
+ try testing.expect(log2_int_ceil(u32, 1) == 0);
+ try testing.expect(log2_int_ceil(u32, 2) == 1);
+ try testing.expect(log2_int_ceil(u32, 3) == 2);
+ try testing.expect(log2_int_ceil(u32, 4) == 2);
+ try testing.expect(log2_int_ceil(u32, 5) == 3);
+ try testing.expect(log2_int_ceil(u32, 6) == 3);
+ try testing.expect(log2_int_ceil(u32, 7) == 3);
+ try testing.expect(log2_int_ceil(u32, 8) == 3);
+ try testing.expect(log2_int_ceil(u32, 9) == 4);
+ try testing.expect(log2_int_ceil(u32, 10) == 4);
}
///Cast a value to a different type. If the value doesn't fit in, or can't be perfectly represented by,
@@ -1112,15 +1112,15 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
}
test "math.lossyCast" {
- testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
- testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
- testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));
+ try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
+ try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
+ try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));
}
test "math.f64_min" {
const f64_min_u64 = 0x0010000000000000;
const fmin: f64 = f64_min;
- testing.expect(@bitCast(u64, fmin) == f64_min_u64);
+ try testing.expect(@bitCast(u64, fmin) == f64_min_u64);
}
pub fn maxInt(comptime T: type) comptime_int {
@@ -1139,45 +1139,45 @@ pub fn minInt(comptime T: type) comptime_int {
}
test "minInt and maxInt" {
- testing.expect(maxInt(u0) == 0);
- testing.expect(maxInt(u1) == 1);
- testing.expect(maxInt(u8) == 255);
- testing.expect(maxInt(u16) == 65535);
- testing.expect(maxInt(u32) == 4294967295);
- testing.expect(maxInt(u64) == 18446744073709551615);
- testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
+ try testing.expect(maxInt(u0) == 0);
+ try testing.expect(maxInt(u1) == 1);
+ try testing.expect(maxInt(u8) == 255);
+ try testing.expect(maxInt(u16) == 65535);
+ try testing.expect(maxInt(u32) == 4294967295);
+ try testing.expect(maxInt(u64) == 18446744073709551615);
+ try testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
- testing.expect(maxInt(i0) == 0);
- testing.expect(maxInt(i1) == 0);
- testing.expect(maxInt(i8) == 127);
- testing.expect(maxInt(i16) == 32767);
- testing.expect(maxInt(i32) == 2147483647);
- testing.expect(maxInt(i63) == 4611686018427387903);
- testing.expect(maxInt(i64) == 9223372036854775807);
- testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);
+ try testing.expect(maxInt(i0) == 0);
+ try testing.expect(maxInt(i1) == 0);
+ try testing.expect(maxInt(i8) == 127);
+ try testing.expect(maxInt(i16) == 32767);
+ try testing.expect(maxInt(i32) == 2147483647);
+ try testing.expect(maxInt(i63) == 4611686018427387903);
+ try testing.expect(maxInt(i64) == 9223372036854775807);
+ try testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);
- testing.expect(minInt(u0) == 0);
- testing.expect(minInt(u1) == 0);
- testing.expect(minInt(u8) == 0);
- testing.expect(minInt(u16) == 0);
- testing.expect(minInt(u32) == 0);
- testing.expect(minInt(u63) == 0);
- testing.expect(minInt(u64) == 0);
- testing.expect(minInt(u128) == 0);
+ try testing.expect(minInt(u0) == 0);
+ try testing.expect(minInt(u1) == 0);
+ try testing.expect(minInt(u8) == 0);
+ try testing.expect(minInt(u16) == 0);
+ try testing.expect(minInt(u32) == 0);
+ try testing.expect(minInt(u63) == 0);
+ try testing.expect(minInt(u64) == 0);
+ try testing.expect(minInt(u128) == 0);
- testing.expect(minInt(i0) == 0);
- testing.expect(minInt(i1) == -1);
- testing.expect(minInt(i8) == -128);
- testing.expect(minInt(i16) == -32768);
- testing.expect(minInt(i32) == -2147483648);
- testing.expect(minInt(i63) == -4611686018427387904);
- testing.expect(minInt(i64) == -9223372036854775808);
- testing.expect(minInt(i128) == -170141183460469231731687303715884105728);
+ try testing.expect(minInt(i0) == 0);
+ try testing.expect(minInt(i1) == -1);
+ try testing.expect(minInt(i8) == -128);
+ try testing.expect(minInt(i16) == -32768);
+ try testing.expect(minInt(i32) == -2147483648);
+ try testing.expect(minInt(i63) == -4611686018427387904);
+ try testing.expect(minInt(i64) == -9223372036854775808);
+ try testing.expect(minInt(i128) == -170141183460469231731687303715884105728);
}
test "max value type" {
const x: u32 = maxInt(i32);
- testing.expect(x == 2147483647);
+ try testing.expect(x == 2147483647);
}
pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits * 2) {
@@ -1186,9 +1186,9 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signe
}
test "math.mulWide" {
- testing.expect(mulWide(u8, 5, 5) == 25);
- testing.expect(mulWide(i8, 5, -5) == -25);
- testing.expect(mulWide(u8, 100, 100) == 10000);
+ try testing.expect(mulWide(u8, 5, 5) == 25);
+ try testing.expect(mulWide(i8, 5, -5) == -25);
+ try testing.expect(mulWide(u8, 100, 100) == 10000);
}
/// See also `CompareOperator`.
@@ -1284,51 +1284,51 @@ pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool {
}
test "compare between signed and unsigned" {
- testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));
- testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));
- testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));
- testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));
- testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));
- testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));
- testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));
- testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));
- testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));
- testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));
- testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));
- testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
- testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
- testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));
- testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));
- testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
- testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
+ try testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));
+ try testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));
+ try testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));
+ try testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));
+ try testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));
+ try testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));
+ try testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));
+ try testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));
+ try testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));
+ try testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));
+ try testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));
+ try testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
+ try testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
+ try testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));
+ try testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));
+ try testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
+ try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
}
test "order" {
- testing.expect(order(0, 0) == .eq);
- testing.expect(order(1, 0) == .gt);
- testing.expect(order(-1, 0) == .lt);
+ try testing.expect(order(0, 0) == .eq);
+ try testing.expect(order(1, 0) == .gt);
+ try testing.expect(order(-1, 0) == .lt);
}
test "order.invert" {
- testing.expect(Order.invert(order(0, 0)) == .eq);
- testing.expect(Order.invert(order(1, 0)) == .lt);
- testing.expect(Order.invert(order(-1, 0)) == .gt);
+ try testing.expect(Order.invert(order(0, 0)) == .eq);
+ try testing.expect(Order.invert(order(1, 0)) == .lt);
+ try testing.expect(Order.invert(order(-1, 0)) == .gt);
}
test "order.compare" {
- testing.expect(order(-1, 0).compare(.lt));
- testing.expect(order(-1, 0).compare(.lte));
- testing.expect(order(0, 0).compare(.lte));
- testing.expect(order(0, 0).compare(.eq));
- testing.expect(order(0, 0).compare(.gte));
- testing.expect(order(1, 0).compare(.gte));
- testing.expect(order(1, 0).compare(.gt));
- testing.expect(order(1, 0).compare(.neq));
+ try testing.expect(order(-1, 0).compare(.lt));
+ try testing.expect(order(-1, 0).compare(.lte));
+ try testing.expect(order(0, 0).compare(.lte));
+ try testing.expect(order(0, 0).compare(.eq));
+ try testing.expect(order(0, 0).compare(.gte));
+ try testing.expect(order(1, 0).compare(.gte));
+ try testing.expect(order(1, 0).compare(.gt));
+ try testing.expect(order(1, 0).compare(.neq));
}
test "math.comptime" {
comptime const v = sin(@as(f32, 1)) + ln(@as(f32, 5));
- testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5)));
+ try testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5)));
}
/// Returns a mask of all ones if value is true,
@@ -1354,26 +1354,26 @@ pub fn boolMask(comptime MaskInt: type, value: bool) callconv(.Inline) MaskInt {
test "boolMask" {
const runTest = struct {
- fn runTest() void {
- testing.expectEqual(@as(u1, 0), boolMask(u1, false));
- testing.expectEqual(@as(u1, 1), boolMask(u1, true));
+ fn runTest() !void {
+ try testing.expectEqual(@as(u1, 0), boolMask(u1, false));
+ try testing.expectEqual(@as(u1, 1), boolMask(u1, true));
- testing.expectEqual(@as(i1, 0), boolMask(i1, false));
- testing.expectEqual(@as(i1, -1), boolMask(i1, true));
+ try testing.expectEqual(@as(i1, 0), boolMask(i1, false));
+ try testing.expectEqual(@as(i1, -1), boolMask(i1, true));
- testing.expectEqual(@as(u13, 0), boolMask(u13, false));
- testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));
+ try testing.expectEqual(@as(u13, 0), boolMask(u13, false));
+ try testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));
- testing.expectEqual(@as(i13, 0), boolMask(i13, false));
- testing.expectEqual(@as(i13, -1), boolMask(i13, true));
+ try testing.expectEqual(@as(i13, 0), boolMask(i13, false));
+ try testing.expectEqual(@as(i13, -1), boolMask(i13, true));
- testing.expectEqual(@as(u32, 0), boolMask(u32, false));
- testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));
+ try testing.expectEqual(@as(u32, 0), boolMask(u32, false));
+ try testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));
- testing.expectEqual(@as(i32, 0), boolMask(i32, false));
- testing.expectEqual(@as(i32, -1), boolMask(i32, true));
+ try testing.expectEqual(@as(i32, 0), boolMask(i32, false));
+ try testing.expectEqual(@as(i32, -1), boolMask(i32, true));
}
}.runTest;
- runTest();
- comptime runTest();
+ try runTest();
+ comptime try runTest();
}
diff --git a/lib/std/math/acos.zig b/lib/std/math/acos.zig
index 7f3d4bfe9b..5e3a289691 100644
--- a/lib/std/math/acos.zig
+++ b/lib/std/math/acos.zig
@@ -154,38 +154,38 @@ fn acos64(x: f64) f64 {
}
test "math.acos" {
- expect(acos(@as(f32, 0.0)) == acos32(0.0));
- expect(acos(@as(f64, 0.0)) == acos64(0.0));
+ try expect(acos(@as(f32, 0.0)) == acos32(0.0));
+ try expect(acos(@as(f64, 0.0)) == acos64(0.0));
}
test "math.acos32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
- expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));
- expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));
- expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));
- expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));
- expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
}
test "math.acos64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
- expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));
- expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));
- expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));
- expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));
- expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));
}
test "math.acos32.special" {
- expect(math.isNan(acos32(-2)));
- expect(math.isNan(acos32(1.5)));
+ try expect(math.isNan(acos32(-2)));
+ try expect(math.isNan(acos32(1.5)));
}
test "math.acos64.special" {
- expect(math.isNan(acos64(-2)));
- expect(math.isNan(acos64(1.5)));
+ try expect(math.isNan(acos64(-2)));
+ try expect(math.isNan(acos64(1.5)));
}
diff --git a/lib/std/math/acosh.zig b/lib/std/math/acosh.zig
index 0993989d47..078e7f5e6e 100644
--- a/lib/std/math/acosh.zig
+++ b/lib/std/math/acosh.zig
@@ -66,34 +66,34 @@ fn acosh64(x: f64) f64 {
}
test "math.acosh" {
- expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
- expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
+ try expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
+ try expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
}
test "math.acosh32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
- expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));
- expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));
- expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
+ try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
+ try expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));
+ try expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));
+ try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
}
test "math.acosh64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
- expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));
- expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));
- expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));
+ try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
+ try expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));
+ try expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));
+ try expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));
}
test "math.acosh32.special" {
- expect(math.isNan(acosh32(math.nan(f32))));
- expect(math.isSignalNan(acosh32(0.5)));
+ try expect(math.isNan(acosh32(math.nan(f32))));
+ try expect(math.isSignalNan(acosh32(0.5)));
}
test "math.acosh64.special" {
- expect(math.isNan(acosh64(math.nan(f64))));
- expect(math.isSignalNan(acosh64(0.5)));
+ try expect(math.isNan(acosh64(math.nan(f64))));
+ try expect(math.isSignalNan(acosh64(0.5)));
}
diff --git a/lib/std/math/asin.zig b/lib/std/math/asin.zig
index c4fca95c10..16560a12cd 100644
--- a/lib/std/math/asin.zig
+++ b/lib/std/math/asin.zig
@@ -147,42 +147,42 @@ fn asin64(x: f64) f64 {
}
test "math.asin" {
- expect(asin(@as(f32, 0.0)) == asin32(0.0));
- expect(asin(@as(f64, 0.0)) == asin64(0.0));
+ try expect(asin(@as(f32, 0.0)) == asin32(0.0));
+ try expect(asin(@as(f64, 0.0)) == asin64(0.0));
}
test "math.asin32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));
- expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));
- expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));
- expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));
- expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
}
test "math.asin64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));
- expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));
- expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));
- expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));
- expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));
}
test "math.asin32.special" {
- expect(asin32(0.0) == 0.0);
- expect(asin32(-0.0) == -0.0);
- expect(math.isNan(asin32(-2)));
- expect(math.isNan(asin32(1.5)));
+ try expect(asin32(0.0) == 0.0);
+ try expect(asin32(-0.0) == -0.0);
+ try expect(math.isNan(asin32(-2)));
+ try expect(math.isNan(asin32(1.5)));
}
test "math.asin64.special" {
- expect(asin64(0.0) == 0.0);
- expect(asin64(-0.0) == -0.0);
- expect(math.isNan(asin64(-2)));
- expect(math.isNan(asin64(1.5)));
+ try expect(asin64(0.0) == 0.0);
+ try expect(asin64(-0.0) == -0.0);
+ try expect(math.isNan(asin64(-2)));
+ try expect(math.isNan(asin64(1.5)));
}
diff --git a/lib/std/math/asinh.zig b/lib/std/math/asinh.zig
index a2c8ee3583..2855a73eb8 100644
--- a/lib/std/math/asinh.zig
+++ b/lib/std/math/asinh.zig
@@ -94,46 +94,46 @@ fn asinh64(x: f64) f64 {
}
test "math.asinh" {
- expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
- expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
+ try expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
+ try expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
}
test "math.asinh32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));
- expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));
- expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));
- expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));
- expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));
- expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
}
test "math.asinh64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));
- expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));
- expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));
- expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));
- expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));
- expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));
}
test "math.asinh32.special" {
- expect(asinh32(0.0) == 0.0);
- expect(asinh32(-0.0) == -0.0);
- expect(math.isPositiveInf(asinh32(math.inf(f32))));
- expect(math.isNegativeInf(asinh32(-math.inf(f32))));
- expect(math.isNan(asinh32(math.nan(f32))));
+ try expect(asinh32(0.0) == 0.0);
+ try expect(asinh32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(asinh32(math.inf(f32))));
+ try expect(math.isNegativeInf(asinh32(-math.inf(f32))));
+ try expect(math.isNan(asinh32(math.nan(f32))));
}
test "math.asinh64.special" {
- expect(asinh64(0.0) == 0.0);
- expect(asinh64(-0.0) == -0.0);
- expect(math.isPositiveInf(asinh64(math.inf(f64))));
- expect(math.isNegativeInf(asinh64(-math.inf(f64))));
- expect(math.isNan(asinh64(math.nan(f64))));
+ try expect(asinh64(0.0) == 0.0);
+ try expect(asinh64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(asinh64(math.inf(f64))));
+ try expect(math.isNegativeInf(asinh64(-math.inf(f64))));
+ try expect(math.isNan(asinh64(math.nan(f64))));
}
diff --git a/lib/std/math/atan.zig b/lib/std/math/atan.zig
index 59dda307cc..bbfaa22b13 100644
--- a/lib/std/math/atan.zig
+++ b/lib/std/math/atan.zig
@@ -217,44 +217,44 @@ fn atan64(x_: f64) f64 {
}
test "math.atan" {
- expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
- expect(atan(@as(f64, 0.2)) == atan64(0.2));
+ try expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
+ try expect(atan(@as(f64, 0.2)) == atan64(0.2));
}
test "math.atan32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
- expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));
- expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));
- expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));
- expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
}
test "math.atan64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
- expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));
- expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));
- expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));
- expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));
}
test "math.atan32.special" {
const epsilon = 0.000001;
- expect(atan32(0.0) == 0.0);
- expect(atan32(-0.0) == -0.0);
- expect(math.approxEqAbs(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
+ try expect(atan32(0.0) == 0.0);
+ try expect(atan32(-0.0) == -0.0);
+ try expect(math.approxEqAbs(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
}
test "math.atan64.special" {
const epsilon = 0.000001;
- expect(atan64(0.0) == 0.0);
- expect(atan64(-0.0) == -0.0);
- expect(math.approxEqAbs(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));
+ try expect(atan64(0.0) == 0.0);
+ try expect(atan64(-0.0) == -0.0);
+ try expect(math.approxEqAbs(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));
}
diff --git a/lib/std/math/atan2.zig b/lib/std/math/atan2.zig
index 3ecabe9e31..21f6b95b8b 100644
--- a/lib/std/math/atan2.zig
+++ b/lib/std/math/atan2.zig
@@ -217,78 +217,78 @@ fn atan2_64(y: f64, x: f64) f64 {
}
test "math.atan2" {
- expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));
- expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
+ try expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));
+ try expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
}
test "math.atan2_32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(0.2, 0.2), 0.785398, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(0.2, -0.2), 2.356194, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(0.34, -0.4), 2.437099, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(0.2, 0.2), 0.785398, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(0.2, -0.2), 2.356194, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(0.34, -0.4), 2.437099, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
}
test "math.atan2_64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(0.2, 0.2), 0.785398, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(0.2, -0.2), 2.356194, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(0.34, -0.4), 2.437099, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(0.2, 0.2), 0.785398, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(0.2, -0.2), 2.356194, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(0.34, -0.4), 2.437099, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
}
test "math.atan2_32.special" {
const epsilon = 0.000001;
- expect(math.isNan(atan2_32(1.0, math.nan(f32))));
- expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
- expect(atan2_32(0.0, 5.0) == 0.0);
- expect(atan2_32(-0.0, 5.0) == -0.0);
- expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
+ try expect(math.isNan(atan2_32(1.0, math.nan(f32))));
+ try expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
+ try expect(atan2_32(0.0, 5.0) == 0.0);
+ try expect(atan2_32(-0.0, 5.0) == -0.0);
+ try expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
//expect(math.approxEqAbs(f32, atan2_32(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?
- expect(math.approxEqAbs(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon));
- expect(atan2_32(1.0, math.inf(f32)) == 0.0);
- expect(math.approxEqAbs(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon));
+ try expect(atan2_32(1.0, math.inf(f32)) == 0.0);
+ try expect(math.approxEqAbs(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
}
test "math.atan2_64.special" {
const epsilon = 0.000001;
- expect(math.isNan(atan2_64(1.0, math.nan(f64))));
- expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
- expect(atan2_64(0.0, 5.0) == 0.0);
- expect(atan2_64(-0.0, 5.0) == -0.0);
- expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
+ try expect(math.isNan(atan2_64(1.0, math.nan(f64))));
+ try expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
+ try expect(atan2_64(0.0, 5.0) == 0.0);
+ try expect(atan2_64(-0.0, 5.0) == -0.0);
+ try expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
//expect(math.approxEqAbs(f64, atan2_64(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?
- expect(math.approxEqAbs(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon));
- expect(atan2_64(1.0, math.inf(f64)) == 0.0);
- expect(math.approxEqAbs(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon));
+ try expect(atan2_64(1.0, math.inf(f64)) == 0.0);
+ try expect(math.approxEqAbs(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));
}
diff --git a/lib/std/math/atanh.zig b/lib/std/math/atanh.zig
index 87d92a9fa5..68824cea7a 100644
--- a/lib/std/math/atanh.zig
+++ b/lib/std/math/atanh.zig
@@ -89,38 +89,38 @@ fn atanh_64(x: f64) f64 {
}
test "math.atanh" {
- expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
- expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
+ try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
+ try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
}
test "math.atanh_32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));
- expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
+ try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));
+ try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
}
test "math.atanh_64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));
- expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));
+ try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));
+ try expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));
}
test "math.atanh32.special" {
- expect(math.isPositiveInf(atanh_32(1)));
- expect(math.isNegativeInf(atanh_32(-1)));
- expect(math.isSignalNan(atanh_32(1.5)));
- expect(math.isSignalNan(atanh_32(-1.5)));
- expect(math.isNan(atanh_32(math.nan(f32))));
+ try expect(math.isPositiveInf(atanh_32(1)));
+ try expect(math.isNegativeInf(atanh_32(-1)));
+ try expect(math.isSignalNan(atanh_32(1.5)));
+ try expect(math.isSignalNan(atanh_32(-1.5)));
+ try expect(math.isNan(atanh_32(math.nan(f32))));
}
test "math.atanh64.special" {
- expect(math.isPositiveInf(atanh_64(1)));
- expect(math.isNegativeInf(atanh_64(-1)));
- expect(math.isSignalNan(atanh_64(1.5)));
- expect(math.isSignalNan(atanh_64(-1.5)));
- expect(math.isNan(atanh_64(math.nan(f64))));
+ try expect(math.isPositiveInf(atanh_64(1)));
+ try expect(math.isNegativeInf(atanh_64(-1)));
+ try expect(math.isSignalNan(atanh_64(1.5)));
+ try expect(math.isSignalNan(atanh_64(-1.5)));
+ try expect(math.isNan(atanh_64(math.nan(f64))));
}
diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig
index 179e55ff69..93291bf217 100644
--- a/lib/std/math/big/int_test.zig
+++ b/lib/std/math/big/int_test.zig
@@ -30,7 +30,7 @@ test "big.int comptime_int set" {
const result = @as(Limb, s & maxInt(Limb));
s >>= @typeInfo(Limb).Int.bits / 2;
s >>= @typeInfo(Limb).Int.bits / 2;
- testing.expect(a.limbs[i] == result);
+ try testing.expect(a.limbs[i] == result);
}
}
@@ -38,37 +38,37 @@ test "big.int comptime_int set negative" {
var a = try Managed.initSet(testing.allocator, -10);
defer a.deinit();
- testing.expect(a.limbs[0] == 10);
- testing.expect(a.isPositive() == false);
+ try testing.expect(a.limbs[0] == 10);
+ try testing.expect(a.isPositive() == false);
}
test "big.int int set unaligned small" {
var a = try Managed.initSet(testing.allocator, @as(u7, 45));
defer a.deinit();
- testing.expect(a.limbs[0] == 45);
- testing.expect(a.isPositive() == true);
+ try testing.expect(a.limbs[0] == 45);
+ try testing.expect(a.isPositive() == true);
}
test "big.int comptime_int to" {
var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
defer a.deinit();
- testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
+ try testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
}
test "big.int sub-limb to" {
var a = try Managed.initSet(testing.allocator, 10);
defer a.deinit();
- testing.expect((try a.to(u8)) == 10);
+ try testing.expect((try a.to(u8)) == 10);
}
test "big.int to target too small error" {
var a = try Managed.initSet(testing.allocator, 0xffffffff);
defer a.deinit();
- testing.expectError(error.TargetTooSmall, a.to(u8));
+ try testing.expectError(error.TargetTooSmall, a.to(u8));
}
test "big.int normalize" {
@@ -81,22 +81,22 @@ test "big.int normalize" {
a.limbs[2] = 3;
a.limbs[3] = 0;
a.normalize(4);
- testing.expect(a.len() == 3);
+ try testing.expect(a.len() == 3);
a.limbs[0] = 1;
a.limbs[1] = 2;
a.limbs[2] = 3;
a.normalize(3);
- testing.expect(a.len() == 3);
+ try testing.expect(a.len() == 3);
a.limbs[0] = 0;
a.limbs[1] = 0;
a.normalize(2);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
a.limbs[0] = 0;
a.normalize(1);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
}
test "big.int normalize multi" {
@@ -109,24 +109,24 @@ test "big.int normalize multi" {
a.limbs[2] = 0;
a.limbs[3] = 0;
a.normalize(4);
- testing.expect(a.len() == 2);
+ try testing.expect(a.len() == 2);
a.limbs[0] = 1;
a.limbs[1] = 2;
a.limbs[2] = 3;
a.normalize(3);
- testing.expect(a.len() == 3);
+ try testing.expect(a.len() == 3);
a.limbs[0] = 0;
a.limbs[1] = 0;
a.limbs[2] = 0;
a.limbs[3] = 0;
a.normalize(4);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
a.limbs[0] = 0;
a.normalize(1);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
}
test "big.int parity" {
@@ -134,12 +134,12 @@ test "big.int parity" {
defer a.deinit();
try a.set(0);
- testing.expect(a.isEven());
- testing.expect(!a.isOdd());
+ try testing.expect(a.isEven());
+ try testing.expect(!a.isOdd());
try a.set(7);
- testing.expect(!a.isEven());
- testing.expect(a.isOdd());
+ try testing.expect(!a.isEven());
+ try testing.expect(a.isOdd());
}
test "big.int bitcount + sizeInBaseUpperBound" {
@@ -147,27 +147,27 @@ test "big.int bitcount + sizeInBaseUpperBound" {
defer a.deinit();
try a.set(0b100);
- testing.expect(a.bitCountAbs() == 3);
- testing.expect(a.sizeInBaseUpperBound(2) >= 3);
- testing.expect(a.sizeInBaseUpperBound(10) >= 1);
+ try testing.expect(a.bitCountAbs() == 3);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 3);
+ try testing.expect(a.sizeInBaseUpperBound(10) >= 1);
a.negate();
- testing.expect(a.bitCountAbs() == 3);
- testing.expect(a.sizeInBaseUpperBound(2) >= 4);
- testing.expect(a.sizeInBaseUpperBound(10) >= 2);
+ try testing.expect(a.bitCountAbs() == 3);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 4);
+ try testing.expect(a.sizeInBaseUpperBound(10) >= 2);
try a.set(0xffffffff);
- testing.expect(a.bitCountAbs() == 32);
- testing.expect(a.sizeInBaseUpperBound(2) >= 32);
- testing.expect(a.sizeInBaseUpperBound(10) >= 10);
+ try testing.expect(a.bitCountAbs() == 32);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 32);
+ try testing.expect(a.sizeInBaseUpperBound(10) >= 10);
try a.shiftLeft(a, 5000);
- testing.expect(a.bitCountAbs() == 5032);
- testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
+ try testing.expect(a.bitCountAbs() == 5032);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
a.setSign(false);
- testing.expect(a.bitCountAbs() == 5032);
- testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
+ try testing.expect(a.bitCountAbs() == 5032);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
}
test "big.int bitcount/to" {
@@ -175,30 +175,30 @@ test "big.int bitcount/to" {
defer a.deinit();
try a.set(0);
- testing.expect(a.bitCountTwosComp() == 0);
+ try testing.expect(a.bitCountTwosComp() == 0);
- testing.expect((try a.to(u0)) == 0);
- testing.expect((try a.to(i0)) == 0);
+ try testing.expect((try a.to(u0)) == 0);
+ try testing.expect((try a.to(i0)) == 0);
try a.set(-1);
- testing.expect(a.bitCountTwosComp() == 1);
- testing.expect((try a.to(i1)) == -1);
+ try testing.expect(a.bitCountTwosComp() == 1);
+ try testing.expect((try a.to(i1)) == -1);
try a.set(-8);
- testing.expect(a.bitCountTwosComp() == 4);
- testing.expect((try a.to(i4)) == -8);
+ try testing.expect(a.bitCountTwosComp() == 4);
+ try testing.expect((try a.to(i4)) == -8);
try a.set(127);
- testing.expect(a.bitCountTwosComp() == 7);
- testing.expect((try a.to(u7)) == 127);
+ try testing.expect(a.bitCountTwosComp() == 7);
+ try testing.expect((try a.to(u7)) == 127);
try a.set(-128);
- testing.expect(a.bitCountTwosComp() == 8);
- testing.expect((try a.to(i8)) == -128);
+ try testing.expect(a.bitCountTwosComp() == 8);
+ try testing.expect((try a.to(i8)) == -128);
try a.set(-129);
- testing.expect(a.bitCountTwosComp() == 9);
- testing.expect((try a.to(i9)) == -129);
+ try testing.expect(a.bitCountTwosComp() == 9);
+ try testing.expect((try a.to(i9)) == -129);
}
test "big.int fits" {
@@ -206,27 +206,27 @@ test "big.int fits" {
defer a.deinit();
try a.set(0);
- testing.expect(a.fits(u0));
- testing.expect(a.fits(i0));
+ try testing.expect(a.fits(u0));
+ try testing.expect(a.fits(i0));
try a.set(255);
- testing.expect(!a.fits(u0));
- testing.expect(!a.fits(u1));
- testing.expect(!a.fits(i8));
- testing.expect(a.fits(u8));
- testing.expect(a.fits(u9));
- testing.expect(a.fits(i9));
+ try testing.expect(!a.fits(u0));
+ try testing.expect(!a.fits(u1));
+ try testing.expect(!a.fits(i8));
+ try testing.expect(a.fits(u8));
+ try testing.expect(a.fits(u9));
+ try testing.expect(a.fits(i9));
try a.set(-128);
- testing.expect(!a.fits(i7));
- testing.expect(a.fits(i8));
- testing.expect(a.fits(i9));
- testing.expect(!a.fits(u9));
+ try testing.expect(!a.fits(i7));
+ try testing.expect(a.fits(i8));
+ try testing.expect(a.fits(i9));
+ try testing.expect(!a.fits(u9));
try a.set(0x1ffffffffeeeeeeee);
- testing.expect(!a.fits(u32));
- testing.expect(!a.fits(u64));
- testing.expect(a.fits(u65));
+ try testing.expect(!a.fits(u32));
+ try testing.expect(!a.fits(u64));
+ try testing.expect(a.fits(u65));
}
test "big.int string set" {
@@ -234,7 +234,7 @@ test "big.int string set" {
defer a.deinit();
try a.setString(10, "120317241209124781241290847124");
- testing.expect((try a.to(u128)) == 120317241209124781241290847124);
+ try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
}
test "big.int string negative" {
@@ -242,7 +242,7 @@ test "big.int string negative" {
defer a.deinit();
try a.setString(10, "-1023");
- testing.expect((try a.to(i32)) == -1023);
+ try testing.expect((try a.to(i32)) == -1023);
}
test "big.int string set number with underscores" {
@@ -250,7 +250,7 @@ test "big.int string set number with underscores" {
defer a.deinit();
try a.setString(10, "__1_2_0_3_1_7_2_4_1_2_0_____9_1__2__4_7_8_1_2_4_1_2_9_0_8_4_7_1_2_4___");
- testing.expect((try a.to(u128)) == 120317241209124781241290847124);
+ try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
}
test "big.int string set case insensitive number" {
@@ -258,19 +258,19 @@ test "big.int string set case insensitive number" {
defer a.deinit();
try a.setString(16, "aB_cD_eF");
- testing.expect((try a.to(u32)) == 0xabcdef);
+ try testing.expect((try a.to(u32)) == 0xabcdef);
}
test "big.int string set bad char error" {
var a = try Managed.init(testing.allocator);
defer a.deinit();
- testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
+ try testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
}
test "big.int string set bad base error" {
var a = try Managed.init(testing.allocator);
defer a.deinit();
- testing.expectError(error.InvalidBase, a.setString(45, "10"));
+ try testing.expectError(error.InvalidBase, a.setString(45, "10"));
}
test "big.int string to" {
@@ -281,14 +281,14 @@ test "big.int string to" {
defer testing.allocator.free(as);
const es = "120317241209124781241290847124";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int string to base base error" {
var a = try Managed.initSet(testing.allocator, 0xffffffff);
defer a.deinit();
- testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, false));
+ try testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, false));
}
test "big.int string to base 2" {
@@ -299,7 +299,7 @@ test "big.int string to base 2" {
defer testing.allocator.free(as);
const es = "-1011";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int string to base 16" {
@@ -310,7 +310,7 @@ test "big.int string to base 16" {
defer testing.allocator.free(as);
const es = "efffffff00000001eeeeeeefaaaaaaab";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int neg string to" {
@@ -321,7 +321,7 @@ test "big.int neg string to" {
defer testing.allocator.free(as);
const es = "-123907434";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int zero string to" {
@@ -332,7 +332,7 @@ test "big.int zero string to" {
defer testing.allocator.free(as);
const es = "0";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int clone" {
@@ -341,12 +341,12 @@ test "big.int clone" {
var b = try a.clone();
defer b.deinit();
- testing.expect((try a.to(u32)) == 1234);
- testing.expect((try b.to(u32)) == 1234);
+ try testing.expect((try a.to(u32)) == 1234);
+ try testing.expect((try b.to(u32)) == 1234);
try a.set(77);
- testing.expect((try a.to(u32)) == 77);
- testing.expect((try b.to(u32)) == 1234);
+ try testing.expect((try a.to(u32)) == 77);
+ try testing.expect((try b.to(u32)) == 1234);
}
test "big.int swap" {
@@ -355,20 +355,20 @@ test "big.int swap" {
var b = try Managed.initSet(testing.allocator, 5678);
defer b.deinit();
- testing.expect((try a.to(u32)) == 1234);
- testing.expect((try b.to(u32)) == 5678);
+ try testing.expect((try a.to(u32)) == 1234);
+ try testing.expect((try b.to(u32)) == 5678);
a.swap(&b);
- testing.expect((try a.to(u32)) == 5678);
- testing.expect((try b.to(u32)) == 1234);
+ try testing.expect((try a.to(u32)) == 5678);
+ try testing.expect((try b.to(u32)) == 1234);
}
test "big.int to negative" {
var a = try Managed.initSet(testing.allocator, -10);
defer a.deinit();
- testing.expect((try a.to(i32)) == -10);
+ try testing.expect((try a.to(i32)) == -10);
}
test "big.int compare" {
@@ -377,8 +377,8 @@ test "big.int compare" {
var b = try Managed.initSet(testing.allocator, 10);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .gt);
- testing.expect(a.order(b) == .lt);
+ try testing.expect(a.orderAbs(b) == .gt);
+ try testing.expect(a.order(b) == .lt);
}
test "big.int compare similar" {
@@ -387,8 +387,8 @@ test "big.int compare similar" {
var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .lt);
- testing.expect(b.orderAbs(a) == .gt);
+ try testing.expect(a.orderAbs(b) == .lt);
+ try testing.expect(b.orderAbs(a) == .gt);
}
test "big.int compare different limb size" {
@@ -397,8 +397,8 @@ test "big.int compare different limb size" {
var b = try Managed.initSet(testing.allocator, 1);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .gt);
- testing.expect(b.orderAbs(a) == .lt);
+ try testing.expect(a.orderAbs(b) == .gt);
+ try testing.expect(b.orderAbs(a) == .lt);
}
test "big.int compare multi-limb" {
@@ -407,8 +407,8 @@ test "big.int compare multi-limb" {
var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .gt);
- testing.expect(a.order(b) == .lt);
+ try testing.expect(a.orderAbs(b) == .gt);
+ try testing.expect(a.order(b) == .lt);
}
test "big.int equality" {
@@ -417,8 +417,8 @@ test "big.int equality" {
var b = try Managed.initSet(testing.allocator, -0xffffffff1);
defer b.deinit();
- testing.expect(a.eqAbs(b));
- testing.expect(!a.eq(b));
+ try testing.expect(a.eqAbs(b));
+ try testing.expect(!a.eq(b));
}
test "big.int abs" {
@@ -426,10 +426,10 @@ test "big.int abs" {
defer a.deinit();
a.abs();
- testing.expect((try a.to(u32)) == 5);
+ try testing.expect((try a.to(u32)) == 5);
a.abs();
- testing.expect((try a.to(u32)) == 5);
+ try testing.expect((try a.to(u32)) == 5);
}
test "big.int negate" {
@@ -437,10 +437,10 @@ test "big.int negate" {
defer a.deinit();
a.negate();
- testing.expect((try a.to(i32)) == -5);
+ try testing.expect((try a.to(i32)) == -5);
a.negate();
- testing.expect((try a.to(i32)) == 5);
+ try testing.expect((try a.to(i32)) == 5);
}
test "big.int add single-single" {
@@ -453,7 +453,7 @@ test "big.int add single-single" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 55);
+ try testing.expect((try c.to(u32)) == 55);
}
test "big.int add multi-single" {
@@ -466,10 +466,10 @@ test "big.int add multi-single" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
+ try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
try c.add(b.toConst(), a.toConst());
- testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
+ try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
}
test "big.int add multi-multi" {
@@ -484,7 +484,7 @@ test "big.int add multi-multi" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(u128)) == op1 + op2);
+ try testing.expect((try c.to(u128)) == op1 + op2);
}
test "big.int add zero-zero" {
@@ -497,7 +497,7 @@ test "big.int add zero-zero" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int add alias multi-limb nonzero-zero" {
@@ -509,7 +509,7 @@ test "big.int add alias multi-limb nonzero-zero" {
try a.add(a.toConst(), b.toConst());
- testing.expect((try a.to(u128)) == op1);
+ try testing.expect((try a.to(u128)) == op1);
}
test "big.int add sign" {
@@ -526,16 +526,16 @@ test "big.int add sign" {
defer neg_two.deinit();
try a.add(one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == 3);
+ try testing.expect((try a.to(i32)) == 3);
try a.add(neg_one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == 1);
+ try testing.expect((try a.to(i32)) == 1);
try a.add(one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == -1);
+ try testing.expect((try a.to(i32)) == -1);
try a.add(neg_one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == -3);
+ try testing.expect((try a.to(i32)) == -3);
}
test "big.int sub single-single" {
@@ -548,7 +548,7 @@ test "big.int sub single-single" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 45);
+ try testing.expect((try c.to(u32)) == 45);
}
test "big.int sub multi-single" {
@@ -561,7 +561,7 @@ test "big.int sub multi-single" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(Limb)) == maxInt(Limb));
+ try testing.expect((try c.to(Limb)) == maxInt(Limb));
}
test "big.int sub multi-multi" {
@@ -577,7 +577,7 @@ test "big.int sub multi-multi" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(u128)) == op1 - op2);
+ try testing.expect((try c.to(u128)) == op1 - op2);
}
test "big.int sub equal" {
@@ -590,7 +590,7 @@ test "big.int sub equal" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int sub sign" {
@@ -607,19 +607,19 @@ test "big.int sub sign" {
defer neg_two.deinit();
try a.sub(one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == -1);
+ try testing.expect((try a.to(i32)) == -1);
try a.sub(neg_one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == -3);
+ try testing.expect((try a.to(i32)) == -3);
try a.sub(one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == 3);
+ try testing.expect((try a.to(i32)) == 3);
try a.sub(neg_one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == 1);
+ try testing.expect((try a.to(i32)) == 1);
try a.sub(neg_two.toConst(), neg_one.toConst());
- testing.expect((try a.to(i32)) == -1);
+ try testing.expect((try a.to(i32)) == -1);
}
test "big.int mul single-single" {
@@ -632,7 +632,7 @@ test "big.int mul single-single" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u64)) == 250);
+ try testing.expect((try c.to(u64)) == 250);
}
test "big.int mul multi-single" {
@@ -645,7 +645,7 @@ test "big.int mul multi-single" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
+ try testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
}
test "big.int mul multi-multi" {
@@ -660,7 +660,7 @@ test "big.int mul multi-multi" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u256)) == op1 * op2);
+ try testing.expect((try c.to(u256)) == op1 * op2);
}
test "big.int mul alias r with a" {
@@ -671,7 +671,7 @@ test "big.int mul alias r with a" {
try a.mul(a.toConst(), b.toConst());
- testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
}
test "big.int mul alias r with b" {
@@ -682,7 +682,7 @@ test "big.int mul alias r with b" {
try a.mul(b.toConst(), a.toConst());
- testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
}
test "big.int mul alias r with a and b" {
@@ -691,7 +691,7 @@ test "big.int mul alias r with a and b" {
try a.mul(a.toConst(), a.toConst());
- testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
}
test "big.int mul a*0" {
@@ -704,7 +704,7 @@ test "big.int mul a*0" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int mul 0*0" {
@@ -717,7 +717,7 @@ test "big.int mul 0*0" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int mul large" {
@@ -738,7 +738,7 @@ test "big.int mul large" {
try b.mul(a.toConst(), a.toConst());
try c.sqr(a.toConst());
- testing.expect(b.eq(c));
+ try testing.expect(b.eq(c));
}
test "big.int div single-single no rem" {
@@ -753,8 +753,8 @@ test "big.int div single-single no rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u32)) == 10);
- testing.expect((try r.to(u32)) == 0);
+ try testing.expect((try q.to(u32)) == 10);
+ try testing.expect((try r.to(u32)) == 0);
}
test "big.int div single-single with rem" {
@@ -769,8 +769,8 @@ test "big.int div single-single with rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u32)) == 9);
- testing.expect((try r.to(u32)) == 4);
+ try testing.expect((try q.to(u32)) == 9);
+ try testing.expect((try r.to(u32)) == 4);
}
test "big.int div multi-single no rem" {
@@ -788,8 +788,8 @@ test "big.int div multi-single no rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == op1 / op2);
- testing.expect((try r.to(u64)) == 0);
+ try testing.expect((try q.to(u64)) == op1 / op2);
+ try testing.expect((try r.to(u64)) == 0);
}
test "big.int div multi-single with rem" {
@@ -807,8 +807,8 @@ test "big.int div multi-single with rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == op1 / op2);
- testing.expect((try r.to(u64)) == 3);
+ try testing.expect((try q.to(u64)) == op1 / op2);
+ try testing.expect((try r.to(u64)) == 3);
}
test "big.int div multi>2-single" {
@@ -826,8 +826,8 @@ test "big.int div multi>2-single" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == op1 / op2);
- testing.expect((try r.to(u32)) == 0x3e4e);
+ try testing.expect((try q.to(u128)) == op1 / op2);
+ try testing.expect((try r.to(u32)) == 0x3e4e);
}
test "big.int div single-single q < r" {
@@ -842,8 +842,8 @@ test "big.int div single-single q < r" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == 0);
- testing.expect((try r.to(u64)) == 0x0078f432);
+ try testing.expect((try q.to(u64)) == 0);
+ try testing.expect((try r.to(u64)) == 0x0078f432);
}
test "big.int div single-single q == r" {
@@ -858,8 +858,8 @@ test "big.int div single-single q == r" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == 1);
- testing.expect((try r.to(u64)) == 0);
+ try testing.expect((try q.to(u64)) == 1);
+ try testing.expect((try r.to(u64)) == 0);
}
test "big.int div q=0 alias" {
@@ -870,8 +870,8 @@ test "big.int div q=0 alias" {
try Managed.divTrunc(&a, &b, a.toConst(), b.toConst());
- testing.expect((try a.to(u64)) == 0);
- testing.expect((try b.to(u64)) == 3);
+ try testing.expect((try a.to(u64)) == 0);
+ try testing.expect((try b.to(u64)) == 3);
}
test "big.int div multi-multi q < r" {
@@ -888,8 +888,8 @@ test "big.int div multi-multi q < r" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0);
- testing.expect((try r.to(u128)) == op1);
+ try testing.expect((try q.to(u128)) == 0);
+ try testing.expect((try r.to(u128)) == op1);
}
test "big.int div trunc single-single +/+" {
@@ -912,8 +912,8 @@ test "big.int div trunc single-single +/+" {
const eq = @divTrunc(u, v);
const er = @mod(u, v);
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div trunc single-single -/+" {
@@ -936,8 +936,8 @@ test "big.int div trunc single-single -/+" {
const eq = -1;
const er = -2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div trunc single-single +/-" {
@@ -960,8 +960,8 @@ test "big.int div trunc single-single +/-" {
const eq = -1;
const er = 2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div trunc single-single -/-" {
@@ -984,8 +984,8 @@ test "big.int div trunc single-single -/-" {
const eq = 1;
const er = -2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single +/+" {
@@ -1008,8 +1008,8 @@ test "big.int div floor single-single +/+" {
const eq = 1;
const er = 2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single -/+" {
@@ -1032,8 +1032,8 @@ test "big.int div floor single-single -/+" {
const eq = -2;
const er = 1;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single +/-" {
@@ -1056,8 +1056,8 @@ test "big.int div floor single-single +/-" {
const eq = -2;
const er = -1;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single -/-" {
@@ -1080,8 +1080,8 @@ test "big.int div floor single-single -/-" {
const eq = 1;
const er = -2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div multi-multi with rem" {
@@ -1096,8 +1096,8 @@ test "big.int div multi-multi with rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
- testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
+ try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
+ try testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
}
test "big.int div multi-multi no rem" {
@@ -1112,8 +1112,8 @@ test "big.int div multi-multi no rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
- testing.expect((try r.to(u128)) == 0);
+ try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
+ try testing.expect((try r.to(u128)) == 0);
}
test "big.int div multi-multi (2 branch)" {
@@ -1128,8 +1128,8 @@ test "big.int div multi-multi (2 branch)" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0x10000000000000000);
- testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
+ try testing.expect((try q.to(u128)) == 0x10000000000000000);
+ try testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
}
test "big.int div multi-multi (3.1/3.3 branch)" {
@@ -1144,8 +1144,8 @@ test "big.int div multi-multi (3.1/3.3 branch)" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
- testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
+ try testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
+ try testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
}
test "big.int div multi-single zero-limb trailing" {
@@ -1162,8 +1162,8 @@ test "big.int div multi-single zero-limb trailing" {
var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000);
defer expected.deinit();
- testing.expect(q.eq(expected));
- testing.expect(r.eqZero());
+ try testing.expect(q.eq(expected));
+ try testing.expect(r.eqZero());
}
test "big.int div multi-multi zero-limb trailing (with rem)" {
@@ -1178,11 +1178,11 @@ test "big.int div multi-multi zero-limb trailing (with rem)" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0x10000000000000000);
+ try testing.expect((try q.to(u128)) == 0x10000000000000000);
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
}
test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" {
@@ -1197,11 +1197,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0x1);
+ try testing.expect((try q.to(u128)) == 0x1);
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
}
test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" {
@@ -1218,11 +1218,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
const qs = try q.toString(testing.allocator, 16, false);
defer testing.allocator.free(qs);
- testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
+ try testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
}
test "big.int div multi-multi fuzz case #1" {
@@ -1242,11 +1242,11 @@ test "big.int div multi-multi fuzz case #1" {
const qs = try q.toString(testing.allocator, 16, false);
defer testing.allocator.free(qs);
- testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
+ try testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
+ try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
}
test "big.int div multi-multi fuzz case #2" {
@@ -1266,11 +1266,11 @@ test "big.int div multi-multi fuzz case #2" {
const qs = try q.toString(testing.allocator, 16, false);
defer testing.allocator.free(qs);
- testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
+ try testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
}
test "big.int shift-right single" {
@@ -1278,7 +1278,7 @@ test "big.int shift-right single" {
defer a.deinit();
try a.shiftRight(a, 16);
- testing.expect((try a.to(u32)) == 0xffff);
+ try testing.expect((try a.to(u32)) == 0xffff);
}
test "big.int shift-right multi" {
@@ -1286,13 +1286,13 @@ test "big.int shift-right multi" {
defer a.deinit();
try a.shiftRight(a, 67);
- testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
+ try testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
try a.set(0xffff0000eeee1111dddd2222cccc3333);
try a.shiftRight(a, 63);
try a.shiftRight(a, 63);
try a.shiftRight(a, 2);
- testing.expect(a.eqZero());
+ try testing.expect(a.eqZero());
}
test "big.int shift-left single" {
@@ -1300,7 +1300,7 @@ test "big.int shift-left single" {
defer a.deinit();
try a.shiftLeft(a, 16);
- testing.expect((try a.to(u64)) == 0xffff0000);
+ try testing.expect((try a.to(u64)) == 0xffff0000);
}
test "big.int shift-left multi" {
@@ -1308,7 +1308,7 @@ test "big.int shift-left multi" {
defer a.deinit();
try a.shiftLeft(a, 67);
- testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
+ try testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
}
test "big.int shift-right negative" {
@@ -1318,12 +1318,12 @@ test "big.int shift-right negative" {
var arg = try Managed.initSet(testing.allocator, -20);
defer arg.deinit();
try a.shiftRight(arg, 2);
- testing.expect((try a.to(i32)) == -20 >> 2);
+ try testing.expect((try a.to(i32)) == -20 >> 2);
var arg2 = try Managed.initSet(testing.allocator, -5);
defer arg2.deinit();
try a.shiftRight(arg2, 10);
- testing.expect((try a.to(i32)) == -5 >> 10);
+ try testing.expect((try a.to(i32)) == -5 >> 10);
}
test "big.int shift-left negative" {
@@ -1333,7 +1333,7 @@ test "big.int shift-left negative" {
var arg = try Managed.initSet(testing.allocator, -10);
defer arg.deinit();
try a.shiftRight(arg, 1232);
- testing.expect((try a.to(i32)) == -10 >> 1232);
+ try testing.expect((try a.to(i32)) == -10 >> 1232);
}
test "big.int bitwise and simple" {
@@ -1344,7 +1344,7 @@ test "big.int bitwise and simple" {
try a.bitAnd(a, b);
- testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
+ try testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
}
test "big.int bitwise and multi-limb" {
@@ -1355,7 +1355,7 @@ test "big.int bitwise and multi-limb" {
try a.bitAnd(a, b);
- testing.expect((try a.to(u128)) == 0);
+ try testing.expect((try a.to(u128)) == 0);
}
test "big.int bitwise xor simple" {
@@ -1366,7 +1366,7 @@ test "big.int bitwise xor simple" {
try a.bitXor(a, b);
- testing.expect((try a.to(u64)) == 0x1111111133333333);
+ try testing.expect((try a.to(u64)) == 0x1111111133333333);
}
test "big.int bitwise xor multi-limb" {
@@ -1377,7 +1377,7 @@ test "big.int bitwise xor multi-limb" {
try a.bitXor(a, b);
- testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
}
test "big.int bitwise or simple" {
@@ -1388,7 +1388,7 @@ test "big.int bitwise or simple" {
try a.bitOr(a, b);
- testing.expect((try a.to(u64)) == 0xffffffff33333333);
+ try testing.expect((try a.to(u64)) == 0xffffffff33333333);
}
test "big.int bitwise or multi-limb" {
@@ -1400,7 +1400,7 @@ test "big.int bitwise or multi-limb" {
try a.bitOr(a, b);
// TODO: big.int.cpp or is wrong on multi-limb.
- testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
}
test "big.int var args" {
@@ -1410,15 +1410,15 @@ test "big.int var args" {
var b = try Managed.initSet(testing.allocator, 6);
defer b.deinit();
try a.add(a.toConst(), b.toConst());
- testing.expect((try a.to(u64)) == 11);
+ try testing.expect((try a.to(u64)) == 11);
var c = try Managed.initSet(testing.allocator, 11);
defer c.deinit();
- testing.expect(a.order(c) == .eq);
+ try testing.expect(a.order(c) == .eq);
var d = try Managed.initSet(testing.allocator, 14);
defer d.deinit();
- testing.expect(a.order(d) != .gt);
+ try testing.expect(a.order(d) != .gt);
}
test "big.int gcd non-one small" {
@@ -1431,7 +1431,7 @@ test "big.int gcd non-one small" {
try r.gcd(a, b);
- testing.expect((try r.to(u32)) == 1);
+ try testing.expect((try r.to(u32)) == 1);
}
test "big.int gcd non-one small" {
@@ -1444,7 +1444,7 @@ test "big.int gcd non-one small" {
try r.gcd(a, b);
- testing.expect((try r.to(u32)) == 38);
+ try testing.expect((try r.to(u32)) == 38);
}
test "big.int gcd non-one large" {
@@ -1457,7 +1457,7 @@ test "big.int gcd non-one large" {
try r.gcd(a, b);
- testing.expect((try r.to(u32)) == 4369);
+ try testing.expect((try r.to(u32)) == 4369);
}
test "big.int gcd large multi-limb result" {
@@ -1471,7 +1471,7 @@ test "big.int gcd large multi-limb result" {
try r.gcd(a, b);
const answer = (try r.to(u256));
- testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
+ try testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
}
test "big.int gcd one large" {
@@ -1484,7 +1484,7 @@ test "big.int gcd one large" {
try r.gcd(a, b);
- testing.expect((try r.to(u64)) == 1);
+ try testing.expect((try r.to(u64)) == 1);
}
test "big.int mutable to managed" {
@@ -1495,7 +1495,7 @@ test "big.int mutable to managed" {
var a = Mutable.init(limbs_buf, 0xdeadbeef);
var a_managed = a.toManaged(allocator);
- testing.expect(a.toConst().eq(a_managed.toConst()));
+ try testing.expect(a.toConst().eq(a_managed.toConst()));
}
test "big.int const to managed" {
@@ -1505,7 +1505,7 @@ test "big.int const to managed" {
var b = try a.toConst().toManaged(testing.allocator);
defer b.deinit();
- testing.expect(a.toConst().eq(b.toConst()));
+ try testing.expect(a.toConst().eq(b.toConst()));
}
test "big.int pow" {
@@ -1514,10 +1514,10 @@ test "big.int pow" {
defer a.deinit();
try a.pow(a.toConst(), 3);
- testing.expectEqual(@as(i32, -27), try a.to(i32));
+ try testing.expectEqual(@as(i32, -27), try a.to(i32));
try a.pow(a.toConst(), 4);
- testing.expectEqual(@as(i32, 531441), try a.to(i32));
+ try testing.expectEqual(@as(i32, 531441), try a.to(i32));
}
{
var a = try Managed.initSet(testing.allocator, 10);
@@ -1531,11 +1531,11 @@ test "big.int pow" {
// y and a are aliased
try a.pow(a.toConst(), 123);
- testing.expect(a.eq(y));
+ try testing.expect(a.eq(y));
const ys = try y.toString(testing.allocator, 16, false);
defer testing.allocator.free(ys);
- testing.expectEqualSlices(
+ try testing.expectEqualSlices(
u8,
"183425a5f872f126e00a5ad62c839075cd6846c6fb0230887c7ad7a9dc530fcb" ++
"4933f60e8000000000000000000000000000000",
@@ -1548,17 +1548,17 @@ test "big.int pow" {
defer a.deinit();
try a.pow(a.toConst(), 100);
- testing.expectEqual(@as(i32, 0), try a.to(i32));
+ try testing.expectEqual(@as(i32, 0), try a.to(i32));
try a.set(1);
try a.pow(a.toConst(), 0);
- testing.expectEqual(@as(i32, 1), try a.to(i32));
+ try testing.expectEqual(@as(i32, 1), try a.to(i32));
try a.pow(a.toConst(), 100);
- testing.expectEqual(@as(i32, 1), try a.to(i32));
+ try testing.expectEqual(@as(i32, 1), try a.to(i32));
try a.set(-1);
try a.pow(a.toConst(), 15);
- testing.expectEqual(@as(i32, -1), try a.to(i32));
+ try testing.expectEqual(@as(i32, -1), try a.to(i32));
try a.pow(a.toConst(), 16);
- testing.expectEqual(@as(i32, 1), try a.to(i32));
+ try testing.expectEqual(@as(i32, 1), try a.to(i32));
}
}
diff --git a/lib/std/math/big/rational.zig b/lib/std/math/big/rational.zig
index 2299205e7b..987889feca 100644
--- a/lib/std/math/big/rational.zig
+++ b/lib/std/math/big/rational.zig
@@ -473,7 +473,7 @@ pub const Rational = struct {
};
fn extractLowBits(a: Int, comptime T: type) T {
- testing.expect(@typeInfo(T) == .Int);
+ debug.assert(@typeInfo(T) == .Int);
const t_bits = @typeInfo(T).Int.bits;
const limb_bits = @typeInfo(Limb).Int.bits;
@@ -498,19 +498,19 @@ test "big.rational extractLowBits" {
defer a.deinit();
const a1 = extractLowBits(a, u8);
- testing.expect(a1 == 0x21);
+ try testing.expect(a1 == 0x21);
const a2 = extractLowBits(a, u16);
- testing.expect(a2 == 0x4321);
+ try testing.expect(a2 == 0x4321);
const a3 = extractLowBits(a, u32);
- testing.expect(a3 == 0x87654321);
+ try testing.expect(a3 == 0x87654321);
const a4 = extractLowBits(a, u64);
- testing.expect(a4 == 0x1234567887654321);
+ try testing.expect(a4 == 0x1234567887654321);
const a5 = extractLowBits(a, u128);
- testing.expect(a5 == 0x11112222333344441234567887654321);
+ try testing.expect(a5 == 0x11112222333344441234567887654321);
}
test "big.rational set" {
@@ -518,28 +518,28 @@ test "big.rational set" {
defer a.deinit();
try a.setInt(5);
- testing.expect((try a.p.to(u32)) == 5);
- testing.expect((try a.q.to(u32)) == 1);
+ try testing.expect((try a.p.to(u32)) == 5);
+ try testing.expect((try a.q.to(u32)) == 1);
try a.setRatio(7, 3);
- testing.expect((try a.p.to(u32)) == 7);
- testing.expect((try a.q.to(u32)) == 3);
+ try testing.expect((try a.p.to(u32)) == 7);
+ try testing.expect((try a.q.to(u32)) == 3);
try a.setRatio(9, 3);
- testing.expect((try a.p.to(i32)) == 3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 3);
+ try testing.expect((try a.q.to(i32)) == 1);
try a.setRatio(-9, 3);
- testing.expect((try a.p.to(i32)) == -3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -3);
+ try testing.expect((try a.q.to(i32)) == 1);
try a.setRatio(9, -3);
- testing.expect((try a.p.to(i32)) == -3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -3);
+ try testing.expect((try a.q.to(i32)) == 1);
try a.setRatio(-9, -3);
- testing.expect((try a.p.to(i32)) == 3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 3);
+ try testing.expect((try a.q.to(i32)) == 1);
}
test "big.rational setFloat" {
@@ -547,24 +547,24 @@ test "big.rational setFloat" {
defer a.deinit();
try a.setFloat(f64, 2.5);
- testing.expect((try a.p.to(i32)) == 5);
- testing.expect((try a.q.to(i32)) == 2);
+ try testing.expect((try a.p.to(i32)) == 5);
+ try testing.expect((try a.q.to(i32)) == 2);
try a.setFloat(f32, -2.5);
- testing.expect((try a.p.to(i32)) == -5);
- testing.expect((try a.q.to(i32)) == 2);
+ try testing.expect((try a.p.to(i32)) == -5);
+ try testing.expect((try a.q.to(i32)) == 2);
try a.setFloat(f32, 3.141593);
// = 3.14159297943115234375
- testing.expect((try a.p.to(u32)) == 3294199);
- testing.expect((try a.q.to(u32)) == 1048576);
+ try testing.expect((try a.p.to(u32)) == 3294199);
+ try testing.expect((try a.q.to(u32)) == 1048576);
try a.setFloat(f64, 72.141593120712409172417410926841290461290467124);
// = 72.1415931207124145885245525278151035308837890625
- testing.expect((try a.p.to(u128)) == 5076513310880537);
- testing.expect((try a.q.to(u128)) == 70368744177664);
+ try testing.expect((try a.p.to(u128)) == 5076513310880537);
+ try testing.expect((try a.q.to(u128)) == 70368744177664);
}
test "big.rational setFloatString" {
@@ -574,8 +574,8 @@ test "big.rational setFloatString" {
try a.setFloatString("72.14159312071241458852455252781510353");
// = 72.1415931207124145885245525278151035308837890625
- testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
- testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
+ try testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
+ try testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
}
test "big.rational toFloat" {
@@ -584,11 +584,11 @@ test "big.rational toFloat" {
// = 3.14159297943115234375
try a.setRatio(3294199, 1048576);
- testing.expect((try a.toFloat(f64)) == 3.14159297943115234375);
+ try testing.expect((try a.toFloat(f64)) == 3.14159297943115234375);
// = 72.1415931207124145885245525278151035308837890625
try a.setRatio(5076513310880537, 70368744177664);
- testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
+ try testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
}
test "big.rational set/to Float round-trip" {
@@ -599,7 +599,7 @@ test "big.rational set/to Float round-trip" {
while (i < 512) : (i += 1) {
const r = prng.random.float(f64);
try a.setFloat(f64, r);
- testing.expect((try a.toFloat(f64)) == r);
+ try testing.expect((try a.toFloat(f64)) == r);
}
}
@@ -611,8 +611,8 @@ test "big.rational copy" {
defer b.deinit();
try a.copyInt(b);
- testing.expect((try a.p.to(u32)) == 5);
- testing.expect((try a.q.to(u32)) == 1);
+ try testing.expect((try a.p.to(u32)) == 5);
+ try testing.expect((try a.q.to(u32)) == 1);
var c = try Int.initSet(testing.allocator, 7);
defer c.deinit();
@@ -620,8 +620,8 @@ test "big.rational copy" {
defer d.deinit();
try a.copyRatio(c, d);
- testing.expect((try a.p.to(u32)) == 7);
- testing.expect((try a.q.to(u32)) == 3);
+ try testing.expect((try a.p.to(u32)) == 7);
+ try testing.expect((try a.q.to(u32)) == 3);
var e = try Int.initSet(testing.allocator, 9);
defer e.deinit();
@@ -629,8 +629,8 @@ test "big.rational copy" {
defer f.deinit();
try a.copyRatio(e, f);
- testing.expect((try a.p.to(u32)) == 3);
- testing.expect((try a.q.to(u32)) == 1);
+ try testing.expect((try a.p.to(u32)) == 3);
+ try testing.expect((try a.q.to(u32)) == 1);
}
test "big.rational negate" {
@@ -638,16 +638,16 @@ test "big.rational negate" {
defer a.deinit();
try a.setInt(-50);
- testing.expect((try a.p.to(i32)) == -50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.negate();
- testing.expect((try a.p.to(i32)) == 50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.negate();
- testing.expect((try a.p.to(i32)) == -50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -50);
+ try testing.expect((try a.q.to(i32)) == 1);
}
test "big.rational abs" {
@@ -655,16 +655,16 @@ test "big.rational abs" {
defer a.deinit();
try a.setInt(-50);
- testing.expect((try a.p.to(i32)) == -50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.abs();
- testing.expect((try a.p.to(i32)) == 50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.abs();
- testing.expect((try a.p.to(i32)) == 50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 50);
+ try testing.expect((try a.q.to(i32)) == 1);
}
test "big.rational swap" {
@@ -676,19 +676,19 @@ test "big.rational swap" {
try a.setRatio(50, 23);
try b.setRatio(17, 3);
- testing.expect((try a.p.to(u32)) == 50);
- testing.expect((try a.q.to(u32)) == 23);
+ try testing.expect((try a.p.to(u32)) == 50);
+ try testing.expect((try a.q.to(u32)) == 23);
- testing.expect((try b.p.to(u32)) == 17);
- testing.expect((try b.q.to(u32)) == 3);
+ try testing.expect((try b.p.to(u32)) == 17);
+ try testing.expect((try b.q.to(u32)) == 3);
a.swap(&b);
- testing.expect((try a.p.to(u32)) == 17);
- testing.expect((try a.q.to(u32)) == 3);
+ try testing.expect((try a.p.to(u32)) == 17);
+ try testing.expect((try a.q.to(u32)) == 3);
- testing.expect((try b.p.to(u32)) == 50);
- testing.expect((try b.q.to(u32)) == 23);
+ try testing.expect((try b.p.to(u32)) == 50);
+ try testing.expect((try b.q.to(u32)) == 23);
}
test "big.rational order" {
@@ -699,11 +699,11 @@ test "big.rational order" {
try a.setRatio(500, 231);
try b.setRatio(18903, 8584);
- testing.expect((try a.order(b)) == .lt);
+ try testing.expect((try a.order(b)) == .lt);
try a.setRatio(890, 10);
try b.setRatio(89, 1);
- testing.expect((try a.order(b)) == .eq);
+ try testing.expect((try a.order(b)) == .eq);
}
test "big.rational add single-limb" {
@@ -714,11 +714,11 @@ test "big.rational add single-limb" {
try a.setRatio(500, 231);
try b.setRatio(18903, 8584);
- testing.expect((try a.order(b)) == .lt);
+ try testing.expect((try a.order(b)) == .lt);
try a.setRatio(890, 10);
try b.setRatio(89, 1);
- testing.expect((try a.order(b)) == .eq);
+ try testing.expect((try a.order(b)) == .eq);
}
test "big.rational add" {
@@ -734,7 +734,7 @@ test "big.rational add" {
try a.add(a, b);
try r.setRatio(984786924199, 290395044174);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational sub" {
@@ -750,7 +750,7 @@ test "big.rational sub" {
try a.sub(a, b);
try r.setRatio(979040510045, 290395044174);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational mul" {
@@ -766,7 +766,7 @@ test "big.rational mul" {
try a.mul(a, b);
try r.setRatio(571481443, 17082061422);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational div" {
@@ -782,7 +782,7 @@ test "big.rational div" {
try a.div(a, b);
try r.setRatio(75531824394, 221015929);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational div" {
@@ -795,11 +795,11 @@ test "big.rational div" {
a.invert();
try r.setRatio(23341, 78923);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
try a.setRatio(-78923, 23341);
a.invert();
try r.setRatio(-23341, 78923);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
diff --git a/lib/std/math/cbrt.zig b/lib/std/math/cbrt.zig
index a876e0a9d1..504657894d 100644
--- a/lib/std/math/cbrt.zig
+++ b/lib/std/math/cbrt.zig
@@ -125,44 +125,44 @@ fn cbrt64(x: f64) f64 {
}
test "math.cbrt" {
- expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
- expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
+ try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
+ try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
}
test "math.cbrt32" {
const epsilon = 0.000001;
- expect(cbrt32(0.0) == 0.0);
- expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));
- expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));
- expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));
- expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));
- expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
+ try expect(cbrt32(0.0) == 0.0);
+ try expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));
+ try expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));
+ try expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));
+ try expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));
+ try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
}
test "math.cbrt64" {
const epsilon = 0.000001;
- expect(cbrt64(0.0) == 0.0);
- expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));
- expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));
- expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));
- expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));
- expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));
+ try expect(cbrt64(0.0) == 0.0);
+ try expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));
+ try expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));
+ try expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));
+ try expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));
+ try expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));
}
test "math.cbrt.special" {
- expect(cbrt32(0.0) == 0.0);
- expect(cbrt32(-0.0) == -0.0);
- expect(math.isPositiveInf(cbrt32(math.inf(f32))));
- expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
- expect(math.isNan(cbrt32(math.nan(f32))));
+ try expect(cbrt32(0.0) == 0.0);
+ try expect(cbrt32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(cbrt32(math.inf(f32))));
+ try expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
+ try expect(math.isNan(cbrt32(math.nan(f32))));
}
test "math.cbrt64.special" {
- expect(cbrt64(0.0) == 0.0);
- expect(cbrt64(-0.0) == -0.0);
- expect(math.isPositiveInf(cbrt64(math.inf(f64))));
- expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
- expect(math.isNan(cbrt64(math.nan(f64))));
+ try expect(cbrt64(0.0) == 0.0);
+ try expect(cbrt64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(cbrt64(math.inf(f64))));
+ try expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
+ try expect(math.isNan(cbrt64(math.nan(f64))));
}
diff --git a/lib/std/math/ceil.zig b/lib/std/math/ceil.zig
index d313475717..7b516c77c6 100644
--- a/lib/std/math/ceil.zig
+++ b/lib/std/math/ceil.zig
@@ -120,49 +120,49 @@ fn ceil128(x: f128) f128 {
}
test "math.ceil" {
- expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
- expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
- expect(ceil(@as(f128, 0.0)) == ceil128(0.0));
+ try expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
+ try expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
+ try expect(ceil(@as(f128, 0.0)) == ceil128(0.0));
}
test "math.ceil32" {
- expect(ceil32(1.3) == 2.0);
- expect(ceil32(-1.3) == -1.0);
- expect(ceil32(0.2) == 1.0);
+ try expect(ceil32(1.3) == 2.0);
+ try expect(ceil32(-1.3) == -1.0);
+ try expect(ceil32(0.2) == 1.0);
}
test "math.ceil64" {
- expect(ceil64(1.3) == 2.0);
- expect(ceil64(-1.3) == -1.0);
- expect(ceil64(0.2) == 1.0);
+ try expect(ceil64(1.3) == 2.0);
+ try expect(ceil64(-1.3) == -1.0);
+ try expect(ceil64(0.2) == 1.0);
}
test "math.ceil128" {
- expect(ceil128(1.3) == 2.0);
- expect(ceil128(-1.3) == -1.0);
- expect(ceil128(0.2) == 1.0);
+ try expect(ceil128(1.3) == 2.0);
+ try expect(ceil128(-1.3) == -1.0);
+ try expect(ceil128(0.2) == 1.0);
}
test "math.ceil32.special" {
- expect(ceil32(0.0) == 0.0);
- expect(ceil32(-0.0) == -0.0);
- expect(math.isPositiveInf(ceil32(math.inf(f32))));
- expect(math.isNegativeInf(ceil32(-math.inf(f32))));
- expect(math.isNan(ceil32(math.nan(f32))));
+ try expect(ceil32(0.0) == 0.0);
+ try expect(ceil32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(ceil32(math.inf(f32))));
+ try expect(math.isNegativeInf(ceil32(-math.inf(f32))));
+ try expect(math.isNan(ceil32(math.nan(f32))));
}
test "math.ceil64.special" {
- expect(ceil64(0.0) == 0.0);
- expect(ceil64(-0.0) == -0.0);
- expect(math.isPositiveInf(ceil64(math.inf(f64))));
- expect(math.isNegativeInf(ceil64(-math.inf(f64))));
- expect(math.isNan(ceil64(math.nan(f64))));
+ try expect(ceil64(0.0) == 0.0);
+ try expect(ceil64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(ceil64(math.inf(f64))));
+ try expect(math.isNegativeInf(ceil64(-math.inf(f64))));
+ try expect(math.isNan(ceil64(math.nan(f64))));
}
test "math.ceil128.special" {
- expect(ceil128(0.0) == 0.0);
- expect(ceil128(-0.0) == -0.0);
- expect(math.isPositiveInf(ceil128(math.inf(f128))));
- expect(math.isNegativeInf(ceil128(-math.inf(f128))));
- expect(math.isNan(ceil128(math.nan(f128))));
+ try expect(ceil128(0.0) == 0.0);
+ try expect(ceil128(-0.0) == -0.0);
+ try expect(math.isPositiveInf(ceil128(math.inf(f128))));
+ try expect(math.isNegativeInf(ceil128(-math.inf(f128))));
+ try expect(math.isNan(ceil128(math.nan(f128))));
}
diff --git a/lib/std/math/complex.zig b/lib/std/math/complex.zig
index e046ed9fa9..abac923cdd 100644
--- a/lib/std/math/complex.zig
+++ b/lib/std/math/complex.zig
@@ -114,7 +114,7 @@ test "complex.add" {
const b = Complex(f32).new(2, 7);
const c = a.add(b);
- testing.expect(c.re == 7 and c.im == 10);
+ try testing.expect(c.re == 7 and c.im == 10);
}
test "complex.sub" {
@@ -122,7 +122,7 @@ test "complex.sub" {
const b = Complex(f32).new(2, 7);
const c = a.sub(b);
- testing.expect(c.re == 3 and c.im == -4);
+ try testing.expect(c.re == 3 and c.im == -4);
}
test "complex.mul" {
@@ -130,7 +130,7 @@ test "complex.mul" {
const b = Complex(f32).new(2, 7);
const c = a.mul(b);
- testing.expect(c.re == -11 and c.im == 41);
+ try testing.expect(c.re == -11 and c.im == 41);
}
test "complex.div" {
@@ -138,7 +138,7 @@ test "complex.div" {
const b = Complex(f32).new(2, 7);
const c = a.div(b);
- testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and
+ try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and
math.approxEqAbs(f32, c.im, @as(f32, -29) / 53, epsilon));
}
@@ -146,14 +146,14 @@ test "complex.conjugate" {
const a = Complex(f32).new(5, 3);
const c = a.conjugate();
- testing.expect(c.re == 5 and c.im == -3);
+ try testing.expect(c.re == 5 and c.im == -3);
}
test "complex.reciprocal" {
const a = Complex(f32).new(5, 3);
const c = a.reciprocal();
- testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and
+ try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and
math.approxEqAbs(f32, c.im, @as(f32, -3) / 34, epsilon));
}
@@ -161,7 +161,7 @@ test "complex.magnitude" {
const a = Complex(f32).new(5, 3);
const c = a.magnitude();
- testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
}
test "complex.cmath" {
diff --git a/lib/std/math/complex/abs.zig b/lib/std/math/complex/abs.zig
index 609cdba5a7..a2678d21db 100644
--- a/lib/std/math/complex/abs.zig
+++ b/lib/std/math/complex/abs.zig
@@ -20,5 +20,5 @@ const epsilon = 0.0001;
test "complex.cabs" {
const a = Complex(f32).new(5, 3);
const c = abs(a);
- testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
}
diff --git a/lib/std/math/complex/acos.zig b/lib/std/math/complex/acos.zig
index b7c43e9381..72abea47fe 100644
--- a/lib/std/math/complex/acos.zig
+++ b/lib/std/math/complex/acos.zig
@@ -22,6 +22,6 @@ test "complex.cacos" {
const a = Complex(f32).new(5, 3);
const c = acos(a);
- testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));
}
diff --git a/lib/std/math/complex/acosh.zig b/lib/std/math/complex/acosh.zig
index d7d596e084..4f76dea01a 100644
--- a/lib/std/math/complex/acosh.zig
+++ b/lib/std/math/complex/acosh.zig
@@ -22,6 +22,6 @@ test "complex.cacosh" {
const a = Complex(f32).new(5, 3);
const c = acosh(a);
- testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));
}
diff --git a/lib/std/math/complex/arg.zig b/lib/std/math/complex/arg.zig
index 7c3b00bd5d..c583b9e360 100644
--- a/lib/std/math/complex/arg.zig
+++ b/lib/std/math/complex/arg.zig
@@ -20,5 +20,5 @@ const epsilon = 0.0001;
test "complex.carg" {
const a = Complex(f32).new(5, 3);
const c = arg(a);
- testing.expect(math.approxEqAbs(f32, c, 0.540420, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c, 0.540420, epsilon));
}
diff --git a/lib/std/math/complex/asin.zig b/lib/std/math/complex/asin.zig
index 0ed352b3b7..7ce200fae2 100644
--- a/lib/std/math/complex/asin.zig
+++ b/lib/std/math/complex/asin.zig
@@ -28,6 +28,6 @@ test "complex.casin" {
const a = Complex(f32).new(5, 3);
const c = asin(a);
- testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));
}
diff --git a/lib/std/math/complex/asinh.zig b/lib/std/math/complex/asinh.zig
index 762a601fbf..821218acf7 100644
--- a/lib/std/math/complex/asinh.zig
+++ b/lib/std/math/complex/asinh.zig
@@ -23,6 +23,6 @@ test "complex.casinh" {
const a = Complex(f32).new(5, 3);
const c = asinh(a);
- testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));
}
diff --git a/lib/std/math/complex/atan.zig b/lib/std/math/complex/atan.zig
index af40c05a81..d9a95c8dc1 100644
--- a/lib/std/math/complex/atan.zig
+++ b/lib/std/math/complex/atan.zig
@@ -130,14 +130,14 @@ test "complex.catan32" {
const a = Complex(f32).new(5, 3);
const c = atan(a);
- testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
}
test "complex.catan64" {
const a = Complex(f64).new(5, 3);
const c = atan(a);
- testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));
}
diff --git a/lib/std/math/complex/atanh.zig b/lib/std/math/complex/atanh.zig
index 2c3708f57f..420f401f17 100644
--- a/lib/std/math/complex/atanh.zig
+++ b/lib/std/math/complex/atanh.zig
@@ -23,6 +23,6 @@ test "complex.catanh" {
const a = Complex(f32).new(5, 3);
const c = atanh(a);
- testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));
}
diff --git a/lib/std/math/complex/conj.zig b/lib/std/math/complex/conj.zig
index b79c7de6ca..960295830a 100644
--- a/lib/std/math/complex/conj.zig
+++ b/lib/std/math/complex/conj.zig
@@ -19,5 +19,5 @@ test "complex.conj" {
const a = Complex(f32).new(5, 3);
const c = a.conjugate();
- testing.expect(c.re == 5 and c.im == -3);
+ try testing.expect(c.re == 5 and c.im == -3);
}
diff --git a/lib/std/math/complex/cos.zig b/lib/std/math/complex/cos.zig
index 66fd5b9b7b..2de3735d12 100644
--- a/lib/std/math/complex/cos.zig
+++ b/lib/std/math/complex/cos.zig
@@ -22,6 +22,6 @@ test "complex.ccos" {
const a = Complex(f32).new(5, 3);
const c = cos(a);
- testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));
}
diff --git a/lib/std/math/complex/cosh.zig b/lib/std/math/complex/cosh.zig
index e43cd1d665..2514e72bdb 100644
--- a/lib/std/math/complex/cosh.zig
+++ b/lib/std/math/complex/cosh.zig
@@ -165,14 +165,14 @@ test "complex.ccosh32" {
const a = Complex(f32).new(5, 3);
const c = cosh(a);
- testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
}
test "complex.ccosh64" {
const a = Complex(f64).new(5, 3);
const c = cosh(a);
- testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));
}
diff --git a/lib/std/math/complex/exp.zig b/lib/std/math/complex/exp.zig
index eb738a6d88..a7eb3d51b5 100644
--- a/lib/std/math/complex/exp.zig
+++ b/lib/std/math/complex/exp.zig
@@ -131,14 +131,14 @@ test "complex.cexp32" {
const a = Complex(f32).new(5, 3);
const c = exp(a);
- testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));
}
test "complex.cexp64" {
const a = Complex(f64).new(5, 3);
const c = exp(a);
- testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));
}
diff --git a/lib/std/math/complex/log.zig b/lib/std/math/complex/log.zig
index 90124af2eb..7f8f649953 100644
--- a/lib/std/math/complex/log.zig
+++ b/lib/std/math/complex/log.zig
@@ -24,6 +24,6 @@ test "complex.clog" {
const a = Complex(f32).new(5, 3);
const c = log(a);
- testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));
}
diff --git a/lib/std/math/complex/pow.zig b/lib/std/math/complex/pow.zig
index a6589262cd..0d3a45e6d2 100644
--- a/lib/std/math/complex/pow.zig
+++ b/lib/std/math/complex/pow.zig
@@ -23,6 +23,6 @@ test "complex.cpow" {
const b = Complex(f32).new(2.3, -1.3);
const c = pow(Complex(f32), a, b);
- testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));
}
diff --git a/lib/std/math/complex/proj.zig b/lib/std/math/complex/proj.zig
index 42886d8263..260816481b 100644
--- a/lib/std/math/complex/proj.zig
+++ b/lib/std/math/complex/proj.zig
@@ -26,5 +26,5 @@ test "complex.cproj" {
const a = Complex(f32).new(5, 3);
const c = proj(a);
- testing.expect(c.re == 5 and c.im == 3);
+ try testing.expect(c.re == 5 and c.im == 3);
}
diff --git a/lib/std/math/complex/sin.zig b/lib/std/math/complex/sin.zig
index 4288dbb1a1..68551b8596 100644
--- a/lib/std/math/complex/sin.zig
+++ b/lib/std/math/complex/sin.zig
@@ -23,6 +23,6 @@ test "complex.csin" {
const a = Complex(f32).new(5, 3);
const c = sin(a);
- testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));
}
diff --git a/lib/std/math/complex/sinh.zig b/lib/std/math/complex/sinh.zig
index 2861d99f9a..ea09f8e17d 100644
--- a/lib/std/math/complex/sinh.zig
+++ b/lib/std/math/complex/sinh.zig
@@ -164,14 +164,14 @@ test "complex.csinh32" {
const a = Complex(f32).new(5, 3);
const c = sinh(a);
- testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
}
test "complex.csinh64" {
const a = Complex(f64).new(5, 3);
const c = sinh(a);
- testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));
}
diff --git a/lib/std/math/complex/sqrt.zig b/lib/std/math/complex/sqrt.zig
index e03ed221eb..25c486f838 100644
--- a/lib/std/math/complex/sqrt.zig
+++ b/lib/std/math/complex/sqrt.zig
@@ -138,14 +138,14 @@ test "complex.csqrt32" {
const a = Complex(f32).new(5, 3);
const c = sqrt(a);
- testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
}
test "complex.csqrt64" {
const a = Complex(f64).new(5, 3);
const c = sqrt(a);
- testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));
}
diff --git a/lib/std/math/complex/tan.zig b/lib/std/math/complex/tan.zig
index 04d900bd99..ca9d4ce7e9 100644
--- a/lib/std/math/complex/tan.zig
+++ b/lib/std/math/complex/tan.zig
@@ -23,6 +23,6 @@ test "complex.ctan" {
const a = Complex(f32).new(5, 3);
const c = tan(a);
- testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));
}
diff --git a/lib/std/math/complex/tanh.zig b/lib/std/math/complex/tanh.zig
index 19fda8d82f..096bdaac06 100644
--- a/lib/std/math/complex/tanh.zig
+++ b/lib/std/math/complex/tanh.zig
@@ -113,14 +113,14 @@ test "complex.ctanh32" {
const a = Complex(f32).new(5, 3);
const c = tanh(a);
- testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
}
test "complex.ctanh64" {
const a = Complex(f64).new(5, 3);
const c = tanh(a);
- testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));
}
diff --git a/lib/std/math/copysign.zig b/lib/std/math/copysign.zig
index 7861cda8eb..47065fedad 100644
--- a/lib/std/math/copysign.zig
+++ b/lib/std/math/copysign.zig
@@ -62,36 +62,36 @@ fn copysign128(x: f128, y: f128) f128 {
}
test "math.copysign" {
- expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));
- expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));
- expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));
- expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0));
+ try expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));
+ try expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));
+ try expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));
+ try expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0));
}
test "math.copysign16" {
- expect(copysign16(5.0, 1.0) == 5.0);
- expect(copysign16(5.0, -1.0) == -5.0);
- expect(copysign16(-5.0, -1.0) == -5.0);
- expect(copysign16(-5.0, 1.0) == 5.0);
+ try expect(copysign16(5.0, 1.0) == 5.0);
+ try expect(copysign16(5.0, -1.0) == -5.0);
+ try expect(copysign16(-5.0, -1.0) == -5.0);
+ try expect(copysign16(-5.0, 1.0) == 5.0);
}
test "math.copysign32" {
- expect(copysign32(5.0, 1.0) == 5.0);
- expect(copysign32(5.0, -1.0) == -5.0);
- expect(copysign32(-5.0, -1.0) == -5.0);
- expect(copysign32(-5.0, 1.0) == 5.0);
+ try expect(copysign32(5.0, 1.0) == 5.0);
+ try expect(copysign32(5.0, -1.0) == -5.0);
+ try expect(copysign32(-5.0, -1.0) == -5.0);
+ try expect(copysign32(-5.0, 1.0) == 5.0);
}
test "math.copysign64" {
- expect(copysign64(5.0, 1.0) == 5.0);
- expect(copysign64(5.0, -1.0) == -5.0);
- expect(copysign64(-5.0, -1.0) == -5.0);
- expect(copysign64(-5.0, 1.0) == 5.0);
+ try expect(copysign64(5.0, 1.0) == 5.0);
+ try expect(copysign64(5.0, -1.0) == -5.0);
+ try expect(copysign64(-5.0, -1.0) == -5.0);
+ try expect(copysign64(-5.0, 1.0) == 5.0);
}
test "math.copysign128" {
- expect(copysign128(5.0, 1.0) == 5.0);
- expect(copysign128(5.0, -1.0) == -5.0);
- expect(copysign128(-5.0, -1.0) == -5.0);
- expect(copysign128(-5.0, 1.0) == 5.0);
+ try expect(copysign128(5.0, 1.0) == 5.0);
+ try expect(copysign128(5.0, -1.0) == -5.0);
+ try expect(copysign128(-5.0, -1.0) == -5.0);
+ try expect(copysign128(-5.0, 1.0) == 5.0);
}
diff --git a/lib/std/math/cos.zig b/lib/std/math/cos.zig
index 21804a8e5e..de5efacb8d 100644
--- a/lib/std/math/cos.zig
+++ b/lib/std/math/cos.zig
@@ -88,42 +88,42 @@ fn cos_(comptime T: type, x_: T) T {
}
test "math.cos" {
- expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
- expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
+ try expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
+ try expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
}
test "math.cos32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, -1.5), 0.070737, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, -1.5), 0.070737, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));
}
test "math.cos64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, -1.5), 0.070737, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, -1.5), 0.070737, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));
}
test "math.cos32.special" {
- expect(math.isNan(cos_(f32, math.inf(f32))));
- expect(math.isNan(cos_(f32, -math.inf(f32))));
- expect(math.isNan(cos_(f32, math.nan(f32))));
+ try expect(math.isNan(cos_(f32, math.inf(f32))));
+ try expect(math.isNan(cos_(f32, -math.inf(f32))));
+ try expect(math.isNan(cos_(f32, math.nan(f32))));
}
test "math.cos64.special" {
- expect(math.isNan(cos_(f64, math.inf(f64))));
- expect(math.isNan(cos_(f64, -math.inf(f64))));
- expect(math.isNan(cos_(f64, math.nan(f64))));
+ try expect(math.isNan(cos_(f64, math.inf(f64))));
+ try expect(math.isNan(cos_(f64, -math.inf(f64))));
+ try expect(math.isNan(cos_(f64, math.nan(f64))));
}
diff --git a/lib/std/math/cosh.zig b/lib/std/math/cosh.zig
index 25d22057ef..b78c72a882 100644
--- a/lib/std/math/cosh.zig
+++ b/lib/std/math/cosh.zig
@@ -93,48 +93,48 @@ fn cosh64(x: f64) f64 {
}
test "math.cosh" {
- expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
- expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
+ try expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
+ try expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
}
test "math.cosh32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));
- expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));
- expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));
- expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));
- expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));
- expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
}
test "math.cosh64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));
- expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));
- expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));
- expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));
- expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));
- expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));
}
test "math.cosh32.special" {
- expect(cosh32(0.0) == 1.0);
- expect(cosh32(-0.0) == 1.0);
- expect(math.isPositiveInf(cosh32(math.inf(f32))));
- expect(math.isPositiveInf(cosh32(-math.inf(f32))));
- expect(math.isNan(cosh32(math.nan(f32))));
+ try expect(cosh32(0.0) == 1.0);
+ try expect(cosh32(-0.0) == 1.0);
+ try expect(math.isPositiveInf(cosh32(math.inf(f32))));
+ try expect(math.isPositiveInf(cosh32(-math.inf(f32))));
+ try expect(math.isNan(cosh32(math.nan(f32))));
}
test "math.cosh64.special" {
- expect(cosh64(0.0) == 1.0);
- expect(cosh64(-0.0) == 1.0);
- expect(math.isPositiveInf(cosh64(math.inf(f64))));
- expect(math.isPositiveInf(cosh64(-math.inf(f64))));
- expect(math.isNan(cosh64(math.nan(f64))));
+ try expect(cosh64(0.0) == 1.0);
+ try expect(cosh64(-0.0) == 1.0);
+ try expect(math.isPositiveInf(cosh64(math.inf(f64))));
+ try expect(math.isPositiveInf(cosh64(-math.inf(f64))));
+ try expect(math.isNan(cosh64(math.nan(f64))));
}
diff --git a/lib/std/math/exp.zig b/lib/std/math/exp.zig
index 1156cc6c5a..43da387e46 100644
--- a/lib/std/math/exp.zig
+++ b/lib/std/math/exp.zig
@@ -187,36 +187,36 @@ fn exp64(x_: f64) f64 {
}
test "math.exp" {
- expect(exp(@as(f32, 0.0)) == exp32(0.0));
- expect(exp(@as(f64, 0.0)) == exp64(0.0));
+ try expect(exp(@as(f32, 0.0)) == exp32(0.0));
+ try expect(exp(@as(f64, 0.0)) == exp64(0.0));
}
test "math.exp32" {
const epsilon = 0.000001;
- expect(exp32(0.0) == 1.0);
- expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
- expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
- expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
+ try expect(exp32(0.0) == 1.0);
+ try expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
+ try expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
+ try expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
}
test "math.exp64" {
const epsilon = 0.000001;
- expect(exp64(0.0) == 1.0);
- expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
- expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
- expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
+ try expect(exp64(0.0) == 1.0);
+ try expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
+ try expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
+ try expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
}
test "math.exp32.special" {
- expect(math.isPositiveInf(exp32(math.inf(f32))));
- expect(math.isNan(exp32(math.nan(f32))));
+ try expect(math.isPositiveInf(exp32(math.inf(f32))));
+ try expect(math.isNan(exp32(math.nan(f32))));
}
test "math.exp64.special" {
- expect(math.isPositiveInf(exp64(math.inf(f64))));
- expect(math.isNan(exp64(math.nan(f64))));
+ try expect(math.isPositiveInf(exp64(math.inf(f64))));
+ try expect(math.isNan(exp64(math.nan(f64))));
}
diff --git a/lib/std/math/exp2.zig b/lib/std/math/exp2.zig
index 155d10c7f1..e01c997dd7 100644
--- a/lib/std/math/exp2.zig
+++ b/lib/std/math/exp2.zig
@@ -426,35 +426,35 @@ fn exp2_64(x: f64) f64 {
}
test "math.exp2" {
- expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
- expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
+ try expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
+ try expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
}
test "math.exp2_32" {
const epsilon = 0.000001;
- expect(exp2_32(0.0) == 1.0);
- expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));
- expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));
- expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));
- expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));
+ try expect(exp2_32(0.0) == 1.0);
+ try expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));
+ try expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));
+ try expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));
+ try expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));
}
test "math.exp2_64" {
const epsilon = 0.000001;
- expect(exp2_64(0.0) == 1.0);
- expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));
- expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));
- expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));
+ try expect(exp2_64(0.0) == 1.0);
+ try expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));
+ try expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));
+ try expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));
}
test "math.exp2_32.special" {
- expect(math.isPositiveInf(exp2_32(math.inf(f32))));
- expect(math.isNan(exp2_32(math.nan(f32))));
+ try expect(math.isPositiveInf(exp2_32(math.inf(f32))));
+ try expect(math.isNan(exp2_32(math.nan(f32))));
}
test "math.exp2_64.special" {
- expect(math.isPositiveInf(exp2_64(math.inf(f64))));
- expect(math.isNan(exp2_64(math.nan(f64))));
+ try expect(math.isPositiveInf(exp2_64(math.inf(f64))));
+ try expect(math.isNan(exp2_64(math.nan(f64))));
}
diff --git a/lib/std/math/expm1.zig b/lib/std/math/expm1.zig
index 8389b01eb9..7563194880 100644
--- a/lib/std/math/expm1.zig
+++ b/lib/std/math/expm1.zig
@@ -292,42 +292,42 @@ fn expm1_64(x_: f64) f64 {
}
test "math.exp1m" {
- expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
- expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
+ try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
+ try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
}
test "math.expm1_32" {
const epsilon = 0.000001;
- expect(expm1_32(0.0) == 0.0);
- expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));
- expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));
- expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
+ try expect(expm1_32(0.0) == 0.0);
+ try expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));
+ try expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));
+ try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
}
test "math.expm1_64" {
const epsilon = 0.000001;
- expect(expm1_64(0.0) == 0.0);
- expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));
- expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));
- expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));
+ try expect(expm1_64(0.0) == 0.0);
+ try expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));
+ try expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));
+ try expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));
}
test "math.expm1_32.special" {
const epsilon = 0.000001;
- expect(math.isPositiveInf(expm1_32(math.inf(f32))));
- expect(expm1_32(-math.inf(f32)) == -1.0);
- expect(math.isNan(expm1_32(math.nan(f32))));
+ try expect(math.isPositiveInf(expm1_32(math.inf(f32))));
+ try expect(expm1_32(-math.inf(f32)) == -1.0);
+ try expect(math.isNan(expm1_32(math.nan(f32))));
}
test "math.expm1_64.special" {
const epsilon = 0.000001;
- expect(math.isPositiveInf(expm1_64(math.inf(f64))));
- expect(expm1_64(-math.inf(f64)) == -1.0);
- expect(math.isNan(expm1_64(math.nan(f64))));
+ try expect(math.isPositiveInf(expm1_64(math.inf(f64))));
+ try expect(expm1_64(-math.inf(f64)) == -1.0);
+ try expect(math.isNan(expm1_64(math.nan(f64))));
}
diff --git a/lib/std/math/fabs.zig b/lib/std/math/fabs.zig
index d59d185b99..0b3c800b12 100644
--- a/lib/std/math/fabs.zig
+++ b/lib/std/math/fabs.zig
@@ -55,52 +55,52 @@ fn fabs128(x: f128) f128 {
}
test "math.fabs" {
- expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
- expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
- expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
- expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
+ try expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
+ try expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
+ try expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
+ try expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
}
test "math.fabs16" {
- expect(fabs16(1.0) == 1.0);
- expect(fabs16(-1.0) == 1.0);
+ try expect(fabs16(1.0) == 1.0);
+ try expect(fabs16(-1.0) == 1.0);
}
test "math.fabs32" {
- expect(fabs32(1.0) == 1.0);
- expect(fabs32(-1.0) == 1.0);
+ try expect(fabs32(1.0) == 1.0);
+ try expect(fabs32(-1.0) == 1.0);
}
test "math.fabs64" {
- expect(fabs64(1.0) == 1.0);
- expect(fabs64(-1.0) == 1.0);
+ try expect(fabs64(1.0) == 1.0);
+ try expect(fabs64(-1.0) == 1.0);
}
test "math.fabs128" {
- expect(fabs128(1.0) == 1.0);
- expect(fabs128(-1.0) == 1.0);
+ try expect(fabs128(1.0) == 1.0);
+ try expect(fabs128(-1.0) == 1.0);
}
test "math.fabs16.special" {
- expect(math.isPositiveInf(fabs(math.inf(f16))));
- expect(math.isPositiveInf(fabs(-math.inf(f16))));
- expect(math.isNan(fabs(math.nan(f16))));
+ try expect(math.isPositiveInf(fabs(math.inf(f16))));
+ try expect(math.isPositiveInf(fabs(-math.inf(f16))));
+ try expect(math.isNan(fabs(math.nan(f16))));
}
test "math.fabs32.special" {
- expect(math.isPositiveInf(fabs(math.inf(f32))));
- expect(math.isPositiveInf(fabs(-math.inf(f32))));
- expect(math.isNan(fabs(math.nan(f32))));
+ try expect(math.isPositiveInf(fabs(math.inf(f32))));
+ try expect(math.isPositiveInf(fabs(-math.inf(f32))));
+ try expect(math.isNan(fabs(math.nan(f32))));
}
test "math.fabs64.special" {
- expect(math.isPositiveInf(fabs(math.inf(f64))));
- expect(math.isPositiveInf(fabs(-math.inf(f64))));
- expect(math.isNan(fabs(math.nan(f64))));
+ try expect(math.isPositiveInf(fabs(math.inf(f64))));
+ try expect(math.isPositiveInf(fabs(-math.inf(f64))));
+ try expect(math.isNan(fabs(math.nan(f64))));
}
test "math.fabs128.special" {
- expect(math.isPositiveInf(fabs(math.inf(f128))));
- expect(math.isPositiveInf(fabs(-math.inf(f128))));
- expect(math.isNan(fabs(math.nan(f128))));
+ try expect(math.isPositiveInf(fabs(math.inf(f128))));
+ try expect(math.isPositiveInf(fabs(-math.inf(f128))));
+ try expect(math.isNan(fabs(math.nan(f128))));
}
diff --git a/lib/std/math/floor.zig b/lib/std/math/floor.zig
index 6e0b99f47c..ea70ce3969 100644
--- a/lib/std/math/floor.zig
+++ b/lib/std/math/floor.zig
@@ -156,64 +156,64 @@ fn floor128(x: f128) f128 {
}
test "math.floor" {
- expect(floor(@as(f16, 1.3)) == floor16(1.3));
- expect(floor(@as(f32, 1.3)) == floor32(1.3));
- expect(floor(@as(f64, 1.3)) == floor64(1.3));
- expect(floor(@as(f128, 1.3)) == floor128(1.3));
+ try expect(floor(@as(f16, 1.3)) == floor16(1.3));
+ try expect(floor(@as(f32, 1.3)) == floor32(1.3));
+ try expect(floor(@as(f64, 1.3)) == floor64(1.3));
+ try expect(floor(@as(f128, 1.3)) == floor128(1.3));
}
test "math.floor16" {
- expect(floor16(1.3) == 1.0);
- expect(floor16(-1.3) == -2.0);
- expect(floor16(0.2) == 0.0);
+ try expect(floor16(1.3) == 1.0);
+ try expect(floor16(-1.3) == -2.0);
+ try expect(floor16(0.2) == 0.0);
}
test "math.floor32" {
- expect(floor32(1.3) == 1.0);
- expect(floor32(-1.3) == -2.0);
- expect(floor32(0.2) == 0.0);
+ try expect(floor32(1.3) == 1.0);
+ try expect(floor32(-1.3) == -2.0);
+ try expect(floor32(0.2) == 0.0);
}
test "math.floor64" {
- expect(floor64(1.3) == 1.0);
- expect(floor64(-1.3) == -2.0);
- expect(floor64(0.2) == 0.0);
+ try expect(floor64(1.3) == 1.0);
+ try expect(floor64(-1.3) == -2.0);
+ try expect(floor64(0.2) == 0.0);
}
test "math.floor128" {
- expect(floor128(1.3) == 1.0);
- expect(floor128(-1.3) == -2.0);
- expect(floor128(0.2) == 0.0);
+ try expect(floor128(1.3) == 1.0);
+ try expect(floor128(-1.3) == -2.0);
+ try expect(floor128(0.2) == 0.0);
}
test "math.floor16.special" {
- expect(floor16(0.0) == 0.0);
- expect(floor16(-0.0) == -0.0);
- expect(math.isPositiveInf(floor16(math.inf(f16))));
- expect(math.isNegativeInf(floor16(-math.inf(f16))));
- expect(math.isNan(floor16(math.nan(f16))));
+ try expect(floor16(0.0) == 0.0);
+ try expect(floor16(-0.0) == -0.0);
+ try expect(math.isPositiveInf(floor16(math.inf(f16))));
+ try expect(math.isNegativeInf(floor16(-math.inf(f16))));
+ try expect(math.isNan(floor16(math.nan(f16))));
}
test "math.floor32.special" {
- expect(floor32(0.0) == 0.0);
- expect(floor32(-0.0) == -0.0);
- expect(math.isPositiveInf(floor32(math.inf(f32))));
- expect(math.isNegativeInf(floor32(-math.inf(f32))));
- expect(math.isNan(floor32(math.nan(f32))));
+ try expect(floor32(0.0) == 0.0);
+ try expect(floor32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(floor32(math.inf(f32))));
+ try expect(math.isNegativeInf(floor32(-math.inf(f32))));
+ try expect(math.isNan(floor32(math.nan(f32))));
}
test "math.floor64.special" {
- expect(floor64(0.0) == 0.0);
- expect(floor64(-0.0) == -0.0);
- expect(math.isPositiveInf(floor64(math.inf(f64))));
- expect(math.isNegativeInf(floor64(-math.inf(f64))));
- expect(math.isNan(floor64(math.nan(f64))));
+ try expect(floor64(0.0) == 0.0);
+ try expect(floor64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(floor64(math.inf(f64))));
+ try expect(math.isNegativeInf(floor64(-math.inf(f64))));
+ try expect(math.isNan(floor64(math.nan(f64))));
}
test "math.floor128.special" {
- expect(floor128(0.0) == 0.0);
- expect(floor128(-0.0) == -0.0);
- expect(math.isPositiveInf(floor128(math.inf(f128))));
- expect(math.isNegativeInf(floor128(-math.inf(f128))));
- expect(math.isNan(floor128(math.nan(f128))));
+ try expect(floor128(0.0) == 0.0);
+ try expect(floor128(-0.0) == -0.0);
+ try expect(math.isPositiveInf(floor128(math.inf(f128))));
+ try expect(math.isNegativeInf(floor128(-math.inf(f128))));
+ try expect(math.isNan(floor128(math.nan(f128))));
}
diff --git a/lib/std/math/fma.zig b/lib/std/math/fma.zig
index 1b04e1aa18..0bc3271e36 100644
--- a/lib/std/math/fma.zig
+++ b/lib/std/math/fma.zig
@@ -148,30 +148,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
}
test "math.fma" {
- expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));
- expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
+ try expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));
+ try expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
}
test "math.fma32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));
- expect(math.approxEqAbs(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon));
- expect(math.approxEqAbs(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon));
- expect(math.approxEqAbs(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon));
- expect(math.approxEqAbs(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon));
- expect(math.approxEqAbs(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon));
- expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
}
test "math.fma64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));
- expect(math.approxEqAbs(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon));
- expect(math.approxEqAbs(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon));
- expect(math.approxEqAbs(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon));
- expect(math.approxEqAbs(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon));
- expect(math.approxEqAbs(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon));
- expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
}
diff --git a/lib/std/math/frexp.zig b/lib/std/math/frexp.zig
index 5f7bafb494..4f3a03b0bc 100644
--- a/lib/std/math/frexp.zig
+++ b/lib/std/math/frexp.zig
@@ -115,11 +115,11 @@ fn frexp64(x: f64) frexp64_result {
test "math.frexp" {
const a = frexp(@as(f32, 1.3));
const b = frexp32(1.3);
- expect(a.significand == b.significand and a.exponent == b.exponent);
+ try expect(a.significand == b.significand and a.exponent == b.exponent);
const c = frexp(@as(f64, 1.3));
const d = frexp64(1.3);
- expect(c.significand == d.significand and c.exponent == d.exponent);
+ try expect(c.significand == d.significand and c.exponent == d.exponent);
}
test "math.frexp32" {
@@ -127,10 +127,10 @@ test "math.frexp32" {
var r: frexp32_result = undefined;
r = frexp32(1.3);
- expect(math.approxEqAbs(f32, r.significand, 0.65, epsilon) and r.exponent == 1);
+ try expect(math.approxEqAbs(f32, r.significand, 0.65, epsilon) and r.exponent == 1);
r = frexp32(78.0234);
- expect(math.approxEqAbs(f32, r.significand, 0.609558, epsilon) and r.exponent == 7);
+ try expect(math.approxEqAbs(f32, r.significand, 0.609558, epsilon) and r.exponent == 7);
}
test "math.frexp64" {
@@ -138,46 +138,46 @@ test "math.frexp64" {
var r: frexp64_result = undefined;
r = frexp64(1.3);
- expect(math.approxEqAbs(f64, r.significand, 0.65, epsilon) and r.exponent == 1);
+ try expect(math.approxEqAbs(f64, r.significand, 0.65, epsilon) and r.exponent == 1);
r = frexp64(78.0234);
- expect(math.approxEqAbs(f64, r.significand, 0.609558, epsilon) and r.exponent == 7);
+ try expect(math.approxEqAbs(f64, r.significand, 0.609558, epsilon) and r.exponent == 7);
}
test "math.frexp32.special" {
var r: frexp32_result = undefined;
r = frexp32(0.0);
- expect(r.significand == 0.0 and r.exponent == 0);
+ try expect(r.significand == 0.0 and r.exponent == 0);
r = frexp32(-0.0);
- expect(r.significand == -0.0 and r.exponent == 0);
+ try expect(r.significand == -0.0 and r.exponent == 0);
r = frexp32(math.inf(f32));
- expect(math.isPositiveInf(r.significand) and r.exponent == 0);
+ try expect(math.isPositiveInf(r.significand) and r.exponent == 0);
r = frexp32(-math.inf(f32));
- expect(math.isNegativeInf(r.significand) and r.exponent == 0);
+ try expect(math.isNegativeInf(r.significand) and r.exponent == 0);
r = frexp32(math.nan(f32));
- expect(math.isNan(r.significand));
+ try expect(math.isNan(r.significand));
}
test "math.frexp64.special" {
var r: frexp64_result = undefined;
r = frexp64(0.0);
- expect(r.significand == 0.0 and r.exponent == 0);
+ try expect(r.significand == 0.0 and r.exponent == 0);
r = frexp64(-0.0);
- expect(r.significand == -0.0 and r.exponent == 0);
+ try expect(r.significand == -0.0 and r.exponent == 0);
r = frexp64(math.inf(f64));
- expect(math.isPositiveInf(r.significand) and r.exponent == 0);
+ try expect(math.isPositiveInf(r.significand) and r.exponent == 0);
r = frexp64(-math.inf(f64));
- expect(math.isNegativeInf(r.significand) and r.exponent == 0);
+ try expect(math.isNegativeInf(r.significand) and r.exponent == 0);
r = frexp64(math.nan(f64));
- expect(math.isNan(r.significand));
+ try expect(math.isNan(r.significand));
}
diff --git a/lib/std/math/hypot.zig b/lib/std/math/hypot.zig
index 78aef476f9..61f172aa6a 100644
--- a/lib/std/math/hypot.zig
+++ b/lib/std/math/hypot.zig
@@ -126,48 +126,48 @@ fn hypot64(x: f64, y: f64) f64 {
}
test "math.hypot" {
- expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));
- expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
+ try expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));
+ try expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
}
test "math.hypot32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
- expect(math.approxEqAbs(f32, hypot32(0.2, -0.34), 0.394462, epsilon));
- expect(math.approxEqAbs(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));
- expect(math.approxEqAbs(f32, hypot32(1.5, 5.25), 5.460083, epsilon));
- expect(math.approxEqAbs(f32, hypot32(37.45, 159.835), 164.163742, epsilon));
- expect(math.approxEqAbs(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));
- expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(0.2, -0.34), 0.394462, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(1.5, 5.25), 5.460083, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(37.45, 159.835), 164.163742, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
}
test "math.hypot64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));
- expect(math.approxEqAbs(f64, hypot64(0.2, -0.34), 0.394462, epsilon));
- expect(math.approxEqAbs(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));
- expect(math.approxEqAbs(f64, hypot64(1.5, 5.25), 5.460082, epsilon));
- expect(math.approxEqAbs(f64, hypot64(37.45, 159.835), 164.163728, epsilon));
- expect(math.approxEqAbs(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));
- expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(0.2, -0.34), 0.394462, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(1.5, 5.25), 5.460082, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(37.45, 159.835), 164.163728, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
}
test "math.hypot32.special" {
- expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
- expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
- expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
- expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
- expect(math.isNan(hypot32(math.nan(f32), 0.0)));
- expect(math.isNan(hypot32(0.0, math.nan(f32))));
+ try expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
+ try expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
+ try expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
+ try expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
+ try expect(math.isNan(hypot32(math.nan(f32), 0.0)));
+ try expect(math.isNan(hypot32(0.0, math.nan(f32))));
}
test "math.hypot64.special" {
- expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
- expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
- expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
- expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
- expect(math.isNan(hypot64(math.nan(f64), 0.0)));
- expect(math.isNan(hypot64(0.0, math.nan(f64))));
+ try expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
+ try expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
+ try expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
+ try expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
+ try expect(math.isNan(hypot64(math.nan(f64), 0.0)));
+ try expect(math.isNan(hypot64(0.0, math.nan(f64))));
}
diff --git a/lib/std/math/ilogb.zig b/lib/std/math/ilogb.zig
index e43012b831..deafeda7ce 100644
--- a/lib/std/math/ilogb.zig
+++ b/lib/std/math/ilogb.zig
@@ -106,38 +106,38 @@ fn ilogb64(x: f64) i32 {
}
test "math.ilogb" {
- expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
- expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
+ try expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
+ try expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
}
test "math.ilogb32" {
- expect(ilogb32(0.0) == fp_ilogb0);
- expect(ilogb32(0.5) == -1);
- expect(ilogb32(0.8923) == -1);
- expect(ilogb32(10.0) == 3);
- expect(ilogb32(-123984) == 16);
- expect(ilogb32(2398.23) == 11);
+ try expect(ilogb32(0.0) == fp_ilogb0);
+ try expect(ilogb32(0.5) == -1);
+ try expect(ilogb32(0.8923) == -1);
+ try expect(ilogb32(10.0) == 3);
+ try expect(ilogb32(-123984) == 16);
+ try expect(ilogb32(2398.23) == 11);
}
test "math.ilogb64" {
- expect(ilogb64(0.0) == fp_ilogb0);
- expect(ilogb64(0.5) == -1);
- expect(ilogb64(0.8923) == -1);
- expect(ilogb64(10.0) == 3);
- expect(ilogb64(-123984) == 16);
- expect(ilogb64(2398.23) == 11);
+ try expect(ilogb64(0.0) == fp_ilogb0);
+ try expect(ilogb64(0.5) == -1);
+ try expect(ilogb64(0.8923) == -1);
+ try expect(ilogb64(10.0) == 3);
+ try expect(ilogb64(-123984) == 16);
+ try expect(ilogb64(2398.23) == 11);
}
test "math.ilogb32.special" {
- expect(ilogb32(math.inf(f32)) == maxInt(i32));
- expect(ilogb32(-math.inf(f32)) == maxInt(i32));
- expect(ilogb32(0.0) == minInt(i32));
- expect(ilogb32(math.nan(f32)) == maxInt(i32));
+ try expect(ilogb32(math.inf(f32)) == maxInt(i32));
+ try expect(ilogb32(-math.inf(f32)) == maxInt(i32));
+ try expect(ilogb32(0.0) == minInt(i32));
+ try expect(ilogb32(math.nan(f32)) == maxInt(i32));
}
test "math.ilogb64.special" {
- expect(ilogb64(math.inf(f64)) == maxInt(i32));
- expect(ilogb64(-math.inf(f64)) == maxInt(i32));
- expect(ilogb64(0.0) == minInt(i32));
- expect(ilogb64(math.nan(f64)) == maxInt(i32));
+ try expect(ilogb64(math.inf(f64)) == maxInt(i32));
+ try expect(ilogb64(-math.inf(f64)) == maxInt(i32));
+ try expect(ilogb64(0.0) == minInt(i32));
+ try expect(ilogb64(math.nan(f64)) == maxInt(i32));
}
diff --git a/lib/std/math/isfinite.zig b/lib/std/math/isfinite.zig
index 11a352b042..68aec258b0 100644
--- a/lib/std/math/isfinite.zig
+++ b/lib/std/math/isfinite.zig
@@ -35,30 +35,30 @@ pub fn isFinite(x: anytype) bool {
}
test "math.isFinite" {
- expect(isFinite(@as(f16, 0.0)));
- expect(isFinite(@as(f16, -0.0)));
- expect(isFinite(@as(f32, 0.0)));
- expect(isFinite(@as(f32, -0.0)));
- expect(isFinite(@as(f64, 0.0)));
- expect(isFinite(@as(f64, -0.0)));
- expect(isFinite(@as(f128, 0.0)));
- expect(isFinite(@as(f128, -0.0)));
+ try expect(isFinite(@as(f16, 0.0)));
+ try expect(isFinite(@as(f16, -0.0)));
+ try expect(isFinite(@as(f32, 0.0)));
+ try expect(isFinite(@as(f32, -0.0)));
+ try expect(isFinite(@as(f64, 0.0)));
+ try expect(isFinite(@as(f64, -0.0)));
+ try expect(isFinite(@as(f128, 0.0)));
+ try expect(isFinite(@as(f128, -0.0)));
- expect(!isFinite(math.inf(f16)));
- expect(!isFinite(-math.inf(f16)));
- expect(!isFinite(math.inf(f32)));
- expect(!isFinite(-math.inf(f32)));
- expect(!isFinite(math.inf(f64)));
- expect(!isFinite(-math.inf(f64)));
- expect(!isFinite(math.inf(f128)));
- expect(!isFinite(-math.inf(f128)));
+ try expect(!isFinite(math.inf(f16)));
+ try expect(!isFinite(-math.inf(f16)));
+ try expect(!isFinite(math.inf(f32)));
+ try expect(!isFinite(-math.inf(f32)));
+ try expect(!isFinite(math.inf(f64)));
+ try expect(!isFinite(-math.inf(f64)));
+ try expect(!isFinite(math.inf(f128)));
+ try expect(!isFinite(-math.inf(f128)));
- expect(!isFinite(math.nan(f16)));
- expect(!isFinite(-math.nan(f16)));
- expect(!isFinite(math.nan(f32)));
- expect(!isFinite(-math.nan(f32)));
- expect(!isFinite(math.nan(f64)));
- expect(!isFinite(-math.nan(f64)));
- expect(!isFinite(math.nan(f128)));
- expect(!isFinite(-math.nan(f128)));
+ try expect(!isFinite(math.nan(f16)));
+ try expect(!isFinite(-math.nan(f16)));
+ try expect(!isFinite(math.nan(f32)));
+ try expect(!isFinite(-math.nan(f32)));
+ try expect(!isFinite(math.nan(f64)));
+ try expect(!isFinite(-math.nan(f64)));
+ try expect(!isFinite(math.nan(f128)));
+ try expect(!isFinite(-math.nan(f128)));
}
diff --git a/lib/std/math/isinf.zig b/lib/std/math/isinf.zig
index b7c3199f15..792e6b38f3 100644
--- a/lib/std/math/isinf.zig
+++ b/lib/std/math/isinf.zig
@@ -79,58 +79,58 @@ pub fn isNegativeInf(x: anytype) bool {
}
test "math.isInf" {
- expect(!isInf(@as(f16, 0.0)));
- expect(!isInf(@as(f16, -0.0)));
- expect(!isInf(@as(f32, 0.0)));
- expect(!isInf(@as(f32, -0.0)));
- expect(!isInf(@as(f64, 0.0)));
- expect(!isInf(@as(f64, -0.0)));
- expect(!isInf(@as(f128, 0.0)));
- expect(!isInf(@as(f128, -0.0)));
- expect(isInf(math.inf(f16)));
- expect(isInf(-math.inf(f16)));
- expect(isInf(math.inf(f32)));
- expect(isInf(-math.inf(f32)));
- expect(isInf(math.inf(f64)));
- expect(isInf(-math.inf(f64)));
- expect(isInf(math.inf(f128)));
- expect(isInf(-math.inf(f128)));
+ try expect(!isInf(@as(f16, 0.0)));
+ try expect(!isInf(@as(f16, -0.0)));
+ try expect(!isInf(@as(f32, 0.0)));
+ try expect(!isInf(@as(f32, -0.0)));
+ try expect(!isInf(@as(f64, 0.0)));
+ try expect(!isInf(@as(f64, -0.0)));
+ try expect(!isInf(@as(f128, 0.0)));
+ try expect(!isInf(@as(f128, -0.0)));
+ try expect(isInf(math.inf(f16)));
+ try expect(isInf(-math.inf(f16)));
+ try expect(isInf(math.inf(f32)));
+ try expect(isInf(-math.inf(f32)));
+ try expect(isInf(math.inf(f64)));
+ try expect(isInf(-math.inf(f64)));
+ try expect(isInf(math.inf(f128)));
+ try expect(isInf(-math.inf(f128)));
}
test "math.isPositiveInf" {
- expect(!isPositiveInf(@as(f16, 0.0)));
- expect(!isPositiveInf(@as(f16, -0.0)));
- expect(!isPositiveInf(@as(f32, 0.0)));
- expect(!isPositiveInf(@as(f32, -0.0)));
- expect(!isPositiveInf(@as(f64, 0.0)));
- expect(!isPositiveInf(@as(f64, -0.0)));
- expect(!isPositiveInf(@as(f128, 0.0)));
- expect(!isPositiveInf(@as(f128, -0.0)));
- expect(isPositiveInf(math.inf(f16)));
- expect(!isPositiveInf(-math.inf(f16)));
- expect(isPositiveInf(math.inf(f32)));
- expect(!isPositiveInf(-math.inf(f32)));
- expect(isPositiveInf(math.inf(f64)));
- expect(!isPositiveInf(-math.inf(f64)));
- expect(isPositiveInf(math.inf(f128)));
- expect(!isPositiveInf(-math.inf(f128)));
+ try expect(!isPositiveInf(@as(f16, 0.0)));
+ try expect(!isPositiveInf(@as(f16, -0.0)));
+ try expect(!isPositiveInf(@as(f32, 0.0)));
+ try expect(!isPositiveInf(@as(f32, -0.0)));
+ try expect(!isPositiveInf(@as(f64, 0.0)));
+ try expect(!isPositiveInf(@as(f64, -0.0)));
+ try expect(!isPositiveInf(@as(f128, 0.0)));
+ try expect(!isPositiveInf(@as(f128, -0.0)));
+ try expect(isPositiveInf(math.inf(f16)));
+ try expect(!isPositiveInf(-math.inf(f16)));
+ try expect(isPositiveInf(math.inf(f32)));
+ try expect(!isPositiveInf(-math.inf(f32)));
+ try expect(isPositiveInf(math.inf(f64)));
+ try expect(!isPositiveInf(-math.inf(f64)));
+ try expect(isPositiveInf(math.inf(f128)));
+ try expect(!isPositiveInf(-math.inf(f128)));
}
test "math.isNegativeInf" {
- expect(!isNegativeInf(@as(f16, 0.0)));
- expect(!isNegativeInf(@as(f16, -0.0)));
- expect(!isNegativeInf(@as(f32, 0.0)));
- expect(!isNegativeInf(@as(f32, -0.0)));
- expect(!isNegativeInf(@as(f64, 0.0)));
- expect(!isNegativeInf(@as(f64, -0.0)));
- expect(!isNegativeInf(@as(f128, 0.0)));
- expect(!isNegativeInf(@as(f128, -0.0)));
- expect(!isNegativeInf(math.inf(f16)));
- expect(isNegativeInf(-math.inf(f16)));
- expect(!isNegativeInf(math.inf(f32)));
- expect(isNegativeInf(-math.inf(f32)));
- expect(!isNegativeInf(math.inf(f64)));
- expect(isNegativeInf(-math.inf(f64)));
- expect(!isNegativeInf(math.inf(f128)));
- expect(isNegativeInf(-math.inf(f128)));
+ try expect(!isNegativeInf(@as(f16, 0.0)));
+ try expect(!isNegativeInf(@as(f16, -0.0)));
+ try expect(!isNegativeInf(@as(f32, 0.0)));
+ try expect(!isNegativeInf(@as(f32, -0.0)));
+ try expect(!isNegativeInf(@as(f64, 0.0)));
+ try expect(!isNegativeInf(@as(f64, -0.0)));
+ try expect(!isNegativeInf(@as(f128, 0.0)));
+ try expect(!isNegativeInf(@as(f128, -0.0)));
+ try expect(!isNegativeInf(math.inf(f16)));
+ try expect(isNegativeInf(-math.inf(f16)));
+ try expect(!isNegativeInf(math.inf(f32)));
+ try expect(isNegativeInf(-math.inf(f32)));
+ try expect(!isNegativeInf(math.inf(f64)));
+ try expect(isNegativeInf(-math.inf(f64)));
+ try expect(!isNegativeInf(math.inf(f128)));
+ try expect(isNegativeInf(-math.inf(f128)));
}
diff --git a/lib/std/math/isnan.zig b/lib/std/math/isnan.zig
index 498d181118..cf598322e5 100644
--- a/lib/std/math/isnan.zig
+++ b/lib/std/math/isnan.zig
@@ -21,12 +21,12 @@ pub fn isSignalNan(x: anytype) bool {
}
test "math.isNan" {
- expect(isNan(math.nan(f16)));
- expect(isNan(math.nan(f32)));
- expect(isNan(math.nan(f64)));
- expect(isNan(math.nan(f128)));
- expect(!isNan(@as(f16, 1.0)));
- expect(!isNan(@as(f32, 1.0)));
- expect(!isNan(@as(f64, 1.0)));
- expect(!isNan(@as(f128, 1.0)));
+ try expect(isNan(math.nan(f16)));
+ try expect(isNan(math.nan(f32)));
+ try expect(isNan(math.nan(f64)));
+ try expect(isNan(math.nan(f128)));
+ try expect(!isNan(@as(f16, 1.0)));
+ try expect(!isNan(@as(f32, 1.0)));
+ try expect(!isNan(@as(f64, 1.0)));
+ try expect(!isNan(@as(f128, 1.0)));
}
diff --git a/lib/std/math/isnormal.zig b/lib/std/math/isnormal.zig
index 6317535203..b10a6e2286 100644
--- a/lib/std/math/isnormal.zig
+++ b/lib/std/math/isnormal.zig
@@ -31,13 +31,13 @@ pub fn isNormal(x: anytype) bool {
}
test "math.isNormal" {
- expect(!isNormal(math.nan(f16)));
- expect(!isNormal(math.nan(f32)));
- expect(!isNormal(math.nan(f64)));
- expect(!isNormal(@as(f16, 0)));
- expect(!isNormal(@as(f32, 0)));
- expect(!isNormal(@as(f64, 0)));
- expect(isNormal(@as(f16, 1.0)));
- expect(isNormal(@as(f32, 1.0)));
- expect(isNormal(@as(f64, 1.0)));
+ try expect(!isNormal(math.nan(f16)));
+ try expect(!isNormal(math.nan(f32)));
+ try expect(!isNormal(math.nan(f64)));
+ try expect(!isNormal(@as(f16, 0)));
+ try expect(!isNormal(@as(f32, 0)));
+ try expect(!isNormal(@as(f64, 0)));
+ try expect(isNormal(@as(f16, 1.0)));
+ try expect(isNormal(@as(f32, 1.0)));
+ try expect(isNormal(@as(f64, 1.0)));
}
diff --git a/lib/std/math/ln.zig b/lib/std/math/ln.zig
index ce7cb3d882..f85571fe34 100644
--- a/lib/std/math/ln.zig
+++ b/lib/std/math/ln.zig
@@ -153,42 +153,42 @@ pub fn ln_64(x_: f64) f64 {
}
test "math.ln" {
- expect(ln(@as(f32, 0.2)) == ln_32(0.2));
- expect(ln(@as(f64, 0.2)) == ln_64(0.2));
+ try expect(ln(@as(f32, 0.2)) == ln_32(0.2));
+ try expect(ln(@as(f64, 0.2)) == ln_64(0.2));
}
test "math.ln32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));
- expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));
- expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));
- expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));
- expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));
- expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));
}
test "math.ln64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));
- expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));
- expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));
- expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));
- expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));
- expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));
}
test "math.ln32.special" {
- expect(math.isPositiveInf(ln_32(math.inf(f32))));
- expect(math.isNegativeInf(ln_32(0.0)));
- expect(math.isNan(ln_32(-1.0)));
- expect(math.isNan(ln_32(math.nan(f32))));
+ try expect(math.isPositiveInf(ln_32(math.inf(f32))));
+ try expect(math.isNegativeInf(ln_32(0.0)));
+ try expect(math.isNan(ln_32(-1.0)));
+ try expect(math.isNan(ln_32(math.nan(f32))));
}
test "math.ln64.special" {
- expect(math.isPositiveInf(ln_64(math.inf(f64))));
- expect(math.isNegativeInf(ln_64(0.0)));
- expect(math.isNan(ln_64(-1.0)));
- expect(math.isNan(ln_64(math.nan(f64))));
+ try expect(math.isPositiveInf(ln_64(math.inf(f64))));
+ try expect(math.isNegativeInf(ln_64(0.0)));
+ try expect(math.isNan(ln_64(-1.0)));
+ try expect(math.isNan(ln_64(math.nan(f64))));
}
diff --git a/lib/std/math/log.zig b/lib/std/math/log.zig
index 1a8101e67a..bf170aa95b 100644
--- a/lib/std/math/log.zig
+++ b/lib/std/math/log.zig
@@ -53,25 +53,25 @@ pub fn log(comptime T: type, base: T, x: T) T {
}
test "math.log integer" {
- expect(log(u8, 2, 0x1) == 0);
- expect(log(u8, 2, 0x2) == 1);
- expect(log(u16, 2, 0x72) == 6);
- expect(log(u32, 2, 0xFFFFFF) == 23);
- expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
+ try expect(log(u8, 2, 0x1) == 0);
+ try expect(log(u8, 2, 0x2) == 1);
+ try expect(log(u16, 2, 0x72) == 6);
+ try expect(log(u32, 2, 0xFFFFFF) == 23);
+ try expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
}
test "math.log float" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
- expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
- expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
+ try expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
+ try expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
+ try expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
}
test "math.log float_special" {
- expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
- expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));
+ try expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
+ try expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));
- expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
- expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
+ try expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
+ try expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
}
diff --git a/lib/std/math/log10.zig b/lib/std/math/log10.zig
index a8211a7270..56e4afbab6 100644
--- a/lib/std/math/log10.zig
+++ b/lib/std/math/log10.zig
@@ -181,42 +181,42 @@ pub fn log10_64(x_: f64) f64 {
}
test "math.log10" {
- testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
- testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
+ try testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
+ try testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
}
test "math.log10_32" {
const epsilon = 0.000001;
- testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon));
- testing.expect(math.approxEqAbs(f32, log10_32(0.8923), -0.049489, epsilon));
- testing.expect(math.approxEqAbs(f32, log10_32(1.5), 0.176091, epsilon));
- testing.expect(math.approxEqAbs(f32, log10_32(37.45), 1.573452, epsilon));
- testing.expect(math.approxEqAbs(f32, log10_32(89.123), 1.94999, epsilon));
- testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(0.8923), -0.049489, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(1.5), 0.176091, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(37.45), 1.573452, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(89.123), 1.94999, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon));
}
test "math.log10_64" {
const epsilon = 0.000001;
- testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon));
- testing.expect(math.approxEqAbs(f64, log10_64(0.8923), -0.049489, epsilon));
- testing.expect(math.approxEqAbs(f64, log10_64(1.5), 0.176091, epsilon));
- testing.expect(math.approxEqAbs(f64, log10_64(37.45), 1.573452, epsilon));
- testing.expect(math.approxEqAbs(f64, log10_64(89.123), 1.94999, epsilon));
- testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(0.8923), -0.049489, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(1.5), 0.176091, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(37.45), 1.573452, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(89.123), 1.94999, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon));
}
test "math.log10_32.special" {
- testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
- testing.expect(math.isNegativeInf(log10_32(0.0)));
- testing.expect(math.isNan(log10_32(-1.0)));
- testing.expect(math.isNan(log10_32(math.nan(f32))));
+ try testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
+ try testing.expect(math.isNegativeInf(log10_32(0.0)));
+ try testing.expect(math.isNan(log10_32(-1.0)));
+ try testing.expect(math.isNan(log10_32(math.nan(f32))));
}
test "math.log10_64.special" {
- testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
- testing.expect(math.isNegativeInf(log10_64(0.0)));
- testing.expect(math.isNan(log10_64(-1.0)));
- testing.expect(math.isNan(log10_64(math.nan(f64))));
+ try testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
+ try testing.expect(math.isNegativeInf(log10_64(0.0)));
+ try testing.expect(math.isNan(log10_64(-1.0)));
+ try testing.expect(math.isNan(log10_64(math.nan(f64))));
}
diff --git a/lib/std/math/log1p.zig b/lib/std/math/log1p.zig
index 4eaee2c43f..6c03d7b263 100644
--- a/lib/std/math/log1p.zig
+++ b/lib/std/math/log1p.zig
@@ -188,48 +188,48 @@ fn log1p_64(x: f64) f64 {
}
test "math.log1p" {
- expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
- expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
+ try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
+ try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
}
test "math.log1p_32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
}
test "math.log1p_64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));
}
test "math.log1p_32.special" {
- expect(math.isPositiveInf(log1p_32(math.inf(f32))));
- expect(log1p_32(0.0) == 0.0);
- expect(log1p_32(-0.0) == -0.0);
- expect(math.isNegativeInf(log1p_32(-1.0)));
- expect(math.isNan(log1p_32(-2.0)));
- expect(math.isNan(log1p_32(math.nan(f32))));
+ try expect(math.isPositiveInf(log1p_32(math.inf(f32))));
+ try expect(log1p_32(0.0) == 0.0);
+ try expect(log1p_32(-0.0) == -0.0);
+ try expect(math.isNegativeInf(log1p_32(-1.0)));
+ try expect(math.isNan(log1p_32(-2.0)));
+ try expect(math.isNan(log1p_32(math.nan(f32))));
}
test "math.log1p_64.special" {
- expect(math.isPositiveInf(log1p_64(math.inf(f64))));
- expect(log1p_64(0.0) == 0.0);
- expect(log1p_64(-0.0) == -0.0);
- expect(math.isNegativeInf(log1p_64(-1.0)));
- expect(math.isNan(log1p_64(-2.0)));
- expect(math.isNan(log1p_64(math.nan(f64))));
+ try expect(math.isPositiveInf(log1p_64(math.inf(f64))));
+ try expect(log1p_64(0.0) == 0.0);
+ try expect(log1p_64(-0.0) == -0.0);
+ try expect(math.isNegativeInf(log1p_64(-1.0)));
+ try expect(math.isNan(log1p_64(-2.0)));
+ try expect(math.isNan(log1p_64(math.nan(f64))));
}
diff --git a/lib/std/math/log2.zig b/lib/std/math/log2.zig
index 76bc79407c..1a42404fea 100644
--- a/lib/std/math/log2.zig
+++ b/lib/std/math/log2.zig
@@ -179,40 +179,40 @@ pub fn log2_64(x_: f64) f64 {
}
test "math.log2" {
- expect(log2(@as(f32, 0.2)) == log2_32(0.2));
- expect(log2(@as(f64, 0.2)) == log2_64(0.2));
+ try expect(log2(@as(f32, 0.2)) == log2_32(0.2));
+ try expect(log2(@as(f64, 0.2)) == log2_64(0.2));
}
test "math.log2_32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));
- expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));
- expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));
- expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));
- expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));
+ try expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));
+ try expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));
+ try expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));
+ try expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));
+ try expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));
}
test "math.log2_64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));
- expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));
- expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));
- expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));
- expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));
+ try expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));
+ try expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));
+ try expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));
+ try expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));
+ try expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));
}
test "math.log2_32.special" {
- expect(math.isPositiveInf(log2_32(math.inf(f32))));
- expect(math.isNegativeInf(log2_32(0.0)));
- expect(math.isNan(log2_32(-1.0)));
- expect(math.isNan(log2_32(math.nan(f32))));
+ try expect(math.isPositiveInf(log2_32(math.inf(f32))));
+ try expect(math.isNegativeInf(log2_32(0.0)));
+ try expect(math.isNan(log2_32(-1.0)));
+ try expect(math.isNan(log2_32(math.nan(f32))));
}
test "math.log2_64.special" {
- expect(math.isPositiveInf(log2_64(math.inf(f64))));
- expect(math.isNegativeInf(log2_64(0.0)));
- expect(math.isNan(log2_64(-1.0)));
- expect(math.isNan(log2_64(math.nan(f64))));
+ try expect(math.isPositiveInf(log2_64(math.inf(f64))));
+ try expect(math.isNegativeInf(log2_64(0.0)));
+ try expect(math.isNan(log2_64(-1.0)));
+ try expect(math.isNan(log2_64(math.nan(f64))));
}
diff --git a/lib/std/math/modf.zig b/lib/std/math/modf.zig
index 390b3e4f49..6eef6fdd37 100644
--- a/lib/std/math/modf.zig
+++ b/lib/std/math/modf.zig
@@ -131,11 +131,11 @@ test "math.modf" {
const a = modf(@as(f32, 1.0));
const b = modf32(1.0);
// NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
- expect(a.ipart == b.ipart and a.fpart == b.fpart);
+ try expect(a.ipart == b.ipart and a.fpart == b.fpart);
const c = modf(@as(f64, 1.0));
const d = modf64(1.0);
- expect(a.ipart == b.ipart and a.fpart == b.fpart);
+ try expect(a.ipart == b.ipart and a.fpart == b.fpart);
}
test "math.modf32" {
@@ -143,24 +143,24 @@ test "math.modf32" {
var r: modf32_result = undefined;
r = modf32(1.0);
- expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));
- expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));
r = modf32(2.545);
- expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));
- expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));
+ try expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));
r = modf32(3.978123);
- expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));
- expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));
+ try expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));
+ try expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));
r = modf32(43874.3);
- expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));
- expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));
+ try expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));
+ try expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));
r = modf32(1234.340780);
- expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));
- expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
+ try expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));
+ try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
}
test "math.modf64" {
@@ -168,48 +168,48 @@ test "math.modf64" {
var r: modf64_result = undefined;
r = modf64(1.0);
- expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));
- expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));
r = modf64(2.545);
- expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));
- expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));
+ try expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));
r = modf64(3.978123);
- expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));
- expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));
+ try expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));
+ try expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));
r = modf64(43874.3);
- expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));
- expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));
+ try expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));
+ try expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));
r = modf64(1234.340780);
- expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));
- expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));
+ try expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));
+ try expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));
}
test "math.modf32.special" {
var r: modf32_result = undefined;
r = modf32(math.inf(f32));
- expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
r = modf32(-math.inf(f32));
- expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
r = modf32(math.nan(f32));
- expect(math.isNan(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isNan(r.ipart) and math.isNan(r.fpart));
}
test "math.modf64.special" {
var r: modf64_result = undefined;
r = modf64(math.inf(f64));
- expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
r = modf64(-math.inf(f64));
- expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
r = modf64(math.nan(f64));
- expect(math.isNan(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isNan(r.ipart) and math.isNan(r.fpart));
}
diff --git a/lib/std/math/pow.zig b/lib/std/math/pow.zig
index 5c49c95865..686724761c 100644
--- a/lib/std/math/pow.zig
+++ b/lib/std/math/pow.zig
@@ -191,67 +191,67 @@ fn isOddInteger(x: f64) bool {
test "math.pow" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
}
test "math.pow.special" {
const epsilon = 0.000001;
- expect(pow(f32, 4, 0.0) == 1.0);
- expect(pow(f32, 7, -0.0) == 1.0);
- expect(pow(f32, 45, 1.0) == 45);
- expect(pow(f32, -45, 1.0) == -45);
- expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
- expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));
- expect(math.isPositiveInf(pow(f32, -0, -0.5)));
- expect(pow(f32, -0, 0.5) == 0);
- expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
- expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
+ try expect(pow(f32, 4, 0.0) == 1.0);
+ try expect(pow(f32, 7, -0.0) == 1.0);
+ try expect(pow(f32, 45, 1.0) == 45);
+ try expect(pow(f32, -45, 1.0) == -45);
+ try expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
+ try expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));
+ try expect(math.isPositiveInf(pow(f32, -0, -0.5)));
+ try expect(pow(f32, -0, 0.5) == 0);
+ try expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
+ try expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
//expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?
- expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
- expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
- expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
- expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
- expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
- expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
- expect(pow(f32, 0.0, 1.0) == 0.0);
- expect(pow(f32, -0.0, 1.0) == -0.0);
- expect(pow(f32, 0.0, 2.0) == 0.0);
- expect(pow(f32, -0.0, 2.0) == 0.0);
- expect(math.approxEqAbs(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon));
- expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
- expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
- expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
- expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
- expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
- expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
- expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
- expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
- expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
- expect(pow(f32, math.inf(f32), -1.0) == 0.0);
+ try expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
+ try expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
+ try expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
+ try expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
+ try expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
+ try expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
+ try expect(pow(f32, 0.0, 1.0) == 0.0);
+ try expect(pow(f32, -0.0, 1.0) == -0.0);
+ try expect(pow(f32, 0.0, 2.0) == 0.0);
+ try expect(pow(f32, -0.0, 2.0) == 0.0);
+ try expect(math.approxEqAbs(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon));
+ try expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
+ try expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
+ try expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
+ try expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
+ try expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
+ try expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
+ try expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
+ try expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
+ try expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
+ try expect(pow(f32, math.inf(f32), -1.0) == 0.0);
//expect(pow(f32, -math.inf(f32), 5.0) == pow(f32, -0.0, -5.0)); TODO support negative 0?
- expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
- expect(math.isNan(pow(f32, -1.0, 1.2)));
- expect(math.isNan(pow(f32, -12.4, 78.5)));
+ try expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
+ try expect(math.isNan(pow(f32, -1.0, 1.2)));
+ try expect(math.isNan(pow(f32, -12.4, 78.5)));
}
test "math.pow.overflow" {
- expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));
- expect(pow(f64, 2, -(1 << 32)) == 0);
- expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));
- expect(pow(f64, 0.5, 1 << 45) == 0);
- expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));
+ try expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));
+ try expect(pow(f64, 2, -(1 << 32)) == 0);
+ try expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));
+ try expect(pow(f64, 0.5, 1 << 45) == 0);
+ try expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));
}
diff --git a/lib/std/math/powi.zig b/lib/std/math/powi.zig
index e415b74d87..3643a119ba 100644
--- a/lib/std/math/powi.zig
+++ b/lib/std/math/powi.zig
@@ -112,82 +112,82 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
}
test "math.powi" {
- testing.expectError(error.Underflow, powi(i8, -66, 6));
- testing.expectError(error.Underflow, powi(i16, -13, 13));
- testing.expectError(error.Underflow, powi(i32, -32, 21));
- testing.expectError(error.Underflow, powi(i64, -24, 61));
- testing.expectError(error.Underflow, powi(i17, -15, 15));
- testing.expectError(error.Underflow, powi(i42, -6, 40));
+ try testing.expectError(error.Underflow, powi(i8, -66, 6));
+ try testing.expectError(error.Underflow, powi(i16, -13, 13));
+ try testing.expectError(error.Underflow, powi(i32, -32, 21));
+ try testing.expectError(error.Underflow, powi(i64, -24, 61));
+ try testing.expectError(error.Underflow, powi(i17, -15, 15));
+ try testing.expectError(error.Underflow, powi(i42, -6, 40));
- testing.expect((try powi(i8, -5, 3)) == -125);
- testing.expect((try powi(i16, -16, 3)) == -4096);
- testing.expect((try powi(i32, -91, 3)) == -753571);
- testing.expect((try powi(i64, -36, 6)) == 2176782336);
- testing.expect((try powi(i17, -2, 15)) == -32768);
- testing.expect((try powi(i42, -5, 7)) == -78125);
+ try testing.expect((try powi(i8, -5, 3)) == -125);
+ try testing.expect((try powi(i16, -16, 3)) == -4096);
+ try testing.expect((try powi(i32, -91, 3)) == -753571);
+ try testing.expect((try powi(i64, -36, 6)) == 2176782336);
+ try testing.expect((try powi(i17, -2, 15)) == -32768);
+ try testing.expect((try powi(i42, -5, 7)) == -78125);
- testing.expect((try powi(u8, 6, 2)) == 36);
- testing.expect((try powi(u16, 5, 4)) == 625);
- testing.expect((try powi(u32, 12, 6)) == 2985984);
- testing.expect((try powi(u64, 34, 2)) == 1156);
- testing.expect((try powi(u17, 16, 3)) == 4096);
- testing.expect((try powi(u42, 34, 6)) == 1544804416);
+ try testing.expect((try powi(u8, 6, 2)) == 36);
+ try testing.expect((try powi(u16, 5, 4)) == 625);
+ try testing.expect((try powi(u32, 12, 6)) == 2985984);
+ try testing.expect((try powi(u64, 34, 2)) == 1156);
+ try testing.expect((try powi(u17, 16, 3)) == 4096);
+ try testing.expect((try powi(u42, 34, 6)) == 1544804416);
- testing.expectError(error.Overflow, powi(i8, 120, 7));
- testing.expectError(error.Overflow, powi(i16, 73, 15));
- testing.expectError(error.Overflow, powi(i32, 23, 31));
- testing.expectError(error.Overflow, powi(i64, 68, 61));
- testing.expectError(error.Overflow, powi(i17, 15, 15));
- testing.expectError(error.Overflow, powi(i42, 121312, 41));
+ try testing.expectError(error.Overflow, powi(i8, 120, 7));
+ try testing.expectError(error.Overflow, powi(i16, 73, 15));
+ try testing.expectError(error.Overflow, powi(i32, 23, 31));
+ try testing.expectError(error.Overflow, powi(i64, 68, 61));
+ try testing.expectError(error.Overflow, powi(i17, 15, 15));
+ try testing.expectError(error.Overflow, powi(i42, 121312, 41));
- testing.expectError(error.Overflow, powi(u8, 123, 7));
- testing.expectError(error.Overflow, powi(u16, 2313, 15));
- testing.expectError(error.Overflow, powi(u32, 8968, 31));
- testing.expectError(error.Overflow, powi(u64, 2342, 63));
- testing.expectError(error.Overflow, powi(u17, 2723, 16));
- testing.expectError(error.Overflow, powi(u42, 8234, 41));
+ try testing.expectError(error.Overflow, powi(u8, 123, 7));
+ try testing.expectError(error.Overflow, powi(u16, 2313, 15));
+ try testing.expectError(error.Overflow, powi(u32, 8968, 31));
+ try testing.expectError(error.Overflow, powi(u64, 2342, 63));
+ try testing.expectError(error.Overflow, powi(u17, 2723, 16));
+ try testing.expectError(error.Overflow, powi(u42, 8234, 41));
}
test "math.powi.special" {
- testing.expectError(error.Underflow, powi(i8, -2, 8));
- testing.expectError(error.Underflow, powi(i16, -2, 16));
- testing.expectError(error.Underflow, powi(i32, -2, 32));
- testing.expectError(error.Underflow, powi(i64, -2, 64));
- testing.expectError(error.Underflow, powi(i17, -2, 17));
- testing.expectError(error.Underflow, powi(i42, -2, 42));
+ try testing.expectError(error.Underflow, powi(i8, -2, 8));
+ try testing.expectError(error.Underflow, powi(i16, -2, 16));
+ try testing.expectError(error.Underflow, powi(i32, -2, 32));
+ try testing.expectError(error.Underflow, powi(i64, -2, 64));
+ try testing.expectError(error.Underflow, powi(i17, -2, 17));
+ try testing.expectError(error.Underflow, powi(i42, -2, 42));
- testing.expect((try powi(i8, -1, 3)) == -1);
- testing.expect((try powi(i16, -1, 2)) == 1);
- testing.expect((try powi(i32, -1, 16)) == 1);
- testing.expect((try powi(i64, -1, 6)) == 1);
- testing.expect((try powi(i17, -1, 15)) == -1);
- testing.expect((try powi(i42, -1, 7)) == -1);
+ try testing.expect((try powi(i8, -1, 3)) == -1);
+ try testing.expect((try powi(i16, -1, 2)) == 1);
+ try testing.expect((try powi(i32, -1, 16)) == 1);
+ try testing.expect((try powi(i64, -1, 6)) == 1);
+ try testing.expect((try powi(i17, -1, 15)) == -1);
+ try testing.expect((try powi(i42, -1, 7)) == -1);
- testing.expect((try powi(u8, 1, 2)) == 1);
- testing.expect((try powi(u16, 1, 4)) == 1);
- testing.expect((try powi(u32, 1, 6)) == 1);
- testing.expect((try powi(u64, 1, 2)) == 1);
- testing.expect((try powi(u17, 1, 3)) == 1);
- testing.expect((try powi(u42, 1, 6)) == 1);
+ try testing.expect((try powi(u8, 1, 2)) == 1);
+ try testing.expect((try powi(u16, 1, 4)) == 1);
+ try testing.expect((try powi(u32, 1, 6)) == 1);
+ try testing.expect((try powi(u64, 1, 2)) == 1);
+ try testing.expect((try powi(u17, 1, 3)) == 1);
+ try testing.expect((try powi(u42, 1, 6)) == 1);
- testing.expectError(error.Overflow, powi(i8, 2, 7));
- testing.expectError(error.Overflow, powi(i16, 2, 15));
- testing.expectError(error.Overflow, powi(i32, 2, 31));
- testing.expectError(error.Overflow, powi(i64, 2, 63));
- testing.expectError(error.Overflow, powi(i17, 2, 16));
- testing.expectError(error.Overflow, powi(i42, 2, 41));
+ try testing.expectError(error.Overflow, powi(i8, 2, 7));
+ try testing.expectError(error.Overflow, powi(i16, 2, 15));
+ try testing.expectError(error.Overflow, powi(i32, 2, 31));
+ try testing.expectError(error.Overflow, powi(i64, 2, 63));
+ try testing.expectError(error.Overflow, powi(i17, 2, 16));
+ try testing.expectError(error.Overflow, powi(i42, 2, 41));
- testing.expectError(error.Overflow, powi(u8, 2, 8));
- testing.expectError(error.Overflow, powi(u16, 2, 16));
- testing.expectError(error.Overflow, powi(u32, 2, 32));
- testing.expectError(error.Overflow, powi(u64, 2, 64));
- testing.expectError(error.Overflow, powi(u17, 2, 17));
- testing.expectError(error.Overflow, powi(u42, 2, 42));
+ try testing.expectError(error.Overflow, powi(u8, 2, 8));
+ try testing.expectError(error.Overflow, powi(u16, 2, 16));
+ try testing.expectError(error.Overflow, powi(u32, 2, 32));
+ try testing.expectError(error.Overflow, powi(u64, 2, 64));
+ try testing.expectError(error.Overflow, powi(u17, 2, 17));
+ try testing.expectError(error.Overflow, powi(u42, 2, 42));
- testing.expect((try powi(u8, 6, 0)) == 1);
- testing.expect((try powi(u16, 5, 0)) == 1);
- testing.expect((try powi(u32, 12, 0)) == 1);
- testing.expect((try powi(u64, 34, 0)) == 1);
- testing.expect((try powi(u17, 16, 0)) == 1);
- testing.expect((try powi(u42, 34, 0)) == 1);
+ try testing.expect((try powi(u8, 6, 0)) == 1);
+ try testing.expect((try powi(u16, 5, 0)) == 1);
+ try testing.expect((try powi(u32, 12, 0)) == 1);
+ try testing.expect((try powi(u64, 34, 0)) == 1);
+ try testing.expect((try powi(u17, 16, 0)) == 1);
+ try testing.expect((try powi(u42, 34, 0)) == 1);
}
diff --git a/lib/std/math/round.zig b/lib/std/math/round.zig
index 9167bcfc82..3e3ea2cdc8 100644
--- a/lib/std/math/round.zig
+++ b/lib/std/math/round.zig
@@ -130,52 +130,52 @@ fn round128(x_: f128) f128 {
}
test "math.round" {
- expect(round(@as(f32, 1.3)) == round32(1.3));
- expect(round(@as(f64, 1.3)) == round64(1.3));
- expect(round(@as(f128, 1.3)) == round128(1.3));
+ try expect(round(@as(f32, 1.3)) == round32(1.3));
+ try expect(round(@as(f64, 1.3)) == round64(1.3));
+ try expect(round(@as(f128, 1.3)) == round128(1.3));
}
test "math.round32" {
- expect(round32(1.3) == 1.0);
- expect(round32(-1.3) == -1.0);
- expect(round32(0.2) == 0.0);
- expect(round32(1.8) == 2.0);
+ try expect(round32(1.3) == 1.0);
+ try expect(round32(-1.3) == -1.0);
+ try expect(round32(0.2) == 0.0);
+ try expect(round32(1.8) == 2.0);
}
test "math.round64" {
- expect(round64(1.3) == 1.0);
- expect(round64(-1.3) == -1.0);
- expect(round64(0.2) == 0.0);
- expect(round64(1.8) == 2.0);
+ try expect(round64(1.3) == 1.0);
+ try expect(round64(-1.3) == -1.0);
+ try expect(round64(0.2) == 0.0);
+ try expect(round64(1.8) == 2.0);
}
test "math.round128" {
- expect(round128(1.3) == 1.0);
- expect(round128(-1.3) == -1.0);
- expect(round128(0.2) == 0.0);
- expect(round128(1.8) == 2.0);
+ try expect(round128(1.3) == 1.0);
+ try expect(round128(-1.3) == -1.0);
+ try expect(round128(0.2) == 0.0);
+ try expect(round128(1.8) == 2.0);
}
test "math.round32.special" {
- expect(round32(0.0) == 0.0);
- expect(round32(-0.0) == -0.0);
- expect(math.isPositiveInf(round32(math.inf(f32))));
- expect(math.isNegativeInf(round32(-math.inf(f32))));
- expect(math.isNan(round32(math.nan(f32))));
+ try expect(round32(0.0) == 0.0);
+ try expect(round32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(round32(math.inf(f32))));
+ try expect(math.isNegativeInf(round32(-math.inf(f32))));
+ try expect(math.isNan(round32(math.nan(f32))));
}
test "math.round64.special" {
- expect(round64(0.0) == 0.0);
- expect(round64(-0.0) == -0.0);
- expect(math.isPositiveInf(round64(math.inf(f64))));
- expect(math.isNegativeInf(round64(-math.inf(f64))));
- expect(math.isNan(round64(math.nan(f64))));
+ try expect(round64(0.0) == 0.0);
+ try expect(round64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(round64(math.inf(f64))));
+ try expect(math.isNegativeInf(round64(-math.inf(f64))));
+ try expect(math.isNan(round64(math.nan(f64))));
}
test "math.round128.special" {
- expect(round128(0.0) == 0.0);
- expect(round128(-0.0) == -0.0);
- expect(math.isPositiveInf(round128(math.inf(f128))));
- expect(math.isNegativeInf(round128(-math.inf(f128))));
- expect(math.isNan(round128(math.nan(f128))));
+ try expect(round128(0.0) == 0.0);
+ try expect(round128(-0.0) == -0.0);
+ try expect(math.isPositiveInf(round128(math.inf(f128))));
+ try expect(math.isNegativeInf(round128(-math.inf(f128))));
+ try expect(math.isNan(round128(math.nan(f128))));
}
diff --git a/lib/std/math/scalbn.zig b/lib/std/math/scalbn.zig
index cf8ff9003d..49aea08931 100644
--- a/lib/std/math/scalbn.zig
+++ b/lib/std/math/scalbn.zig
@@ -84,14 +84,14 @@ fn scalbn64(x: f64, n_: i32) f64 {
}
test "math.scalbn" {
- expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
- expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
+ try expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
+ try expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
}
test "math.scalbn32" {
- expect(scalbn32(1.5, 4) == 24.0);
+ try expect(scalbn32(1.5, 4) == 24.0);
}
test "math.scalbn64" {
- expect(scalbn64(1.5, 4) == 24.0);
+ try expect(scalbn64(1.5, 4) == 24.0);
}
diff --git a/lib/std/math/signbit.zig b/lib/std/math/signbit.zig
index 08963b3d94..a1f2f127d4 100644
--- a/lib/std/math/signbit.zig
+++ b/lib/std/math/signbit.zig
@@ -40,28 +40,28 @@ fn signbit128(x: f128) bool {
}
test "math.signbit" {
- expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
- expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
- expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
- expect(signbit(@as(f128, 4.0)) == signbit128(4.0));
+ try expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
+ try expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
+ try expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
+ try expect(signbit(@as(f128, 4.0)) == signbit128(4.0));
}
test "math.signbit16" {
- expect(!signbit16(4.0));
- expect(signbit16(-3.0));
+ try expect(!signbit16(4.0));
+ try expect(signbit16(-3.0));
}
test "math.signbit32" {
- expect(!signbit32(4.0));
- expect(signbit32(-3.0));
+ try expect(!signbit32(4.0));
+ try expect(signbit32(-3.0));
}
test "math.signbit64" {
- expect(!signbit64(4.0));
- expect(signbit64(-3.0));
+ try expect(!signbit64(4.0));
+ try expect(signbit64(-3.0));
}
test "math.signbit128" {
- expect(!signbit128(4.0));
- expect(signbit128(-3.0));
+ try expect(!signbit128(4.0));
+ try expect(signbit128(-3.0));
}
diff --git a/lib/std/math/sin.zig b/lib/std/math/sin.zig
index d051e3f88a..544d55bd53 100644
--- a/lib/std/math/sin.zig
+++ b/lib/std/math/sin.zig
@@ -89,47 +89,47 @@ fn sin_(comptime T: type, x_: T) T {
}
test "math.sin" {
- expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
- expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
- expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
+ try expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
+ try expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
+ try expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
}
test "math.sin32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, -1.5), -0.997495, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, -1.5), -0.997495, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));
}
test "math.sin64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, -1.5), -0.997495, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, -1.5), -0.997495, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));
}
test "math.sin32.special" {
- expect(sin_(f32, 0.0) == 0.0);
- expect(sin_(f32, -0.0) == -0.0);
- expect(math.isNan(sin_(f32, math.inf(f32))));
- expect(math.isNan(sin_(f32, -math.inf(f32))));
- expect(math.isNan(sin_(f32, math.nan(f32))));
+ try expect(sin_(f32, 0.0) == 0.0);
+ try expect(sin_(f32, -0.0) == -0.0);
+ try expect(math.isNan(sin_(f32, math.inf(f32))));
+ try expect(math.isNan(sin_(f32, -math.inf(f32))));
+ try expect(math.isNan(sin_(f32, math.nan(f32))));
}
test "math.sin64.special" {
- expect(sin_(f64, 0.0) == 0.0);
- expect(sin_(f64, -0.0) == -0.0);
- expect(math.isNan(sin_(f64, math.inf(f64))));
- expect(math.isNan(sin_(f64, -math.inf(f64))));
- expect(math.isNan(sin_(f64, math.nan(f64))));
+ try expect(sin_(f64, 0.0) == 0.0);
+ try expect(sin_(f64, -0.0) == -0.0);
+ try expect(math.isNan(sin_(f64, math.inf(f64))));
+ try expect(math.isNan(sin_(f64, -math.inf(f64))));
+ try expect(math.isNan(sin_(f64, math.nan(f64))));
}
diff --git a/lib/std/math/sinh.zig b/lib/std/math/sinh.zig
index 16329a9108..4161afca63 100644
--- a/lib/std/math/sinh.zig
+++ b/lib/std/math/sinh.zig
@@ -98,48 +98,48 @@ fn sinh64(x: f64) f64 {
}
test "math.sinh" {
- expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
- expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
+ try expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
+ try expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
}
test "math.sinh32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));
- expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));
- expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));
- expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));
- expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));
- expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));
- expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
}
test "math.sinh64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));
- expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));
- expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));
- expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));
- expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));
- expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));
- expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));
}
test "math.sinh32.special" {
- expect(sinh32(0.0) == 0.0);
- expect(sinh32(-0.0) == -0.0);
- expect(math.isPositiveInf(sinh32(math.inf(f32))));
- expect(math.isNegativeInf(sinh32(-math.inf(f32))));
- expect(math.isNan(sinh32(math.nan(f32))));
+ try expect(sinh32(0.0) == 0.0);
+ try expect(sinh32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(sinh32(math.inf(f32))));
+ try expect(math.isNegativeInf(sinh32(-math.inf(f32))));
+ try expect(math.isNan(sinh32(math.nan(f32))));
}
test "math.sinh64.special" {
- expect(sinh64(0.0) == 0.0);
- expect(sinh64(-0.0) == -0.0);
- expect(math.isPositiveInf(sinh64(math.inf(f64))));
- expect(math.isNegativeInf(sinh64(-math.inf(f64))));
- expect(math.isNan(sinh64(math.nan(f64))));
+ try expect(sinh64(0.0) == 0.0);
+ try expect(sinh64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(sinh64(math.inf(f64))));
+ try expect(math.isNegativeInf(sinh64(-math.inf(f64))));
+ try expect(math.isNan(sinh64(math.nan(f64))));
}
diff --git a/lib/std/math/sqrt.zig b/lib/std/math/sqrt.zig
index 4f32581270..e9bbe40295 100644
--- a/lib/std/math/sqrt.zig
+++ b/lib/std/math/sqrt.zig
@@ -69,14 +69,14 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
}
test "math.sqrt_int" {
- expect(sqrt_int(u0, 0) == 0);
- expect(sqrt_int(u1, 1) == 1);
- expect(sqrt_int(u32, 3) == 1);
- expect(sqrt_int(u32, 4) == 2);
- expect(sqrt_int(u32, 5) == 2);
- expect(sqrt_int(u32, 8) == 2);
- expect(sqrt_int(u32, 9) == 3);
- expect(sqrt_int(u32, 10) == 3);
+ try expect(sqrt_int(u0, 0) == 0);
+ try expect(sqrt_int(u1, 1) == 1);
+ try expect(sqrt_int(u32, 3) == 1);
+ try expect(sqrt_int(u32, 4) == 2);
+ try expect(sqrt_int(u32, 5) == 2);
+ try expect(sqrt_int(u32, 8) == 2);
+ try expect(sqrt_int(u32, 9) == 3);
+ try expect(sqrt_int(u32, 10) == 3);
}
/// Returns the return type `sqrt` will return given an operand of type `T`.
diff --git a/lib/std/math/tan.zig b/lib/std/math/tan.zig
index d0e8a0d4f8..0db96e34a4 100644
--- a/lib/std/math/tan.zig
+++ b/lib/std/math/tan.zig
@@ -80,44 +80,44 @@ fn tan_(comptime T: type, x_: T) T {
}
test "math.tan" {
- expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
- expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
+ try expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
+ try expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
}
test "math.tan32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));
- expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));
- expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));
- expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));
- expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));
}
test "math.tan64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));
- expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));
- expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));
- expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));
- expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));
}
test "math.tan32.special" {
- expect(tan_(f32, 0.0) == 0.0);
- expect(tan_(f32, -0.0) == -0.0);
- expect(math.isNan(tan_(f32, math.inf(f32))));
- expect(math.isNan(tan_(f32, -math.inf(f32))));
- expect(math.isNan(tan_(f32, math.nan(f32))));
+ try expect(tan_(f32, 0.0) == 0.0);
+ try expect(tan_(f32, -0.0) == -0.0);
+ try expect(math.isNan(tan_(f32, math.inf(f32))));
+ try expect(math.isNan(tan_(f32, -math.inf(f32))));
+ try expect(math.isNan(tan_(f32, math.nan(f32))));
}
test "math.tan64.special" {
- expect(tan_(f64, 0.0) == 0.0);
- expect(tan_(f64, -0.0) == -0.0);
- expect(math.isNan(tan_(f64, math.inf(f64))));
- expect(math.isNan(tan_(f64, -math.inf(f64))));
- expect(math.isNan(tan_(f64, math.nan(f64))));
+ try expect(tan_(f64, 0.0) == 0.0);
+ try expect(tan_(f64, -0.0) == -0.0);
+ try expect(math.isNan(tan_(f64, math.inf(f64))));
+ try expect(math.isNan(tan_(f64, -math.inf(f64))));
+ try expect(math.isNan(tan_(f64, math.nan(f64))));
}
diff --git a/lib/std/math/tanh.zig b/lib/std/math/tanh.zig
index c53f03122b..e8d57d7f14 100644
--- a/lib/std/math/tanh.zig
+++ b/lib/std/math/tanh.zig
@@ -124,42 +124,42 @@ fn tanh64(x: f64) f64 {
}
test "math.tanh" {
- expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
- expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
+ try expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
+ try expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
}
test "math.tanh32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));
- expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));
- expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));
- expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));
+ try expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));
+ try expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));
+ try expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));
}
test "math.tanh64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));
- expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));
- expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));
- expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));
+ try expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));
+ try expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));
+ try expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));
}
test "math.tanh32.special" {
- expect(tanh32(0.0) == 0.0);
- expect(tanh32(-0.0) == -0.0);
- expect(tanh32(math.inf(f32)) == 1.0);
- expect(tanh32(-math.inf(f32)) == -1.0);
- expect(math.isNan(tanh32(math.nan(f32))));
+ try expect(tanh32(0.0) == 0.0);
+ try expect(tanh32(-0.0) == -0.0);
+ try expect(tanh32(math.inf(f32)) == 1.0);
+ try expect(tanh32(-math.inf(f32)) == -1.0);
+ try expect(math.isNan(tanh32(math.nan(f32))));
}
test "math.tanh64.special" {
- expect(tanh64(0.0) == 0.0);
- expect(tanh64(-0.0) == -0.0);
- expect(tanh64(math.inf(f64)) == 1.0);
- expect(tanh64(-math.inf(f64)) == -1.0);
- expect(math.isNan(tanh64(math.nan(f64))));
+ try expect(tanh64(0.0) == 0.0);
+ try expect(tanh64(-0.0) == -0.0);
+ try expect(tanh64(math.inf(f64)) == 1.0);
+ try expect(tanh64(-math.inf(f64)) == -1.0);
+ try expect(math.isNan(tanh64(math.nan(f64))));
}
diff --git a/lib/std/math/trunc.zig b/lib/std/math/trunc.zig
index 69c300efee..0d83dc608d 100644
--- a/lib/std/math/trunc.zig
+++ b/lib/std/math/trunc.zig
@@ -94,49 +94,49 @@ fn trunc128(x: f128) f128 {
}
test "math.trunc" {
- expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
- expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
- expect(trunc(@as(f128, 1.3)) == trunc128(1.3));
+ try expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
+ try expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
+ try expect(trunc(@as(f128, 1.3)) == trunc128(1.3));
}
test "math.trunc32" {
- expect(trunc32(1.3) == 1.0);
- expect(trunc32(-1.3) == -1.0);
- expect(trunc32(0.2) == 0.0);
+ try expect(trunc32(1.3) == 1.0);
+ try expect(trunc32(-1.3) == -1.0);
+ try expect(trunc32(0.2) == 0.0);
}
test "math.trunc64" {
- expect(trunc64(1.3) == 1.0);
- expect(trunc64(-1.3) == -1.0);
- expect(trunc64(0.2) == 0.0);
+ try expect(trunc64(1.3) == 1.0);
+ try expect(trunc64(-1.3) == -1.0);
+ try expect(trunc64(0.2) == 0.0);
}
test "math.trunc128" {
- expect(trunc128(1.3) == 1.0);
- expect(trunc128(-1.3) == -1.0);
- expect(trunc128(0.2) == 0.0);
+ try expect(trunc128(1.3) == 1.0);
+ try expect(trunc128(-1.3) == -1.0);
+ try expect(trunc128(0.2) == 0.0);
}
test "math.trunc32.special" {
- expect(trunc32(0.0) == 0.0); // 0x3F800000
- expect(trunc32(-0.0) == -0.0);
- expect(math.isPositiveInf(trunc32(math.inf(f32))));
- expect(math.isNegativeInf(trunc32(-math.inf(f32))));
- expect(math.isNan(trunc32(math.nan(f32))));
+ try expect(trunc32(0.0) == 0.0); // 0x3F800000
+ try expect(trunc32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(trunc32(math.inf(f32))));
+ try expect(math.isNegativeInf(trunc32(-math.inf(f32))));
+ try expect(math.isNan(trunc32(math.nan(f32))));
}
test "math.trunc64.special" {
- expect(trunc64(0.0) == 0.0);
- expect(trunc64(-0.0) == -0.0);
- expect(math.isPositiveInf(trunc64(math.inf(f64))));
- expect(math.isNegativeInf(trunc64(-math.inf(f64))));
- expect(math.isNan(trunc64(math.nan(f64))));
+ try expect(trunc64(0.0) == 0.0);
+ try expect(trunc64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(trunc64(math.inf(f64))));
+ try expect(math.isNegativeInf(trunc64(-math.inf(f64))));
+ try expect(math.isNan(trunc64(math.nan(f64))));
}
test "math.trunc128.special" {
- expect(trunc128(0.0) == 0.0);
- expect(trunc128(-0.0) == -0.0);
- expect(math.isPositiveInf(trunc128(math.inf(f128))));
- expect(math.isNegativeInf(trunc128(-math.inf(f128))));
- expect(math.isNan(trunc128(math.nan(f128))));
+ try expect(trunc128(0.0) == 0.0);
+ try expect(trunc128(-0.0) == -0.0);
+ try expect(math.isPositiveInf(trunc128(math.inf(f128))));
+ try expect(math.isNegativeInf(trunc128(-math.inf(f128))));
+ try expect(math.isNan(trunc128(math.nan(f128))));
}
diff --git a/lib/std/mem.zig b/lib/std/mem.zig
index 274da3b8f1..df91adddb2 100644
--- a/lib/std/mem.zig
+++ b/lib/std/mem.zig
@@ -142,8 +142,8 @@ fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29
}
test "mem.Allocator basics" {
- testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
- testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
+ try testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
+ try testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
}
/// Copy all of source into dest at position 0.
@@ -276,8 +276,8 @@ test "mem.zeroes" {
var a = zeroes(C_struct);
a.y += 10;
- testing.expect(a.x == 0);
- testing.expect(a.y == 10);
+ try testing.expect(a.x == 0);
+ try testing.expect(a.y == 10);
const ZigStruct = struct {
integral_types: struct {
@@ -314,32 +314,32 @@ test "mem.zeroes" {
};
const b = zeroes(ZigStruct);
- testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
- testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
- testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
- testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
- testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);
- testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);
- testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);
- testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);
- testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);
- testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);
- testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);
- testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);
- testing.expectEqual(@as(f32, 0), b.integral_types.float_32);
- testing.expectEqual(@as(f64, 0), b.integral_types.float_64);
- testing.expectEqual(@as(?*u8, null), b.pointers.optional);
- testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);
- testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);
+ try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
+ try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
+ try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
+ try testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
+ try testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);
+ try testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);
+ try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);
+ try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);
+ try testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);
+ try testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);
+ try testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);
+ try testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);
+ try testing.expectEqual(@as(f32, 0), b.integral_types.float_32);
+ try testing.expectEqual(@as(f64, 0), b.integral_types.float_64);
+ try testing.expectEqual(@as(?*u8, null), b.pointers.optional);
+ try testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);
+ try testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);
for (b.array) |e| {
- testing.expectEqual(@as(u32, 0), e);
+ try testing.expectEqual(@as(u32, 0), e);
}
- testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);
- testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);
- testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);
- testing.expectEqual(@as(?u8, null), b.optional_int);
+ try testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);
+ try testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);
+ try testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);
+ try testing.expectEqual(@as(?u8, null), b.optional_int);
for (b.sentinel) |e| {
- testing.expectEqual(@as(u8, 0), e);
+ try testing.expectEqual(@as(u8, 0), e);
}
const C_union = extern union {
@@ -348,7 +348,7 @@ test "mem.zeroes" {
};
var c = zeroes(C_union);
- testing.expectEqual(@as(u8, 0), c.a);
+ try testing.expectEqual(@as(u8, 0), c.a);
}
/// Initializes all fields of the struct with their default value, or zero values if no default value is present.
@@ -421,7 +421,7 @@ test "zeroInit" {
.a = 42,
});
- testing.expectEqual(S{
+ try testing.expectEqual(S{
.a = 42,
.b = null,
.c = .{
@@ -439,7 +439,7 @@ test "zeroInit" {
};
const c = zeroInit(Color, .{ 255, 255 });
- testing.expectEqual(Color{
+ try testing.expectEqual(Color{
.r = 255,
.g = 255,
.b = 0,
@@ -462,11 +462,11 @@ pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order {
}
test "order" {
- testing.expect(order(u8, "abcd", "bee") == .lt);
- testing.expect(order(u8, "abc", "abc") == .eq);
- testing.expect(order(u8, "abc", "abc0") == .lt);
- testing.expect(order(u8, "", "") == .eq);
- testing.expect(order(u8, "", "a") == .lt);
+ try testing.expect(order(u8, "abcd", "bee") == .lt);
+ try testing.expect(order(u8, "abc", "abc") == .eq);
+ try testing.expect(order(u8, "abc", "abc0") == .lt);
+ try testing.expect(order(u8, "", "") == .eq);
+ try testing.expect(order(u8, "", "a") == .lt);
}
/// Returns true if lhs < rhs, false otherwise
@@ -475,11 +475,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {
}
test "mem.lessThan" {
- testing.expect(lessThan(u8, "abcd", "bee"));
- testing.expect(!lessThan(u8, "abc", "abc"));
- testing.expect(lessThan(u8, "abc", "abc0"));
- testing.expect(!lessThan(u8, "", ""));
- testing.expect(lessThan(u8, "", "a"));
+ try testing.expect(lessThan(u8, "abcd", "bee"));
+ try testing.expect(!lessThan(u8, "abc", "abc"));
+ try testing.expect(lessThan(u8, "abc", "abc0"));
+ try testing.expect(!lessThan(u8, "", ""));
+ try testing.expect(lessThan(u8, "", "a"));
}
/// Compares two slices and returns whether they are equal.
@@ -504,11 +504,11 @@ pub fn indexOfDiff(comptime T: type, a: []const T, b: []const T) ?usize {
}
test "indexOfDiff" {
- testing.expectEqual(indexOfDiff(u8, "one", "one"), null);
- testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);
- testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);
- testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);
- testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
+ try testing.expectEqual(indexOfDiff(u8, "one", "one"), null);
+ try testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);
+ try testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);
+ try testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);
+ try testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
}
pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");
@@ -548,26 +548,26 @@ pub fn Span(comptime T: type) type {
}
test "Span" {
- testing.expect(Span(*[5]u16) == []u16);
- testing.expect(Span(?*[5]u16) == ?[]u16);
- testing.expect(Span(*const [5]u16) == []const u16);
- testing.expect(Span(?*const [5]u16) == ?[]const u16);
- testing.expect(Span([]u16) == []u16);
- testing.expect(Span(?[]u16) == ?[]u16);
- testing.expect(Span([]const u8) == []const u8);
- testing.expect(Span(?[]const u8) == ?[]const u8);
- testing.expect(Span([:1]u16) == [:1]u16);
- testing.expect(Span(?[:1]u16) == ?[:1]u16);
- testing.expect(Span([:1]const u8) == [:1]const u8);
- testing.expect(Span(?[:1]const u8) == ?[:1]const u8);
- testing.expect(Span([*:1]u16) == [:1]u16);
- testing.expect(Span(?[*:1]u16) == ?[:1]u16);
- testing.expect(Span([*:1]const u8) == [:1]const u8);
- testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);
- testing.expect(Span([*c]u16) == [:0]u16);
- testing.expect(Span(?[*c]u16) == ?[:0]u16);
- testing.expect(Span([*c]const u8) == [:0]const u8);
- testing.expect(Span(?[*c]const u8) == ?[:0]const u8);
+ try testing.expect(Span(*[5]u16) == []u16);
+ try testing.expect(Span(?*[5]u16) == ?[]u16);
+ try testing.expect(Span(*const [5]u16) == []const u16);
+ try testing.expect(Span(?*const [5]u16) == ?[]const u16);
+ try testing.expect(Span([]u16) == []u16);
+ try testing.expect(Span(?[]u16) == ?[]u16);
+ try testing.expect(Span([]const u8) == []const u8);
+ try testing.expect(Span(?[]const u8) == ?[]const u8);
+ try testing.expect(Span([:1]u16) == [:1]u16);
+ try testing.expect(Span(?[:1]u16) == ?[:1]u16);
+ try testing.expect(Span([:1]const u8) == [:1]const u8);
+ try testing.expect(Span(?[:1]const u8) == ?[:1]const u8);
+ try testing.expect(Span([*:1]u16) == [:1]u16);
+ try testing.expect(Span(?[*:1]u16) == ?[:1]u16);
+ try testing.expect(Span([*:1]const u8) == [:1]const u8);
+ try testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);
+ try testing.expect(Span([*c]u16) == [:0]u16);
+ try testing.expect(Span(?[*c]u16) == ?[:0]u16);
+ try testing.expect(Span([*c]const u8) == [:0]const u8);
+ try testing.expect(Span(?[*c]const u8) == ?[:0]const u8);
}
/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and
@@ -597,9 +597,9 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
test "span" {
var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
const ptr = @as([*:3]u16, array[0..2 :3]);
- testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));
- testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
- testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
+ try testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));
+ try testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
+ try testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
}
/// Same as `span`, except when there is both a sentinel and an array
@@ -625,9 +625,9 @@ pub fn spanZ(ptr: anytype) Span(@TypeOf(ptr)) {
test "spanZ" {
var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
const ptr = @as([*:3]u16, array[0..2 :3]);
- testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
- testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
- testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
+ try testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
+ try testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
+ try testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
}
/// Takes a pointer to an array, an array, a vector, a sentinel-terminated pointer,
@@ -661,30 +661,30 @@ pub fn len(value: anytype) usize {
}
test "len" {
- testing.expect(len("aoeu") == 4);
+ try testing.expect(len("aoeu") == 4);
{
var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
- testing.expect(len(&array) == 5);
- testing.expect(len(array[0..3]) == 3);
+ try testing.expect(len(&array) == 5);
+ try testing.expect(len(array[0..3]) == 3);
array[2] = 0;
const ptr = @as([*:0]u16, array[0..2 :0]);
- testing.expect(len(ptr) == 2);
+ try testing.expect(len(ptr) == 2);
}
{
var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
- testing.expect(len(&array) == 5);
+ try testing.expect(len(&array) == 5);
array[2] = 0;
- testing.expect(len(&array) == 5);
+ try testing.expect(len(&array) == 5);
}
{
const vector: meta.Vector(2, u32) = [2]u32{ 1, 2 };
- testing.expect(len(vector) == 2);
+ try testing.expect(len(vector) == 2);
}
{
const tuple = .{ 1, 2 };
- testing.expect(len(tuple) == 2);
- testing.expect(tuple[0] == 1);
+ try testing.expect(len(tuple) == 2);
+ try testing.expect(tuple[0] == 1);
}
}
@@ -725,21 +725,21 @@ pub fn lenZ(ptr: anytype) usize {
}
test "lenZ" {
- testing.expect(lenZ("aoeu") == 4);
+ try testing.expect(lenZ("aoeu") == 4);
{
var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
- testing.expect(lenZ(&array) == 5);
- testing.expect(lenZ(array[0..3]) == 3);
+ try testing.expect(lenZ(&array) == 5);
+ try testing.expect(lenZ(array[0..3]) == 3);
array[2] = 0;
const ptr = @as([*:0]u16, array[0..2 :0]);
- testing.expect(lenZ(ptr) == 2);
+ try testing.expect(lenZ(ptr) == 2);
}
{
var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
- testing.expect(lenZ(&array) == 5);
+ try testing.expect(lenZ(&array) == 5);
array[2] = 0;
- testing.expect(lenZ(&array) == 2);
+ try testing.expect(lenZ(&array) == 2);
}
}
@@ -793,10 +793,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co
}
test "mem.trim" {
- testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
- testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
- testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
- testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
+ try testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
+ try testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
+ try testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
+ try testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
}
/// Linear search for the index of a scalar value inside a slice.
@@ -951,28 +951,28 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee
}
test "mem.indexOf" {
- testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
- testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
- testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
- testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
+ try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
+ try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
+ try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
+ try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
- testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);
- testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);
+ try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);
+ try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);
- testing.expect(indexOf(u8, "one two three four", "four").? == 14);
- testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
- testing.expect(indexOf(u8, "one two three four", "gour") == null);
- testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
- testing.expect(indexOf(u8, "foo", "foo").? == 0);
- testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
- testing.expect(indexOf(u8, "foo", "fool") == null);
- testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
- testing.expect(lastIndexOf(u8, "foo", "fool") == null);
+ try testing.expect(indexOf(u8, "one two three four", "four").? == 14);
+ try testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
+ try testing.expect(indexOf(u8, "one two three four", "gour") == null);
+ try testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
+ try testing.expect(indexOf(u8, "foo", "foo").? == 0);
+ try testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
+ try testing.expect(indexOf(u8, "foo", "fool") == null);
+ try testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
+ try testing.expect(lastIndexOf(u8, "foo", "fool") == null);
- testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
- testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
- testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
- testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
+ try testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
+ try testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
+ try testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
+ try testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
}
/// Returns the number of needles inside the haystack
@@ -992,17 +992,17 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize {
}
test "mem.count" {
- testing.expect(count(u8, "", "h") == 0);
- testing.expect(count(u8, "h", "h") == 1);
- testing.expect(count(u8, "hh", "h") == 2);
- testing.expect(count(u8, "world!", "hello") == 0);
- testing.expect(count(u8, "hello world!", "hello") == 1);
- testing.expect(count(u8, " abcabc abc", "abc") == 3);
- testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);
- testing.expect(count(u8, "foo bar", "o bar") == 1);
- testing.expect(count(u8, "foofoofoo", "foo") == 3);
- testing.expect(count(u8, "fffffff", "ff") == 3);
- testing.expect(count(u8, "owowowu", "owowu") == 1);
+ try testing.expect(count(u8, "", "h") == 0);
+ try testing.expect(count(u8, "h", "h") == 1);
+ try testing.expect(count(u8, "hh", "h") == 2);
+ try testing.expect(count(u8, "world!", "hello") == 0);
+ try testing.expect(count(u8, "hello world!", "hello") == 1);
+ try testing.expect(count(u8, " abcabc abc", "abc") == 3);
+ try testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);
+ try testing.expect(count(u8, "foo bar", "o bar") == 1);
+ try testing.expect(count(u8, "foofoofoo", "foo") == 3);
+ try testing.expect(count(u8, "fffffff", "ff") == 3);
+ try testing.expect(count(u8, "owowowu", "owowu") == 1);
}
/// Returns true if the haystack contains expected_count or more needles
@@ -1024,19 +1024,19 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us
}
test "mem.containsAtLeast" {
- testing.expect(containsAtLeast(u8, "aa", 0, "a"));
- testing.expect(containsAtLeast(u8, "aa", 1, "a"));
- testing.expect(containsAtLeast(u8, "aa", 2, "a"));
- testing.expect(!containsAtLeast(u8, "aa", 3, "a"));
+ try testing.expect(containsAtLeast(u8, "aa", 0, "a"));
+ try testing.expect(containsAtLeast(u8, "aa", 1, "a"));
+ try testing.expect(containsAtLeast(u8, "aa", 2, "a"));
+ try testing.expect(!containsAtLeast(u8, "aa", 3, "a"));
- testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));
- testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));
+ try testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));
+ try testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));
- testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));
- testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));
+ try testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));
+ try testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));
- testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));
- testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
+ try testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));
+ try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
}
/// Reads an integer from memory with size equal to bytes.len.
@@ -1141,34 +1141,34 @@ test "comptime read/write int" {
var bytes: [2]u8 = undefined;
writeIntLittle(u16, &bytes, 0x1234);
const result = readIntBig(u16, &bytes);
- testing.expect(result == 0x3412);
+ try testing.expect(result == 0x3412);
}
comptime {
var bytes: [2]u8 = undefined;
writeIntBig(u16, &bytes, 0x1234);
const result = readIntLittle(u16, &bytes);
- testing.expect(result == 0x3412);
+ try testing.expect(result == 0x3412);
}
}
test "readIntBig and readIntLittle" {
- testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
- testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
+ try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
+ try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
- testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
- testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
+ try testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
+ try testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
- testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
- testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
+ try testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
+ try testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
- testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
- testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
+ try testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
+ try testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
- testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
- testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
+ try testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
+ try testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
- testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
- testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
+ try testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
+ try testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
}
/// Writes an integer to memory, storing it in twos-complement.
@@ -1283,34 +1283,34 @@ test "writeIntBig and writeIntLittle" {
var buf9: [9]u8 = undefined;
writeIntBig(u0, &buf0, 0x0);
- testing.expect(eql(u8, buf0[0..], &[_]u8{}));
+ try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
writeIntLittle(u0, &buf0, 0x0);
- testing.expect(eql(u8, buf0[0..], &[_]u8{}));
+ try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
writeIntBig(u8, &buf1, 0x12);
- testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
+ try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
writeIntLittle(u8, &buf1, 0x34);
- testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
+ try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
writeIntBig(u16, &buf2, 0x1234);
- testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
+ try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
writeIntLittle(u16, &buf2, 0x5678);
- testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
+ try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
writeIntBig(u72, &buf9, 0x123456789abcdef024);
- testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
+ try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
- testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
+ try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
writeIntBig(i8, &buf1, -1);
- testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
+ try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
writeIntLittle(i8, &buf1, -2);
- testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
+ try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
writeIntBig(i16, &buf2, -3);
- testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
+ try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
writeIntLittle(i16, &buf2, -4);
- testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
+ try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
}
/// Returns an iterator that iterates over the slices of `buffer` that are not
@@ -1331,60 +1331,60 @@ pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {
test "mem.tokenize" {
var it = tokenize(" abc def ghi ", " ");
- testing.expect(eql(u8, it.next().?, "abc"));
- testing.expect(eql(u8, it.next().?, "def"));
- testing.expect(eql(u8, it.next().?, "ghi"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "abc"));
+ try testing.expect(eql(u8, it.next().?, "def"));
+ try testing.expect(eql(u8, it.next().?, "ghi"));
+ try testing.expect(it.next() == null);
it = tokenize("..\\bob", "\\");
- testing.expect(eql(u8, it.next().?, ".."));
- testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
- testing.expect(eql(u8, it.next().?, "bob"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, ".."));
+ try testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
+ try testing.expect(eql(u8, it.next().?, "bob"));
+ try testing.expect(it.next() == null);
it = tokenize("//a/b", "/");
- testing.expect(eql(u8, it.next().?, "a"));
- testing.expect(eql(u8, it.next().?, "b"));
- testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "a"));
+ try testing.expect(eql(u8, it.next().?, "b"));
+ try testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
+ try testing.expect(it.next() == null);
it = tokenize("|", "|");
- testing.expect(it.next() == null);
+ try testing.expect(it.next() == null);
it = tokenize("", "|");
- testing.expect(it.next() == null);
+ try testing.expect(it.next() == null);
it = tokenize("hello", "");
- testing.expect(eql(u8, it.next().?, "hello"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "hello"));
+ try testing.expect(it.next() == null);
it = tokenize("hello", " ");
- testing.expect(eql(u8, it.next().?, "hello"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "hello"));
+ try testing.expect(it.next() == null);
}
test "mem.tokenize (multibyte)" {
var it = tokenize("a|b,c/d e", " /,|");
- testing.expect(eql(u8, it.next().?, "a"));
- testing.expect(eql(u8, it.next().?, "b"));
- testing.expect(eql(u8, it.next().?, "c"));
- testing.expect(eql(u8, it.next().?, "d"));
- testing.expect(eql(u8, it.next().?, "e"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "a"));
+ try testing.expect(eql(u8, it.next().?, "b"));
+ try testing.expect(eql(u8, it.next().?, "c"));
+ try testing.expect(eql(u8, it.next().?, "d"));
+ try testing.expect(eql(u8, it.next().?, "e"));
+ try testing.expect(it.next() == null);
}
test "mem.tokenize (reset)" {
var it = tokenize(" abc def ghi ", " ");
- testing.expect(eql(u8, it.next().?, "abc"));
- testing.expect(eql(u8, it.next().?, "def"));
- testing.expect(eql(u8, it.next().?, "ghi"));
+ try testing.expect(eql(u8, it.next().?, "abc"));
+ try testing.expect(eql(u8, it.next().?, "def"));
+ try testing.expect(eql(u8, it.next().?, "ghi"));
it.reset();
- testing.expect(eql(u8, it.next().?, "abc"));
- testing.expect(eql(u8, it.next().?, "def"));
- testing.expect(eql(u8, it.next().?, "ghi"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "abc"));
+ try testing.expect(eql(u8, it.next().?, "def"));
+ try testing.expect(eql(u8, it.next().?, "ghi"));
+ try testing.expect(it.next() == null);
}
/// Returns an iterator that iterates over the slices of `buffer` that
@@ -1408,34 +1408,34 @@ pub const separate = @compileError("deprecated: renamed to split (behavior remai
test "mem.split" {
var it = split("abc|def||ghi", "|");
- testing.expect(eql(u8, it.next().?, "abc"));
- testing.expect(eql(u8, it.next().?, "def"));
- testing.expect(eql(u8, it.next().?, ""));
- testing.expect(eql(u8, it.next().?, "ghi"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "abc"));
+ try testing.expect(eql(u8, it.next().?, "def"));
+ try testing.expect(eql(u8, it.next().?, ""));
+ try testing.expect(eql(u8, it.next().?, "ghi"));
+ try testing.expect(it.next() == null);
it = split("", "|");
- testing.expect(eql(u8, it.next().?, ""));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, ""));
+ try testing.expect(it.next() == null);
it = split("|", "|");
- testing.expect(eql(u8, it.next().?, ""));
- testing.expect(eql(u8, it.next().?, ""));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, ""));
+ try testing.expect(eql(u8, it.next().?, ""));
+ try testing.expect(it.next() == null);
it = split("hello", " ");
- testing.expect(eql(u8, it.next().?, "hello"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "hello"));
+ try testing.expect(it.next() == null);
}
test "mem.split (multibyte)" {
var it = split("a, b ,, c, d, e", ", ");
- testing.expect(eql(u8, it.next().?, "a"));
- testing.expect(eql(u8, it.next().?, "b ,"));
- testing.expect(eql(u8, it.next().?, "c"));
- testing.expect(eql(u8, it.next().?, "d"));
- testing.expect(eql(u8, it.next().?, "e"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "a"));
+ try testing.expect(eql(u8, it.next().?, "b ,"));
+ try testing.expect(eql(u8, it.next().?, "c"));
+ try testing.expect(eql(u8, it.next().?, "d"));
+ try testing.expect(eql(u8, it.next().?, "e"));
+ try testing.expect(it.next() == null);
}
pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
@@ -1443,8 +1443,8 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool
}
test "mem.startsWith" {
- testing.expect(startsWith(u8, "Bob", "Bo"));
- testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
+ try testing.expect(startsWith(u8, "Bob", "Bo"));
+ try testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
}
pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
@@ -1452,8 +1452,8 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
}
test "mem.endsWith" {
- testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
- testing.expect(!endsWith(u8, "Bob", "Bo"));
+ try testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
+ try testing.expect(!endsWith(u8, "Bob", "Bo"));
}
pub const TokenIterator = struct {
@@ -1571,22 +1571,22 @@ test "mem.join" {
{
const str = try join(testing.allocator, ",", &[_][]const u8{});
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, ""));
+ try testing.expect(eql(u8, str, ""));
}
{
const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a,b,c"));
+ try testing.expect(eql(u8, str, "a,b,c"));
}
{
const str = try join(testing.allocator, ",", &[_][]const u8{"a"});
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a"));
+ try testing.expect(eql(u8, str, "a"));
}
{
const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a,,b,,c"));
+ try testing.expect(eql(u8, str, "a,,b,,c"));
}
}
@@ -1594,26 +1594,26 @@ test "mem.joinZ" {
{
const str = try joinZ(testing.allocator, ",", &[_][]const u8{});
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, ""));
- testing.expectEqual(str[str.len], 0);
+ try testing.expect(eql(u8, str, ""));
+ try testing.expectEqual(str[str.len], 0);
}
{
const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a,b,c"));
- testing.expectEqual(str[str.len], 0);
+ try testing.expect(eql(u8, str, "a,b,c"));
+ try testing.expectEqual(str[str.len], 0);
}
{
const str = try joinZ(testing.allocator, ",", &[_][]const u8{"a"});
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a"));
- testing.expectEqual(str[str.len], 0);
+ try testing.expect(eql(u8, str, "a"));
+ try testing.expectEqual(str[str.len], 0);
}
{
const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a,,b,,c"));
- testing.expectEqual(str[str.len], 0);
+ try testing.expect(eql(u8, str, "a,,b,,c"));
+ try testing.expectEqual(str[str.len], 0);
}
}
@@ -1646,7 +1646,7 @@ test "concat" {
{
const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" });
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "abcdefghi"));
+ try testing.expect(eql(u8, str, "abcdefghi"));
}
{
const str = try concat(testing.allocator, u32, &[_][]const u32{
@@ -1656,21 +1656,21 @@ test "concat" {
&[_]u32{5},
});
defer testing.allocator.free(str);
- testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 }));
+ try testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 }));
}
}
test "testStringEquality" {
- testing.expect(eql(u8, "abcd", "abcd"));
- testing.expect(!eql(u8, "abcdef", "abZdef"));
- testing.expect(!eql(u8, "abcdefg", "abcdef"));
+ try testing.expect(eql(u8, "abcd", "abcd"));
+ try testing.expect(!eql(u8, "abcdef", "abZdef"));
+ try testing.expect(!eql(u8, "abcdefg", "abcdef"));
}
test "testReadInt" {
- testReadIntImpl();
- comptime testReadIntImpl();
+ try testReadIntImpl();
+ comptime try testReadIntImpl();
}
-fn testReadIntImpl() void {
+fn testReadIntImpl() !void {
{
const bytes = [_]u8{
0x12,
@@ -1678,12 +1678,12 @@ fn testReadIntImpl() void {
0x56,
0x78,
};
- testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);
- testing.expect(readIntBig(u32, &bytes) == 0x12345678);
- testing.expect(readIntBig(i32, &bytes) == 0x12345678);
- testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);
- testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
- testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
+ try testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);
+ try testing.expect(readIntBig(u32, &bytes) == 0x12345678);
+ try testing.expect(readIntBig(i32, &bytes) == 0x12345678);
+ try testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);
+ try testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
+ try testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
}
{
const buf = [_]u8{
@@ -1693,7 +1693,7 @@ fn testReadIntImpl() void {
0x34,
};
const answer = readInt(u32, &buf, builtin.Endian.Big);
- testing.expect(answer == 0x00001234);
+ try testing.expect(answer == 0x00001234);
}
{
const buf = [_]u8{
@@ -1703,41 +1703,41 @@ fn testReadIntImpl() void {
0x00,
};
const answer = readInt(u32, &buf, builtin.Endian.Little);
- testing.expect(answer == 0x00003412);
+ try testing.expect(answer == 0x00003412);
}
{
const bytes = [_]u8{
0xff,
0xfe,
};
- testing.expect(readIntBig(u16, &bytes) == 0xfffe);
- testing.expect(readIntBig(i16, &bytes) == -0x0002);
- testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
- testing.expect(readIntLittle(i16, &bytes) == -0x0101);
+ try testing.expect(readIntBig(u16, &bytes) == 0xfffe);
+ try testing.expect(readIntBig(i16, &bytes) == -0x0002);
+ try testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
+ try testing.expect(readIntLittle(i16, &bytes) == -0x0101);
}
}
test "writeIntSlice" {
- testWriteIntImpl();
- comptime testWriteIntImpl();
+ try testWriteIntImpl();
+ comptime try testWriteIntImpl();
}
-fn testWriteIntImpl() void {
+fn testWriteIntImpl() !void {
var bytes: [8]u8 = undefined;
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}));
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}));
writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x12,
0x34,
0x56,
@@ -1749,7 +1749,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x12,
0x34,
0x56,
@@ -1761,7 +1761,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x00,
0x00,
0x00,
@@ -1773,7 +1773,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x12,
0x34,
0x56,
@@ -1785,7 +1785,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x00,
0x00,
0x00,
@@ -1797,7 +1797,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x34,
0x12,
0x00,
@@ -1820,7 +1820,7 @@ pub fn min(comptime T: type, slice: []const T) T {
}
test "mem.min" {
- testing.expect(min(u8, "abcdefg") == 'a');
+ try testing.expect(min(u8, "abcdefg") == 'a');
}
/// Returns the largest number in a slice. O(n).
@@ -1834,7 +1834,7 @@ pub fn max(comptime T: type, slice: []const T) T {
}
test "mem.max" {
- testing.expect(max(u8, "abcdefg") == 'g');
+ try testing.expect(max(u8, "abcdefg") == 'g');
}
pub fn swap(comptime T: type, a: *T, b: *T) void {
@@ -1856,7 +1856,7 @@ test "reverse" {
var arr = [_]i32{ 5, 3, 1, 2, 4 };
reverse(i32, arr[0..]);
- testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
+ try testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
}
/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)
@@ -1871,7 +1871,7 @@ test "rotate" {
var arr = [_]i32{ 5, 3, 1, 2, 4 };
rotate(i32, arr[0..], 2);
- testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
+ try testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
}
/// Replace needle with replacement as many times as possible, writing to an output buffer which is assumed to be of
@@ -1904,31 +1904,31 @@ test "replace" {
var output: [29]u8 = undefined;
var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]);
var expected: []const u8 = "All your Zig are belong to us";
- testing.expect(replacements == 1);
- testing.expectEqualStrings(expected, output[0..expected.len]);
+ try testing.expect(replacements == 1);
+ try testing.expectEqualStrings(expected, output[0..expected.len]);
replacements = replace(u8, "Favor reading code over writing code.", "code", "", output[0..]);
expected = "Favor reading over writing .";
- testing.expect(replacements == 2);
- testing.expectEqualStrings(expected, output[0..expected.len]);
+ try testing.expect(replacements == 2);
+ try testing.expectEqualStrings(expected, output[0..expected.len]);
// Empty needle is not allowed but input may be empty.
replacements = replace(u8, "", "x", "y", output[0..0]);
expected = "";
- testing.expect(replacements == 0);
- testing.expectEqualStrings(expected, output[0..expected.len]);
+ try testing.expect(replacements == 0);
+ try testing.expectEqualStrings(expected, output[0..expected.len]);
// Adjacent replacements.
replacements = replace(u8, "\\n\\n", "\\n", "\n", output[0..]);
expected = "\n\n";
- testing.expect(replacements == 2);
- testing.expectEqualStrings(expected, output[0..expected.len]);
+ try testing.expect(replacements == 2);
+ try testing.expectEqualStrings(expected, output[0..expected.len]);
replacements = replace(u8, "abbba", "b", "cd", output[0..]);
expected = "acdcdcda";
- testing.expect(replacements == 3);
- testing.expectEqualStrings(expected, output[0..expected.len]);
+ try testing.expect(replacements == 3);
+ try testing.expectEqualStrings(expected, output[0..expected.len]);
}
/// Calculate the size needed in an output buffer to perform a replacement.
@@ -1952,16 +1952,16 @@ pub fn replacementSize(comptime T: type, input: []const T, needle: []const T, re
}
test "replacementSize" {
- testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29);
- testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29);
- testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41);
+ try testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29);
+ try testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29);
+ try testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41);
// Empty needle is not allowed but input may be empty.
- testing.expect(replacementSize(u8, "", "x", "y") == 0);
+ try testing.expect(replacementSize(u8, "", "x", "y") == 0);
// Adjacent replacements.
- testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);
- testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);
+ try testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);
+ try testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);
}
/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.
@@ -1976,11 +1976,11 @@ test "replaceOwned" {
const base_replace = replaceOwned(u8, allocator, "All your base are belong to us", "base", "Zig") catch unreachable;
defer allocator.free(base_replace);
- testing.expect(eql(u8, base_replace, "All your Zig are belong to us"));
+ try testing.expect(eql(u8, base_replace, "All your Zig are belong to us"));
const zen_replace = replaceOwned(u8, allocator, "Favor reading code over writing code.", " code", "") catch unreachable;
defer allocator.free(zen_replace);
- testing.expect(eql(u8, zen_replace, "Favor reading over writing."));
+ try testing.expect(eql(u8, zen_replace, "Favor reading over writing."));
}
/// Converts a little-endian integer to host endianness.
@@ -2068,12 +2068,12 @@ test "asBytes" {
.Little => "\xEF\xBE\xAD\xDE",
};
- testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
+ try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
var codeface = @as(u32, 0xC0DEFACE);
for (asBytes(&codeface).*) |*b|
b.* = 0;
- testing.expect(codeface == 0);
+ try testing.expect(codeface == 0);
const S = packed struct {
a: u8,
@@ -2088,11 +2088,11 @@ test "asBytes" {
.c = 0xDE,
.d = 0xA1,
};
- testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
+ try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
const ZST = struct {};
const zero = ZST{};
- testing.expect(eql(u8, asBytes(&zero), ""));
+ try testing.expect(eql(u8, asBytes(&zero), ""));
}
test "asBytes preserves pointer attributes" {
@@ -2103,10 +2103,10 @@ test "asBytes preserves pointer attributes" {
const in = @typeInfo(@TypeOf(inPtr)).Pointer;
const out = @typeInfo(@TypeOf(outSlice)).Pointer;
- testing.expectEqual(in.is_const, out.is_const);
- testing.expectEqual(in.is_volatile, out.is_volatile);
- testing.expectEqual(in.is_allowzero, out.is_allowzero);
- testing.expectEqual(in.alignment, out.alignment);
+ try testing.expectEqual(in.is_const, out.is_const);
+ try testing.expectEqual(in.is_volatile, out.is_volatile);
+ try testing.expectEqual(in.is_allowzero, out.is_allowzero);
+ try testing.expectEqual(in.alignment, out.alignment);
}
/// Given any value, returns a copy of its bytes in an array.
@@ -2117,14 +2117,14 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {
test "toBytes" {
var my_bytes = toBytes(@as(u32, 0x12345678));
switch (builtin.endian) {
- .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
- .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
+ .Big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
+ .Little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
}
my_bytes[0] = '\x99';
switch (builtin.endian) {
- .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
- .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
+ .Big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
+ .Little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
}
}
@@ -2154,17 +2154,17 @@ test "bytesAsValue" {
.Little => "\xEF\xBE\xAD\xDE",
};
- testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
+ try testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
var codeface_bytes: [4]u8 = switch (builtin.endian) {
.Big => "\xC0\xDE\xFA\xCE",
.Little => "\xCE\xFA\xDE\xC0",
}.*;
var codeface = bytesAsValue(u32, &codeface_bytes);
- testing.expect(codeface.* == 0xC0DEFACE);
+ try testing.expect(codeface.* == 0xC0DEFACE);
codeface.* = 0;
for (codeface_bytes) |b|
- testing.expect(b == 0);
+ try testing.expect(b == 0);
const S = packed struct {
a: u8,
@@ -2181,7 +2181,7 @@ test "bytesAsValue" {
};
const inst_bytes = "\xBE\xEF\xDE\xA1";
const inst2 = bytesAsValue(S, inst_bytes);
- testing.expect(meta.eql(inst, inst2.*));
+ try testing.expect(meta.eql(inst, inst2.*));
}
test "bytesAsValue preserves pointer attributes" {
@@ -2192,10 +2192,10 @@ test "bytesAsValue preserves pointer attributes" {
const in = @typeInfo(@TypeOf(inSlice)).Pointer;
const out = @typeInfo(@TypeOf(outPtr)).Pointer;
- testing.expectEqual(in.is_const, out.is_const);
- testing.expectEqual(in.is_volatile, out.is_volatile);
- testing.expectEqual(in.is_allowzero, out.is_allowzero);
- testing.expectEqual(in.alignment, out.alignment);
+ try testing.expectEqual(in.is_const, out.is_const);
+ try testing.expectEqual(in.is_volatile, out.is_volatile);
+ try testing.expectEqual(in.is_allowzero, out.is_allowzero);
+ try testing.expectEqual(in.alignment, out.alignment);
}
/// Given a pointer to an array of bytes, returns a value of the specified type backed by a
@@ -2210,7 +2210,7 @@ test "bytesToValue" {
};
const deadbeef = bytesToValue(u32, deadbeef_bytes);
- testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
+ try testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
}
fn BytesAsSliceReturnType(comptime T: type, comptime bytesType: type) type {
@@ -2243,17 +2243,17 @@ test "bytesAsSlice" {
{
const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
const slice = bytesAsSlice(u16, bytes[0..]);
- testing.expect(slice.len == 2);
- testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
- testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
+ try testing.expect(slice.len == 2);
+ try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
+ try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
}
{
const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
var runtime_zero: usize = 0;
const slice = bytesAsSlice(u16, bytes[runtime_zero..]);
- testing.expect(slice.len == 2);
- testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
- testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
+ try testing.expect(slice.len == 2);
+ try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
+ try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
}
}
@@ -2261,13 +2261,13 @@ test "bytesAsSlice keeps pointer alignment" {
{
var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
const numbers = bytesAsSlice(u32, bytes[0..]);
- comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
+ comptime try testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
}
{
var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
var runtime_zero: usize = 0;
const numbers = bytesAsSlice(u32, bytes[runtime_zero..]);
- comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
+ comptime try testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
}
}
@@ -2278,7 +2278,7 @@ test "bytesAsSlice on a packed struct" {
var b = [1]u8{9};
var f = bytesAsSlice(F, &b);
- testing.expect(f[0].a == 9);
+ try testing.expect(f[0].a == 9);
}
test "bytesAsSlice with specified alignment" {
@@ -2289,7 +2289,7 @@ test "bytesAsSlice with specified alignment" {
0x33,
};
const slice: []u32 = std.mem.bytesAsSlice(u32, bytes[0..]);
- testing.expect(slice[0] == 0x33333333);
+ try testing.expect(slice[0] == 0x33333333);
}
test "bytesAsSlice preserves pointer attributes" {
@@ -2300,10 +2300,10 @@ test "bytesAsSlice preserves pointer attributes" {
const in = @typeInfo(@TypeOf(inSlice)).Pointer;
const out = @typeInfo(@TypeOf(outSlice)).Pointer;
- testing.expectEqual(in.is_const, out.is_const);
- testing.expectEqual(in.is_volatile, out.is_volatile);
- testing.expectEqual(in.is_allowzero, out.is_allowzero);
- testing.expectEqual(in.alignment, out.alignment);
+ try testing.expectEqual(in.is_const, out.is_const);
+ try testing.expectEqual(in.is_volatile, out.is_volatile);
+ try testing.expectEqual(in.is_allowzero, out.is_allowzero);
+ try testing.expectEqual(in.alignment, out.alignment);
}
fn SliceAsBytesReturnType(comptime sliceType: type) type {
@@ -2332,8 +2332,8 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {
test "sliceAsBytes" {
const bytes = [_]u16{ 0xDEAD, 0xBEEF };
const slice = sliceAsBytes(bytes[0..]);
- testing.expect(slice.len == 4);
- testing.expect(eql(u8, slice, switch (builtin.endian) {
+ try testing.expect(slice.len == 4);
+ try testing.expect(eql(u8, slice, switch (builtin.endian) {
.Big => "\xDE\xAD\xBE\xEF",
.Little => "\xAD\xDE\xEF\xBE",
}));
@@ -2342,7 +2342,7 @@ test "sliceAsBytes" {
test "sliceAsBytes with sentinel slice" {
const empty_string: [:0]const u8 = "";
const bytes = sliceAsBytes(empty_string);
- testing.expect(bytes.len == 0);
+ try testing.expect(bytes.len == 0);
}
test "sliceAsBytes packed struct at runtime and comptime" {
@@ -2351,49 +2351,49 @@ test "sliceAsBytes packed struct at runtime and comptime" {
b: u4,
};
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var foo: Foo = undefined;
var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);
slice[0] = 0x13;
switch (builtin.endian) {
.Big => {
- testing.expect(foo.a == 0x1);
- testing.expect(foo.b == 0x3);
+ try testing.expect(foo.a == 0x1);
+ try testing.expect(foo.b == 0x3);
},
.Little => {
- testing.expect(foo.a == 0x3);
- testing.expect(foo.b == 0x1);
+ try testing.expect(foo.a == 0x3);
+ try testing.expect(foo.b == 0x1);
},
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "sliceAsBytes and bytesAsSlice back" {
- testing.expect(@sizeOf(i32) == 4);
+ try testing.expect(@sizeOf(i32) == 4);
var big_thing_array = [_]i32{ 1, 2, 3, 4 };
const big_thing_slice: []i32 = big_thing_array[0..];
const bytes = sliceAsBytes(big_thing_slice);
- testing.expect(bytes.len == 4 * 4);
+ try testing.expect(bytes.len == 4 * 4);
bytes[4] = 0;
bytes[5] = 0;
bytes[6] = 0;
bytes[7] = 0;
- testing.expect(big_thing_slice[1] == 0);
+ try testing.expect(big_thing_slice[1] == 0);
const big_thing_again = bytesAsSlice(i32, bytes);
- testing.expect(big_thing_again[2] == 3);
+ try testing.expect(big_thing_again[2] == 3);
big_thing_again[2] = -1;
- testing.expect(bytes[8] == math.maxInt(u8));
- testing.expect(bytes[9] == math.maxInt(u8));
- testing.expect(bytes[10] == math.maxInt(u8));
- testing.expect(bytes[11] == math.maxInt(u8));
+ try testing.expect(bytes[8] == math.maxInt(u8));
+ try testing.expect(bytes[9] == math.maxInt(u8));
+ try testing.expect(bytes[10] == math.maxInt(u8));
+ try testing.expect(bytes[11] == math.maxInt(u8));
}
test "sliceAsBytes preserves pointer attributes" {
@@ -2404,10 +2404,10 @@ test "sliceAsBytes preserves pointer attributes" {
const in = @typeInfo(@TypeOf(inSlice)).Pointer;
const out = @typeInfo(@TypeOf(outSlice)).Pointer;
- testing.expectEqual(in.is_const, out.is_const);
- testing.expectEqual(in.is_volatile, out.is_volatile);
- testing.expectEqual(in.is_allowzero, out.is_allowzero);
- testing.expectEqual(in.alignment, out.alignment);
+ try testing.expectEqual(in.is_const, out.is_const);
+ try testing.expectEqual(in.is_volatile, out.is_volatile);
+ try testing.expectEqual(in.is_allowzero, out.is_allowzero);
+ try testing.expectEqual(in.alignment, out.alignment);
}
/// Round an address up to the nearest aligned address
@@ -2434,18 +2434,18 @@ pub fn doNotOptimizeAway(val: anytype) void {
}
test "alignForward" {
- testing.expect(alignForward(1, 1) == 1);
- testing.expect(alignForward(2, 1) == 2);
- testing.expect(alignForward(1, 2) == 2);
- testing.expect(alignForward(2, 2) == 2);
- testing.expect(alignForward(3, 2) == 4);
- testing.expect(alignForward(4, 2) == 4);
- testing.expect(alignForward(7, 8) == 8);
- testing.expect(alignForward(8, 8) == 8);
- testing.expect(alignForward(9, 8) == 16);
- testing.expect(alignForward(15, 8) == 16);
- testing.expect(alignForward(16, 8) == 16);
- testing.expect(alignForward(17, 8) == 24);
+ try testing.expect(alignForward(1, 1) == 1);
+ try testing.expect(alignForward(2, 1) == 2);
+ try testing.expect(alignForward(1, 2) == 2);
+ try testing.expect(alignForward(2, 2) == 2);
+ try testing.expect(alignForward(3, 2) == 4);
+ try testing.expect(alignForward(4, 2) == 4);
+ try testing.expect(alignForward(7, 8) == 8);
+ try testing.expect(alignForward(8, 8) == 8);
+ try testing.expect(alignForward(9, 8) == 16);
+ try testing.expect(alignForward(15, 8) == 16);
+ try testing.expect(alignForward(16, 8) == 16);
+ try testing.expect(alignForward(17, 8) == 24);
}
/// Round an address up to the previous aligned address
@@ -2497,19 +2497,19 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool {
}
test "isAligned" {
- testing.expect(isAligned(0, 4));
- testing.expect(isAligned(1, 1));
- testing.expect(isAligned(2, 1));
- testing.expect(isAligned(2, 2));
- testing.expect(!isAligned(2, 4));
- testing.expect(isAligned(3, 1));
- testing.expect(!isAligned(3, 2));
- testing.expect(!isAligned(3, 4));
- testing.expect(isAligned(4, 4));
- testing.expect(isAligned(4, 2));
- testing.expect(isAligned(4, 1));
- testing.expect(!isAligned(4, 8));
- testing.expect(!isAligned(4, 16));
+ try testing.expect(isAligned(0, 4));
+ try testing.expect(isAligned(1, 1));
+ try testing.expect(isAligned(2, 1));
+ try testing.expect(isAligned(2, 2));
+ try testing.expect(!isAligned(2, 4));
+ try testing.expect(isAligned(3, 1));
+ try testing.expect(!isAligned(3, 2));
+ try testing.expect(!isAligned(3, 4));
+ try testing.expect(isAligned(4, 4));
+ try testing.expect(isAligned(4, 2));
+ try testing.expect(isAligned(4, 1));
+ try testing.expect(!isAligned(4, 8));
+ try testing.expect(!isAligned(4, 16));
}
test "freeing empty string with null-terminated sentinel" {
diff --git a/lib/std/meta.zig b/lib/std/meta.zig
index 600f3d3c5d..391b7259e3 100644
--- a/lib/std/meta.zig
+++ b/lib/std/meta.zig
@@ -47,16 +47,16 @@ test "std.meta.tagName" {
var u2a = U2{ .C = 0 };
var u2b = U2{ .D = 0 };
- testing.expect(mem.eql(u8, tagName(E1.A), "A"));
- testing.expect(mem.eql(u8, tagName(E1.B), "B"));
- testing.expect(mem.eql(u8, tagName(E2.C), "C"));
- testing.expect(mem.eql(u8, tagName(E2.D), "D"));
- testing.expect(mem.eql(u8, tagName(error.E), "E"));
- testing.expect(mem.eql(u8, tagName(error.F), "F"));
- testing.expect(mem.eql(u8, tagName(u1g), "G"));
- testing.expect(mem.eql(u8, tagName(u1h), "H"));
- testing.expect(mem.eql(u8, tagName(u2a), "C"));
- testing.expect(mem.eql(u8, tagName(u2b), "D"));
+ try testing.expect(mem.eql(u8, tagName(E1.A), "A"));
+ try testing.expect(mem.eql(u8, tagName(E1.B), "B"));
+ try testing.expect(mem.eql(u8, tagName(E2.C), "C"));
+ try testing.expect(mem.eql(u8, tagName(E2.D), "D"));
+ try testing.expect(mem.eql(u8, tagName(error.E), "E"));
+ try testing.expect(mem.eql(u8, tagName(error.F), "F"));
+ try testing.expect(mem.eql(u8, tagName(u1g), "G"));
+ try testing.expect(mem.eql(u8, tagName(u1h), "H"));
+ try testing.expect(mem.eql(u8, tagName(u2a), "C"));
+ try testing.expect(mem.eql(u8, tagName(u2b), "D"));
}
pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
@@ -98,9 +98,9 @@ test "std.meta.stringToEnum" {
A,
B,
};
- testing.expect(E1.A == stringToEnum(E1, "A").?);
- testing.expect(E1.B == stringToEnum(E1, "B").?);
- testing.expect(null == stringToEnum(E1, "C"));
+ try testing.expect(E1.A == stringToEnum(E1, "A").?);
+ try testing.expect(E1.B == stringToEnum(E1, "B").?);
+ try testing.expect(null == stringToEnum(E1, "C"));
}
pub fn bitCount(comptime T: type) comptime_int {
@@ -113,8 +113,8 @@ pub fn bitCount(comptime T: type) comptime_int {
}
test "std.meta.bitCount" {
- testing.expect(bitCount(u8) == 8);
- testing.expect(bitCount(f32) == 32);
+ try testing.expect(bitCount(u8) == 8);
+ try testing.expect(bitCount(f32) == 32);
}
/// Returns the alignment of type T.
@@ -135,13 +135,13 @@ pub fn alignment(comptime T: type) comptime_int {
}
test "std.meta.alignment" {
- testing.expect(alignment(u8) == 1);
- testing.expect(alignment(*align(1) u8) == 1);
- testing.expect(alignment(*align(2) u8) == 2);
- testing.expect(alignment([]align(1) u8) == 1);
- testing.expect(alignment([]align(2) u8) == 2);
- testing.expect(alignment(fn () void) > 0);
- testing.expect(alignment(fn () align(128) void) == 128);
+ try testing.expect(alignment(u8) == 1);
+ try testing.expect(alignment(*align(1) u8) == 1);
+ try testing.expect(alignment(*align(2) u8) == 2);
+ try testing.expect(alignment([]align(1) u8) == 1);
+ try testing.expect(alignment([]align(2) u8) == 2);
+ try testing.expect(alignment(fn () void) > 0);
+ try testing.expect(alignment(fn () align(128) void) == 128);
}
pub fn Child(comptime T: type) type {
@@ -155,11 +155,11 @@ pub fn Child(comptime T: type) type {
}
test "std.meta.Child" {
- testing.expect(Child([1]u8) == u8);
- testing.expect(Child(*u8) == u8);
- testing.expect(Child([]u8) == u8);
- testing.expect(Child(?u8) == u8);
- testing.expect(Child(Vector(2, u8)) == u8);
+ try testing.expect(Child([1]u8) == u8);
+ try testing.expect(Child(*u8) == u8);
+ try testing.expect(Child([]u8) == u8);
+ try testing.expect(Child(?u8) == u8);
+ try testing.expect(Child(Vector(2, u8)) == u8);
}
/// Given a "memory span" type, returns the "element type".
@@ -188,13 +188,13 @@ pub fn Elem(comptime T: type) type {
}
test "std.meta.Elem" {
- testing.expect(Elem([1]u8) == u8);
- testing.expect(Elem([*]u8) == u8);
- testing.expect(Elem([]u8) == u8);
- testing.expect(Elem(*[10]u8) == u8);
- testing.expect(Elem(Vector(2, u8)) == u8);
- testing.expect(Elem(*Vector(2, u8)) == u8);
- testing.expect(Elem(?[*]u8) == u8);
+ try testing.expect(Elem([1]u8) == u8);
+ try testing.expect(Elem([*]u8) == u8);
+ try testing.expect(Elem([]u8) == u8);
+ try testing.expect(Elem(*[10]u8) == u8);
+ try testing.expect(Elem(Vector(2, u8)) == u8);
+ try testing.expect(Elem(*Vector(2, u8)) == u8);
+ try testing.expect(Elem(?[*]u8) == u8);
}
/// Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value,
@@ -219,20 +219,20 @@ pub fn sentinel(comptime T: type) ?Elem(T) {
}
test "std.meta.sentinel" {
- testSentinel();
- comptime testSentinel();
+ try testSentinel();
+ comptime try testSentinel();
}
-fn testSentinel() void {
- testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);
- testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);
- testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);
- testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);
+fn testSentinel() !void {
+ try testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);
+ try testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);
+ try testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);
+ try testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);
- testing.expect(sentinel([]u8) == null);
- testing.expect(sentinel([*]u8) == null);
- testing.expect(sentinel([5]u8) == null);
- testing.expect(sentinel(*const [5]u8) == null);
+ try testing.expect(sentinel([]u8) == null);
+ try testing.expect(sentinel([*]u8) == null);
+ try testing.expect(sentinel([5]u8) == null);
+ try testing.expect(sentinel(*const [5]u8) == null);
}
/// Given a "memory span" type, returns the same type except with the given sentinel value.
@@ -322,17 +322,17 @@ pub fn assumeSentinel(p: anytype, comptime sentinel_val: Elem(@TypeOf(p))) Senti
}
test "std.meta.assumeSentinel" {
- testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));
- testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));
- testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0)));
- testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0)));
- testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));
- testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));
- testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));
- testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));
- testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));
- testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));
- testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));
+ try testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));
+ try testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));
+ try testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0)));
+ try testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0)));
+ try testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));
+ try testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));
+ try testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));
+ try testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));
+ try testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));
+ try testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));
+ try testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));
}
pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
@@ -367,15 +367,15 @@ test "std.meta.containerLayout" {
a: u8,
};
- testing.expect(containerLayout(E1) == .Auto);
- testing.expect(containerLayout(E2) == .Packed);
- testing.expect(containerLayout(E3) == .Extern);
- testing.expect(containerLayout(S1) == .Auto);
- testing.expect(containerLayout(S2) == .Packed);
- testing.expect(containerLayout(S3) == .Extern);
- testing.expect(containerLayout(U1) == .Auto);
- testing.expect(containerLayout(U2) == .Packed);
- testing.expect(containerLayout(U3) == .Extern);
+ try testing.expect(containerLayout(E1) == .Auto);
+ try testing.expect(containerLayout(E2) == .Packed);
+ try testing.expect(containerLayout(E3) == .Extern);
+ try testing.expect(containerLayout(S1) == .Auto);
+ try testing.expect(containerLayout(S2) == .Packed);
+ try testing.expect(containerLayout(S3) == .Extern);
+ try testing.expect(containerLayout(U1) == .Auto);
+ try testing.expect(containerLayout(U2) == .Packed);
+ try testing.expect(containerLayout(U3) == .Extern);
}
pub fn declarations(comptime T: type) []const TypeInfo.Declaration {
@@ -414,8 +414,8 @@ test "std.meta.declarations" {
};
inline for (decls) |decl| {
- testing.expect(decl.len == 1);
- testing.expect(comptime mem.eql(u8, decl[0].name, "a"));
+ try testing.expect(decl.len == 1);
+ try testing.expect(comptime mem.eql(u8, decl[0].name, "a"));
}
}
@@ -450,8 +450,8 @@ test "std.meta.declarationInfo" {
};
inline for (infos) |info| {
- testing.expect(comptime mem.eql(u8, info.name, "a"));
- testing.expect(!info.is_pub);
+ try testing.expect(comptime mem.eql(u8, info.name, "a"));
+ try testing.expect(!info.is_pub);
}
}
@@ -488,16 +488,16 @@ test "std.meta.fields" {
const sf = comptime fields(S1);
const uf = comptime fields(U1);
- testing.expect(e1f.len == 1);
- testing.expect(e2f.len == 1);
- testing.expect(sf.len == 1);
- testing.expect(uf.len == 1);
- testing.expect(mem.eql(u8, e1f[0].name, "A"));
- testing.expect(mem.eql(u8, e2f[0].name, "A"));
- testing.expect(mem.eql(u8, sf[0].name, "a"));
- testing.expect(mem.eql(u8, uf[0].name, "a"));
- testing.expect(comptime sf[0].field_type == u8);
- testing.expect(comptime uf[0].field_type == u8);
+ try testing.expect(e1f.len == 1);
+ try testing.expect(e2f.len == 1);
+ try testing.expect(sf.len == 1);
+ try testing.expect(uf.len == 1);
+ try testing.expect(mem.eql(u8, e1f[0].name, "A"));
+ try testing.expect(mem.eql(u8, e2f[0].name, "A"));
+ try testing.expect(mem.eql(u8, sf[0].name, "a"));
+ try testing.expect(mem.eql(u8, uf[0].name, "a"));
+ try testing.expect(comptime sf[0].field_type == u8);
+ try testing.expect(comptime uf[0].field_type == u8);
}
pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
@@ -527,12 +527,12 @@ test "std.meta.fieldInfo" {
const sf = fieldInfo(S1, .a);
const uf = fieldInfo(U1, .a);
- testing.expect(mem.eql(u8, e1f.name, "A"));
- testing.expect(mem.eql(u8, e2f.name, "A"));
- testing.expect(mem.eql(u8, sf.name, "a"));
- testing.expect(mem.eql(u8, uf.name, "a"));
- testing.expect(comptime sf.field_type == u8);
- testing.expect(comptime uf.field_type == u8);
+ try testing.expect(mem.eql(u8, e1f.name, "A"));
+ try testing.expect(mem.eql(u8, e2f.name, "A"));
+ try testing.expect(mem.eql(u8, sf.name, "a"));
+ try testing.expect(mem.eql(u8, uf.name, "a"));
+ try testing.expect(comptime sf.field_type == u8);
+ try testing.expect(comptime uf.field_type == u8);
}
pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 {
@@ -562,16 +562,16 @@ test "std.meta.fieldNames" {
const s1names = fieldNames(S1);
const u1names = fieldNames(U1);
- testing.expect(e1names.len == 2);
- testing.expectEqualSlices(u8, e1names[0], "A");
- testing.expectEqualSlices(u8, e1names[1], "B");
- testing.expect(e2names.len == 1);
- testing.expectEqualSlices(u8, e2names[0], "A");
- testing.expect(s1names.len == 1);
- testing.expectEqualSlices(u8, s1names[0], "a");
- testing.expect(u1names.len == 2);
- testing.expectEqualSlices(u8, u1names[0], "a");
- testing.expectEqualSlices(u8, u1names[1], "b");
+ try testing.expect(e1names.len == 2);
+ try testing.expectEqualSlices(u8, e1names[0], "A");
+ try testing.expectEqualSlices(u8, e1names[1], "B");
+ try testing.expect(e2names.len == 1);
+ try testing.expectEqualSlices(u8, e2names[0], "A");
+ try testing.expect(s1names.len == 1);
+ try testing.expectEqualSlices(u8, s1names[0], "a");
+ try testing.expect(u1names.len == 2);
+ try testing.expectEqualSlices(u8, u1names[0], "a");
+ try testing.expectEqualSlices(u8, u1names[1], "b");
}
pub fn FieldEnum(comptime T: type) type {
@@ -595,20 +595,20 @@ pub fn FieldEnum(comptime T: type) type {
});
}
-fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) void {
+fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
// TODO: https://github.com/ziglang/zig/issues/7419
// testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum);
- testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);
- testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type);
- comptime testing.expectEqualSlices(std.builtin.TypeInfo.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields);
- comptime testing.expectEqualSlices(std.builtin.TypeInfo.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls);
- testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive);
+ try testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);
+ try testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type);
+ comptime try testing.expectEqualSlices(std.builtin.TypeInfo.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields);
+ comptime try testing.expectEqualSlices(std.builtin.TypeInfo.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls);
+ try testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive);
}
test "std.meta.FieldEnum" {
- expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
- expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));
- expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
+ try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
+ try expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));
+ try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
}
// Deprecated: use Tag
@@ -632,8 +632,8 @@ test "std.meta.Tag" {
D: u16,
};
- testing.expect(Tag(E) == u8);
- testing.expect(Tag(U) == E);
+ try testing.expect(Tag(E) == u8);
+ try testing.expect(Tag(U) == E);
}
///Returns the active tag of a tagged union
@@ -654,10 +654,10 @@ test "std.meta.activeTag" {
};
var u = U{ .Int = 32 };
- testing.expect(activeTag(u) == UE.Int);
+ try testing.expect(activeTag(u) == UE.Int);
u = U{ .Float = 112.9876 };
- testing.expect(activeTag(u) == UE.Float);
+ try testing.expect(activeTag(u) == UE.Float);
}
const TagPayloadType = TagPayload;
@@ -665,7 +665,7 @@ const TagPayloadType = TagPayload;
///Given a tagged union type, and an enum, return the type of the union
/// field corresponding to the enum tag.
pub fn TagPayload(comptime U: type, tag: Tag(U)) type {
- testing.expect(trait.is(.Union)(U));
+ try testing.expect(trait.is(.Union)(U));
const info = @typeInfo(U).Union;
const tag_info = @typeInfo(Tag(U)).Enum;
@@ -687,7 +687,7 @@ test "std.meta.TagPayload" {
};
const MovedEvent = TagPayload(Event, Event.Moved);
var e: Event = undefined;
- testing.expect(MovedEvent == @TypeOf(e.Moved));
+ try testing.expect(MovedEvent == @TypeOf(e.Moved));
}
/// Compares two of any type for equality. Containers are compared on a field-by-field basis,
@@ -787,19 +787,19 @@ test "std.meta.eql" {
const u_2 = U{ .s = s_1 };
const u_3 = U{ .f = 24 };
- testing.expect(eql(s_1, s_3));
- testing.expect(eql(&s_1, &s_1));
- testing.expect(!eql(&s_1, &s_3));
- testing.expect(eql(u_1, u_3));
- testing.expect(!eql(u_1, u_2));
+ try testing.expect(eql(s_1, s_3));
+ try testing.expect(eql(&s_1, &s_1));
+ try testing.expect(!eql(&s_1, &s_3));
+ try testing.expect(eql(u_1, u_3));
+ try testing.expect(!eql(u_1, u_2));
var a1 = "abcdef".*;
var a2 = "abcdef".*;
var a3 = "ghijkl".*;
- testing.expect(eql(a1, a2));
- testing.expect(!eql(a1, a3));
- testing.expect(!eql(a1[0..], a2[0..]));
+ try testing.expect(eql(a1, a2));
+ try testing.expect(!eql(a1, a3));
+ try testing.expect(!eql(a1[0..], a2[0..]));
const EU = struct {
fn tst(err: bool) !u8 {
@@ -808,16 +808,16 @@ test "std.meta.eql" {
}
};
- testing.expect(eql(EU.tst(true), EU.tst(true)));
- testing.expect(eql(EU.tst(false), EU.tst(false)));
- testing.expect(!eql(EU.tst(false), EU.tst(true)));
+ try testing.expect(eql(EU.tst(true), EU.tst(true)));
+ try testing.expect(eql(EU.tst(false), EU.tst(false)));
+ try testing.expect(!eql(EU.tst(false), EU.tst(true)));
var v1 = @splat(4, @as(u32, 1));
var v2 = @splat(4, @as(u32, 1));
var v3 = @splat(4, @as(u32, 2));
- testing.expect(eql(v1, v2));
- testing.expect(!eql(v1, v3));
+ try testing.expect(eql(v1, v2));
+ try testing.expect(!eql(v1, v3));
}
test "intToEnum with error return" {
@@ -831,9 +831,9 @@ test "intToEnum with error return" {
var zero: u8 = 0;
var one: u16 = 1;
- testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
- testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
- testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
+ try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
+ try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
+ try testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
}
pub const IntToEnumError = error{InvalidEnumTag};
@@ -1008,27 +1008,27 @@ test "std.meta.cast" {
var i = @as(i64, 10);
- testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
- testing.expect(cast(*u64, &i).* == @as(u64, 10));
- testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
+ try testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
+ try testing.expect(cast(*u64, &i).* == @as(u64, 10));
+ try testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
- testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
- testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
- testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
+ try testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
+ try testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
+ try testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
- testing.expect(cast(E, 1) == .One);
+ try testing.expect(cast(E, 1) == .One);
- testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));
- testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
- testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
- testing.expectEqual(@as(u8, 2), cast(u8, E.Two));
+ try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));
+ try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
+ try testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
+ try testing.expectEqual(@as(u8, 2), cast(u8, E.Two));
- testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000)));
+ try testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000)));
- testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));
- testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));
+ try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));
+ try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));
- testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2)));
+ try testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2)));
const C_ENUM = extern enum(c_int) {
A = 0,
@@ -1036,10 +1036,10 @@ test "std.meta.cast" {
C,
_,
};
- testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
- testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
- testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
- testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
+ try testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
+ try testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
+ try testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
+ try testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
}
/// Given a value returns its size as C's sizeof operator would.
@@ -1118,43 +1118,43 @@ test "sizeof" {
const ptr_size = @sizeOf(*c_void);
- testing.expect(sizeof(u32) == 4);
- testing.expect(sizeof(@as(u32, 2)) == 4);
- testing.expect(sizeof(2) == @sizeOf(c_int));
+ try testing.expect(sizeof(u32) == 4);
+ try testing.expect(sizeof(@as(u32, 2)) == 4);
+ try testing.expect(sizeof(2) == @sizeOf(c_int));
- testing.expect(sizeof(2.0) == @sizeOf(f64));
+ try testing.expect(sizeof(2.0) == @sizeOf(f64));
- testing.expect(sizeof(E) == @sizeOf(c_int));
- testing.expect(sizeof(E.One) == @sizeOf(c_int));
+ try testing.expect(sizeof(E) == @sizeOf(c_int));
+ try testing.expect(sizeof(E.One) == @sizeOf(c_int));
- testing.expect(sizeof(S) == 4);
+ try testing.expect(sizeof(S) == 4);
- testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
- testing.expect(sizeof([3]u32) == 12);
- testing.expect(sizeof([3:0]u32) == 16);
- testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
+ try testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
+ try testing.expect(sizeof([3]u32) == 12);
+ try testing.expect(sizeof([3:0]u32) == 16);
+ try testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
- testing.expect(sizeof(*u32) == ptr_size);
- testing.expect(sizeof([*]u32) == ptr_size);
- testing.expect(sizeof([*c]u32) == ptr_size);
- testing.expect(sizeof(?*u32) == ptr_size);
- testing.expect(sizeof(?[*]u32) == ptr_size);
- testing.expect(sizeof(*c_void) == ptr_size);
- testing.expect(sizeof(*void) == ptr_size);
- testing.expect(sizeof(null) == ptr_size);
+ try testing.expect(sizeof(*u32) == ptr_size);
+ try testing.expect(sizeof([*]u32) == ptr_size);
+ try testing.expect(sizeof([*c]u32) == ptr_size);
+ try testing.expect(sizeof(?*u32) == ptr_size);
+ try testing.expect(sizeof(?[*]u32) == ptr_size);
+ try testing.expect(sizeof(*c_void) == ptr_size);
+ try testing.expect(sizeof(*void) == ptr_size);
+ try testing.expect(sizeof(null) == ptr_size);
- testing.expect(sizeof("foobar") == 7);
- testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
- testing.expect(sizeof(*const [4:0]u8) == 5);
- testing.expect(sizeof(*[4:0]u8) == ptr_size);
- testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
- testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);
- testing.expect(sizeof(*const [4]u8) == ptr_size);
+ try testing.expect(sizeof("foobar") == 7);
+ try testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
+ try testing.expect(sizeof(*const [4:0]u8) == 5);
+ try testing.expect(sizeof(*[4:0]u8) == ptr_size);
+ try testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
+ try testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);
+ try testing.expect(sizeof(*const [4]u8) == ptr_size);
- testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof)));
+ try testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof)));
- testing.expect(sizeof(void) == 1);
- testing.expect(sizeof(c_void) == 1);
+ try testing.expect(sizeof(void) == 1);
+ try testing.expect(sizeof(c_void) == 1);
}
pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
@@ -1193,7 +1193,7 @@ pub fn promoteIntLiteral(
test "promoteIntLiteral" {
const signed_hex = promoteIntLiteral(c_int, math.maxInt(c_int) + 1, .hexadecimal);
- testing.expectEqual(c_uint, @TypeOf(signed_hex));
+ try testing.expectEqual(c_uint, @TypeOf(signed_hex));
if (math.maxInt(c_longlong) == math.maxInt(c_int)) return;
@@ -1201,11 +1201,11 @@ test "promoteIntLiteral" {
const unsigned = promoteIntLiteral(c_uint, math.maxInt(c_uint) + 1, .hexadecimal);
if (math.maxInt(c_long) > math.maxInt(c_int)) {
- testing.expectEqual(c_long, @TypeOf(signed_decimal));
- testing.expectEqual(c_ulong, @TypeOf(unsigned));
+ try testing.expectEqual(c_long, @TypeOf(signed_decimal));
+ try testing.expectEqual(c_ulong, @TypeOf(unsigned));
} else {
- testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
- testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
+ try testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
+ try testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
}
}
@@ -1347,17 +1347,17 @@ pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len
test "shuffleVectorIndex" {
const vector_len: usize = 4;
- testing.expect(shuffleVectorIndex(-1, vector_len) == 0);
+ try testing.expect(shuffleVectorIndex(-1, vector_len) == 0);
- testing.expect(shuffleVectorIndex(0, vector_len) == 0);
- testing.expect(shuffleVectorIndex(1, vector_len) == 1);
- testing.expect(shuffleVectorIndex(2, vector_len) == 2);
- testing.expect(shuffleVectorIndex(3, vector_len) == 3);
+ try testing.expect(shuffleVectorIndex(0, vector_len) == 0);
+ try testing.expect(shuffleVectorIndex(1, vector_len) == 1);
+ try testing.expect(shuffleVectorIndex(2, vector_len) == 2);
+ try testing.expect(shuffleVectorIndex(3, vector_len) == 3);
- testing.expect(shuffleVectorIndex(4, vector_len) == -1);
- testing.expect(shuffleVectorIndex(5, vector_len) == -2);
- testing.expect(shuffleVectorIndex(6, vector_len) == -3);
- testing.expect(shuffleVectorIndex(7, vector_len) == -4);
+ try testing.expect(shuffleVectorIndex(4, vector_len) == -1);
+ try testing.expect(shuffleVectorIndex(5, vector_len) == -2);
+ try testing.expect(shuffleVectorIndex(6, vector_len) == -3);
+ try testing.expect(shuffleVectorIndex(7, vector_len) == -4);
}
/// Returns whether `error_union` contains an error.
@@ -1366,6 +1366,6 @@ pub fn isError(error_union: anytype) bool {
}
test "isError" {
- std.testing.expect(isError(math.absInt(@as(i8, -128))));
- std.testing.expect(!isError(math.absInt(@as(i8, -127))));
+ try std.testing.expect(isError(math.absInt(@as(i8, -128))));
+ try std.testing.expect(!isError(math.absInt(@as(i8, -127))));
}
diff --git a/lib/std/meta/trailer_flags.zig b/lib/std/meta/trailer_flags.zig
index 1697e9fe43..94f2043b00 100644
--- a/lib/std/meta/trailer_flags.zig
+++ b/lib/std/meta/trailer_flags.zig
@@ -146,7 +146,7 @@ test "TrailerFlags" {
b: bool,
c: u64,
});
- testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));
+ try testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));
var flags = Flags.init(.{
.b = true,
@@ -158,16 +158,16 @@ test "TrailerFlags" {
flags.set(slice.ptr, .b, false);
flags.set(slice.ptr, .c, 12345678);
- testing.expect(flags.get(slice.ptr, .a) == null);
- testing.expect(!flags.get(slice.ptr, .b).?);
- testing.expect(flags.get(slice.ptr, .c).? == 12345678);
+ try testing.expect(flags.get(slice.ptr, .a) == null);
+ try testing.expect(!flags.get(slice.ptr, .b).?);
+ try testing.expect(flags.get(slice.ptr, .c).? == 12345678);
flags.setMany(slice.ptr, .{
.b = true,
.c = 5678,
});
- testing.expect(flags.get(slice.ptr, .a) == null);
- testing.expect(flags.get(slice.ptr, .b).?);
- testing.expect(flags.get(slice.ptr, .c).? == 5678);
+ try testing.expect(flags.get(slice.ptr, .a) == null);
+ try testing.expect(flags.get(slice.ptr, .b).?);
+ try testing.expect(flags.get(slice.ptr, .c).? == 5678);
}
diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig
index 481bfe212b..2bf2e6a0a5 100644
--- a/lib/std/meta/trait.zig
+++ b/lib/std/meta/trait.zig
@@ -45,8 +45,8 @@ test "std.meta.trait.multiTrait" {
hasField("x"),
hasField("y"),
});
- testing.expect(isVector(Vector2));
- testing.expect(!isVector(u8));
+ try testing.expect(isVector(Vector2));
+ try testing.expect(!isVector(u8));
}
pub fn hasFn(comptime name: []const u8) TraitFn {
@@ -66,9 +66,9 @@ test "std.meta.trait.hasFn" {
pub fn useless() void {}
};
- testing.expect(hasFn("useless")(TestStruct));
- testing.expect(!hasFn("append")(TestStruct));
- testing.expect(!hasFn("useless")(u8));
+ try testing.expect(hasFn("useless")(TestStruct));
+ try testing.expect(!hasFn("append")(TestStruct));
+ try testing.expect(!hasFn("useless")(u8));
}
pub fn hasField(comptime name: []const u8) TraitFn {
@@ -96,11 +96,11 @@ test "std.meta.trait.hasField" {
value: u32,
};
- testing.expect(hasField("value")(TestStruct));
- testing.expect(!hasField("value")(*TestStruct));
- testing.expect(!hasField("x")(TestStruct));
- testing.expect(!hasField("x")(**TestStruct));
- testing.expect(!hasField("value")(u8));
+ try testing.expect(hasField("value")(TestStruct));
+ try testing.expect(!hasField("value")(*TestStruct));
+ try testing.expect(!hasField("x")(TestStruct));
+ try testing.expect(!hasField("x")(**TestStruct));
+ try testing.expect(!hasField("value")(u8));
}
pub fn is(comptime id: builtin.TypeId) TraitFn {
@@ -113,11 +113,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {
}
test "std.meta.trait.is" {
- testing.expect(is(.Int)(u8));
- testing.expect(!is(.Int)(f32));
- testing.expect(is(.Pointer)(*u8));
- testing.expect(is(.Void)(void));
- testing.expect(!is(.Optional)(anyerror));
+ try testing.expect(is(.Int)(u8));
+ try testing.expect(!is(.Int)(f32));
+ try testing.expect(is(.Pointer)(*u8));
+ try testing.expect(is(.Void)(void));
+ try testing.expect(!is(.Optional)(anyerror));
}
pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
@@ -131,9 +131,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
}
test "std.meta.trait.isPtrTo" {
- testing.expect(!isPtrTo(.Struct)(struct {}));
- testing.expect(isPtrTo(.Struct)(*struct {}));
- testing.expect(!isPtrTo(.Struct)(**struct {}));
+ try testing.expect(!isPtrTo(.Struct)(struct {}));
+ try testing.expect(isPtrTo(.Struct)(*struct {}));
+ try testing.expect(!isPtrTo(.Struct)(**struct {}));
}
pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
@@ -147,9 +147,9 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
}
test "std.meta.trait.isSliceOf" {
- testing.expect(!isSliceOf(.Struct)(struct {}));
- testing.expect(isSliceOf(.Struct)([]struct {}));
- testing.expect(!isSliceOf(.Struct)([][]struct {}));
+ try testing.expect(!isSliceOf(.Struct)(struct {}));
+ try testing.expect(isSliceOf(.Struct)([]struct {}));
+ try testing.expect(!isSliceOf(.Struct)([][]struct {}));
}
///////////Strait trait Fns
@@ -170,9 +170,9 @@ test "std.meta.trait.isExtern" {
const TestExStruct = extern struct {};
const TestStruct = struct {};
- testing.expect(isExtern(TestExStruct));
- testing.expect(!isExtern(TestStruct));
- testing.expect(!isExtern(u8));
+ try testing.expect(isExtern(TestExStruct));
+ try testing.expect(!isExtern(TestStruct));
+ try testing.expect(!isExtern(u8));
}
pub fn isPacked(comptime T: type) bool {
@@ -188,9 +188,9 @@ test "std.meta.trait.isPacked" {
const TestPStruct = packed struct {};
const TestStruct = struct {};
- testing.expect(isPacked(TestPStruct));
- testing.expect(!isPacked(TestStruct));
- testing.expect(!isPacked(u8));
+ try testing.expect(isPacked(TestPStruct));
+ try testing.expect(!isPacked(TestStruct));
+ try testing.expect(!isPacked(u8));
}
pub fn isUnsignedInt(comptime T: type) bool {
@@ -201,10 +201,10 @@ pub fn isUnsignedInt(comptime T: type) bool {
}
test "isUnsignedInt" {
- testing.expect(isUnsignedInt(u32) == true);
- testing.expect(isUnsignedInt(comptime_int) == false);
- testing.expect(isUnsignedInt(i64) == false);
- testing.expect(isUnsignedInt(f64) == false);
+ try testing.expect(isUnsignedInt(u32) == true);
+ try testing.expect(isUnsignedInt(comptime_int) == false);
+ try testing.expect(isUnsignedInt(i64) == false);
+ try testing.expect(isUnsignedInt(f64) == false);
}
pub fn isSignedInt(comptime T: type) bool {
@@ -216,10 +216,10 @@ pub fn isSignedInt(comptime T: type) bool {
}
test "isSignedInt" {
- testing.expect(isSignedInt(u32) == false);
- testing.expect(isSignedInt(comptime_int) == true);
- testing.expect(isSignedInt(i64) == true);
- testing.expect(isSignedInt(f64) == false);
+ try testing.expect(isSignedInt(u32) == false);
+ try testing.expect(isSignedInt(comptime_int) == true);
+ try testing.expect(isSignedInt(i64) == true);
+ try testing.expect(isSignedInt(f64) == false);
}
pub fn isSingleItemPtr(comptime T: type) bool {
@@ -231,10 +231,10 @@ pub fn isSingleItemPtr(comptime T: type) bool {
test "std.meta.trait.isSingleItemPtr" {
const array = [_]u8{0} ** 10;
- comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
- comptime testing.expect(!isSingleItemPtr(@TypeOf(array)));
+ comptime try testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
+ comptime try testing.expect(!isSingleItemPtr(@TypeOf(array)));
var runtime_zero: usize = 0;
- testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
+ try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
}
pub fn isManyItemPtr(comptime T: type) bool {
@@ -247,9 +247,9 @@ pub fn isManyItemPtr(comptime T: type) bool {
test "std.meta.trait.isManyItemPtr" {
const array = [_]u8{0} ** 10;
const mip = @ptrCast([*]const u8, &array[0]);
- testing.expect(isManyItemPtr(@TypeOf(mip)));
- testing.expect(!isManyItemPtr(@TypeOf(array)));
- testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
+ try testing.expect(isManyItemPtr(@TypeOf(mip)));
+ try testing.expect(!isManyItemPtr(@TypeOf(array)));
+ try testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
}
pub fn isSlice(comptime T: type) bool {
@@ -262,9 +262,9 @@ pub fn isSlice(comptime T: type) bool {
test "std.meta.trait.isSlice" {
const array = [_]u8{0} ** 10;
var runtime_zero: usize = 0;
- testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
- testing.expect(!isSlice(@TypeOf(array)));
- testing.expect(!isSlice(@TypeOf(&array[0])));
+ try testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
+ try testing.expect(!isSlice(@TypeOf(array)));
+ try testing.expect(!isSlice(@TypeOf(&array[0])));
}
pub fn isIndexable(comptime T: type) bool {
@@ -283,12 +283,12 @@ test "std.meta.trait.isIndexable" {
const vector: meta.Vector(2, u32) = [_]u32{0} ** 2;
const tuple = .{ 1, 2, 3 };
- testing.expect(isIndexable(@TypeOf(array)));
- testing.expect(isIndexable(@TypeOf(&array)));
- testing.expect(isIndexable(@TypeOf(slice)));
- testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
- testing.expect(isIndexable(@TypeOf(vector)));
- testing.expect(isIndexable(@TypeOf(tuple)));
+ try testing.expect(isIndexable(@TypeOf(array)));
+ try testing.expect(isIndexable(@TypeOf(&array)));
+ try testing.expect(isIndexable(@TypeOf(slice)));
+ try testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
+ try testing.expect(isIndexable(@TypeOf(vector)));
+ try testing.expect(isIndexable(@TypeOf(tuple)));
}
pub fn isNumber(comptime T: type) bool {
@@ -317,13 +317,13 @@ test "std.meta.trait.isNumber" {
number: u8,
};
- testing.expect(isNumber(u32));
- testing.expect(isNumber(f32));
- testing.expect(isNumber(u64));
- testing.expect(isNumber(@TypeOf(102)));
- testing.expect(isNumber(@TypeOf(102.123)));
- testing.expect(!isNumber([]u8));
- testing.expect(!isNumber(NotANumber));
+ try testing.expect(isNumber(u32));
+ try testing.expect(isNumber(f32));
+ try testing.expect(isNumber(u64));
+ try testing.expect(isNumber(@TypeOf(102)));
+ try testing.expect(isNumber(@TypeOf(102.123)));
+ try testing.expect(!isNumber([]u8));
+ try testing.expect(!isNumber(NotANumber));
}
pub fn isIntegral(comptime T: type) bool {
@@ -334,12 +334,12 @@ pub fn isIntegral(comptime T: type) bool {
}
test "isIntegral" {
- testing.expect(isIntegral(u32));
- testing.expect(!isIntegral(f32));
- testing.expect(isIntegral(@TypeOf(102)));
- testing.expect(!isIntegral(@TypeOf(102.123)));
- testing.expect(!isIntegral(*u8));
- testing.expect(!isIntegral([]u8));
+ try testing.expect(isIntegral(u32));
+ try testing.expect(!isIntegral(f32));
+ try testing.expect(isIntegral(@TypeOf(102)));
+ try testing.expect(!isIntegral(@TypeOf(102.123)));
+ try testing.expect(!isIntegral(*u8));
+ try testing.expect(!isIntegral([]u8));
}
pub fn isFloat(comptime T: type) bool {
@@ -350,12 +350,12 @@ pub fn isFloat(comptime T: type) bool {
}
test "isFloat" {
- testing.expect(!isFloat(u32));
- testing.expect(isFloat(f32));
- testing.expect(!isFloat(@TypeOf(102)));
- testing.expect(isFloat(@TypeOf(102.123)));
- testing.expect(!isFloat(*f64));
- testing.expect(!isFloat([]f32));
+ try testing.expect(!isFloat(u32));
+ try testing.expect(isFloat(f32));
+ try testing.expect(!isFloat(@TypeOf(102)));
+ try testing.expect(isFloat(@TypeOf(102.123)));
+ try testing.expect(!isFloat(*f64));
+ try testing.expect(!isFloat([]f32));
}
pub fn isConstPtr(comptime T: type) bool {
@@ -366,10 +366,10 @@ pub fn isConstPtr(comptime T: type) bool {
test "std.meta.trait.isConstPtr" {
var t = @as(u8, 0);
const c = @as(u8, 0);
- testing.expect(isConstPtr(*const @TypeOf(t)));
- testing.expect(isConstPtr(@TypeOf(&c)));
- testing.expect(!isConstPtr(*@TypeOf(t)));
- testing.expect(!isConstPtr(@TypeOf(6)));
+ try testing.expect(isConstPtr(*const @TypeOf(t)));
+ try testing.expect(isConstPtr(@TypeOf(&c)));
+ try testing.expect(!isConstPtr(*@TypeOf(t)));
+ try testing.expect(!isConstPtr(@TypeOf(6)));
}
pub fn isContainer(comptime T: type) bool {
@@ -389,10 +389,10 @@ test "std.meta.trait.isContainer" {
B,
};
- testing.expect(isContainer(TestStruct));
- testing.expect(isContainer(TestUnion));
- testing.expect(isContainer(TestEnum));
- testing.expect(!isContainer(u8));
+ try testing.expect(isContainer(TestStruct));
+ try testing.expect(isContainer(TestUnion));
+ try testing.expect(isContainer(TestEnum));
+ try testing.expect(!isContainer(u8));
}
pub fn isTuple(comptime T: type) bool {
@@ -403,9 +403,9 @@ test "std.meta.trait.isTuple" {
const t1 = struct {};
const t2 = .{ .a = 0 };
const t3 = .{ 1, 2, 3 };
- testing.expect(!isTuple(t1));
- testing.expect(!isTuple(@TypeOf(t2)));
- testing.expect(isTuple(@TypeOf(t3)));
+ try testing.expect(!isTuple(t1));
+ try testing.expect(!isTuple(@TypeOf(t2)));
+ try testing.expect(isTuple(@TypeOf(t3)));
}
/// Returns true if the passed type will coerce to []const u8.
@@ -449,41 +449,41 @@ pub fn isZigString(comptime T: type) bool {
}
test "std.meta.trait.isZigString" {
- testing.expect(isZigString([]const u8));
- testing.expect(isZigString([]u8));
- testing.expect(isZigString([:0]const u8));
- testing.expect(isZigString([:0]u8));
- testing.expect(isZigString([:5]const u8));
- testing.expect(isZigString([:5]u8));
- testing.expect(isZigString(*const [0]u8));
- testing.expect(isZigString(*[0]u8));
- testing.expect(isZigString(*const [0:0]u8));
- testing.expect(isZigString(*[0:0]u8));
- testing.expect(isZigString(*const [0:5]u8));
- testing.expect(isZigString(*[0:5]u8));
- testing.expect(isZigString(*const [10]u8));
- testing.expect(isZigString(*[10]u8));
- testing.expect(isZigString(*const [10:0]u8));
- testing.expect(isZigString(*[10:0]u8));
- testing.expect(isZigString(*const [10:5]u8));
- testing.expect(isZigString(*[10:5]u8));
+ try testing.expect(isZigString([]const u8));
+ try testing.expect(isZigString([]u8));
+ try testing.expect(isZigString([:0]const u8));
+ try testing.expect(isZigString([:0]u8));
+ try testing.expect(isZigString([:5]const u8));
+ try testing.expect(isZigString([:5]u8));
+ try testing.expect(isZigString(*const [0]u8));
+ try testing.expect(isZigString(*[0]u8));
+ try testing.expect(isZigString(*const [0:0]u8));
+ try testing.expect(isZigString(*[0:0]u8));
+ try testing.expect(isZigString(*const [0:5]u8));
+ try testing.expect(isZigString(*[0:5]u8));
+ try testing.expect(isZigString(*const [10]u8));
+ try testing.expect(isZigString(*[10]u8));
+ try testing.expect(isZigString(*const [10:0]u8));
+ try testing.expect(isZigString(*[10:0]u8));
+ try testing.expect(isZigString(*const [10:5]u8));
+ try testing.expect(isZigString(*[10:5]u8));
- testing.expect(!isZigString(u8));
- testing.expect(!isZigString([4]u8));
- testing.expect(!isZigString([4:0]u8));
- testing.expect(!isZigString([*]const u8));
- testing.expect(!isZigString([*]const [4]u8));
- testing.expect(!isZigString([*c]const u8));
- testing.expect(!isZigString([*c]const [4]u8));
- testing.expect(!isZigString([*:0]const u8));
- testing.expect(!isZigString([*:0]const u8));
- testing.expect(!isZigString(*[]const u8));
- testing.expect(!isZigString(?[]const u8));
- testing.expect(!isZigString(?*const [4]u8));
- testing.expect(!isZigString([]allowzero u8));
- testing.expect(!isZigString([]volatile u8));
- testing.expect(!isZigString(*allowzero [4]u8));
- testing.expect(!isZigString(*volatile [4]u8));
+ try testing.expect(!isZigString(u8));
+ try testing.expect(!isZigString([4]u8));
+ try testing.expect(!isZigString([4:0]u8));
+ try testing.expect(!isZigString([*]const u8));
+ try testing.expect(!isZigString([*]const [4]u8));
+ try testing.expect(!isZigString([*c]const u8));
+ try testing.expect(!isZigString([*c]const [4]u8));
+ try testing.expect(!isZigString([*:0]const u8));
+ try testing.expect(!isZigString([*:0]const u8));
+ try testing.expect(!isZigString(*[]const u8));
+ try testing.expect(!isZigString(?[]const u8));
+ try testing.expect(!isZigString(?*const [4]u8));
+ try testing.expect(!isZigString([]allowzero u8));
+ try testing.expect(!isZigString([]volatile u8));
+ try testing.expect(!isZigString(*allowzero [4]u8));
+ try testing.expect(!isZigString(*volatile [4]u8));
}
pub fn hasDecls(comptime T: type, comptime names: anytype) bool {
@@ -505,11 +505,11 @@ test "std.meta.trait.hasDecls" {
const tuple = .{ "a", "b", "c" };
- testing.expect(!hasDecls(TestStruct1, .{"a"}));
- testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));
- testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));
- testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));
- testing.expect(!hasDecls(TestStruct2, tuple));
+ try testing.expect(!hasDecls(TestStruct1, .{"a"}));
+ try testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));
+ try testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));
+ try testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));
+ try testing.expect(!hasDecls(TestStruct2, tuple));
}
pub fn hasFields(comptime T: type, comptime names: anytype) bool {
@@ -531,11 +531,11 @@ test "std.meta.trait.hasFields" {
const tuple = .{ "a", "b", "c" };
- testing.expect(!hasFields(TestStruct1, .{"a"}));
- testing.expect(hasFields(TestStruct2, .{ "a", "b" }));
- testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));
- testing.expect(hasFields(TestStruct2, tuple));
- testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));
+ try testing.expect(!hasFields(TestStruct1, .{"a"}));
+ try testing.expect(hasFields(TestStruct2, .{ "a", "b" }));
+ try testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));
+ try testing.expect(hasFields(TestStruct2, tuple));
+ try testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));
}
pub fn hasFunctions(comptime T: type, comptime names: anytype) bool {
@@ -555,10 +555,10 @@ test "std.meta.trait.hasFunctions" {
const tuple = .{ "a", "b", "c" };
- testing.expect(!hasFunctions(TestStruct1, .{"a"}));
- testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));
- testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));
- testing.expect(!hasFunctions(TestStruct2, tuple));
+ try testing.expect(!hasFunctions(TestStruct1, .{"a"}));
+ try testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));
+ try testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));
+ try testing.expect(!hasFunctions(TestStruct2, tuple));
}
/// True if every value of the type `T` has a unique bit pattern representing it.
@@ -606,65 +606,65 @@ test "std.meta.trait.hasUniqueRepresentation" {
b: u32,
};
- testing.expect(hasUniqueRepresentation(TestStruct1));
+ try testing.expect(hasUniqueRepresentation(TestStruct1));
const TestStruct2 = struct {
a: u32,
b: u16,
};
- testing.expect(!hasUniqueRepresentation(TestStruct2));
+ try testing.expect(!hasUniqueRepresentation(TestStruct2));
const TestStruct3 = struct {
a: u32,
b: u32,
};
- testing.expect(hasUniqueRepresentation(TestStruct3));
+ try testing.expect(hasUniqueRepresentation(TestStruct3));
const TestStruct4 = struct { a: []const u8 };
- testing.expect(!hasUniqueRepresentation(TestStruct4));
+ try testing.expect(!hasUniqueRepresentation(TestStruct4));
const TestStruct5 = struct { a: TestStruct4 };
- testing.expect(!hasUniqueRepresentation(TestStruct5));
+ try testing.expect(!hasUniqueRepresentation(TestStruct5));
const TestUnion1 = packed union {
a: u32,
b: u16,
};
- testing.expect(!hasUniqueRepresentation(TestUnion1));
+ try testing.expect(!hasUniqueRepresentation(TestUnion1));
const TestUnion2 = extern union {
a: u32,
b: u16,
};
- testing.expect(!hasUniqueRepresentation(TestUnion2));
+ try testing.expect(!hasUniqueRepresentation(TestUnion2));
const TestUnion3 = union {
a: u32,
b: u16,
};
- testing.expect(!hasUniqueRepresentation(TestUnion3));
+ try testing.expect(!hasUniqueRepresentation(TestUnion3));
const TestUnion4 = union(enum) {
a: u32,
b: u16,
};
- testing.expect(!hasUniqueRepresentation(TestUnion4));
+ try testing.expect(!hasUniqueRepresentation(TestUnion4));
inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
- testing.expect(hasUniqueRepresentation(T));
+ try testing.expect(hasUniqueRepresentation(T));
}
inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {
- testing.expect(!hasUniqueRepresentation(T));
+ try testing.expect(!hasUniqueRepresentation(T));
}
- testing.expect(!hasUniqueRepresentation([]u8));
- testing.expect(!hasUniqueRepresentation([]const u8));
+ try testing.expect(!hasUniqueRepresentation([]u8));
+ try testing.expect(!hasUniqueRepresentation([]const u8));
}
diff --git a/lib/std/multi_array_list.zig b/lib/std/multi_array_list.zig
index f4d89d198c..394acee2c3 100644
--- a/lib/std/multi_array_list.zig
+++ b/lib/std/multi_array_list.zig
@@ -303,7 +303,7 @@ test "basic usage" {
var list = MultiArrayList(Foo){};
defer list.deinit(ally);
- testing.expectEqual(@as(usize, 0), list.items(.a).len);
+ try testing.expectEqual(@as(usize, 0), list.items(.a).len);
try list.ensureCapacity(ally, 2);
@@ -319,12 +319,12 @@ test "basic usage" {
.c = 'b',
});
- testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });
- testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });
+ try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });
+ try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });
- testing.expectEqual(@as(usize, 2), list.items(.b).len);
- testing.expectEqualStrings("foobar", list.items(.b)[0]);
- testing.expectEqualStrings("zigzag", list.items(.b)[1]);
+ try testing.expectEqual(@as(usize, 2), list.items(.b).len);
+ try testing.expectEqualStrings("foobar", list.items(.b)[0]);
+ try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
try list.append(ally, .{
.a = 3,
@@ -332,13 +332,13 @@ test "basic usage" {
.c = 'c',
});
- testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
- testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
+ try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
+ try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
- testing.expectEqual(@as(usize, 3), list.items(.b).len);
- testing.expectEqualStrings("foobar", list.items(.b)[0]);
- testing.expectEqualStrings("zigzag", list.items(.b)[1]);
- testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
+ try testing.expectEqual(@as(usize, 3), list.items(.b).len);
+ try testing.expectEqualStrings("foobar", list.items(.b)[0]);
+ try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
+ try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
// Add 6 more things to force a capacity increase.
var i: usize = 0;
@@ -350,12 +350,12 @@ test "basic usage" {
});
}
- testing.expectEqualSlices(
+ try testing.expectEqualSlices(
u32,
&[_]u32{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },
list.items(.a),
);
- testing.expectEqualSlices(
+ try testing.expectEqualSlices(
u8,
&[_]u8{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' },
list.items(.c),
@@ -363,13 +363,13 @@ test "basic usage" {
list.shrinkAndFree(ally, 3);
- testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
- testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
+ try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
+ try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
- testing.expectEqual(@as(usize, 3), list.items(.b).len);
- testing.expectEqualStrings("foobar", list.items(.b)[0]);
- testing.expectEqualStrings("zigzag", list.items(.b)[1]);
- testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
+ try testing.expectEqual(@as(usize, 3), list.items(.b).len);
+ try testing.expectEqualStrings("foobar", list.items(.b)[0]);
+ try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
+ try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
}
// This was observed to fail on aarch64 with LLVM 11, when the capacityInBytes
@@ -418,37 +418,37 @@ test "regression test for @reduce bug" {
try list.append(ally, .{ .tag = .eof, .start = 123 });
const tags = list.items(.tag);
- testing.expectEqual(tags[1], .identifier);
- testing.expectEqual(tags[2], .equal);
- testing.expectEqual(tags[3], .builtin);
- testing.expectEqual(tags[4], .l_paren);
- testing.expectEqual(tags[5], .string_literal);
- testing.expectEqual(tags[6], .r_paren);
- testing.expectEqual(tags[7], .semicolon);
- testing.expectEqual(tags[8], .keyword_pub);
- testing.expectEqual(tags[9], .keyword_fn);
- testing.expectEqual(tags[10], .identifier);
- testing.expectEqual(tags[11], .l_paren);
- testing.expectEqual(tags[12], .r_paren);
- testing.expectEqual(tags[13], .identifier);
- testing.expectEqual(tags[14], .bang);
- testing.expectEqual(tags[15], .identifier);
- testing.expectEqual(tags[16], .l_brace);
- testing.expectEqual(tags[17], .identifier);
- testing.expectEqual(tags[18], .period);
- testing.expectEqual(tags[19], .identifier);
- testing.expectEqual(tags[20], .period);
- testing.expectEqual(tags[21], .identifier);
- testing.expectEqual(tags[22], .l_paren);
- testing.expectEqual(tags[23], .string_literal);
- testing.expectEqual(tags[24], .comma);
- testing.expectEqual(tags[25], .period);
- testing.expectEqual(tags[26], .l_brace);
- testing.expectEqual(tags[27], .r_brace);
- testing.expectEqual(tags[28], .r_paren);
- testing.expectEqual(tags[29], .semicolon);
- testing.expectEqual(tags[30], .r_brace);
- testing.expectEqual(tags[31], .eof);
+ try testing.expectEqual(tags[1], .identifier);
+ try testing.expectEqual(tags[2], .equal);
+ try testing.expectEqual(tags[3], .builtin);
+ try testing.expectEqual(tags[4], .l_paren);
+ try testing.expectEqual(tags[5], .string_literal);
+ try testing.expectEqual(tags[6], .r_paren);
+ try testing.expectEqual(tags[7], .semicolon);
+ try testing.expectEqual(tags[8], .keyword_pub);
+ try testing.expectEqual(tags[9], .keyword_fn);
+ try testing.expectEqual(tags[10], .identifier);
+ try testing.expectEqual(tags[11], .l_paren);
+ try testing.expectEqual(tags[12], .r_paren);
+ try testing.expectEqual(tags[13], .identifier);
+ try testing.expectEqual(tags[14], .bang);
+ try testing.expectEqual(tags[15], .identifier);
+ try testing.expectEqual(tags[16], .l_brace);
+ try testing.expectEqual(tags[17], .identifier);
+ try testing.expectEqual(tags[18], .period);
+ try testing.expectEqual(tags[19], .identifier);
+ try testing.expectEqual(tags[20], .period);
+ try testing.expectEqual(tags[21], .identifier);
+ try testing.expectEqual(tags[22], .l_paren);
+ try testing.expectEqual(tags[23], .string_literal);
+ try testing.expectEqual(tags[24], .comma);
+ try testing.expectEqual(tags[25], .period);
+ try testing.expectEqual(tags[26], .l_brace);
+ try testing.expectEqual(tags[27], .r_brace);
+ try testing.expectEqual(tags[28], .r_paren);
+ try testing.expectEqual(tags[29], .semicolon);
+ try testing.expectEqual(tags[30], .r_brace);
+ try testing.expectEqual(tags[31], .eof);
}
test "ensure capacity on empty list" {
@@ -466,15 +466,15 @@ test "ensure capacity on empty list" {
list.appendAssumeCapacity(.{ .a = 1, .b = 2 });
list.appendAssumeCapacity(.{ .a = 3, .b = 4 });
- testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));
- testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));
+ try testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));
+ try testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));
list.len = 0;
list.appendAssumeCapacity(.{ .a = 5, .b = 6 });
list.appendAssumeCapacity(.{ .a = 7, .b = 8 });
- testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));
- testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));
+ try testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));
+ try testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));
list.len = 0;
try list.ensureCapacity(ally, 16);
@@ -482,6 +482,6 @@ test "ensure capacity on empty list" {
list.appendAssumeCapacity(.{ .a = 9, .b = 10 });
list.appendAssumeCapacity(.{ .a = 11, .b = 12 });
- testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));
- testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));
+ try testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));
+ try testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));
}
diff --git a/lib/std/net/test.zig b/lib/std/net/test.zig
index 4470d17aeb..c2596b733c 100644
--- a/lib/std/net/test.zig
+++ b/lib/std/net/test.zig
@@ -38,26 +38,26 @@ test "parse and render IPv6 addresses" {
for (ips) |ip, i| {
var addr = net.Address.parseIp6(ip, 0) catch unreachable;
var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
- std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
+ try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
if (std.builtin.os.tag == .linux) {
var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;
- std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));
+ try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));
}
}
- testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));
- testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));
- testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0));
- testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));
- testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
- testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
+ try testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));
+ try testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));
+ try testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0));
+ try testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));
+ try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
+ try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
// TODO Make this test pass on other operating systems.
if (std.builtin.os.tag == .linux) {
- testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
- testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
- testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
+ try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
+ try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
+ try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
}
}
@@ -68,7 +68,7 @@ test "invalid but parseable IPv6 scope ids" {
return error.SkipZigTest;
}
- testing.expectError(error.InterfaceNotFound, net.Address.resolveIp6("ff01::fb%123s45678901234", 0));
+ try testing.expectError(error.InterfaceNotFound, net.Address.resolveIp6("ff01::fb%123s45678901234", 0));
}
test "parse and render IPv4 addresses" {
@@ -84,14 +84,14 @@ test "parse and render IPv4 addresses" {
}) |ip| {
var addr = net.Address.parseIp4(ip, 0) catch unreachable;
var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
- std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
+ try std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
}
- testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0));
- testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0));
- testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0));
- testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0));
- testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));
+ try testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0));
+ try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0));
+ try testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0));
+ try testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0));
+ try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));
}
test "resolve DNS" {
@@ -169,8 +169,8 @@ test "listen on a port, send bytes, receive bytes" {
var buf: [16]u8 = undefined;
const n = try client.stream.reader().read(&buf);
- testing.expectEqual(@as(usize, 12), n);
- testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
+ try testing.expectEqual(@as(usize, 12), n);
+ try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
}
test "listen on a port, send bytes, receive bytes" {
@@ -230,7 +230,7 @@ fn testClientToHost(allocator: *mem.Allocator, name: []const u8, port: u16) anye
var buf: [100]u8 = undefined;
const len = try connection.read(&buf);
const msg = buf[0..len];
- testing.expect(mem.eql(u8, msg, "hello from server\n"));
+ try testing.expect(mem.eql(u8, msg, "hello from server\n"));
}
fn testClient(addr: net.Address) anyerror!void {
@@ -242,7 +242,7 @@ fn testClient(addr: net.Address) anyerror!void {
var buf: [100]u8 = undefined;
const len = try socket_file.read(&buf);
const msg = buf[0..len];
- testing.expect(mem.eql(u8, msg, "hello from server\n"));
+ try testing.expect(mem.eql(u8, msg, "hello from server\n"));
}
fn testServer(server: *net.StreamServer) anyerror!void {
@@ -293,6 +293,6 @@ test "listen on a unix socket, send bytes, receive bytes" {
var buf: [16]u8 = undefined;
const n = try client.stream.reader().read(&buf);
- testing.expectEqual(@as(usize, 12), n);
- testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
+ try testing.expectEqual(@as(usize, 12), n);
+ try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
}
diff --git a/lib/std/once.zig b/lib/std/once.zig
index 79d273b86a..c56e572570 100644
--- a/lib/std/once.zig
+++ b/lib/std/once.zig
@@ -67,5 +67,5 @@ test "Once executes its function just once" {
}
}
- testing.expectEqual(@as(i32, 1), global_number);
+ try testing.expectEqual(@as(i32, 1), global_number);
}
diff --git a/lib/std/os/linux/bpf.zig b/lib/std/os/linux/bpf.zig
index 0d7e0a19ed..8c1500740b 100644
--- a/lib/std/os/linux/bpf.zig
+++ b/lib/std/os/linux/bpf.zig
@@ -737,11 +737,11 @@ pub const Insn = packed struct {
};
test "insn bitsize" {
- expectEqual(@bitSizeOf(Insn), 64);
+ try expectEqual(@bitSizeOf(Insn), 64);
}
-fn expect_opcode(code: u8, insn: Insn) void {
- expectEqual(code, insn.code);
+fn expect_opcode(code: u8, insn: Insn) !void {
+ try expectEqual(code, insn.code);
}
// The opcodes were grabbed from https://github.com/iovisor/bpf-docs/blob/master/eBPF.md
@@ -750,108 +750,108 @@ test "opcodes" {
// loading 64-bit immediates (imm is only 32 bits wide)
// alu instructions
- expect_opcode(0x07, Insn.add(.r1, 0));
- expect_opcode(0x0f, Insn.add(.r1, .r2));
- expect_opcode(0x17, Insn.sub(.r1, 0));
- expect_opcode(0x1f, Insn.sub(.r1, .r2));
- expect_opcode(0x27, Insn.mul(.r1, 0));
- expect_opcode(0x2f, Insn.mul(.r1, .r2));
- expect_opcode(0x37, Insn.div(.r1, 0));
- expect_opcode(0x3f, Insn.div(.r1, .r2));
- expect_opcode(0x47, Insn.alu_or(.r1, 0));
- expect_opcode(0x4f, Insn.alu_or(.r1, .r2));
- expect_opcode(0x57, Insn.alu_and(.r1, 0));
- expect_opcode(0x5f, Insn.alu_and(.r1, .r2));
- expect_opcode(0x67, Insn.lsh(.r1, 0));
- expect_opcode(0x6f, Insn.lsh(.r1, .r2));
- expect_opcode(0x77, Insn.rsh(.r1, 0));
- expect_opcode(0x7f, Insn.rsh(.r1, .r2));
- expect_opcode(0x87, Insn.neg(.r1));
- expect_opcode(0x97, Insn.mod(.r1, 0));
- expect_opcode(0x9f, Insn.mod(.r1, .r2));
- expect_opcode(0xa7, Insn.xor(.r1, 0));
- expect_opcode(0xaf, Insn.xor(.r1, .r2));
- expect_opcode(0xb7, Insn.mov(.r1, 0));
- expect_opcode(0xbf, Insn.mov(.r1, .r2));
- expect_opcode(0xc7, Insn.arsh(.r1, 0));
- expect_opcode(0xcf, Insn.arsh(.r1, .r2));
+ try expect_opcode(0x07, Insn.add(.r1, 0));
+ try expect_opcode(0x0f, Insn.add(.r1, .r2));
+ try expect_opcode(0x17, Insn.sub(.r1, 0));
+ try expect_opcode(0x1f, Insn.sub(.r1, .r2));
+ try expect_opcode(0x27, Insn.mul(.r1, 0));
+ try expect_opcode(0x2f, Insn.mul(.r1, .r2));
+ try expect_opcode(0x37, Insn.div(.r1, 0));
+ try expect_opcode(0x3f, Insn.div(.r1, .r2));
+ try expect_opcode(0x47, Insn.alu_or(.r1, 0));
+ try expect_opcode(0x4f, Insn.alu_or(.r1, .r2));
+ try expect_opcode(0x57, Insn.alu_and(.r1, 0));
+ try expect_opcode(0x5f, Insn.alu_and(.r1, .r2));
+ try expect_opcode(0x67, Insn.lsh(.r1, 0));
+ try expect_opcode(0x6f, Insn.lsh(.r1, .r2));
+ try expect_opcode(0x77, Insn.rsh(.r1, 0));
+ try expect_opcode(0x7f, Insn.rsh(.r1, .r2));
+ try expect_opcode(0x87, Insn.neg(.r1));
+ try expect_opcode(0x97, Insn.mod(.r1, 0));
+ try expect_opcode(0x9f, Insn.mod(.r1, .r2));
+ try expect_opcode(0xa7, Insn.xor(.r1, 0));
+ try expect_opcode(0xaf, Insn.xor(.r1, .r2));
+ try expect_opcode(0xb7, Insn.mov(.r1, 0));
+ try expect_opcode(0xbf, Insn.mov(.r1, .r2));
+ try expect_opcode(0xc7, Insn.arsh(.r1, 0));
+ try expect_opcode(0xcf, Insn.arsh(.r1, .r2));
// atomic instructions: might be more of these not documented in the wild
- expect_opcode(0xdb, Insn.xadd(.r1, .r2));
+ try expect_opcode(0xdb, Insn.xadd(.r1, .r2));
// TODO: byteswap instructions
- expect_opcode(0xd4, Insn.le(.half_word, .r1));
- expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);
- expect_opcode(0xd4, Insn.le(.word, .r1));
- expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);
- expect_opcode(0xd4, Insn.le(.double_word, .r1));
- expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);
- expect_opcode(0xdc, Insn.be(.half_word, .r1));
- expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);
- expect_opcode(0xdc, Insn.be(.word, .r1));
- expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);
- expect_opcode(0xdc, Insn.be(.double_word, .r1));
- expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);
+ try expect_opcode(0xd4, Insn.le(.half_word, .r1));
+ try expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);
+ try expect_opcode(0xd4, Insn.le(.word, .r1));
+ try expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);
+ try expect_opcode(0xd4, Insn.le(.double_word, .r1));
+ try expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);
+ try expect_opcode(0xdc, Insn.be(.half_word, .r1));
+ try expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);
+ try expect_opcode(0xdc, Insn.be(.word, .r1));
+ try expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);
+ try expect_opcode(0xdc, Insn.be(.double_word, .r1));
+ try expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);
// memory instructions
- expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
- expect_opcode(0x00, Insn.ld_dw2(0));
+ try expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
+ try expect_opcode(0x00, Insn.ld_dw2(0));
// loading a map fd
- expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));
- expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);
- expect_opcode(0x00, Insn.ld_map_fd2(0));
+ try expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));
+ try expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);
+ try expect_opcode(0x00, Insn.ld_map_fd2(0));
- expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));
- expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));
- expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));
- expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));
+ try expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));
+ try expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));
+ try expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));
+ try expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));
- expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));
- expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));
- expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));
- expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));
+ try expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));
+ try expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));
+ try expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));
+ try expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));
- expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));
- expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));
- expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));
- expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));
+ try expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));
+ try expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));
+ try expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));
+ try expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));
- expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));
- expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));
- expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));
+ try expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));
+ try expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));
+ try expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));
- expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));
- expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));
- expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));
- expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));
+ try expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));
+ try expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));
+ try expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));
+ try expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));
// branch instructions
- expect_opcode(0x05, Insn.ja(0));
- expect_opcode(0x15, Insn.jeq(.r1, 0, 0));
- expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));
- expect_opcode(0x25, Insn.jgt(.r1, 0, 0));
- expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));
- expect_opcode(0x35, Insn.jge(.r1, 0, 0));
- expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));
- expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));
- expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));
- expect_opcode(0xb5, Insn.jle(.r1, 0, 0));
- expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));
- expect_opcode(0x45, Insn.jset(.r1, 0, 0));
- expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));
- expect_opcode(0x55, Insn.jne(.r1, 0, 0));
- expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));
- expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));
- expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));
- expect_opcode(0x75, Insn.jsge(.r1, 0, 0));
- expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));
- expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));
- expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));
- expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));
- expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));
- expect_opcode(0x85, Insn.call(.unspec));
- expect_opcode(0x95, Insn.exit());
+ try expect_opcode(0x05, Insn.ja(0));
+ try expect_opcode(0x15, Insn.jeq(.r1, 0, 0));
+ try expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));
+ try expect_opcode(0x25, Insn.jgt(.r1, 0, 0));
+ try expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));
+ try expect_opcode(0x35, Insn.jge(.r1, 0, 0));
+ try expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));
+ try expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));
+ try expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));
+ try expect_opcode(0xb5, Insn.jle(.r1, 0, 0));
+ try expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));
+ try expect_opcode(0x45, Insn.jset(.r1, 0, 0));
+ try expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));
+ try expect_opcode(0x55, Insn.jne(.r1, 0, 0));
+ try expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));
+ try expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));
+ try expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));
+ try expect_opcode(0x75, Insn.jsge(.r1, 0, 0));
+ try expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));
+ try expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));
+ try expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));
+ try expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));
+ try expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));
+ try expect_opcode(0x85, Insn.call(.unspec));
+ try expect_opcode(0x95, Insn.exit());
}
pub const Cmd = extern enum(usize) {
@@ -1596,7 +1596,7 @@ test "map lookup, update, and delete" {
var value = std.mem.zeroes([value_size]u8);
// fails looking up value that doesn't exist
- expectError(error.NotFound, map_lookup_elem(map, &key, &value));
+ try expectError(error.NotFound, map_lookup_elem(map, &key, &value));
// succeed at updating and looking up element
try map_update_elem(map, &key, &value, 0);
@@ -1604,14 +1604,14 @@ test "map lookup, update, and delete" {
// fails inserting more than max entries
const second_key = [key_size]u8{ 0, 0, 0, 1 };
- expectError(error.ReachedMaxEntries, map_update_elem(map, &second_key, &value, 0));
+ try expectError(error.ReachedMaxEntries, map_update_elem(map, &second_key, &value, 0));
// succeed at deleting an existing elem
try map_delete_elem(map, &key);
- expectError(error.NotFound, map_lookup_elem(map, &key, &value));
+ try expectError(error.NotFound, map_lookup_elem(map, &key, &value));
// fail at deleting a non-existing elem
- expectError(error.NotFound, map_delete_elem(map, &key));
+ try expectError(error.NotFound, map_delete_elem(map, &key));
}
pub fn prog_load(
@@ -1662,5 +1662,5 @@ test "prog_load" {
const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0);
defer std.os.close(prog);
- expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0));
+ try expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0));
}
diff --git a/lib/std/os/linux/bpf/btf.zig b/lib/std/os/linux/bpf/btf.zig
index 9ba3a0f942..d8a0cb57a9 100644
--- a/lib/std/os/linux/bpf/btf.zig
+++ b/lib/std/os/linux/bpf/btf.zig
@@ -92,7 +92,7 @@ pub const IntInfo = packed struct {
};
test "IntInfo is 32 bits" {
- std.testing.expectEqual(@bitSizeOf(IntInfo), 32);
+ try std.testing.expectEqual(@bitSizeOf(IntInfo), 32);
}
/// Enum kind is followed by this struct
diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig
index fc5af34696..ca80a381f5 100644
--- a/lib/std/os/linux/io_uring.zig
+++ b/lib/std/os/linux/io_uring.zig
@@ -937,16 +937,16 @@ pub fn io_uring_prep_fallocate(
test "structs/offsets/entries" {
if (builtin.os.tag != .linux) return error.SkipZigTest;
- testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));
- testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));
- testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));
+ try testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));
+ try testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));
+ try testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));
- testing.expectEqual(0, linux.IORING_OFF_SQ_RING);
- testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);
- testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);
+ try testing.expectEqual(0, linux.IORING_OFF_SQ_RING);
+ try testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);
+ try testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);
- testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));
- testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));
+ try testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));
+ try testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));
}
test "nop" {
@@ -959,11 +959,11 @@ test "nop" {
};
defer {
ring.deinit();
- testing.expectEqual(@as(os.fd_t, -1), ring.fd);
+ testing.expectEqual(@as(os.fd_t, -1), ring.fd) catch @panic("test failed");
}
const sqe = try ring.nop(0xaaaaaaaa);
- testing.expectEqual(io_uring_sqe{
+ try testing.expectEqual(io_uring_sqe{
.opcode = .NOP,
.flags = 0,
.ioprio = 0,
@@ -979,40 +979,40 @@ test "nop" {
.__pad2 = [2]u64{ 0, 0 },
}, sqe.*);
- testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);
- testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
- testing.expectEqual(@as(u32, 0), ring.sq.tail.*);
- testing.expectEqual(@as(u32, 0), ring.cq.head.*);
- testing.expectEqual(@as(u32, 1), ring.sq_ready());
- testing.expectEqual(@as(u32, 0), ring.cq_ready());
+ try testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);
+ try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
+ try testing.expectEqual(@as(u32, 0), ring.sq.tail.*);
+ try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
+ try testing.expectEqual(@as(u32, 1), ring.sq_ready());
+ try testing.expectEqual(@as(u32, 0), ring.cq_ready());
- testing.expectEqual(@as(u32, 1), try ring.submit());
- testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);
- testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
- testing.expectEqual(@as(u32, 1), ring.sq.tail.*);
- testing.expectEqual(@as(u32, 0), ring.cq.head.*);
- testing.expectEqual(@as(u32, 0), ring.sq_ready());
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);
+ try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
+ try testing.expectEqual(@as(u32, 1), ring.sq.tail.*);
+ try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
+ try testing.expectEqual(@as(u32, 0), ring.sq_ready());
- testing.expectEqual(io_uring_cqe{
+ try testing.expectEqual(io_uring_cqe{
.user_data = 0xaaaaaaaa,
.res = 0,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqual(@as(u32, 1), ring.cq.head.*);
- testing.expectEqual(@as(u32, 0), ring.cq_ready());
+ try testing.expectEqual(@as(u32, 1), ring.cq.head.*);
+ try testing.expectEqual(@as(u32, 0), ring.cq_ready());
const sqe_barrier = try ring.nop(0xbbbbbbbb);
sqe_barrier.flags |= linux.IOSQE_IO_DRAIN;
- testing.expectEqual(@as(u32, 1), try ring.submit());
- testing.expectEqual(io_uring_cqe{
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(io_uring_cqe{
.user_data = 0xbbbbbbbb,
.res = 0,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);
- testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);
- testing.expectEqual(@as(u32, 2), ring.sq.tail.*);
- testing.expectEqual(@as(u32, 2), ring.cq.head.*);
+ try testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);
+ try testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);
+ try testing.expectEqual(@as(u32, 2), ring.sq.tail.*);
+ try testing.expectEqual(@as(u32, 2), ring.cq.head.*);
}
test "readv" {
@@ -1042,17 +1042,17 @@ test "readv" {
var buffer = [_]u8{42} ** 128;
var iovecs = [_]os.iovec{os.iovec{ .iov_base = &buffer, .iov_len = buffer.len }};
const sqe = try ring.readv(0xcccccccc, fd_index, iovecs[0..], 0);
- testing.expectEqual(linux.IORING_OP.READV, sqe.opcode);
+ try testing.expectEqual(linux.IORING_OP.READV, sqe.opcode);
sqe.flags |= linux.IOSQE_FIXED_FILE;
- testing.expectError(error.SubmissionQueueFull, ring.nop(0));
- testing.expectEqual(@as(u32, 1), try ring.submit());
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectError(error.SubmissionQueueFull, ring.nop(0));
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xcccccccc,
.res = buffer.len,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]);
+ try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]);
try ring.unregister_files();
}
@@ -1083,46 +1083,46 @@ test "writev/fsync/readv" {
};
const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17);
- testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);
- testing.expectEqual(@as(u64, 17), sqe_writev.off);
+ try testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);
+ try testing.expectEqual(@as(u64, 17), sqe_writev.off);
sqe_writev.flags |= linux.IOSQE_IO_LINK;
const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0);
- testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);
- testing.expectEqual(fd, sqe_fsync.fd);
+ try testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);
+ try testing.expectEqual(fd, sqe_fsync.fd);
sqe_fsync.flags |= linux.IOSQE_IO_LINK;
const sqe_readv = try ring.readv(0xffffffff, fd, iovecs_read[0..], 17);
- testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);
- testing.expectEqual(@as(u64, 17), sqe_readv.off);
+ try testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);
+ try testing.expectEqual(@as(u64, 17), sqe_readv.off);
- testing.expectEqual(@as(u32, 3), ring.sq_ready());
- testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));
- testing.expectEqual(@as(u32, 0), ring.sq_ready());
- testing.expectEqual(@as(u32, 3), ring.cq_ready());
+ try testing.expectEqual(@as(u32, 3), ring.sq_ready());
+ try testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));
+ try testing.expectEqual(@as(u32, 0), ring.sq_ready());
+ try testing.expectEqual(@as(u32, 3), ring.cq_ready());
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xdddddddd,
.res = buffer_write.len,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqual(@as(u32, 2), ring.cq_ready());
+ try testing.expectEqual(@as(u32, 2), ring.cq_ready());
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xeeeeeeee,
.res = 0,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqual(@as(u32, 1), ring.cq_ready());
+ try testing.expectEqual(@as(u32, 1), ring.cq_ready());
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xffffffff,
.res = buffer_read.len,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqual(@as(u32, 0), ring.cq_ready());
+ try testing.expectEqual(@as(u32, 0), ring.cq_ready());
- testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
+ try testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
}
test "write/read" {
@@ -1144,13 +1144,13 @@ test "write/read" {
const buffer_write = [_]u8{97} ** 20;
var buffer_read = [_]u8{98} ** 20;
const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10);
- testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);
- testing.expectEqual(@as(u64, 10), sqe_write.off);
+ try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);
+ try testing.expectEqual(@as(u64, 10), sqe_write.off);
sqe_write.flags |= linux.IOSQE_IO_LINK;
const sqe_read = try ring.read(0x22222222, fd, buffer_read[0..], 10);
- testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);
- testing.expectEqual(@as(u64, 10), sqe_read.off);
- testing.expectEqual(@as(u32, 2), try ring.submit());
+ try testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);
+ try testing.expectEqual(@as(u64, 10), sqe_read.off);
+ try testing.expectEqual(@as(u32, 2), try ring.submit());
const cqe_write = try ring.copy_cqe();
const cqe_read = try ring.copy_cqe();
@@ -1158,17 +1158,17 @@ test "write/read" {
// https://lwn.net/Articles/809820/
if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;
if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x11111111,
.res = buffer_write.len,
.flags = 0,
}, cqe_write);
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x22222222,
.res = buffer_read.len,
.flags = 0,
}, cqe_read);
- testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
+ try testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
}
test "openat" {
@@ -1187,7 +1187,7 @@ test "openat" {
const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT;
const mode: os.mode_t = 0o666;
const sqe_openat = try ring.openat(0x33333333, linux.AT_FDCWD, path, flags, mode);
- testing.expectEqual(io_uring_sqe{
+ try testing.expectEqual(io_uring_sqe{
.opcode = .OPENAT,
.flags = 0,
.ioprio = 0,
@@ -1202,10 +1202,10 @@ test "openat" {
.splice_fd_in = 0,
.__pad2 = [2]u64{ 0, 0 },
}, sqe_openat.*);
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
const cqe_openat = try ring.copy_cqe();
- testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data);
+ try testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data);
if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest;
// AT_FDCWD is not fully supported before kernel 5.6:
// See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/
@@ -1214,8 +1214,8 @@ test "openat" {
return error.SkipZigTest;
}
if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});
- testing.expect(cqe_openat.res > 0);
- testing.expectEqual(@as(u32, 0), cqe_openat.flags);
+ try testing.expect(cqe_openat.res > 0);
+ try testing.expectEqual(@as(u32, 0), cqe_openat.flags);
os.close(cqe_openat.res);
}
@@ -1236,13 +1236,13 @@ test "close" {
defer std.fs.cwd().deleteFile(path) catch {};
const sqe_close = try ring.close(0x44444444, file.handle);
- testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);
- testing.expectEqual(file.handle, sqe_close.fd);
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);
+ try testing.expectEqual(file.handle, sqe_close.fd);
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
const cqe_close = try ring.copy_cqe();
if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x44444444,
.res = 0,
.flags = 0,
@@ -1273,12 +1273,12 @@ test "accept/connect/send/recv" {
var accept_addr: os.sockaddr = undefined;
var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));
const accept = try ring.accept(0xaaaaaaaa, server, &accept_addr, &accept_addr_len, 0);
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);
defer os.close(client);
const connect = try ring.connect(0xcccccccc, client, &address.any, address.getOsSockLen());
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
var cqe_accept = try ring.copy_cqe();
if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest;
@@ -1293,11 +1293,11 @@ test "accept/connect/send/recv" {
cqe_connect = a;
}
- testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);
+ try testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);
if (cqe_accept.res <= 0) std.debug.print("\ncqe_accept.res={}\n", .{cqe_accept.res});
- testing.expect(cqe_accept.res > 0);
- testing.expectEqual(@as(u32, 0), cqe_accept.flags);
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expect(cqe_accept.res > 0);
+ try testing.expectEqual(@as(u32, 0), cqe_accept.flags);
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xcccccccc,
.res = 0,
.flags = 0,
@@ -1306,11 +1306,11 @@ test "accept/connect/send/recv" {
const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0);
send.flags |= linux.IOSQE_IO_LINK;
const recv = try ring.recv(0xffffffff, cqe_accept.res, buffer_recv[0..], 0);
- testing.expectEqual(@as(u32, 2), try ring.submit());
+ try testing.expectEqual(@as(u32, 2), try ring.submit());
const cqe_send = try ring.copy_cqe();
if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xeeeeeeee,
.res = buffer_send.len,
.flags = 0,
@@ -1318,13 +1318,13 @@ test "accept/connect/send/recv" {
const cqe_recv = try ring.copy_cqe();
if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xffffffff,
.res = buffer_recv.len,
.flags = 0,
}, cqe_recv);
- testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);
+ try testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);
}
test "timeout (after a relative time)" {
@@ -1343,12 +1343,12 @@ test "timeout (after a relative time)" {
const started = std.time.milliTimestamp();
const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
- testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
const cqe = try ring.copy_cqe();
const stopped = std.time.milliTimestamp();
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x55555555,
.res = -linux.ETIME,
.flags = 0,
@@ -1371,20 +1371,20 @@ test "timeout (after a number of completions)" {
const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
const count_completions: u64 = 1;
const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
- testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
- testing.expectEqual(count_completions, sqe_timeout.off);
+ try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
+ try testing.expectEqual(count_completions, sqe_timeout.off);
_ = try ring.nop(0x77777777);
- testing.expectEqual(@as(u32, 2), try ring.submit());
+ try testing.expectEqual(@as(u32, 2), try ring.submit());
const cqe_nop = try ring.copy_cqe();
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x77777777,
.res = 0,
.flags = 0,
}, cqe_nop);
const cqe_timeout = try ring.copy_cqe();
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x66666666,
.res = 0,
.flags = 0,
@@ -1403,15 +1403,15 @@ test "timeout_remove" {
const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
- testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
- testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
+ try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
+ try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
const sqe_timeout_remove = try ring.timeout_remove(0x99999999, 0x88888888, 0);
- testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);
- testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);
- testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data);
+ try testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);
+ try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);
+ try testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data);
- testing.expectEqual(@as(u32, 2), try ring.submit());
+ try testing.expectEqual(@as(u32, 2), try ring.submit());
const cqe_timeout = try ring.copy_cqe();
// IORING_OP_TIMEOUT_REMOVE is not supported by this kernel version:
@@ -1424,14 +1424,14 @@ test "timeout_remove" {
{
return error.SkipZigTest;
}
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x88888888,
.res = -linux.ECANCELED,
.flags = 0,
}, cqe_timeout);
const cqe_timeout_remove = try ring.copy_cqe();
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x99999999,
.res = 0,
.flags = 0,
@@ -1453,13 +1453,13 @@ test "fallocate" {
defer file.close();
defer std.fs.cwd().deleteFile(path) catch {};
- testing.expectEqual(@as(u64, 0), (try file.stat()).size);
+ try testing.expectEqual(@as(u64, 0), (try file.stat()).size);
const len: u64 = 65536;
const sqe = try ring.fallocate(0xaaaaaaaa, file.handle, 0, 0, len);
- testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);
- testing.expectEqual(file.handle, sqe.fd);
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);
+ try testing.expectEqual(file.handle, sqe.fd);
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
const cqe = try ring.copy_cqe();
switch (-cqe.res) {
@@ -1473,11 +1473,11 @@ test "fallocate" {
linux.EOPNOTSUPP => return error.SkipZigTest,
else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
}
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xaaaaaaaa,
.res = 0,
.flags = 0,
}, cqe);
- testing.expectEqual(len, (try file.stat()).size);
+ try testing.expectEqual(len, (try file.stat()).size);
}
diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig
index 039678e405..5a37713247 100644
--- a/lib/std/os/linux/test.zig
+++ b/lib/std/os/linux/test.zig
@@ -18,7 +18,7 @@ test "fallocate" {
defer file.close();
defer fs.cwd().deleteFile(path) catch {};
- expect((try file.stat()).size == 0);
+ try expect((try file.stat()).size == 0);
const len: u64 = 65536;
switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {
@@ -28,20 +28,20 @@ test "fallocate" {
else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
}
- expect((try file.stat()).size == len);
+ try expect((try file.stat()).size == len);
}
test "getpid" {
- expect(linux.getpid() != 0);
+ try expect(linux.getpid() != 0);
}
test "timer" {
const epoll_fd = linux.epoll_create();
var err: usize = linux.getErrno(epoll_fd);
- expect(err == 0);
+ try expect(err == 0);
const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
- expect(linux.getErrno(timer_fd) == 0);
+ try expect(linux.getErrno(timer_fd) == 0);
const time_interval = linux.timespec{
.tv_sec = 0,
@@ -54,7 +54,7 @@ test "timer" {
};
err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
- expect(err == 0);
+ try expect(err == 0);
var event = linux.epoll_event{
.events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
@@ -62,7 +62,7 @@ test "timer" {
};
err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
- expect(err == 0);
+ try expect(err == 0);
const events_one: linux.epoll_event = undefined;
var events = [_]linux.epoll_event{events_one} ** 8;
@@ -93,18 +93,18 @@ test "statx" {
else => unreachable,
}
- expect(stat_buf.mode == statx_buf.mode);
- expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
- expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
- expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
- expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
- expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
+ try expect(stat_buf.mode == statx_buf.mode);
+ try expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
+ try expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
+ try expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
+ try expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
+ try expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
}
test "user and group ids" {
if (builtin.link_libc) return error.SkipZigTest;
- expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());
- expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());
- expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());
- expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());
+ try expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());
+ try expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());
+ try expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());
+ try expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());
}
diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig
index 16521d7e27..7f10671b35 100644
--- a/lib/std/os/test.zig
+++ b/lib/std/os/test.zig
@@ -37,7 +37,7 @@ test "chdir smoke test" {
try os.chdir(old_cwd);
var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
const new_cwd = try os.getcwd(new_cwd_buf[0..]);
- expect(mem.eql(u8, old_cwd, new_cwd));
+ try expect(mem.eql(u8, old_cwd, new_cwd));
}
{
// Next, change current working directory to one level above
@@ -47,7 +47,7 @@ test "chdir smoke test" {
defer os.chdir(old_cwd) catch unreachable;
var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
const new_cwd = try os.getcwd(new_cwd_buf[0..]);
- expect(mem.eql(u8, parent, new_cwd));
+ try expect(mem.eql(u8, parent, new_cwd));
}
}
@@ -79,7 +79,7 @@ test "open smoke test" {
// Try this again with the same flags. This op should fail with error.PathAlreadyExists.
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
- expectError(error.PathAlreadyExists, os.open(file_path, os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
+ try expectError(error.PathAlreadyExists, os.open(file_path, os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
// Try opening without `O_EXCL` flag.
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
@@ -88,7 +88,7 @@ test "open smoke test" {
// Try opening as a directory which should fail.
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
- expectError(error.NotDir, os.open(file_path, os.O_RDWR | os.O_DIRECTORY, mode));
+ try expectError(error.NotDir, os.open(file_path, os.O_RDWR | os.O_DIRECTORY, mode));
// Create some directory
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
@@ -101,7 +101,7 @@ test "open smoke test" {
// Try opening as file which should fail.
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
- expectError(error.IsDir, os.open(file_path, os.O_RDWR, mode));
+ try expectError(error.IsDir, os.open(file_path, os.O_RDWR, mode));
}
test "openat smoke test" {
@@ -120,14 +120,14 @@ test "openat smoke test" {
os.close(fd);
// Try this again with the same flags. This op should fail with error.PathAlreadyExists.
- expectError(error.PathAlreadyExists, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
+ try expectError(error.PathAlreadyExists, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
// Try opening without `O_EXCL` flag.
fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT, mode);
os.close(fd);
// Try opening as a directory which should fail.
- expectError(error.NotDir, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_DIRECTORY, mode));
+ try expectError(error.NotDir, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_DIRECTORY, mode));
// Create some directory
try os.mkdirat(tmp.dir.fd, "some_dir", mode);
@@ -137,7 +137,7 @@ test "openat smoke test" {
os.close(fd);
// Try opening as file which should fail.
- expectError(error.IsDir, os.openat(tmp.dir.fd, "some_dir", os.O_RDWR, mode));
+ try expectError(error.IsDir, os.openat(tmp.dir.fd, "some_dir", os.O_RDWR, mode));
}
test "symlink with relative paths" {
@@ -171,7 +171,7 @@ test "symlink with relative paths" {
var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
const given = try os.readlink("symlinked", buffer[0..]);
- expect(mem.eql(u8, "file.txt", given));
+ try expect(mem.eql(u8, "file.txt", given));
try cwd.deleteFile("file.txt");
try cwd.deleteFile("symlinked");
@@ -188,7 +188,7 @@ test "readlink on Windows" {
fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {
var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
const given = try os.readlink(symlink_path, buffer[0..]);
- expect(mem.eql(u8, target_path, given));
+ try expect(mem.eql(u8, target_path, given));
}
test "link with relative paths" {
@@ -211,15 +211,15 @@ test "link with relative paths" {
const estat = try os.fstat(efd.handle);
const nstat = try os.fstat(nfd.handle);
- testing.expectEqual(estat.ino, nstat.ino);
- testing.expectEqual(@as(usize, 2), nstat.nlink);
+ try testing.expectEqual(estat.ino, nstat.ino);
+ try testing.expectEqual(@as(usize, 2), nstat.nlink);
}
try os.unlink("new.txt");
{
const estat = try os.fstat(efd.handle);
- testing.expectEqual(@as(usize, 1), estat.nlink);
+ try testing.expectEqual(@as(usize, 1), estat.nlink);
}
try cwd.deleteFile("example.txt");
@@ -246,15 +246,15 @@ test "linkat with different directories" {
const estat = try os.fstat(efd.handle);
const nstat = try os.fstat(nfd.handle);
- testing.expectEqual(estat.ino, nstat.ino);
- testing.expectEqual(@as(usize, 2), nstat.nlink);
+ try testing.expectEqual(estat.ino, nstat.ino);
+ try testing.expectEqual(@as(usize, 2), nstat.nlink);
}
try os.unlinkat(tmp.dir.fd, "new.txt", 0);
{
const estat = try os.fstat(efd.handle);
- testing.expectEqual(@as(usize, 1), estat.nlink);
+ try testing.expectEqual(@as(usize, 1), estat.nlink);
}
try cwd.deleteFile("example.txt");
@@ -283,7 +283,7 @@ test "fstatat" {
// now repeat but using `fstatat` instead
const flags = if (builtin.os.tag == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;
const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);
- expectEqual(stat, statat);
+ try expectEqual(stat, statat);
}
test "readlinkat" {
@@ -312,7 +312,7 @@ test "readlinkat" {
// read the link
var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
const read_link = try os.readlinkat(tmp.dir.fd, "link", buffer[0..]);
- expect(mem.eql(u8, "file.txt", read_link));
+ try expect(mem.eql(u8, "file.txt", read_link));
}
fn testThreadIdFn(thread_id: *Thread.Id) void {
@@ -327,13 +327,13 @@ test "std.Thread.getCurrentId" {
const thread_id = thread.handle();
thread.wait();
if (Thread.use_pthreads) {
- expect(thread_current_id == thread_id);
+ try expect(thread_current_id == thread_id);
} else if (builtin.os.tag == .windows) {
- expect(Thread.getCurrentId() != thread_current_id);
+ try expect(Thread.getCurrentId() != thread_current_id);
} else {
// If the thread completes very quickly, then thread_id can be 0. See the
// documentation comments for `std.Thread.handle`.
- expect(thread_id == 0 or thread_current_id == thread_id);
+ try expect(thread_id == 0 or thread_current_id == thread_id);
}
}
@@ -352,7 +352,7 @@ test "spawn threads" {
thread3.wait();
thread4.wait();
- expect(shared_ctx == 4);
+ try expect(shared_ctx == 4);
}
fn start1(ctx: void) u8 {
@@ -368,23 +368,23 @@ test "cpu count" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
const cpu_count = try Thread.cpuCount();
- expect(cpu_count >= 1);
+ try expect(cpu_count >= 1);
}
test "thread local storage" {
if (builtin.single_threaded) return error.SkipZigTest;
const thread1 = try Thread.spawn(testTls, {});
const thread2 = try Thread.spawn(testTls, {});
- testTls({});
+ try testTls({});
thread1.wait();
thread2.wait();
}
threadlocal var x: i32 = 1234;
-fn testTls(context: void) void {
- if (x != 1234) @panic("bad start value");
+fn testTls(context: void) !void {
+ if (x != 1234) return error.TlsBadStartValue;
x += 1;
- if (x != 1235) @panic("bad end value");
+ if (x != 1235) return error.TlsBadEndValue;
}
test "getrandom" {
@@ -394,7 +394,7 @@ test "getrandom" {
try os.getrandom(&buf_b);
// If this test fails the chance is significantly higher that there is a bug than
// that two sets of 50 bytes were equal.
- expect(!mem.eql(u8, &buf_a, &buf_b));
+ try expect(!mem.eql(u8, &buf_a, &buf_b));
}
test "getcwd" {
@@ -413,7 +413,7 @@ test "sigaltstack" {
// Setting a stack size less than MINSIGSTKSZ returns ENOMEM
st.ss_flags = 0;
st.ss_size = 1;
- testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));
+ try testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));
}
// If the type is not available use void to avoid erroring out when `iter_fn` is
@@ -464,7 +464,7 @@ test "dl_iterate_phdr" {
var counter: usize = 0;
try os.dl_iterate_phdr(&counter, IterFnError, iter_fn);
- expect(counter != 0);
+ try expect(counter != 0);
}
test "gethostname" {
@@ -473,7 +473,7 @@ test "gethostname" {
var buf: [os.HOST_NAME_MAX]u8 = undefined;
const hostname = try os.gethostname(&buf);
- expect(hostname.len != 0);
+ try expect(hostname.len != 0);
}
test "pipe" {
@@ -481,10 +481,10 @@ test "pipe" {
return error.SkipZigTest;
var fds = try os.pipe();
- expect((try os.write(fds[1], "hello")) == 5);
+ try expect((try os.write(fds[1], "hello")) == 5);
var buf: [16]u8 = undefined;
- expect((try os.read(fds[0], buf[0..])) == 5);
- testing.expectEqualSlices(u8, buf[0..5], "hello");
+ try expect((try os.read(fds[0], buf[0..])) == 5);
+ try testing.expectEqualSlices(u8, buf[0..5], "hello");
os.close(fds[1]);
os.close(fds[0]);
}
@@ -503,13 +503,13 @@ test "memfd_create" {
else => |e| return e,
};
defer std.os.close(fd);
- expect((try std.os.write(fd, "test")) == 4);
+ try expect((try std.os.write(fd, "test")) == 4);
try std.os.lseek_SET(fd, 0);
var buf: [10]u8 = undefined;
const bytes_read = try std.os.read(fd, &buf);
- expect(bytes_read == 4);
- expect(mem.eql(u8, buf[0..4], "test"));
+ try expect(bytes_read == 4);
+ try expect(mem.eql(u8, buf[0..4], "test"));
}
test "mmap" {
@@ -531,14 +531,14 @@ test "mmap" {
);
defer os.munmap(data);
- testing.expectEqual(@as(usize, 1234), data.len);
+ try testing.expectEqual(@as(usize, 1234), data.len);
// By definition the data returned by mmap is zero-filled
- testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
+ try testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
// Make sure the memory is writeable as requested
std.mem.set(u8, data, 0x55);
- testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
+ try testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
}
const test_out_file = "os_tmp_test";
@@ -578,7 +578,7 @@ test "mmap" {
var i: u32 = 0;
while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
- testing.expectEqual(i, try stream.readIntNative(u32));
+ try testing.expectEqual(i, try stream.readIntNative(u32));
}
}
@@ -602,7 +602,7 @@ test "mmap" {
var i: u32 = alloc_size / 2 / @sizeOf(u32);
while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
- testing.expectEqual(i, try stream.readIntNative(u32));
+ try testing.expectEqual(i, try stream.readIntNative(u32));
}
}
@@ -611,9 +611,9 @@ test "mmap" {
test "getenv" {
if (builtin.os.tag == .windows) {
- expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);
+ try expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);
} else {
- expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
+ try expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
}
}
@@ -635,17 +635,17 @@ test "fcntl" {
// Note: The test assumes createFile opens the file with O_CLOEXEC
{
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
- expect((flags & os.FD_CLOEXEC) != 0);
+ try expect((flags & os.FD_CLOEXEC) != 0);
}
{
_ = try os.fcntl(file.handle, os.F_SETFD, 0);
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
- expect((flags & os.FD_CLOEXEC) == 0);
+ try expect((flags & os.FD_CLOEXEC) == 0);
}
{
_ = try os.fcntl(file.handle, os.F_SETFD, os.FD_CLOEXEC);
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
- expect((flags & os.FD_CLOEXEC) != 0);
+ try expect((flags & os.FD_CLOEXEC) != 0);
}
}
@@ -750,12 +750,12 @@ test "sigaction" {
os.sigaction(os.SIGUSR1, &sa, null);
// Check that we can read it back correctly.
os.sigaction(os.SIGUSR1, null, &old_sa);
- testing.expectEqual(S.handler, old_sa.handler.sigaction.?);
- testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);
+ try testing.expectEqual(S.handler, old_sa.handler.sigaction.?);
+ try testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);
// Invoke the handler.
try os.raise(os.SIGUSR1);
- testing.expect(signal_test_failed == false);
+ try testing.expect(signal_test_failed == false);
// Check if the handler has been correctly reset to SIG_DFL
os.sigaction(os.SIGUSR1, null, &old_sa);
- testing.expectEqual(os.SIG_DFL, old_sa.handler.sigaction);
+ try testing.expectEqual(os.SIG_DFL, old_sa.handler.sigaction);
}
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig
index 1791fec956..86d1012319 100644
--- a/lib/std/os/windows.zig
+++ b/lib/std/os/windows.zig
@@ -997,7 +997,7 @@ test "QueryObjectName" {
var result_path = try QueryObjectName(handle, &out_buffer);
const required_len_in_u16 = result_path.len + @divExact(@ptrToInt(result_path.ptr) - @ptrToInt(&out_buffer), 2) + 1;
//insufficient size
- std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));
+ try std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));
//exactly-sufficient size
_ = try QueryObjectName(handle, out_buffer[0..required_len_in_u16]);
}
@@ -1155,8 +1155,8 @@ test "GetFinalPathNameByHandle" {
const required_len_in_u16 = nt_path.len + @divExact(@ptrToInt(nt_path.ptr) - @ptrToInt(&buffer), 2) + 1;
//check with insufficient size
- std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0 .. required_len_in_u16 - 1]));
- std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0 .. required_len_in_u16 - 1]));
+ try std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0 .. required_len_in_u16 - 1]));
+ try std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0 .. required_len_in_u16 - 1]));
//check with exactly-sufficient size
_ = try GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0..required_len_in_u16]);
diff --git a/lib/std/packed_int_array.zig b/lib/std/packed_int_array.zig
index c53d6f0505..830fe29d5c 100644
--- a/lib/std/packed_int_array.zig
+++ b/lib/std/packed_int_array.zig
@@ -353,7 +353,7 @@ test "PackedIntArray" {
const PackedArray = PackedIntArray(I, int_count);
const expected_bytes = ((bits * int_count) + 7) / 8;
- testing.expect(@sizeOf(PackedArray) == expected_bytes);
+ try testing.expect(@sizeOf(PackedArray) == expected_bytes);
var data = @as(PackedArray, undefined);
@@ -370,7 +370,7 @@ test "PackedIntArray" {
count = 0;
while (i < data.len()) : (i += 1) {
const val = data.get(i);
- testing.expect(val == count);
+ try testing.expect(val == count);
if (bits > 0) count +%= 1;
}
}
@@ -427,7 +427,7 @@ test "PackedIntSlice" {
count = 0;
while (i < data.len()) : (i += 1) {
const val = data.get(i);
- testing.expect(val == count);
+ try testing.expect(val == count);
if (bits > 0) count +%= 1;
}
}
@@ -454,48 +454,48 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
//slice of array
var packed_slice = packed_array.slice(2, 5);
- testing.expect(packed_slice.len() == 3);
+ try testing.expect(packed_slice.len() == 3);
const ps_bit_count = (bits * packed_slice.len()) + packed_slice.bit_offset;
const ps_expected_bytes = (ps_bit_count + 7) / 8;
- testing.expect(packed_slice.bytes.len == ps_expected_bytes);
- testing.expect(packed_slice.get(0) == 2 % limit);
- testing.expect(packed_slice.get(1) == 3 % limit);
- testing.expect(packed_slice.get(2) == 4 % limit);
+ try testing.expect(packed_slice.bytes.len == ps_expected_bytes);
+ try testing.expect(packed_slice.get(0) == 2 % limit);
+ try testing.expect(packed_slice.get(1) == 3 % limit);
+ try testing.expect(packed_slice.get(2) == 4 % limit);
packed_slice.set(1, 7 % limit);
- testing.expect(packed_slice.get(1) == 7 % limit);
+ try testing.expect(packed_slice.get(1) == 7 % limit);
//write through slice
- testing.expect(packed_array.get(3) == 7 % limit);
+ try testing.expect(packed_array.get(3) == 7 % limit);
//slice of a slice
const packed_slice_two = packed_slice.slice(0, 3);
- testing.expect(packed_slice_two.len() == 3);
+ try testing.expect(packed_slice_two.len() == 3);
const ps2_bit_count = (bits * packed_slice_two.len()) + packed_slice_two.bit_offset;
const ps2_expected_bytes = (ps2_bit_count + 7) / 8;
- testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);
- testing.expect(packed_slice_two.get(1) == 7 % limit);
- testing.expect(packed_slice_two.get(2) == 4 % limit);
+ try testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);
+ try testing.expect(packed_slice_two.get(1) == 7 % limit);
+ try testing.expect(packed_slice_two.get(2) == 4 % limit);
//size one case
const packed_slice_three = packed_slice_two.slice(1, 2);
- testing.expect(packed_slice_three.len() == 1);
+ try testing.expect(packed_slice_three.len() == 1);
const ps3_bit_count = (bits * packed_slice_three.len()) + packed_slice_three.bit_offset;
const ps3_expected_bytes = (ps3_bit_count + 7) / 8;
- testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);
- testing.expect(packed_slice_three.get(0) == 7 % limit);
+ try testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);
+ try testing.expect(packed_slice_three.get(0) == 7 % limit);
//empty slice case
const packed_slice_empty = packed_slice.slice(0, 0);
- testing.expect(packed_slice_empty.len() == 0);
- testing.expect(packed_slice_empty.bytes.len == 0);
+ try testing.expect(packed_slice_empty.len() == 0);
+ try testing.expect(packed_slice_empty.bytes.len == 0);
//slicing at byte boundaries
const packed_slice_edge = packed_array.slice(8, 16);
- testing.expect(packed_slice_edge.len() == 8);
+ try testing.expect(packed_slice_edge.len() == 8);
const pse_bit_count = (bits * packed_slice_edge.len()) + packed_slice_edge.bit_offset;
const pse_expected_bytes = (pse_bit_count + 7) / 8;
- testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);
- testing.expect(packed_slice_edge.bit_offset == 0);
+ try testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);
+ try testing.expect(packed_slice_edge.bit_offset == 0);
}
}
@@ -543,7 +543,7 @@ test "PackedInt(Array/Slice) sliceCast" {
.Big => 0b01,
.Little => 0b10,
};
- testing.expect(packed_slice_cast_2.get(i) == val);
+ try testing.expect(packed_slice_cast_2.get(i) == val);
}
i = 0;
while (i < packed_slice_cast_4.len()) : (i += 1) {
@@ -551,12 +551,12 @@ test "PackedInt(Array/Slice) sliceCast" {
.Big => 0b0101,
.Little => 0b1010,
};
- testing.expect(packed_slice_cast_4.get(i) == val);
+ try testing.expect(packed_slice_cast_4.get(i) == val);
}
i = 0;
while (i < packed_slice_cast_9.len()) : (i += 1) {
const val = 0b010101010;
- testing.expect(packed_slice_cast_9.get(i) == val);
+ try testing.expect(packed_slice_cast_9.get(i) == val);
packed_slice_cast_9.set(i, 0b111000111);
}
i = 0;
@@ -565,7 +565,7 @@ test "PackedInt(Array/Slice) sliceCast" {
.Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
.Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
};
- testing.expect(packed_slice_cast_3.get(i) == val);
+ try testing.expect(packed_slice_cast_3.get(i) == val);
}
}
@@ -575,58 +575,58 @@ test "PackedInt(Array/Slice)Endian" {
{
const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
- testing.expect(packed_array_be.bytes[0] == 0b00000001);
- testing.expect(packed_array_be.bytes[1] == 0b00100011);
+ try testing.expect(packed_array_be.bytes[0] == 0b00000001);
+ try testing.expect(packed_array_be.bytes[1] == 0b00100011);
var i = @as(usize, 0);
while (i < packed_array_be.len()) : (i += 1) {
- testing.expect(packed_array_be.get(i) == i);
+ try testing.expect(packed_array_be.get(i) == i);
}
var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little);
i = 0;
while (i < packed_slice_le.len()) : (i += 1) {
const val = if (i % 2 == 0) i + 1 else i - 1;
- testing.expect(packed_slice_le.get(i) == val);
+ try testing.expect(packed_slice_le.get(i) == val);
}
var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .Little);
i = 0;
while (i < packed_slice_le_shift.len()) : (i += 1) {
const val = if (i % 2 == 0) i else i + 2;
- testing.expect(packed_slice_le_shift.get(i) == val);
+ try testing.expect(packed_slice_le_shift.get(i) == val);
}
}
{
const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
- testing.expect(packed_array_be.bytes[0] == 0b00000000);
- testing.expect(packed_array_be.bytes[1] == 0b00000000);
- testing.expect(packed_array_be.bytes[2] == 0b00000100);
- testing.expect(packed_array_be.bytes[3] == 0b00000001);
- testing.expect(packed_array_be.bytes[4] == 0b00000000);
+ try testing.expect(packed_array_be.bytes[0] == 0b00000000);
+ try testing.expect(packed_array_be.bytes[1] == 0b00000000);
+ try testing.expect(packed_array_be.bytes[2] == 0b00000100);
+ try testing.expect(packed_array_be.bytes[3] == 0b00000001);
+ try testing.expect(packed_array_be.bytes[4] == 0b00000000);
var i = @as(usize, 0);
while (i < packed_array_be.len()) : (i += 1) {
- testing.expect(packed_array_be.get(i) == i);
+ try testing.expect(packed_array_be.get(i) == i);
}
var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little);
- testing.expect(packed_slice_le.get(0) == 0b00000000000);
- testing.expect(packed_slice_le.get(1) == 0b00010000000);
- testing.expect(packed_slice_le.get(2) == 0b00000000100);
- testing.expect(packed_slice_le.get(3) == 0b00000000000);
- testing.expect(packed_slice_le.get(4) == 0b00010000011);
- testing.expect(packed_slice_le.get(5) == 0b00000000010);
- testing.expect(packed_slice_le.get(6) == 0b10000010000);
- testing.expect(packed_slice_le.get(7) == 0b00000111001);
+ try testing.expect(packed_slice_le.get(0) == 0b00000000000);
+ try testing.expect(packed_slice_le.get(1) == 0b00010000000);
+ try testing.expect(packed_slice_le.get(2) == 0b00000000100);
+ try testing.expect(packed_slice_le.get(3) == 0b00000000000);
+ try testing.expect(packed_slice_le.get(4) == 0b00010000011);
+ try testing.expect(packed_slice_le.get(5) == 0b00000000010);
+ try testing.expect(packed_slice_le.get(6) == 0b10000010000);
+ try testing.expect(packed_slice_le.get(7) == 0b00000111001);
var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .Little);
- testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);
- testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);
- testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);
- testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);
+ try testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);
+ try testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);
+ try testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);
+ try testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);
}
}
diff --git a/lib/std/priority_dequeue.zig b/lib/std/priority_dequeue.zig
index 6894dcc997..f0f8d7f6f7 100644
--- a/lib/std/priority_dequeue.zig
+++ b/lib/std/priority_dequeue.zig
@@ -482,12 +482,12 @@ test "std.PriorityDequeue: add and remove min" {
try queue.add(25);
try queue.add(13);
- expectEqual(@as(u32, 7), queue.removeMin());
- expectEqual(@as(u32, 12), queue.removeMin());
- expectEqual(@as(u32, 13), queue.removeMin());
- expectEqual(@as(u32, 23), queue.removeMin());
- expectEqual(@as(u32, 25), queue.removeMin());
- expectEqual(@as(u32, 54), queue.removeMin());
+ try expectEqual(@as(u32, 7), queue.removeMin());
+ try expectEqual(@as(u32, 12), queue.removeMin());
+ try expectEqual(@as(u32, 13), queue.removeMin());
+ try expectEqual(@as(u32, 23), queue.removeMin());
+ try expectEqual(@as(u32, 25), queue.removeMin());
+ try expectEqual(@as(u32, 54), queue.removeMin());
}
test "std.PriorityDequeue: add and remove min structs" {
@@ -508,12 +508,12 @@ test "std.PriorityDequeue: add and remove min structs" {
try queue.add(.{ .size = 25 });
try queue.add(.{ .size = 13 });
- expectEqual(@as(u32, 7), queue.removeMin().size);
- expectEqual(@as(u32, 12), queue.removeMin().size);
- expectEqual(@as(u32, 13), queue.removeMin().size);
- expectEqual(@as(u32, 23), queue.removeMin().size);
- expectEqual(@as(u32, 25), queue.removeMin().size);
- expectEqual(@as(u32, 54), queue.removeMin().size);
+ try expectEqual(@as(u32, 7), queue.removeMin().size);
+ try expectEqual(@as(u32, 12), queue.removeMin().size);
+ try expectEqual(@as(u32, 13), queue.removeMin().size);
+ try expectEqual(@as(u32, 23), queue.removeMin().size);
+ try expectEqual(@as(u32, 25), queue.removeMin().size);
+ try expectEqual(@as(u32, 54), queue.removeMin().size);
}
test "std.PriorityDequeue: add and remove max" {
@@ -527,12 +527,12 @@ test "std.PriorityDequeue: add and remove max" {
try queue.add(25);
try queue.add(13);
- expectEqual(@as(u32, 54), queue.removeMax());
- expectEqual(@as(u32, 25), queue.removeMax());
- expectEqual(@as(u32, 23), queue.removeMax());
- expectEqual(@as(u32, 13), queue.removeMax());
- expectEqual(@as(u32, 12), queue.removeMax());
- expectEqual(@as(u32, 7), queue.removeMax());
+ try expectEqual(@as(u32, 54), queue.removeMax());
+ try expectEqual(@as(u32, 25), queue.removeMax());
+ try expectEqual(@as(u32, 23), queue.removeMax());
+ try expectEqual(@as(u32, 13), queue.removeMax());
+ try expectEqual(@as(u32, 12), queue.removeMax());
+ try expectEqual(@as(u32, 7), queue.removeMax());
}
test "std.PriorityDequeue: add and remove same min" {
@@ -546,12 +546,12 @@ test "std.PriorityDequeue: add and remove same min" {
try queue.add(1);
try queue.add(1);
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 2), queue.removeMin());
- expectEqual(@as(u32, 2), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 2), queue.removeMin());
+ try expectEqual(@as(u32, 2), queue.removeMin());
}
test "std.PriorityDequeue: add and remove same max" {
@@ -565,20 +565,20 @@ test "std.PriorityDequeue: add and remove same max" {
try queue.add(1);
try queue.add(1);
- expectEqual(@as(u32, 2), queue.removeMax());
- expectEqual(@as(u32, 2), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 2), queue.removeMax());
+ try expectEqual(@as(u32, 2), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
}
test "std.PriorityDequeue: removeOrNull empty" {
var queue = PDQ.init(testing.allocator, lessThanComparison);
defer queue.deinit();
- expect(queue.removeMinOrNull() == null);
- expect(queue.removeMaxOrNull() == null);
+ try expect(queue.removeMinOrNull() == null);
+ try expect(queue.removeMaxOrNull() == null);
}
test "std.PriorityDequeue: edge case 3 elements" {
@@ -589,9 +589,9 @@ test "std.PriorityDequeue: edge case 3 elements" {
try queue.add(3);
try queue.add(2);
- expectEqual(@as(u32, 2), queue.removeMin());
- expectEqual(@as(u32, 3), queue.removeMin());
- expectEqual(@as(u32, 9), queue.removeMin());
+ try expectEqual(@as(u32, 2), queue.removeMin());
+ try expectEqual(@as(u32, 3), queue.removeMin());
+ try expectEqual(@as(u32, 9), queue.removeMin());
}
test "std.PriorityDequeue: edge case 3 elements max" {
@@ -602,37 +602,37 @@ test "std.PriorityDequeue: edge case 3 elements max" {
try queue.add(3);
try queue.add(2);
- expectEqual(@as(u32, 9), queue.removeMax());
- expectEqual(@as(u32, 3), queue.removeMax());
- expectEqual(@as(u32, 2), queue.removeMax());
+ try expectEqual(@as(u32, 9), queue.removeMax());
+ try expectEqual(@as(u32, 3), queue.removeMax());
+ try expectEqual(@as(u32, 2), queue.removeMax());
}
test "std.PriorityDequeue: peekMin" {
var queue = PDQ.init(testing.allocator, lessThanComparison);
defer queue.deinit();
- expect(queue.peekMin() == null);
+ try expect(queue.peekMin() == null);
try queue.add(9);
try queue.add(3);
try queue.add(2);
- expect(queue.peekMin().? == 2);
- expect(queue.peekMin().? == 2);
+ try expect(queue.peekMin().? == 2);
+ try expect(queue.peekMin().? == 2);
}
test "std.PriorityDequeue: peekMax" {
var queue = PDQ.init(testing.allocator, lessThanComparison);
defer queue.deinit();
- expect(queue.peekMin() == null);
+ try expect(queue.peekMin() == null);
try queue.add(9);
try queue.add(3);
try queue.add(2);
- expect(queue.peekMax().? == 9);
- expect(queue.peekMax().? == 9);
+ try expect(queue.peekMax().? == 9);
+ try expect(queue.peekMax().? == 9);
}
test "std.PriorityDequeue: sift up with odd indices" {
@@ -645,7 +645,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.removeMin());
+ try expectEqual(e, queue.removeMin());
}
}
@@ -659,7 +659,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
for (sorted_items) |e| {
- expectEqual(e, queue.removeMax());
+ try expectEqual(e, queue.removeMax());
}
}
@@ -671,7 +671,7 @@ test "std.PriorityDequeue: addSlice min" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.removeMin());
+ try expectEqual(e, queue.removeMin());
}
}
@@ -683,7 +683,7 @@ test "std.PriorityDequeue: addSlice max" {
const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
for (sorted_items) |e| {
- expectEqual(e, queue.removeMax());
+ try expectEqual(e, queue.removeMax());
}
}
@@ -692,8 +692,8 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 0" {
const queue_items = try testing.allocator.dupe(u32, &items);
var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
defer queue.deinit();
- expectEqual(@as(usize, 0), queue.len);
- expect(queue.removeMinOrNull() == null);
+ try expectEqual(@as(usize, 0), queue.len);
+ try expect(queue.removeMinOrNull() == null);
}
test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
@@ -702,9 +702,9 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
defer queue.deinit();
- expectEqual(@as(usize, 1), queue.len);
- expectEqual(items[0], queue.removeMin());
- expect(queue.removeMinOrNull() == null);
+ try expectEqual(@as(usize, 1), queue.len);
+ try expectEqual(items[0], queue.removeMin());
+ try expect(queue.removeMinOrNull() == null);
}
test "std.PriorityDequeue: fromOwnedSlice" {
@@ -715,7 +715,7 @@ test "std.PriorityDequeue: fromOwnedSlice" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.removeMin());
+ try expectEqual(e, queue.removeMin());
}
}
@@ -729,9 +729,9 @@ test "std.PriorityDequeue: update min queue" {
try queue.update(55, 5);
try queue.update(44, 4);
try queue.update(11, 1);
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 4), queue.removeMin());
- expectEqual(@as(u32, 5), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 4), queue.removeMin());
+ try expectEqual(@as(u32, 5), queue.removeMin());
}
test "std.PriorityDequeue: update same min queue" {
@@ -744,10 +744,10 @@ test "std.PriorityDequeue: update same min queue" {
try queue.add(2);
try queue.update(1, 5);
try queue.update(2, 4);
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 2), queue.removeMin());
- expectEqual(@as(u32, 4), queue.removeMin());
- expectEqual(@as(u32, 5), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 2), queue.removeMin());
+ try expectEqual(@as(u32, 4), queue.removeMin());
+ try expectEqual(@as(u32, 5), queue.removeMin());
}
test "std.PriorityDequeue: update max queue" {
@@ -761,9 +761,9 @@ test "std.PriorityDequeue: update max queue" {
try queue.update(44, 1);
try queue.update(11, 4);
- expectEqual(@as(u32, 5), queue.removeMax());
- expectEqual(@as(u32, 4), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 5), queue.removeMax());
+ try expectEqual(@as(u32, 4), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
}
test "std.PriorityDequeue: update same max queue" {
@@ -776,10 +776,10 @@ test "std.PriorityDequeue: update same max queue" {
try queue.add(2);
try queue.update(1, 5);
try queue.update(2, 4);
- expectEqual(@as(u32, 5), queue.removeMax());
- expectEqual(@as(u32, 4), queue.removeMax());
- expectEqual(@as(u32, 2), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 5), queue.removeMax());
+ try expectEqual(@as(u32, 4), queue.removeMax());
+ try expectEqual(@as(u32, 2), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
}
test "std.PriorityDequeue: iterator" {
@@ -801,7 +801,7 @@ test "std.PriorityDequeue: iterator" {
_ = map.remove(e);
}
- expectEqual(@as(usize, 0), map.count());
+ try expectEqual(@as(usize, 0), map.count());
}
test "std.PriorityDequeue: remove at index" {
@@ -821,10 +821,10 @@ test "std.PriorityDequeue: remove at index" {
idx += 1;
} else unreachable;
- expectEqual(queue.removeIndex(two_idx), 2);
- expectEqual(queue.removeMin(), 1);
- expectEqual(queue.removeMin(), 3);
- expectEqual(queue.removeMinOrNull(), null);
+ try expectEqual(queue.removeIndex(two_idx), 2);
+ try expectEqual(queue.removeMin(), 1);
+ try expectEqual(queue.removeMin(), 3);
+ try expectEqual(queue.removeMinOrNull(), null);
}
test "std.PriorityDequeue: iterator while empty" {
@@ -833,7 +833,7 @@ test "std.PriorityDequeue: iterator while empty" {
var it = queue.iterator();
- expectEqual(it.next(), null);
+ try expectEqual(it.next(), null);
}
test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
@@ -841,26 +841,26 @@ test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
defer queue.deinit();
try queue.ensureCapacity(4);
- expect(queue.capacity() >= 4);
+ try expect(queue.capacity() >= 4);
try queue.add(1);
try queue.add(2);
try queue.add(3);
- expect(queue.capacity() >= 4);
- expectEqual(@as(usize, 3), queue.len);
+ try expect(queue.capacity() >= 4);
+ try expectEqual(@as(usize, 3), queue.len);
queue.shrinkRetainingCapacity(3);
- expect(queue.capacity() >= 4);
- expectEqual(@as(usize, 3), queue.len);
+ try expect(queue.capacity() >= 4);
+ try expectEqual(@as(usize, 3), queue.len);
queue.shrinkAndFree(3);
- expectEqual(@as(usize, 3), queue.capacity());
- expectEqual(@as(usize, 3), queue.len);
+ try expectEqual(@as(usize, 3), queue.capacity());
+ try expectEqual(@as(usize, 3), queue.len);
- expectEqual(@as(u32, 3), queue.removeMax());
- expectEqual(@as(u32, 2), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
- expect(queue.removeMaxOrNull() == null);
+ try expectEqual(@as(u32, 3), queue.removeMax());
+ try expectEqual(@as(u32, 2), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
+ try expect(queue.removeMaxOrNull() == null);
}
test "std.PriorityDequeue: fuzz testing min" {
@@ -885,7 +885,7 @@ fn fuzzTestMin(rng: *std.rand.Random, comptime queue_size: usize) !void {
var last_removed: ?u32 = null;
while (queue.removeMinOrNull()) |next| {
if (last_removed) |last| {
- expect(last <= next);
+ try expect(last <= next);
}
last_removed = next;
}
@@ -913,7 +913,7 @@ fn fuzzTestMax(rng: *std.rand.Random, queue_size: usize) !void {
var last_removed: ?u32 = null;
while (queue.removeMaxOrNull()) |next| {
if (last_removed) |last| {
- expect(last >= next);
+ try expect(last >= next);
}
last_removed = next;
}
@@ -945,13 +945,13 @@ fn fuzzTestMinMax(rng: *std.rand.Random, queue_size: usize) !void {
if (i % 2 == 0) {
const next = queue.removeMin();
if (last_min) |last| {
- expect(last <= next);
+ try expect(last <= next);
}
last_min = next;
} else {
const next = queue.removeMax();
if (last_max) |last| {
- expect(last >= next);
+ try expect(last >= next);
}
last_max = next;
}
diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig
index 2685a7105e..621af4e97f 100644
--- a/lib/std/priority_queue.zig
+++ b/lib/std/priority_queue.zig
@@ -290,12 +290,12 @@ test "std.PriorityQueue: add and remove min heap" {
try queue.add(23);
try queue.add(25);
try queue.add(13);
- expectEqual(@as(u32, 7), queue.remove());
- expectEqual(@as(u32, 12), queue.remove());
- expectEqual(@as(u32, 13), queue.remove());
- expectEqual(@as(u32, 23), queue.remove());
- expectEqual(@as(u32, 25), queue.remove());
- expectEqual(@as(u32, 54), queue.remove());
+ try expectEqual(@as(u32, 7), queue.remove());
+ try expectEqual(@as(u32, 12), queue.remove());
+ try expectEqual(@as(u32, 13), queue.remove());
+ try expectEqual(@as(u32, 23), queue.remove());
+ try expectEqual(@as(u32, 25), queue.remove());
+ try expectEqual(@as(u32, 54), queue.remove());
}
test "std.PriorityQueue: add and remove same min heap" {
@@ -308,19 +308,19 @@ test "std.PriorityQueue: add and remove same min heap" {
try queue.add(2);
try queue.add(1);
try queue.add(1);
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
}
test "std.PriorityQueue: removeOrNull on empty" {
var queue = PQ.init(testing.allocator, lessThan);
defer queue.deinit();
- expect(queue.removeOrNull() == null);
+ try expect(queue.removeOrNull() == null);
}
test "std.PriorityQueue: edge case 3 elements" {
@@ -330,21 +330,21 @@ test "std.PriorityQueue: edge case 3 elements" {
try queue.add(9);
try queue.add(3);
try queue.add(2);
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 3), queue.remove());
- expectEqual(@as(u32, 9), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 3), queue.remove());
+ try expectEqual(@as(u32, 9), queue.remove());
}
test "std.PriorityQueue: peek" {
var queue = PQ.init(testing.allocator, lessThan);
defer queue.deinit();
- expect(queue.peek() == null);
+ try expect(queue.peek() == null);
try queue.add(9);
try queue.add(3);
try queue.add(2);
- expectEqual(@as(u32, 2), queue.peek().?);
- expectEqual(@as(u32, 2), queue.peek().?);
+ try expectEqual(@as(u32, 2), queue.peek().?);
+ try expectEqual(@as(u32, 2), queue.peek().?);
}
test "std.PriorityQueue: sift up with odd indices" {
@@ -357,7 +357,7 @@ test "std.PriorityQueue: sift up with odd indices" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.remove());
+ try expectEqual(e, queue.remove());
}
}
@@ -369,7 +369,7 @@ test "std.PriorityQueue: addSlice" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.remove());
+ try expectEqual(e, queue.remove());
}
}
@@ -378,8 +378,8 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 0" {
const queue_items = try testing.allocator.dupe(u32, &items);
var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
defer queue.deinit();
- expectEqual(@as(usize, 0), queue.len);
- expect(queue.removeOrNull() == null);
+ try expectEqual(@as(usize, 0), queue.len);
+ try expect(queue.removeOrNull() == null);
}
test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
@@ -388,9 +388,9 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
defer queue.deinit();
- expectEqual(@as(usize, 1), queue.len);
- expectEqual(items[0], queue.remove());
- expect(queue.removeOrNull() == null);
+ try expectEqual(@as(usize, 1), queue.len);
+ try expectEqual(items[0], queue.remove());
+ try expect(queue.removeOrNull() == null);
}
test "std.PriorityQueue: fromOwnedSlice" {
@@ -401,7 +401,7 @@ test "std.PriorityQueue: fromOwnedSlice" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.remove());
+ try expectEqual(e, queue.remove());
}
}
@@ -415,12 +415,12 @@ test "std.PriorityQueue: add and remove max heap" {
try queue.add(23);
try queue.add(25);
try queue.add(13);
- expectEqual(@as(u32, 54), queue.remove());
- expectEqual(@as(u32, 25), queue.remove());
- expectEqual(@as(u32, 23), queue.remove());
- expectEqual(@as(u32, 13), queue.remove());
- expectEqual(@as(u32, 12), queue.remove());
- expectEqual(@as(u32, 7), queue.remove());
+ try expectEqual(@as(u32, 54), queue.remove());
+ try expectEqual(@as(u32, 25), queue.remove());
+ try expectEqual(@as(u32, 23), queue.remove());
+ try expectEqual(@as(u32, 13), queue.remove());
+ try expectEqual(@as(u32, 12), queue.remove());
+ try expectEqual(@as(u32, 7), queue.remove());
}
test "std.PriorityQueue: add and remove same max heap" {
@@ -433,12 +433,12 @@ test "std.PriorityQueue: add and remove same max heap" {
try queue.add(2);
try queue.add(1);
try queue.add(1);
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
}
test "std.PriorityQueue: iterator" {
@@ -460,7 +460,7 @@ test "std.PriorityQueue: iterator" {
_ = map.remove(e);
}
- expectEqual(@as(usize, 0), map.count());
+ try expectEqual(@as(usize, 0), map.count());
}
test "std.PriorityQueue: remove at index" {
@@ -480,10 +480,10 @@ test "std.PriorityQueue: remove at index" {
idx += 1;
} else unreachable;
- expectEqual(queue.removeIndex(two_idx), 2);
- expectEqual(queue.remove(), 1);
- expectEqual(queue.remove(), 3);
- expectEqual(queue.removeOrNull(), null);
+ try expectEqual(queue.removeIndex(two_idx), 2);
+ try expectEqual(queue.remove(), 1);
+ try expectEqual(queue.remove(), 3);
+ try expectEqual(queue.removeOrNull(), null);
}
test "std.PriorityQueue: iterator while empty" {
@@ -492,7 +492,7 @@ test "std.PriorityQueue: iterator while empty" {
var it = queue.iterator();
- expectEqual(it.next(), null);
+ try expectEqual(it.next(), null);
}
test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
@@ -500,26 +500,26 @@ test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
defer queue.deinit();
try queue.ensureCapacity(4);
- expect(queue.capacity() >= 4);
+ try expect(queue.capacity() >= 4);
try queue.add(1);
try queue.add(2);
try queue.add(3);
- expect(queue.capacity() >= 4);
- expectEqual(@as(usize, 3), queue.len);
+ try expect(queue.capacity() >= 4);
+ try expectEqual(@as(usize, 3), queue.len);
queue.shrinkRetainingCapacity(3);
- expect(queue.capacity() >= 4);
- expectEqual(@as(usize, 3), queue.len);
+ try expect(queue.capacity() >= 4);
+ try expectEqual(@as(usize, 3), queue.len);
queue.shrinkAndFree(3);
- expectEqual(@as(usize, 3), queue.capacity());
- expectEqual(@as(usize, 3), queue.len);
+ try expectEqual(@as(usize, 3), queue.capacity());
+ try expectEqual(@as(usize, 3), queue.len);
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 3), queue.remove());
- expect(queue.removeOrNull() == null);
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 3), queue.remove());
+ try expect(queue.removeOrNull() == null);
}
test "std.PriorityQueue: update min heap" {
@@ -532,9 +532,9 @@ test "std.PriorityQueue: update min heap" {
try queue.update(55, 5);
try queue.update(44, 4);
try queue.update(11, 1);
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 4), queue.remove());
- expectEqual(@as(u32, 5), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 4), queue.remove());
+ try expectEqual(@as(u32, 5), queue.remove());
}
test "std.PriorityQueue: update same min heap" {
@@ -547,10 +547,10 @@ test "std.PriorityQueue: update same min heap" {
try queue.add(2);
try queue.update(1, 5);
try queue.update(2, 4);
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 4), queue.remove());
- expectEqual(@as(u32, 5), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 4), queue.remove());
+ try expectEqual(@as(u32, 5), queue.remove());
}
test "std.PriorityQueue: update max heap" {
@@ -563,9 +563,9 @@ test "std.PriorityQueue: update max heap" {
try queue.update(55, 5);
try queue.update(44, 1);
try queue.update(11, 4);
- expectEqual(@as(u32, 5), queue.remove());
- expectEqual(@as(u32, 4), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 5), queue.remove());
+ try expectEqual(@as(u32, 4), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
}
test "std.PriorityQueue: update same max heap" {
@@ -578,8 +578,8 @@ test "std.PriorityQueue: update same max heap" {
try queue.add(2);
try queue.update(1, 5);
try queue.update(2, 4);
- expectEqual(@as(u32, 5), queue.remove());
- expectEqual(@as(u32, 4), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 5), queue.remove());
+ try expectEqual(@as(u32, 4), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
}
diff --git a/lib/std/process.zig b/lib/std/process.zig
index 3ad73db420..8b49e84a8c 100644
--- a/lib/std/process.zig
+++ b/lib/std/process.zig
@@ -181,7 +181,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
test "os.getEnvVarOwned" {
var ga = std.testing.allocator;
- testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
+ try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
}
pub const ArgIteratorPosix = struct {
@@ -516,10 +516,10 @@ test "args iterator" {
};
const given_suffix = std.fs.path.basename(prog_name);
- testing.expect(mem.eql(u8, expected_suffix, given_suffix));
- testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner
- testing.expect(it.next(ga) == null);
- testing.expect(!it.skip());
+ try testing.expect(mem.eql(u8, expected_suffix, given_suffix));
+ try testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner
+ try testing.expect(it.next(ga) == null);
+ try testing.expect(!it.skip());
}
/// Caller must call argsFree on result.
@@ -575,14 +575,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const [:0]u8) void {
test "windows arg parsing" {
const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;
- testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });
- testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" });
- testWindowsCmdLine(utf16Literal("a\\\\\\b d\"e f\"g h"), &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
- testWindowsCmdLine(utf16Literal("a\\\\\\\"b c d"), &[_][]const u8{ "a\\\"b", "c", "d" });
- testWindowsCmdLine(utf16Literal("a\\\\\\\\\"b c\" d e"), &[_][]const u8{ "a\\\\b c", "d", "e" });
- testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" });
+ try testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });
+ try testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" });
+ try testWindowsCmdLine(utf16Literal("a\\\\\\b d\"e f\"g h"), &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
+ try testWindowsCmdLine(utf16Literal("a\\\\\\\"b c d"), &[_][]const u8{ "a\\\"b", "c", "d" });
+ try testWindowsCmdLine(utf16Literal("a\\\\\\\\\"b c\" d e"), &[_][]const u8{ "a\\\\b c", "d", "e" });
+ try testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" });
- testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{
+ try testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{
".\\..\\zig-cache\\build",
"bin\\zig.exe",
".\\..",
@@ -591,14 +591,14 @@ test "windows arg parsing" {
});
}
-fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) void {
+fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) !void {
var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
for (expected_args) |expected_arg| {
const arg = it.next(std.testing.allocator).? catch unreachable;
defer std.testing.allocator.free(arg);
- testing.expectEqualStrings(expected_arg, arg);
+ try testing.expectEqualStrings(expected_arg, arg);
}
- testing.expect(it.next(std.testing.allocator) == null);
+ try testing.expect(it.next(std.testing.allocator) == null);
}
pub const UserInfo = struct {
diff --git a/lib/std/rand.zig b/lib/std/rand.zig
index d0d400b5b0..653015b907 100644
--- a/lib/std/rand.zig
+++ b/lib/std/rand.zig
@@ -319,139 +319,139 @@ const SequentialPrng = struct {
};
test "Random int" {
- testRandomInt();
- comptime testRandomInt();
+ try testRandomInt();
+ comptime try testRandomInt();
}
-fn testRandomInt() void {
+fn testRandomInt() !void {
var r = SequentialPrng.init();
- expect(r.random.int(u0) == 0);
+ try expect(r.random.int(u0) == 0);
r.next_value = 0;
- expect(r.random.int(u1) == 0);
- expect(r.random.int(u1) == 1);
- expect(r.random.int(u2) == 2);
- expect(r.random.int(u2) == 3);
- expect(r.random.int(u2) == 0);
+ try expect(r.random.int(u1) == 0);
+ try expect(r.random.int(u1) == 1);
+ try expect(r.random.int(u2) == 2);
+ try expect(r.random.int(u2) == 3);
+ try expect(r.random.int(u2) == 0);
r.next_value = 0xff;
- expect(r.random.int(u8) == 0xff);
+ try expect(r.random.int(u8) == 0xff);
r.next_value = 0x11;
- expect(r.random.int(u8) == 0x11);
+ try expect(r.random.int(u8) == 0x11);
r.next_value = 0xff;
- expect(r.random.int(u32) == 0xffffffff);
+ try expect(r.random.int(u32) == 0xffffffff);
r.next_value = 0x11;
- expect(r.random.int(u32) == 0x11111111);
+ try expect(r.random.int(u32) == 0x11111111);
r.next_value = 0xff;
- expect(r.random.int(i32) == -1);
+ try expect(r.random.int(i32) == -1);
r.next_value = 0x11;
- expect(r.random.int(i32) == 0x11111111);
+ try expect(r.random.int(i32) == 0x11111111);
r.next_value = 0xff;
- expect(r.random.int(i8) == -1);
+ try expect(r.random.int(i8) == -1);
r.next_value = 0x11;
- expect(r.random.int(i8) == 0x11);
+ try expect(r.random.int(i8) == 0x11);
r.next_value = 0xff;
- expect(r.random.int(u33) == 0x1ffffffff);
+ try expect(r.random.int(u33) == 0x1ffffffff);
r.next_value = 0xff;
- expect(r.random.int(i1) == -1);
+ try expect(r.random.int(i1) == -1);
r.next_value = 0xff;
- expect(r.random.int(i2) == -1);
+ try expect(r.random.int(i2) == -1);
r.next_value = 0xff;
- expect(r.random.int(i33) == -1);
+ try expect(r.random.int(i33) == -1);
}
test "Random boolean" {
- testRandomBoolean();
- comptime testRandomBoolean();
+ try testRandomBoolean();
+ comptime try testRandomBoolean();
}
-fn testRandomBoolean() void {
+fn testRandomBoolean() !void {
var r = SequentialPrng.init();
- expect(r.random.boolean() == false);
- expect(r.random.boolean() == true);
- expect(r.random.boolean() == false);
- expect(r.random.boolean() == true);
+ try expect(r.random.boolean() == false);
+ try expect(r.random.boolean() == true);
+ try expect(r.random.boolean() == false);
+ try expect(r.random.boolean() == true);
}
test "Random intLessThan" {
@setEvalBranchQuota(10000);
- testRandomIntLessThan();
- comptime testRandomIntLessThan();
+ try testRandomIntLessThan();
+ comptime try testRandomIntLessThan();
}
-fn testRandomIntLessThan() void {
+fn testRandomIntLessThan() !void {
var r = SequentialPrng.init();
r.next_value = 0xff;
- expect(r.random.uintLessThan(u8, 4) == 3);
- expect(r.next_value == 0);
- expect(r.random.uintLessThan(u8, 4) == 0);
- expect(r.next_value == 1);
+ try expect(r.random.uintLessThan(u8, 4) == 3);
+ try expect(r.next_value == 0);
+ try expect(r.random.uintLessThan(u8, 4) == 0);
+ try expect(r.next_value == 1);
r.next_value = 0;
- expect(r.random.uintLessThan(u64, 32) == 0);
+ try expect(r.random.uintLessThan(u64, 32) == 0);
// trigger the bias rejection code path
r.next_value = 0;
- expect(r.random.uintLessThan(u8, 3) == 0);
+ try expect(r.random.uintLessThan(u8, 3) == 0);
// verify we incremented twice
- expect(r.next_value == 2);
+ try expect(r.next_value == 2);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
+ try expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
+ try expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
+ try expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
+ try expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
+ try expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
+ try expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
+ try expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
}
test "Random intAtMost" {
@setEvalBranchQuota(10000);
- testRandomIntAtMost();
- comptime testRandomIntAtMost();
+ try testRandomIntAtMost();
+ comptime try testRandomIntAtMost();
}
-fn testRandomIntAtMost() void {
+fn testRandomIntAtMost() !void {
var r = SequentialPrng.init();
r.next_value = 0xff;
- expect(r.random.uintAtMost(u8, 3) == 3);
- expect(r.next_value == 0);
- expect(r.random.uintAtMost(u8, 3) == 0);
+ try expect(r.random.uintAtMost(u8, 3) == 3);
+ try expect(r.next_value == 0);
+ try expect(r.random.uintAtMost(u8, 3) == 0);
// trigger the bias rejection code path
r.next_value = 0;
- expect(r.random.uintAtMost(u8, 2) == 0);
+ try expect(r.random.uintAtMost(u8, 2) == 0);
// verify we incremented twice
- expect(r.next_value == 2);
+ try expect(r.next_value == 2);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
+ try expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
+ try expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
+ try expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
+ try expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
+ try expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
+ try expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(i3, -2, 1) == 1);
+ try expect(r.random.intRangeAtMost(i3, -2, 1) == 1);
- expect(r.random.uintAtMost(u0, 0) == 0);
+ try expect(r.random.uintAtMost(u0, 0) == 0);
}
test "Random Biased" {
@@ -459,30 +459,30 @@ test "Random Biased" {
// Not thoroughly checking the logic here.
// Just want to execute all the paths with different types.
- expect(r.random.uintLessThanBiased(u1, 1) == 0);
- expect(r.random.uintLessThanBiased(u32, 10) < 10);
- expect(r.random.uintLessThanBiased(u64, 20) < 20);
+ try expect(r.random.uintLessThanBiased(u1, 1) == 0);
+ try expect(r.random.uintLessThanBiased(u32, 10) < 10);
+ try expect(r.random.uintLessThanBiased(u64, 20) < 20);
- expect(r.random.uintAtMostBiased(u0, 0) == 0);
- expect(r.random.uintAtMostBiased(u1, 0) <= 0);
- expect(r.random.uintAtMostBiased(u32, 10) <= 10);
- expect(r.random.uintAtMostBiased(u64, 20) <= 20);
+ try expect(r.random.uintAtMostBiased(u0, 0) == 0);
+ try expect(r.random.uintAtMostBiased(u1, 0) <= 0);
+ try expect(r.random.uintAtMostBiased(u32, 10) <= 10);
+ try expect(r.random.uintAtMostBiased(u64, 20) <= 20);
- expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
- expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
- expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
- expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
- expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
- expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
+ try expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
+ try expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
+ try expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
+ try expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
+ try expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
+ try expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
// uncomment for broken module error:
//expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);
- expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
- expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
- expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
- expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
- expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
- expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
+ try expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
+ try expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
+ try expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
+ try expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
+ try expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
+ try expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
}
// Generator to extend 64-bit seed values into longer sequences.
@@ -519,7 +519,7 @@ test "splitmix64 sequence" {
};
for (seq) |s| {
- expect(s == r.next());
+ try expect(s == r.next());
}
}
@@ -530,12 +530,12 @@ test "Random float" {
var i: usize = 0;
while (i < 1000) : (i += 1) {
const val1 = prng.random.float(f32);
- expect(val1 >= 0.0);
- expect(val1 < 1.0);
+ try expect(val1 >= 0.0);
+ try expect(val1 < 1.0);
const val2 = prng.random.float(f64);
- expect(val2 >= 0.0);
- expect(val2 < 1.0);
+ try expect(val2 >= 0.0);
+ try expect(val2 < 1.0);
}
}
@@ -549,12 +549,12 @@ test "Random shuffle" {
while (i < 1000) : (i += 1) {
prng.random.shuffle(u8, seq[0..]);
seen[seq[0]] = true;
- expect(sumArray(seq[0..]) == 10);
+ try expect(sumArray(seq[0..]) == 10);
}
// we should see every entry at the head at least once
for (seen) |e| {
- expect(e == true);
+ try expect(e == true);
}
}
@@ -567,17 +567,17 @@ fn sumArray(s: []const u8) u32 {
test "Random range" {
var prng = DefaultPrng.init(0);
- testRange(&prng.random, -4, 3);
- testRange(&prng.random, -4, -1);
- testRange(&prng.random, 10, 14);
- testRange(&prng.random, -0x80, 0x7f);
+ try testRange(&prng.random, -4, 3);
+ try testRange(&prng.random, -4, -1);
+ try testRange(&prng.random, 10, 14);
+ try testRange(&prng.random, -0x80, 0x7f);
}
-fn testRange(r: *Random, start: i8, end: i8) void {
- testRangeBias(r, start, end, true);
- testRangeBias(r, start, end, false);
+fn testRange(r: *Random, start: i8, end: i8) !void {
+ try testRangeBias(r, start, end, true);
+ try testRangeBias(r, start, end, false);
}
-fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void {
+fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) !void {
const count = @intCast(usize, @as(i32, end) - @as(i32, start));
var values_buffer = [_]bool{false} ** 0x100;
const values = values_buffer[0..count];
@@ -599,7 +599,7 @@ test "CSPRNG" {
const a = csprng.random.int(u64);
const b = csprng.random.int(u64);
const c = csprng.random.int(u64);
- expect(a ^ b ^ c != 0);
+ try expect(a ^ b ^ c != 0);
}
test {
diff --git a/lib/std/rand/Isaac64.zig b/lib/std/rand/Isaac64.zig
index 7efba9b5bc..ec505b0bf6 100644
--- a/lib/std/rand/Isaac64.zig
+++ b/lib/std/rand/Isaac64.zig
@@ -205,7 +205,7 @@ test "isaac64 sequence" {
};
for (seq) |s| {
- std.testing.expect(s == r.next());
+ try std.testing.expect(s == r.next());
}
}
@@ -237,6 +237,6 @@ test "isaac64 fill" {
var buf1: [7]u8 = undefined;
std.mem.writeIntLittle(u64, &buf0, s);
Isaac64.fill(&r.random, &buf1);
- std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
+ try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
}
}
diff --git a/lib/std/rand/Pcg.zig b/lib/std/rand/Pcg.zig
index 87df0521f2..8f468b5ea3 100644
--- a/lib/std/rand/Pcg.zig
+++ b/lib/std/rand/Pcg.zig
@@ -96,7 +96,7 @@ test "pcg sequence" {
};
for (seq) |s| {
- std.testing.expect(s == r.next());
+ try std.testing.expect(s == r.next());
}
}
@@ -120,6 +120,6 @@ test "pcg fill" {
var buf1: [3]u8 = undefined;
std.mem.writeIntLittle(u32, &buf0, s);
Pcg.fill(&r.random, &buf1);
- std.testing.expect(std.mem.eql(u8, buf0[0..3], buf1[0..]));
+ try std.testing.expect(std.mem.eql(u8, buf0[0..3], buf1[0..]));
}
}
diff --git a/lib/std/rand/Sfc64.zig b/lib/std/rand/Sfc64.zig
index 67eb684f60..1966a59ceb 100644
--- a/lib/std/rand/Sfc64.zig
+++ b/lib/std/rand/Sfc64.zig
@@ -103,7 +103,7 @@ test "Sfc64 sequence" {
};
for (seq) |s| {
- std.testing.expectEqual(s, r.next());
+ try std.testing.expectEqual(s, r.next());
}
}
@@ -135,6 +135,6 @@ test "Sfc64 fill" {
var buf1: [7]u8 = undefined;
std.mem.writeIntLittle(u64, &buf0, s);
Sfc64.fill(&r.random, &buf1);
- std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
+ try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
}
}
diff --git a/lib/std/rand/Xoroshiro128.zig b/lib/std/rand/Xoroshiro128.zig
index 04980cea41..4b507cec74 100644
--- a/lib/std/rand/Xoroshiro128.zig
+++ b/lib/std/rand/Xoroshiro128.zig
@@ -113,7 +113,7 @@ test "xoroshiro sequence" {
};
for (seq1) |s| {
- std.testing.expect(s == r.next());
+ try std.testing.expect(s == r.next());
}
r.jump();
@@ -128,7 +128,7 @@ test "xoroshiro sequence" {
};
for (seq2) |s| {
- std.testing.expect(s == r.next());
+ try std.testing.expect(s == r.next());
}
}
@@ -151,6 +151,6 @@ test "xoroshiro fill" {
var buf1: [7]u8 = undefined;
std.mem.writeIntLittle(u64, &buf0, s);
Xoroshiro128.fill(&r.random, &buf1);
- std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
+ try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
}
}
diff --git a/lib/std/sort.zig b/lib/std/sort.zig
index b30fb6ae57..8c330fbff5 100644
--- a/lib/std/sort.zig
+++ b/lib/std/sort.zig
@@ -43,35 +43,35 @@ test "binarySearch" {
return math.order(lhs, rhs);
}
};
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, null),
binarySearch(u32, 1, &[_]u32{}, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, 0),
binarySearch(u32, 1, &[_]u32{1}, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, null),
binarySearch(u32, 1, &[_]u32{0}, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, null),
binarySearch(u32, 0, &[_]u32{1}, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, 4),
binarySearch(u32, 5, &[_]u32{ 1, 2, 3, 4, 5 }, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, 0),
binarySearch(u32, 2, &[_]u32{ 2, 4, 8, 16, 32, 64 }, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, 1),
binarySearch(i32, -4, &[_]i32{ -7, -4, 0, 9, 10 }, {}, S.order_i32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, 3),
binarySearch(i32, 98, &[_]i32{ -100, -25, 2, 98, 99, 100 }, {}, S.order_i32),
);
@@ -1152,10 +1152,10 @@ pub fn desc(comptime T: type) fn (void, T, T) bool {
}
test "stable sort" {
- testStableSort();
- comptime testStableSort();
+ try testStableSort();
+ comptime try testStableSort();
}
-fn testStableSort() void {
+fn testStableSort() !void {
var expected = [_]IdAndValue{
IdAndValue{ .id = 0, .value = 0 },
IdAndValue{ .id = 1, .value = 0 },
@@ -1194,8 +1194,8 @@ fn testStableSort() void {
for (cases) |*case| {
insertionSort(IdAndValue, (case.*)[0..], {}, cmpByValue);
for (case.*) |item, i| {
- testing.expect(item.id == expected[i].id);
- testing.expect(item.value == expected[i].value);
+ try testing.expect(item.id == expected[i].id);
+ try testing.expect(item.value == expected[i].value);
}
}
}
@@ -1245,7 +1245,7 @@ test "sort" {
const slice = buf[0..case[0].len];
mem.copy(u8, slice, case[0]);
sort(u8, slice, {}, asc_u8);
- testing.expect(mem.eql(u8, slice, case[1]));
+ try testing.expect(mem.eql(u8, slice, case[1]));
}
const i32cases = [_][]const []const i32{
@@ -1280,7 +1280,7 @@ test "sort" {
const slice = buf[0..case[0].len];
mem.copy(i32, slice, case[0]);
sort(i32, slice, {}, asc_i32);
- testing.expect(mem.eql(i32, slice, case[1]));
+ try testing.expect(mem.eql(i32, slice, case[1]));
}
}
@@ -1317,7 +1317,7 @@ test "sort descending" {
const slice = buf[0..case[0].len];
mem.copy(i32, slice, case[0]);
sort(i32, slice, {}, desc_i32);
- testing.expect(mem.eql(i32, slice, case[1]));
+ try testing.expect(mem.eql(i32, slice, case[1]));
}
}
@@ -1325,7 +1325,7 @@ test "another sort case" {
var arr = [_]i32{ 5, 3, 1, 2, 4 };
sort(i32, arr[0..], {}, asc_i32);
- testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));
+ try testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));
}
test "sort fuzz testing" {
@@ -1353,9 +1353,9 @@ fn fuzzTest(rng: *std.rand.Random) !void {
var index: usize = 1;
while (index < array.len) : (index += 1) {
if (array[index].value == array[index - 1].value) {
- testing.expect(array[index].id > array[index - 1].id);
+ try testing.expect(array[index].id > array[index - 1].id);
} else {
- testing.expect(array[index].value > array[index - 1].value);
+ try testing.expect(array[index].value > array[index - 1].value);
}
}
}
@@ -1383,13 +1383,13 @@ pub fn argMin(
}
test "argMin" {
- testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
+ try testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
}
pub fn min(
@@ -1403,13 +1403,13 @@ pub fn min(
}
test "min" {
- testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));
- testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32));
- testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 2), min(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, -10), min(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
+ try testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 2), min(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, -10), min(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
}
pub fn argMax(
@@ -1435,13 +1435,13 @@ pub fn argMax(
}
test "argMax" {
- testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32));
- testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 2), argMax(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
+ try testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 2), argMax(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
}
pub fn max(
@@ -1455,13 +1455,13 @@ pub fn max(
}
test "max" {
- testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));
- testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32));
- testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 9), max(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 10), max(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
+ try testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 9), max(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 10), max(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
}
pub fn isSorted(
@@ -1481,28 +1481,28 @@ pub fn isSorted(
}
test "isSorted" {
- testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));
- testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));
- testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
- testing.expect(isSorted(i32, &[_]i32{ -10, 1, 1, 1, 10 }, {}, asc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ -10, 1, 1, 1, 10 }, {}, asc_i32));
- testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32));
- testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));
- testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32));
- testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, desc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, desc_i32));
- testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
- testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, desc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, desc_i32));
- testing.expectEqual(false, isSorted(i32, &[_]i32{ 5, 4, 3, 2, 1 }, {}, asc_i32));
- testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32));
+ try testing.expectEqual(false, isSorted(i32, &[_]i32{ 5, 4, 3, 2, 1 }, {}, asc_i32));
+ try testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32));
- testing.expect(isSorted(u8, "abcd", {}, asc_u8));
- testing.expect(isSorted(u8, "zyxw", {}, desc_u8));
+ try testing.expect(isSorted(u8, "abcd", {}, asc_u8));
+ try testing.expect(isSorted(u8, "zyxw", {}, desc_u8));
- testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));
- testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));
+ try testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));
+ try testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));
- testing.expect(isSorted(u8, "ffff", {}, asc_u8));
- testing.expect(isSorted(u8, "ffff", {}, desc_u8));
+ try testing.expect(isSorted(u8, "ffff", {}, asc_u8));
+ try testing.expect(isSorted(u8, "ffff", {}, desc_u8));
}
diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig
index 29feae830f..db0e107def 100644
--- a/lib/std/special/c.zig
+++ b/lib/std/special/c.zig
@@ -66,7 +66,7 @@ test "strcpy" {
s1[0] = 0;
_ = strcpy(&s1, "foobarbaz");
- std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
+ try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
}
fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8 {
@@ -86,7 +86,7 @@ test "strncpy" {
s1[0] = 0;
_ = strncpy(&s1, "foobarbaz", @sizeOf(@TypeOf(s1)));
- std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
+ try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
}
fn strcat(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 {
@@ -109,7 +109,7 @@ test "strcat" {
_ = strcat(&s1, "foo");
_ = strcat(&s1, "bar");
_ = strcat(&s1, "baz");
- std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
+ try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
}
fn strncat(dest: [*:0]u8, src: [*:0]const u8, avail: usize) callconv(.C) [*:0]u8 {
@@ -132,7 +132,7 @@ test "strncat" {
_ = strncat(&s1, "foo1111", 3);
_ = strncat(&s1, "bar1111", 3);
_ = strncat(&s1, "baz1111", 3);
- std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
+ try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
}
fn strcmp(s1: [*:0]const u8, s2: [*:0]const u8) callconv(.C) c_int {
@@ -161,10 +161,10 @@ fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {
}
test "strncmp" {
- std.testing.expect(strncmp("a", "b", 1) == -1);
- std.testing.expect(strncmp("a", "c", 1) == -2);
- std.testing.expect(strncmp("b", "a", 1) == 1);
- std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
+ try std.testing.expect(strncmp("a", "b", 1) == -1);
+ try std.testing.expect(strncmp("a", "c", 1) == -2);
+ try std.testing.expect(strncmp("b", "a", 1) == 1);
+ try std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
}
// Avoid dragging in the runtime safety mechanisms into this .o file,
@@ -245,9 +245,9 @@ test "memcmp" {
const arr2 = &[_]u8{ 1, 0, 1 };
const arr3 = &[_]u8{ 1, 2, 1 };
- std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
- std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0);
- std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0);
+ try std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
+ try std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0);
+ try std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0);
}
export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) isize {
@@ -269,9 +269,9 @@ test "bcmp" {
const arr2 = &[_]u8{ 1, 0, 1 };
const arr3 = &[_]u8{ 1, 2, 1 };
- std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
- std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0);
- std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);
+ try std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
+ try std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0);
+ try std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);
}
comptime {
@@ -865,19 +865,19 @@ test "fmod, fmodf" {
const nan_val = math.nan(T);
const inf_val = math.inf(T);
- std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));
- std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));
- std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));
- std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));
- std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0)));
+ try std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));
+ try std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));
+ try std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));
+ try std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));
+ try std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0)));
- std.testing.expectEqual(@as(T, 0.0), generic_fmod(T, 0.0, 2.0));
- std.testing.expectEqual(@as(T, -0.0), generic_fmod(T, -0.0, 2.0));
+ try std.testing.expectEqual(@as(T, 0.0), generic_fmod(T, 0.0, 2.0));
+ try std.testing.expectEqual(@as(T, -0.0), generic_fmod(T, -0.0, 2.0));
- std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, 10.0));
- std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, -10.0));
- std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, 10.0));
- std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, -10.0));
+ try std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, 10.0));
+ try std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, -10.0));
+ try std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, 10.0));
+ try std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, -10.0));
}
}
@@ -901,12 +901,12 @@ test "fmin, fminf" {
inline for ([_]type{ f32, f64 }) |T| {
const nan_val = math.nan(T);
- std.testing.expect(isNan(generic_fmin(T, nan_val, nan_val)));
- std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, nan_val, 1.0));
- std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, nan_val));
+ try std.testing.expect(isNan(generic_fmin(T, nan_val, nan_val)));
+ try std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, nan_val, 1.0));
+ try std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, nan_val));
- std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, 10.0));
- std.testing.expectEqual(@as(T, -1.0), generic_fmin(T, 1.0, -1.0));
+ try std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, 10.0));
+ try std.testing.expectEqual(@as(T, -1.0), generic_fmin(T, 1.0, -1.0));
}
}
@@ -930,12 +930,12 @@ test "fmax, fmaxf" {
inline for ([_]type{ f32, f64 }) |T| {
const nan_val = math.nan(T);
- std.testing.expect(isNan(generic_fmax(T, nan_val, nan_val)));
- std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, nan_val, 1.0));
- std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, nan_val));
+ try std.testing.expect(isNan(generic_fmax(T, nan_val, nan_val)));
+ try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, nan_val, 1.0));
+ try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, nan_val));
- std.testing.expectEqual(@as(T, 10.0), generic_fmax(T, 1.0, 10.0));
- std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, -1.0));
+ try std.testing.expectEqual(@as(T, 10.0), generic_fmax(T, 1.0, 10.0));
+ try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, -1.0));
}
}
@@ -1090,15 +1090,15 @@ test "sqrt" {
// Note that @sqrt will either generate the sqrt opcode (if supported by the
// target ISA) or a call to `sqrtf` otherwise.
for (V) |val|
- std.testing.expectEqual(@sqrt(val), sqrt(val));
+ try std.testing.expectEqual(@sqrt(val), sqrt(val));
}
test "sqrt special" {
- std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));
- std.testing.expect(sqrt(0.0) == 0.0);
- std.testing.expect(sqrt(-0.0) == -0.0);
- std.testing.expect(isNan(sqrt(-1.0)));
- std.testing.expect(isNan(sqrt(std.math.nan(f64))));
+ try std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));
+ try std.testing.expect(sqrt(0.0) == 0.0);
+ try std.testing.expect(sqrt(-0.0) == -0.0);
+ try std.testing.expect(isNan(sqrt(-1.0)));
+ try std.testing.expect(isNan(sqrt(std.math.nan(f64))));
}
export fn sqrtf(x: f32) f32 {
@@ -1195,13 +1195,13 @@ test "sqrtf" {
// Note that @sqrt will either generate the sqrt opcode (if supported by the
// target ISA) or a call to `sqrtf` otherwise.
for (V) |val|
- std.testing.expectEqual(@sqrt(val), sqrtf(val));
+ try std.testing.expectEqual(@sqrt(val), sqrtf(val));
}
test "sqrtf special" {
- std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));
- std.testing.expect(sqrtf(0.0) == 0.0);
- std.testing.expect(sqrtf(-0.0) == -0.0);
- std.testing.expect(isNan(sqrtf(-1.0)));
- std.testing.expect(isNan(sqrtf(std.math.nan(f32))));
+ try std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));
+ try std.testing.expect(sqrtf(0.0) == 0.0);
+ try std.testing.expect(sqrtf(-0.0) == -0.0);
+ try std.testing.expect(isNan(sqrtf(-1.0)));
+ try std.testing.expect(isNan(sqrtf(std.math.nan(f32))));
}
diff --git a/lib/std/special/compiler_rt/addXf3_test.zig b/lib/std/special/compiler_rt/addXf3_test.zig
index a8f454384c..33051ed970 100644
--- a/lib/std/special/compiler_rt/addXf3_test.zig
+++ b/lib/std/special/compiler_rt/addXf3_test.zig
@@ -13,7 +13,7 @@ const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);
const __addtf3 = @import("addXf3.zig").__addtf3;
-fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
+fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
const x = __addtf3(a, b);
const rep = @bitCast(u128, x);
@@ -32,28 +32,28 @@ fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
}
}
- @panic("__addtf3 test failure");
+ return error.TestFailed;
}
test "addtf3" {
- test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
+ try test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
// NaN + any = NaN
- test__addtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
+ try test__addtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
// inf + inf = inf
- test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0);
+ try test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0);
// inf + any = inf
- test__addtf3(inf128, 0x1.2335653452436234723489432abcdefp+5, 0x7fff000000000000, 0x0);
+ try test__addtf3(inf128, 0x1.2335653452436234723489432abcdefp+5, 0x7fff000000000000, 0x0);
// any + any
- test__addtf3(0x1.23456734245345543849abcdefp+5, 0x1.edcba52449872455634654321fp-1, 0x40042afc95c8b579, 0x61e58dd6c51eb77c);
+ try test__addtf3(0x1.23456734245345543849abcdefp+5, 0x1.edcba52449872455634654321fp-1, 0x40042afc95c8b579, 0x61e58dd6c51eb77c);
}
const __subtf3 = @import("addXf3.zig").__subtf3;
-fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
+fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
const x = __subtf3(a, b);
const rep = @bitCast(u128, x);
@@ -72,19 +72,19 @@ fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
}
}
- @panic("__subtf3 test failure");
+ return error.TestFailed;
}
test "subtf3" {
// qNaN - any = qNaN
- test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
+ try test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
// NaN + any = NaN
- test__subtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
+ try test__subtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
// inf - any = inf
- test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
+ try test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
// any + any
- test__subtf3(0x1.234567829a3bcdef5678ade36734p+5, 0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x40041b8af1915166, 0xa44a7bca780a166c);
+ try test__subtf3(0x1.234567829a3bcdef5678ade36734p+5, 0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x40041b8af1915166, 0xa44a7bca780a166c);
}
diff --git a/lib/std/special/compiler_rt/ashldi3_test.zig b/lib/std/special/compiler_rt/ashldi3_test.zig
index dfc3712e39..4b1eb1f9e4 100644
--- a/lib/std/special/compiler_rt/ashldi3_test.zig
+++ b/lib/std/special/compiler_rt/ashldi3_test.zig
@@ -6,32 +6,32 @@
const __ashldi3 = @import("shift.zig").__ashldi3;
const testing = @import("std").testing;
-fn test__ashldi3(a: i64, b: i32, expected: u64) void {
+fn test__ashldi3(a: i64, b: i32, expected: u64) !void {
const x = __ashldi3(a, b);
- testing.expectEqual(@bitCast(i64, expected), x);
+ try testing.expectEqual(@bitCast(i64, expected), x);
}
test "ashldi3" {
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);
- test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);
}
diff --git a/lib/std/special/compiler_rt/ashlti3_test.zig b/lib/std/special/compiler_rt/ashlti3_test.zig
index 453fa9e77b..1187120457 100644
--- a/lib/std/special/compiler_rt/ashlti3_test.zig
+++ b/lib/std/special/compiler_rt/ashlti3_test.zig
@@ -6,46 +6,46 @@
const __ashlti3 = @import("shift.zig").__ashlti3;
const testing = @import("std").testing;
-fn test__ashlti3(a: i128, b: i32, expected: i128) void {
+fn test__ashlti3(a: i128, b: i32, expected: i128) !void {
const x = __ashlti3(a, b);
- testing.expectEqual(expected, x);
+ try testing.expectEqual(expected, x);
}
test "ashlti3" {
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642BFDB97530ECA8642A)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C857FB72EA61D950C854)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xEDCBA9876543215FEDCBA98765432150)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x876543215FEDCBA98765432150000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x0ECA8642BFDB97530ECA8642A0000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x1D950C857FB72EA61D950C8540000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x3B2A190AFF6E5D4C3B2A190A80000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x76543215FEDCBA987654321500000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xECA8642BFDB97530ECA8642A00000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xD950C857FB72EA61D950C85400000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xB2A190AFF6E5D4C3B2A190A800000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x6543215FEDCBA9876543215000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x5FEDCBA9876543215000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xBFDB97530ECA8642A000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x7FB72EA61D950C854000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190A8000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFEDCBA98765432150000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642A0000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C8540000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190A80000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xEDCBA987654321500000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x87654321500000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x0ECA8642A00000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x1D950C85400000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x3B2A190A800000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x76543215000000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xECA8642A000000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xD950C854000000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xB2A190A8000000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x65432150000000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x50000000000000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xA0000000000000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x40000000000000000000000000000000)));
- test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x80000000000000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642BFDB97530ECA8642A)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C857FB72EA61D950C854)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xEDCBA9876543215FEDCBA98765432150)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x876543215FEDCBA98765432150000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x0ECA8642BFDB97530ECA8642A0000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x1D950C857FB72EA61D950C8540000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x3B2A190AFF6E5D4C3B2A190A80000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x76543215FEDCBA987654321500000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xECA8642BFDB97530ECA8642A00000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xD950C857FB72EA61D950C85400000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xB2A190AFF6E5D4C3B2A190A800000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x6543215FEDCBA9876543215000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x5FEDCBA9876543215000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xBFDB97530ECA8642A000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x7FB72EA61D950C854000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190A8000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFEDCBA98765432150000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642A0000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C8540000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190A80000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xEDCBA987654321500000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x87654321500000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x0ECA8642A00000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x1D950C85400000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x3B2A190A800000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x76543215000000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xECA8642A000000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xD950C854000000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xB2A190A8000000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x65432150000000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x50000000000000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xA0000000000000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x40000000000000000000000000000000)));
+ try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x80000000000000000000000000000000)));
}
diff --git a/lib/std/special/compiler_rt/ashrdi3_test.zig b/lib/std/special/compiler_rt/ashrdi3_test.zig
index 77fe286185..423c22fc12 100644
--- a/lib/std/special/compiler_rt/ashrdi3_test.zig
+++ b/lib/std/special/compiler_rt/ashrdi3_test.zig
@@ -6,55 +6,55 @@
const __ashrdi3 = @import("shift.zig").__ashrdi3;
const testing = @import("std").testing;
-fn test__ashrdi3(a: i64, b: i32, expected: u64) void {
+fn test__ashrdi3(a: i64, b: i32, expected: u64) !void {
const x = __ashrdi3(a, b);
- testing.expectEqual(@bitCast(i64, expected), x);
+ try testing.expectEqual(@bitCast(i64, expected), x);
}
test "ashrdi3" {
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
- test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);
- test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);
}
diff --git a/lib/std/special/compiler_rt/ashrti3_test.zig b/lib/std/special/compiler_rt/ashrti3_test.zig
index 5f4e166001..e6d1d7ddba 100644
--- a/lib/std/special/compiler_rt/ashrti3_test.zig
+++ b/lib/std/special/compiler_rt/ashrti3_test.zig
@@ -6,56 +6,56 @@
const __ashrti3 = @import("shift.zig").__ashrti3;
const testing = @import("std").testing;
-fn test__ashrti3(a: i128, b: i32, expected: i128) void {
+fn test__ashrti3(a: i128, b: i32, expected: i128) !void {
const x = __ashrti3(a, b);
- testing.expectEqual(expected, x);
+ try testing.expectEqual(expected, x);
}
test "ashrti3" {
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFFB72EA61D950C857FB72EA61D950C85)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xFFDB97530ECA8642BFDB97530ECA8642)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xFFEDCBA9876543215FEDCBA987654321)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFFB72EA61D950C857FB72EA61D950C85)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xFFDB97530ECA8642BFDB97530ECA8642)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xFFEDCBA9876543215FEDCBA987654321)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0xFFFFFFFFEDCBA9876543215FEDCBA987)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFB72EA61D950C857FB72EA61)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFDB97530ECA8642BFDB97530)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0xFFFFFFFFEDCBA9876543215FEDCBA987)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFB72EA61D950C857FB72EA61)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFDB97530ECA8642BFDB97530)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFEDCBA9876543215FEDCBA98)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFEDCBA9876543215FEDCBA98)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFB72EA61D950C857FB72EA6)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFDB97530ECA8642BFDB9753)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFB72EA61D950C857FB72EA6)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFDB97530ECA8642BFDB9753)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
- test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
+ try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
}
diff --git a/lib/std/special/compiler_rt/clzsi2_test.zig b/lib/std/special/compiler_rt/clzsi2_test.zig
index c74a1c3ec2..b7828cf632 100644
--- a/lib/std/special/compiler_rt/clzsi2_test.zig
+++ b/lib/std/special/compiler_rt/clzsi2_test.zig
@@ -6,294 +6,294 @@
const clzsi2 = @import("clzsi2.zig");
const testing = @import("std").testing;
-fn test__clzsi2(a: u32, expected: i32) void {
+fn test__clzsi2(a: u32, expected: i32) !void {
// XXX At high optimization levels this test may be horribly miscompiled if
// one of the naked implementations is selected.
var nakedClzsi2 = clzsi2.__clzsi2;
var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2);
var x = @bitCast(i32, a);
var result = actualClzsi2(x);
- testing.expectEqual(expected, result);
+ try testing.expectEqual(expected, result);
}
test "clzsi2" {
- test__clzsi2(0x00800000, 8);
- test__clzsi2(0x01000000, 7);
- test__clzsi2(0x02000000, 6);
- test__clzsi2(0x03000000, 6);
- test__clzsi2(0x04000000, 5);
- test__clzsi2(0x05000000, 5);
- test__clzsi2(0x06000000, 5);
- test__clzsi2(0x07000000, 5);
- test__clzsi2(0x08000000, 4);
- test__clzsi2(0x09000000, 4);
- test__clzsi2(0x0A000000, 4);
- test__clzsi2(0x0B000000, 4);
- test__clzsi2(0x0C000000, 4);
- test__clzsi2(0x0D000000, 4);
- test__clzsi2(0x0E000000, 4);
- test__clzsi2(0x0F000000, 4);
- test__clzsi2(0x10000000, 3);
- test__clzsi2(0x11000000, 3);
- test__clzsi2(0x12000000, 3);
- test__clzsi2(0x13000000, 3);
- test__clzsi2(0x14000000, 3);
- test__clzsi2(0x15000000, 3);
- test__clzsi2(0x16000000, 3);
- test__clzsi2(0x17000000, 3);
- test__clzsi2(0x18000000, 3);
- test__clzsi2(0x19000000, 3);
- test__clzsi2(0x1A000000, 3);
- test__clzsi2(0x1B000000, 3);
- test__clzsi2(0x1C000000, 3);
- test__clzsi2(0x1D000000, 3);
- test__clzsi2(0x1E000000, 3);
- test__clzsi2(0x1F000000, 3);
- test__clzsi2(0x20000000, 2);
- test__clzsi2(0x21000000, 2);
- test__clzsi2(0x22000000, 2);
- test__clzsi2(0x23000000, 2);
- test__clzsi2(0x24000000, 2);
- test__clzsi2(0x25000000, 2);
- test__clzsi2(0x26000000, 2);
- test__clzsi2(0x27000000, 2);
- test__clzsi2(0x28000000, 2);
- test__clzsi2(0x29000000, 2);
- test__clzsi2(0x2A000000, 2);
- test__clzsi2(0x2B000000, 2);
- test__clzsi2(0x2C000000, 2);
- test__clzsi2(0x2D000000, 2);
- test__clzsi2(0x2E000000, 2);
- test__clzsi2(0x2F000000, 2);
- test__clzsi2(0x30000000, 2);
- test__clzsi2(0x31000000, 2);
- test__clzsi2(0x32000000, 2);
- test__clzsi2(0x33000000, 2);
- test__clzsi2(0x34000000, 2);
- test__clzsi2(0x35000000, 2);
- test__clzsi2(0x36000000, 2);
- test__clzsi2(0x37000000, 2);
- test__clzsi2(0x38000000, 2);
- test__clzsi2(0x39000000, 2);
- test__clzsi2(0x3A000000, 2);
- test__clzsi2(0x3B000000, 2);
- test__clzsi2(0x3C000000, 2);
- test__clzsi2(0x3D000000, 2);
- test__clzsi2(0x3E000000, 2);
- test__clzsi2(0x3F000000, 2);
- test__clzsi2(0x40000000, 1);
- test__clzsi2(0x41000000, 1);
- test__clzsi2(0x42000000, 1);
- test__clzsi2(0x43000000, 1);
- test__clzsi2(0x44000000, 1);
- test__clzsi2(0x45000000, 1);
- test__clzsi2(0x46000000, 1);
- test__clzsi2(0x47000000, 1);
- test__clzsi2(0x48000000, 1);
- test__clzsi2(0x49000000, 1);
- test__clzsi2(0x4A000000, 1);
- test__clzsi2(0x4B000000, 1);
- test__clzsi2(0x4C000000, 1);
- test__clzsi2(0x4D000000, 1);
- test__clzsi2(0x4E000000, 1);
- test__clzsi2(0x4F000000, 1);
- test__clzsi2(0x50000000, 1);
- test__clzsi2(0x51000000, 1);
- test__clzsi2(0x52000000, 1);
- test__clzsi2(0x53000000, 1);
- test__clzsi2(0x54000000, 1);
- test__clzsi2(0x55000000, 1);
- test__clzsi2(0x56000000, 1);
- test__clzsi2(0x57000000, 1);
- test__clzsi2(0x58000000, 1);
- test__clzsi2(0x59000000, 1);
- test__clzsi2(0x5A000000, 1);
- test__clzsi2(0x5B000000, 1);
- test__clzsi2(0x5C000000, 1);
- test__clzsi2(0x5D000000, 1);
- test__clzsi2(0x5E000000, 1);
- test__clzsi2(0x5F000000, 1);
- test__clzsi2(0x60000000, 1);
- test__clzsi2(0x61000000, 1);
- test__clzsi2(0x62000000, 1);
- test__clzsi2(0x63000000, 1);
- test__clzsi2(0x64000000, 1);
- test__clzsi2(0x65000000, 1);
- test__clzsi2(0x66000000, 1);
- test__clzsi2(0x67000000, 1);
- test__clzsi2(0x68000000, 1);
- test__clzsi2(0x69000000, 1);
- test__clzsi2(0x6A000000, 1);
- test__clzsi2(0x6B000000, 1);
- test__clzsi2(0x6C000000, 1);
- test__clzsi2(0x6D000000, 1);
- test__clzsi2(0x6E000000, 1);
- test__clzsi2(0x6F000000, 1);
- test__clzsi2(0x70000000, 1);
- test__clzsi2(0x71000000, 1);
- test__clzsi2(0x72000000, 1);
- test__clzsi2(0x73000000, 1);
- test__clzsi2(0x74000000, 1);
- test__clzsi2(0x75000000, 1);
- test__clzsi2(0x76000000, 1);
- test__clzsi2(0x77000000, 1);
- test__clzsi2(0x78000000, 1);
- test__clzsi2(0x79000000, 1);
- test__clzsi2(0x7A000000, 1);
- test__clzsi2(0x7B000000, 1);
- test__clzsi2(0x7C000000, 1);
- test__clzsi2(0x7D000000, 1);
- test__clzsi2(0x7E000000, 1);
- test__clzsi2(0x7F000000, 1);
- test__clzsi2(0x80000000, 0);
- test__clzsi2(0x81000000, 0);
- test__clzsi2(0x82000000, 0);
- test__clzsi2(0x83000000, 0);
- test__clzsi2(0x84000000, 0);
- test__clzsi2(0x85000000, 0);
- test__clzsi2(0x86000000, 0);
- test__clzsi2(0x87000000, 0);
- test__clzsi2(0x88000000, 0);
- test__clzsi2(0x89000000, 0);
- test__clzsi2(0x8A000000, 0);
- test__clzsi2(0x8B000000, 0);
- test__clzsi2(0x8C000000, 0);
- test__clzsi2(0x8D000000, 0);
- test__clzsi2(0x8E000000, 0);
- test__clzsi2(0x8F000000, 0);
- test__clzsi2(0x90000000, 0);
- test__clzsi2(0x91000000, 0);
- test__clzsi2(0x92000000, 0);
- test__clzsi2(0x93000000, 0);
- test__clzsi2(0x94000000, 0);
- test__clzsi2(0x95000000, 0);
- test__clzsi2(0x96000000, 0);
- test__clzsi2(0x97000000, 0);
- test__clzsi2(0x98000000, 0);
- test__clzsi2(0x99000000, 0);
- test__clzsi2(0x9A000000, 0);
- test__clzsi2(0x9B000000, 0);
- test__clzsi2(0x9C000000, 0);
- test__clzsi2(0x9D000000, 0);
- test__clzsi2(0x9E000000, 0);
- test__clzsi2(0x9F000000, 0);
- test__clzsi2(0xA0000000, 0);
- test__clzsi2(0xA1000000, 0);
- test__clzsi2(0xA2000000, 0);
- test__clzsi2(0xA3000000, 0);
- test__clzsi2(0xA4000000, 0);
- test__clzsi2(0xA5000000, 0);
- test__clzsi2(0xA6000000, 0);
- test__clzsi2(0xA7000000, 0);
- test__clzsi2(0xA8000000, 0);
- test__clzsi2(0xA9000000, 0);
- test__clzsi2(0xAA000000, 0);
- test__clzsi2(0xAB000000, 0);
- test__clzsi2(0xAC000000, 0);
- test__clzsi2(0xAD000000, 0);
- test__clzsi2(0xAE000000, 0);
- test__clzsi2(0xAF000000, 0);
- test__clzsi2(0xB0000000, 0);
- test__clzsi2(0xB1000000, 0);
- test__clzsi2(0xB2000000, 0);
- test__clzsi2(0xB3000000, 0);
- test__clzsi2(0xB4000000, 0);
- test__clzsi2(0xB5000000, 0);
- test__clzsi2(0xB6000000, 0);
- test__clzsi2(0xB7000000, 0);
- test__clzsi2(0xB8000000, 0);
- test__clzsi2(0xB9000000, 0);
- test__clzsi2(0xBA000000, 0);
- test__clzsi2(0xBB000000, 0);
- test__clzsi2(0xBC000000, 0);
- test__clzsi2(0xBD000000, 0);
- test__clzsi2(0xBE000000, 0);
- test__clzsi2(0xBF000000, 0);
- test__clzsi2(0xC0000000, 0);
- test__clzsi2(0xC1000000, 0);
- test__clzsi2(0xC2000000, 0);
- test__clzsi2(0xC3000000, 0);
- test__clzsi2(0xC4000000, 0);
- test__clzsi2(0xC5000000, 0);
- test__clzsi2(0xC6000000, 0);
- test__clzsi2(0xC7000000, 0);
- test__clzsi2(0xC8000000, 0);
- test__clzsi2(0xC9000000, 0);
- test__clzsi2(0xCA000000, 0);
- test__clzsi2(0xCB000000, 0);
- test__clzsi2(0xCC000000, 0);
- test__clzsi2(0xCD000000, 0);
- test__clzsi2(0xCE000000, 0);
- test__clzsi2(0xCF000000, 0);
- test__clzsi2(0xD0000000, 0);
- test__clzsi2(0xD1000000, 0);
- test__clzsi2(0xD2000000, 0);
- test__clzsi2(0xD3000000, 0);
- test__clzsi2(0xD4000000, 0);
- test__clzsi2(0xD5000000, 0);
- test__clzsi2(0xD6000000, 0);
- test__clzsi2(0xD7000000, 0);
- test__clzsi2(0xD8000000, 0);
- test__clzsi2(0xD9000000, 0);
- test__clzsi2(0xDA000000, 0);
- test__clzsi2(0xDB000000, 0);
- test__clzsi2(0xDC000000, 0);
- test__clzsi2(0xDD000000, 0);
- test__clzsi2(0xDE000000, 0);
- test__clzsi2(0xDF000000, 0);
- test__clzsi2(0xE0000000, 0);
- test__clzsi2(0xE1000000, 0);
- test__clzsi2(0xE2000000, 0);
- test__clzsi2(0xE3000000, 0);
- test__clzsi2(0xE4000000, 0);
- test__clzsi2(0xE5000000, 0);
- test__clzsi2(0xE6000000, 0);
- test__clzsi2(0xE7000000, 0);
- test__clzsi2(0xE8000000, 0);
- test__clzsi2(0xE9000000, 0);
- test__clzsi2(0xEA000000, 0);
- test__clzsi2(0xEB000000, 0);
- test__clzsi2(0xEC000000, 0);
- test__clzsi2(0xED000000, 0);
- test__clzsi2(0xEE000000, 0);
- test__clzsi2(0xEF000000, 0);
- test__clzsi2(0xF0000000, 0);
- test__clzsi2(0xF1000000, 0);
- test__clzsi2(0xF2000000, 0);
- test__clzsi2(0xF3000000, 0);
- test__clzsi2(0xF4000000, 0);
- test__clzsi2(0xF5000000, 0);
- test__clzsi2(0xF6000000, 0);
- test__clzsi2(0xF7000000, 0);
- test__clzsi2(0xF8000000, 0);
- test__clzsi2(0xF9000000, 0);
- test__clzsi2(0xFA000000, 0);
- test__clzsi2(0xFB000000, 0);
- test__clzsi2(0xFC000000, 0);
- test__clzsi2(0xFD000000, 0);
- test__clzsi2(0xFE000000, 0);
- test__clzsi2(0xFF000000, 0);
- test__clzsi2(0x00000001, 31);
- test__clzsi2(0x00000002, 30);
- test__clzsi2(0x00000004, 29);
- test__clzsi2(0x00000008, 28);
- test__clzsi2(0x00000010, 27);
- test__clzsi2(0x00000020, 26);
- test__clzsi2(0x00000040, 25);
- test__clzsi2(0x00000080, 24);
- test__clzsi2(0x00000100, 23);
- test__clzsi2(0x00000200, 22);
- test__clzsi2(0x00000400, 21);
- test__clzsi2(0x00000800, 20);
- test__clzsi2(0x00001000, 19);
- test__clzsi2(0x00002000, 18);
- test__clzsi2(0x00004000, 17);
- test__clzsi2(0x00008000, 16);
- test__clzsi2(0x00010000, 15);
- test__clzsi2(0x00020000, 14);
- test__clzsi2(0x00040000, 13);
- test__clzsi2(0x00080000, 12);
- test__clzsi2(0x00100000, 11);
- test__clzsi2(0x00200000, 10);
- test__clzsi2(0x00400000, 9);
+ try test__clzsi2(0x00800000, 8);
+ try test__clzsi2(0x01000000, 7);
+ try test__clzsi2(0x02000000, 6);
+ try test__clzsi2(0x03000000, 6);
+ try test__clzsi2(0x04000000, 5);
+ try test__clzsi2(0x05000000, 5);
+ try test__clzsi2(0x06000000, 5);
+ try test__clzsi2(0x07000000, 5);
+ try test__clzsi2(0x08000000, 4);
+ try test__clzsi2(0x09000000, 4);
+ try test__clzsi2(0x0A000000, 4);
+ try test__clzsi2(0x0B000000, 4);
+ try test__clzsi2(0x0C000000, 4);
+ try test__clzsi2(0x0D000000, 4);
+ try test__clzsi2(0x0E000000, 4);
+ try test__clzsi2(0x0F000000, 4);
+ try test__clzsi2(0x10000000, 3);
+ try test__clzsi2(0x11000000, 3);
+ try test__clzsi2(0x12000000, 3);
+ try test__clzsi2(0x13000000, 3);
+ try test__clzsi2(0x14000000, 3);
+ try test__clzsi2(0x15000000, 3);
+ try test__clzsi2(0x16000000, 3);
+ try test__clzsi2(0x17000000, 3);
+ try test__clzsi2(0x18000000, 3);
+ try test__clzsi2(0x19000000, 3);
+ try test__clzsi2(0x1A000000, 3);
+ try test__clzsi2(0x1B000000, 3);
+ try test__clzsi2(0x1C000000, 3);
+ try test__clzsi2(0x1D000000, 3);
+ try test__clzsi2(0x1E000000, 3);
+ try test__clzsi2(0x1F000000, 3);
+ try test__clzsi2(0x20000000, 2);
+ try test__clzsi2(0x21000000, 2);
+ try test__clzsi2(0x22000000, 2);
+ try test__clzsi2(0x23000000, 2);
+ try test__clzsi2(0x24000000, 2);
+ try test__clzsi2(0x25000000, 2);
+ try test__clzsi2(0x26000000, 2);
+ try test__clzsi2(0x27000000, 2);
+ try test__clzsi2(0x28000000, 2);
+ try test__clzsi2(0x29000000, 2);
+ try test__clzsi2(0x2A000000, 2);
+ try test__clzsi2(0x2B000000, 2);
+ try test__clzsi2(0x2C000000, 2);
+ try test__clzsi2(0x2D000000, 2);
+ try test__clzsi2(0x2E000000, 2);
+ try test__clzsi2(0x2F000000, 2);
+ try test__clzsi2(0x30000000, 2);
+ try test__clzsi2(0x31000000, 2);
+ try test__clzsi2(0x32000000, 2);
+ try test__clzsi2(0x33000000, 2);
+ try test__clzsi2(0x34000000, 2);
+ try test__clzsi2(0x35000000, 2);
+ try test__clzsi2(0x36000000, 2);
+ try test__clzsi2(0x37000000, 2);
+ try test__clzsi2(0x38000000, 2);
+ try test__clzsi2(0x39000000, 2);
+ try test__clzsi2(0x3A000000, 2);
+ try test__clzsi2(0x3B000000, 2);
+ try test__clzsi2(0x3C000000, 2);
+ try test__clzsi2(0x3D000000, 2);
+ try test__clzsi2(0x3E000000, 2);
+ try test__clzsi2(0x3F000000, 2);
+ try test__clzsi2(0x40000000, 1);
+ try test__clzsi2(0x41000000, 1);
+ try test__clzsi2(0x42000000, 1);
+ try test__clzsi2(0x43000000, 1);
+ try test__clzsi2(0x44000000, 1);
+ try test__clzsi2(0x45000000, 1);
+ try test__clzsi2(0x46000000, 1);
+ try test__clzsi2(0x47000000, 1);
+ try test__clzsi2(0x48000000, 1);
+ try test__clzsi2(0x49000000, 1);
+ try test__clzsi2(0x4A000000, 1);
+ try test__clzsi2(0x4B000000, 1);
+ try test__clzsi2(0x4C000000, 1);
+ try test__clzsi2(0x4D000000, 1);
+ try test__clzsi2(0x4E000000, 1);
+ try test__clzsi2(0x4F000000, 1);
+ try test__clzsi2(0x50000000, 1);
+ try test__clzsi2(0x51000000, 1);
+ try test__clzsi2(0x52000000, 1);
+ try test__clzsi2(0x53000000, 1);
+ try test__clzsi2(0x54000000, 1);
+ try test__clzsi2(0x55000000, 1);
+ try test__clzsi2(0x56000000, 1);
+ try test__clzsi2(0x57000000, 1);
+ try test__clzsi2(0x58000000, 1);
+ try test__clzsi2(0x59000000, 1);
+ try test__clzsi2(0x5A000000, 1);
+ try test__clzsi2(0x5B000000, 1);
+ try test__clzsi2(0x5C000000, 1);
+ try test__clzsi2(0x5D000000, 1);
+ try test__clzsi2(0x5E000000, 1);
+ try test__clzsi2(0x5F000000, 1);
+ try test__clzsi2(0x60000000, 1);
+ try test__clzsi2(0x61000000, 1);
+ try test__clzsi2(0x62000000, 1);
+ try test__clzsi2(0x63000000, 1);
+ try test__clzsi2(0x64000000, 1);
+ try test__clzsi2(0x65000000, 1);
+ try test__clzsi2(0x66000000, 1);
+ try test__clzsi2(0x67000000, 1);
+ try test__clzsi2(0x68000000, 1);
+ try test__clzsi2(0x69000000, 1);
+ try test__clzsi2(0x6A000000, 1);
+ try test__clzsi2(0x6B000000, 1);
+ try test__clzsi2(0x6C000000, 1);
+ try test__clzsi2(0x6D000000, 1);
+ try test__clzsi2(0x6E000000, 1);
+ try test__clzsi2(0x6F000000, 1);
+ try test__clzsi2(0x70000000, 1);
+ try test__clzsi2(0x71000000, 1);
+ try test__clzsi2(0x72000000, 1);
+ try test__clzsi2(0x73000000, 1);
+ try test__clzsi2(0x74000000, 1);
+ try test__clzsi2(0x75000000, 1);
+ try test__clzsi2(0x76000000, 1);
+ try test__clzsi2(0x77000000, 1);
+ try test__clzsi2(0x78000000, 1);
+ try test__clzsi2(0x79000000, 1);
+ try test__clzsi2(0x7A000000, 1);
+ try test__clzsi2(0x7B000000, 1);
+ try test__clzsi2(0x7C000000, 1);
+ try test__clzsi2(0x7D000000, 1);
+ try test__clzsi2(0x7E000000, 1);
+ try test__clzsi2(0x7F000000, 1);
+ try test__clzsi2(0x80000000, 0);
+ try test__clzsi2(0x81000000, 0);
+ try test__clzsi2(0x82000000, 0);
+ try test__clzsi2(0x83000000, 0);
+ try test__clzsi2(0x84000000, 0);
+ try test__clzsi2(0x85000000, 0);
+ try test__clzsi2(0x86000000, 0);
+ try test__clzsi2(0x87000000, 0);
+ try test__clzsi2(0x88000000, 0);
+ try test__clzsi2(0x89000000, 0);
+ try test__clzsi2(0x8A000000, 0);
+ try test__clzsi2(0x8B000000, 0);
+ try test__clzsi2(0x8C000000, 0);
+ try test__clzsi2(0x8D000000, 0);
+ try test__clzsi2(0x8E000000, 0);
+ try test__clzsi2(0x8F000000, 0);
+ try test__clzsi2(0x90000000, 0);
+ try test__clzsi2(0x91000000, 0);
+ try test__clzsi2(0x92000000, 0);
+ try test__clzsi2(0x93000000, 0);
+ try test__clzsi2(0x94000000, 0);
+ try test__clzsi2(0x95000000, 0);
+ try test__clzsi2(0x96000000, 0);
+ try test__clzsi2(0x97000000, 0);
+ try test__clzsi2(0x98000000, 0);
+ try test__clzsi2(0x99000000, 0);
+ try test__clzsi2(0x9A000000, 0);
+ try test__clzsi2(0x9B000000, 0);
+ try test__clzsi2(0x9C000000, 0);
+ try test__clzsi2(0x9D000000, 0);
+ try test__clzsi2(0x9E000000, 0);
+ try test__clzsi2(0x9F000000, 0);
+ try test__clzsi2(0xA0000000, 0);
+ try test__clzsi2(0xA1000000, 0);
+ try test__clzsi2(0xA2000000, 0);
+ try test__clzsi2(0xA3000000, 0);
+ try test__clzsi2(0xA4000000, 0);
+ try test__clzsi2(0xA5000000, 0);
+ try test__clzsi2(0xA6000000, 0);
+ try test__clzsi2(0xA7000000, 0);
+ try test__clzsi2(0xA8000000, 0);
+ try test__clzsi2(0xA9000000, 0);
+ try test__clzsi2(0xAA000000, 0);
+ try test__clzsi2(0xAB000000, 0);
+ try test__clzsi2(0xAC000000, 0);
+ try test__clzsi2(0xAD000000, 0);
+ try test__clzsi2(0xAE000000, 0);
+ try test__clzsi2(0xAF000000, 0);
+ try test__clzsi2(0xB0000000, 0);
+ try test__clzsi2(0xB1000000, 0);
+ try test__clzsi2(0xB2000000, 0);
+ try test__clzsi2(0xB3000000, 0);
+ try test__clzsi2(0xB4000000, 0);
+ try test__clzsi2(0xB5000000, 0);
+ try test__clzsi2(0xB6000000, 0);
+ try test__clzsi2(0xB7000000, 0);
+ try test__clzsi2(0xB8000000, 0);
+ try test__clzsi2(0xB9000000, 0);
+ try test__clzsi2(0xBA000000, 0);
+ try test__clzsi2(0xBB000000, 0);
+ try test__clzsi2(0xBC000000, 0);
+ try test__clzsi2(0xBD000000, 0);
+ try test__clzsi2(0xBE000000, 0);
+ try test__clzsi2(0xBF000000, 0);
+ try test__clzsi2(0xC0000000, 0);
+ try test__clzsi2(0xC1000000, 0);
+ try test__clzsi2(0xC2000000, 0);
+ try test__clzsi2(0xC3000000, 0);
+ try test__clzsi2(0xC4000000, 0);
+ try test__clzsi2(0xC5000000, 0);
+ try test__clzsi2(0xC6000000, 0);
+ try test__clzsi2(0xC7000000, 0);
+ try test__clzsi2(0xC8000000, 0);
+ try test__clzsi2(0xC9000000, 0);
+ try test__clzsi2(0xCA000000, 0);
+ try test__clzsi2(0xCB000000, 0);
+ try test__clzsi2(0xCC000000, 0);
+ try test__clzsi2(0xCD000000, 0);
+ try test__clzsi2(0xCE000000, 0);
+ try test__clzsi2(0xCF000000, 0);
+ try test__clzsi2(0xD0000000, 0);
+ try test__clzsi2(0xD1000000, 0);
+ try test__clzsi2(0xD2000000, 0);
+ try test__clzsi2(0xD3000000, 0);
+ try test__clzsi2(0xD4000000, 0);
+ try test__clzsi2(0xD5000000, 0);
+ try test__clzsi2(0xD6000000, 0);
+ try test__clzsi2(0xD7000000, 0);
+ try test__clzsi2(0xD8000000, 0);
+ try test__clzsi2(0xD9000000, 0);
+ try test__clzsi2(0xDA000000, 0);
+ try test__clzsi2(0xDB000000, 0);
+ try test__clzsi2(0xDC000000, 0);
+ try test__clzsi2(0xDD000000, 0);
+ try test__clzsi2(0xDE000000, 0);
+ try test__clzsi2(0xDF000000, 0);
+ try test__clzsi2(0xE0000000, 0);
+ try test__clzsi2(0xE1000000, 0);
+ try test__clzsi2(0xE2000000, 0);
+ try test__clzsi2(0xE3000000, 0);
+ try test__clzsi2(0xE4000000, 0);
+ try test__clzsi2(0xE5000000, 0);
+ try test__clzsi2(0xE6000000, 0);
+ try test__clzsi2(0xE7000000, 0);
+ try test__clzsi2(0xE8000000, 0);
+ try test__clzsi2(0xE9000000, 0);
+ try test__clzsi2(0xEA000000, 0);
+ try test__clzsi2(0xEB000000, 0);
+ try test__clzsi2(0xEC000000, 0);
+ try test__clzsi2(0xED000000, 0);
+ try test__clzsi2(0xEE000000, 0);
+ try test__clzsi2(0xEF000000, 0);
+ try test__clzsi2(0xF0000000, 0);
+ try test__clzsi2(0xF1000000, 0);
+ try test__clzsi2(0xF2000000, 0);
+ try test__clzsi2(0xF3000000, 0);
+ try test__clzsi2(0xF4000000, 0);
+ try test__clzsi2(0xF5000000, 0);
+ try test__clzsi2(0xF6000000, 0);
+ try test__clzsi2(0xF7000000, 0);
+ try test__clzsi2(0xF8000000, 0);
+ try test__clzsi2(0xF9000000, 0);
+ try test__clzsi2(0xFA000000, 0);
+ try test__clzsi2(0xFB000000, 0);
+ try test__clzsi2(0xFC000000, 0);
+ try test__clzsi2(0xFD000000, 0);
+ try test__clzsi2(0xFE000000, 0);
+ try test__clzsi2(0xFF000000, 0);
+ try test__clzsi2(0x00000001, 31);
+ try test__clzsi2(0x00000002, 30);
+ try test__clzsi2(0x00000004, 29);
+ try test__clzsi2(0x00000008, 28);
+ try test__clzsi2(0x00000010, 27);
+ try test__clzsi2(0x00000020, 26);
+ try test__clzsi2(0x00000040, 25);
+ try test__clzsi2(0x00000080, 24);
+ try test__clzsi2(0x00000100, 23);
+ try test__clzsi2(0x00000200, 22);
+ try test__clzsi2(0x00000400, 21);
+ try test__clzsi2(0x00000800, 20);
+ try test__clzsi2(0x00001000, 19);
+ try test__clzsi2(0x00002000, 18);
+ try test__clzsi2(0x00004000, 17);
+ try test__clzsi2(0x00008000, 16);
+ try test__clzsi2(0x00010000, 15);
+ try test__clzsi2(0x00020000, 14);
+ try test__clzsi2(0x00040000, 13);
+ try test__clzsi2(0x00080000, 12);
+ try test__clzsi2(0x00100000, 11);
+ try test__clzsi2(0x00200000, 10);
+ try test__clzsi2(0x00400000, 9);
}
diff --git a/lib/std/special/compiler_rt/comparedf2_test.zig b/lib/std/special/compiler_rt/comparedf2_test.zig
index f5e8cfe372..b0916c10ae 100644
--- a/lib/std/special/compiler_rt/comparedf2_test.zig
+++ b/lib/std/special/compiler_rt/comparedf2_test.zig
@@ -101,6 +101,6 @@ const test_vectors = init: {
test "compare f64" {
for (test_vectors) |vector, i| {
- std.testing.expect(test__cmpdf2(vector));
+ try std.testing.expect(test__cmpdf2(vector));
}
}
diff --git a/lib/std/special/compiler_rt/comparesf2_test.zig b/lib/std/special/compiler_rt/comparesf2_test.zig
index 0a1f5e74f6..9719873f62 100644
--- a/lib/std/special/compiler_rt/comparesf2_test.zig
+++ b/lib/std/special/compiler_rt/comparesf2_test.zig
@@ -101,6 +101,6 @@ const test_vectors = init: {
test "compare f32" {
for (test_vectors) |vector, i| {
- std.testing.expect(test__cmpsf2(vector));
+ try std.testing.expect(test__cmpsf2(vector));
}
}
diff --git a/lib/std/special/compiler_rt/divdf3_test.zig b/lib/std/special/compiler_rt/divdf3_test.zig
index 8bdecc7c6a..a472b5ed08 100644
--- a/lib/std/special/compiler_rt/divdf3_test.zig
+++ b/lib/std/special/compiler_rt/divdf3_test.zig
@@ -27,13 +27,13 @@ fn compareResultD(result: f64, expected: u64) bool {
return false;
}
-fn test__divdf3(a: f64, b: f64, expected: u64) void {
+fn test__divdf3(a: f64, b: f64, expected: u64) !void {
const x = __divdf3(a, b);
const ret = compareResultD(x, expected);
- testing.expect(ret == true);
+ try testing.expect(ret == true);
}
test "divdf3" {
- test__divdf3(1.0, 3.0, 0x3fd5555555555555);
- test__divdf3(4.450147717014403e-308, 2.0, 0x10000000000000);
+ try test__divdf3(1.0, 3.0, 0x3fd5555555555555);
+ try test__divdf3(4.450147717014403e-308, 2.0, 0x10000000000000);
}
diff --git a/lib/std/special/compiler_rt/divsf3_test.zig b/lib/std/special/compiler_rt/divsf3_test.zig
index a14e8e9163..97f34d34a5 100644
--- a/lib/std/special/compiler_rt/divsf3_test.zig
+++ b/lib/std/special/compiler_rt/divsf3_test.zig
@@ -27,13 +27,13 @@ fn compareResultF(result: f32, expected: u32) bool {
return false;
}
-fn test__divsf3(a: f32, b: f32, expected: u32) void {
+fn test__divsf3(a: f32, b: f32, expected: u32) !void {
const x = __divsf3(a, b);
const ret = compareResultF(x, expected);
- testing.expect(ret == true);
+ try testing.expect(ret == true);
}
test "divsf3" {
- test__divsf3(1.0, 3.0, 0x3EAAAAAB);
- test__divsf3(2.3509887e-38, 2.0, 0x00800000);
+ try test__divsf3(1.0, 3.0, 0x3EAAAAAB);
+ try test__divsf3(2.3509887e-38, 2.0, 0x00800000);
}
diff --git a/lib/std/special/compiler_rt/divtf3_test.zig b/lib/std/special/compiler_rt/divtf3_test.zig
index 98910e9994..3915177091 100644
--- a/lib/std/special/compiler_rt/divtf3_test.zig
+++ b/lib/std/special/compiler_rt/divtf3_test.zig
@@ -28,24 +28,24 @@ fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
return false;
}
-fn test__divtf3(a: f128, b: f128, expectedHi: u64, expectedLo: u64) void {
+fn test__divtf3(a: f128, b: f128, expectedHi: u64, expectedLo: u64) !void {
const x = __divtf3(a, b);
const ret = compareResultLD(x, expectedHi, expectedLo);
- testing.expect(ret == true);
+ try testing.expect(ret == true);
}
test "divtf3" {
// qNaN / any = qNaN
- test__divtf3(math.qnan_f128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0);
+ try test__divtf3(math.qnan_f128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0);
// NaN / any = NaN
- test__divtf3(math.nan_f128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0);
+ try test__divtf3(math.nan_f128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0);
// inf / any = inf
- test__divtf3(math.inf_f128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0);
+ try test__divtf3(math.inf_f128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0);
- test__divtf3(0x1.a23b45362464523375893ab4cdefp+5, 0x1.eedcbaba3a94546558237654321fp-1, 0x4004b0b72924d407, 0x0717e84356c6eba2);
- test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50, 0x1.ed2c3ba15935332532287654321fp-9, 0x3fd5b2af3f828c9b, 0x40e51f64cde8b1f2);
- test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456, 0x1.edacbba9874f765463544dd3621fp+6400, 0x28c62e15dc464466, 0xb5a07586348557ac);
- test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234, 0x1.eddcdba39f3c8b7a36564354321fp-4455, 0x507b38442b539266, 0x22ce0f1d024e1252);
- test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234, 0x1.edcba987d6bb3aa467754354321fp-4055, 0x50bf2e02f0798d36, 0x5e6fcb6b60044078);
- test__divtf3(6.72420628622418701252535563464350521E-4932, 2.0, 0x0001000000000000, 0);
+ try test__divtf3(0x1.a23b45362464523375893ab4cdefp+5, 0x1.eedcbaba3a94546558237654321fp-1, 0x4004b0b72924d407, 0x0717e84356c6eba2);
+ try test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50, 0x1.ed2c3ba15935332532287654321fp-9, 0x3fd5b2af3f828c9b, 0x40e51f64cde8b1f2);
+ try test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456, 0x1.edacbba9874f765463544dd3621fp+6400, 0x28c62e15dc464466, 0xb5a07586348557ac);
+ try test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234, 0x1.eddcdba39f3c8b7a36564354321fp-4455, 0x507b38442b539266, 0x22ce0f1d024e1252);
+ try test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234, 0x1.edcba987d6bb3aa467754354321fp-4055, 0x50bf2e02f0798d36, 0x5e6fcb6b60044078);
+ try test__divtf3(6.72420628622418701252535563464350521E-4932, 2.0, 0x0001000000000000, 0);
}
diff --git a/lib/std/special/compiler_rt/divti3_test.zig b/lib/std/special/compiler_rt/divti3_test.zig
index a20be340c6..c4f7fd01b6 100644
--- a/lib/std/special/compiler_rt/divti3_test.zig
+++ b/lib/std/special/compiler_rt/divti3_test.zig
@@ -6,21 +6,21 @@
const __divti3 = @import("divti3.zig").__divti3;
const testing = @import("std").testing;
-fn test__divti3(a: i128, b: i128, expected: i128) void {
+fn test__divti3(a: i128, b: i128, expected: i128) !void {
const x = __divti3(a, b);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "divti3" {
- test__divti3(0, 1, 0);
- test__divti3(0, -1, 0);
- test__divti3(2, 1, 2);
- test__divti3(2, -1, -2);
- test__divti3(-2, 1, -2);
- test__divti3(-2, -1, 2);
+ try test__divti3(0, 1, 0);
+ try test__divti3(0, -1, 0);
+ try test__divti3(2, 1, 2);
+ try test__divti3(2, -1, -2);
+ try test__divti3(-2, 1, -2);
+ try test__divti3(-2, -1, 2);
- test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124)));
- test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124)));
- test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124)));
- test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124)));
+ try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124)));
+ try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124)));
+ try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124)));
+ try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124)));
}
diff --git a/lib/std/special/compiler_rt/emutls.zig b/lib/std/special/compiler_rt/emutls.zig
index 2b0fba5b34..8871afe00b 100644
--- a/lib/std/special/compiler_rt/emutls.zig
+++ b/lib/std/special/compiler_rt/emutls.zig
@@ -339,12 +339,12 @@ test "simple_allocator" {
test "__emutls_get_address zeroed" {
var ctl = emutls_control.init(usize, null);
- expect(ctl.object.index == 0);
+ try expect(ctl.object.index == 0);
// retrieve a variable from ctl
var x = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
- expect(ctl.object.index != 0); // index has been allocated for this ctl
- expect(x.* == 0); // storage has been zeroed
+ try expect(ctl.object.index != 0); // index has been allocated for this ctl
+ try expect(x.* == 0); // storage has been zeroed
// modify the storage
x.* = 1234;
@@ -352,26 +352,26 @@ test "__emutls_get_address zeroed" {
// retrieve a variable from ctl (same ctl)
var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
- expect(y.* == 1234); // same content that x.*
- expect(x == y); // same pointer
+ try expect(y.* == 1234); // same content that x.*
+ try expect(x == y); // same pointer
}
test "__emutls_get_address with default_value" {
var value: usize = 5678; // default value
var ctl = emutls_control.init(usize, &value);
- expect(ctl.object.index == 0);
+ try expect(ctl.object.index == 0);
var x: *usize = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
- expect(ctl.object.index != 0);
- expect(x.* == 5678); // storage initialized with default value
+ try expect(ctl.object.index != 0);
+ try expect(x.* == 5678); // storage initialized with default value
// modify the storage
x.* = 9012;
- expect(value == 5678); // the default value didn't change
+ try expect(value == 5678); // the default value didn't change
var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
- expect(y.* == 9012); // the modified storage persists
+ try expect(y.* == 9012); // the modified storage persists
}
test "test default_value with differents sizes" {
@@ -380,7 +380,7 @@ test "test default_value with differents sizes" {
var def: T = value;
var ctl = emutls_control.init(T, &def);
var x = ctl.get_typed_pointer(T);
- expect(x.* == value);
+ try expect(x.* == value);
}
}._testType;
diff --git a/lib/std/special/compiler_rt/extendXfYf2_test.zig b/lib/std/special/compiler_rt/extendXfYf2_test.zig
index f05d33eac3..f75b9d9297 100644
--- a/lib/std/special/compiler_rt/extendXfYf2_test.zig
+++ b/lib/std/special/compiler_rt/extendXfYf2_test.zig
@@ -9,7 +9,7 @@ const __extendhftf2 = @import("extendXfYf2.zig").__extendhftf2;
const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2;
const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2;
-fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void {
+fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) !void {
const x = __extenddftf2(a);
const rep = @bitCast(u128, x);
@@ -31,7 +31,7 @@ fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void {
@panic("__extenddftf2 test failure");
}
-fn test__extendhfsf2(a: u16, expected: u32) void {
+fn test__extendhfsf2(a: u16, expected: u32) !void {
const x = __extendhfsf2(a);
const rep = @bitCast(u32, x);
@@ -44,10 +44,10 @@ fn test__extendhfsf2(a: u16, expected: u32) void {
}
}
- @panic("__extendhfsf2 test failure");
+ return error.TestFailure;
}
-fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) void {
+fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) !void {
const x = __extendsftf2(a);
const rep = @bitCast(u128, x);
@@ -66,77 +66,77 @@ fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) void {
}
}
- @panic("__extendsftf2 test failure");
+ return error.TestFailure;
}
test "extenddftf2" {
// qNaN
- test__extenddftf2(makeQNaN64(), 0x7fff800000000000, 0x0);
+ try test__extenddftf2(makeQNaN64(), 0x7fff800000000000, 0x0);
// NaN
- test__extenddftf2(makeNaN64(0x7100000000000), 0x7fff710000000000, 0x0);
+ try test__extenddftf2(makeNaN64(0x7100000000000), 0x7fff710000000000, 0x0);
// inf
- test__extenddftf2(makeInf64(), 0x7fff000000000000, 0x0);
+ try test__extenddftf2(makeInf64(), 0x7fff000000000000, 0x0);
// zero
- test__extenddftf2(0.0, 0x0, 0x0);
+ try test__extenddftf2(0.0, 0x0, 0x0);
- test__extenddftf2(0x1.23456789abcdefp+5, 0x400423456789abcd, 0xf000000000000000);
+ try test__extenddftf2(0x1.23456789abcdefp+5, 0x400423456789abcd, 0xf000000000000000);
- test__extenddftf2(0x1.edcba987654321fp-9, 0x3ff6edcba9876543, 0x2000000000000000);
+ try test__extenddftf2(0x1.edcba987654321fp-9, 0x3ff6edcba9876543, 0x2000000000000000);
- test__extenddftf2(0x1.23456789abcdefp+45, 0x402c23456789abcd, 0xf000000000000000);
+ try test__extenddftf2(0x1.23456789abcdefp+45, 0x402c23456789abcd, 0xf000000000000000);
- test__extenddftf2(0x1.edcba987654321fp-45, 0x3fd2edcba9876543, 0x2000000000000000);
+ try test__extenddftf2(0x1.edcba987654321fp-45, 0x3fd2edcba9876543, 0x2000000000000000);
}
test "extendhfsf2" {
- test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN
- test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN
+ try test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN
+ try test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN
// On x86 the NaN becomes quiet because the return is pushed on the x87
// stack due to ABI requirements
if (builtin.arch != .i386 and builtin.os.tag == .windows)
- test__extendhfsf2(0x7c01, 0x7f802000); // sNaN
+ try test__extendhfsf2(0x7c01, 0x7f802000); // sNaN
- test__extendhfsf2(0, 0); // 0
- test__extendhfsf2(0x8000, 0x80000000); // -0
+ try test__extendhfsf2(0, 0); // 0
+ try test__extendhfsf2(0x8000, 0x80000000); // -0
- test__extendhfsf2(0x7c00, 0x7f800000); // inf
- test__extendhfsf2(0xfc00, 0xff800000); // -inf
+ try test__extendhfsf2(0x7c00, 0x7f800000); // inf
+ try test__extendhfsf2(0xfc00, 0xff800000); // -inf
- test__extendhfsf2(0x0001, 0x33800000); // denormal (min), 2**-24
- test__extendhfsf2(0x8001, 0xb3800000); // denormal (min), -2**-24
+ try test__extendhfsf2(0x0001, 0x33800000); // denormal (min), 2**-24
+ try test__extendhfsf2(0x8001, 0xb3800000); // denormal (min), -2**-24
- test__extendhfsf2(0x03ff, 0x387fc000); // denormal (max), 2**-14 - 2**-24
- test__extendhfsf2(0x83ff, 0xb87fc000); // denormal (max), -2**-14 + 2**-24
+ try test__extendhfsf2(0x03ff, 0x387fc000); // denormal (max), 2**-14 - 2**-24
+ try test__extendhfsf2(0x83ff, 0xb87fc000); // denormal (max), -2**-14 + 2**-24
- test__extendhfsf2(0x0400, 0x38800000); // normal (min), 2**-14
- test__extendhfsf2(0x8400, 0xb8800000); // normal (min), -2**-14
+ try test__extendhfsf2(0x0400, 0x38800000); // normal (min), 2**-14
+ try test__extendhfsf2(0x8400, 0xb8800000); // normal (min), -2**-14
- test__extendhfsf2(0x7bff, 0x477fe000); // normal (max), 65504
- test__extendhfsf2(0xfbff, 0xc77fe000); // normal (max), -65504
+ try test__extendhfsf2(0x7bff, 0x477fe000); // normal (max), 65504
+ try test__extendhfsf2(0xfbff, 0xc77fe000); // normal (max), -65504
- test__extendhfsf2(0x3c01, 0x3f802000); // normal, 1 + 2**-10
- test__extendhfsf2(0xbc01, 0xbf802000); // normal, -1 - 2**-10
+ try test__extendhfsf2(0x3c01, 0x3f802000); // normal, 1 + 2**-10
+ try test__extendhfsf2(0xbc01, 0xbf802000); // normal, -1 - 2**-10
- test__extendhfsf2(0x3555, 0x3eaaa000); // normal, approx. 1/3
- test__extendhfsf2(0xb555, 0xbeaaa000); // normal, approx. -1/3
+ try test__extendhfsf2(0x3555, 0x3eaaa000); // normal, approx. 1/3
+ try test__extendhfsf2(0xb555, 0xbeaaa000); // normal, approx. -1/3
}
test "extendsftf2" {
// qNaN
- test__extendsftf2(makeQNaN32(), 0x7fff800000000000, 0x0);
+ try test__extendsftf2(makeQNaN32(), 0x7fff800000000000, 0x0);
// NaN
- test__extendsftf2(makeNaN32(0x410000), 0x7fff820000000000, 0x0);
+ try test__extendsftf2(makeNaN32(0x410000), 0x7fff820000000000, 0x0);
// inf
- test__extendsftf2(makeInf32(), 0x7fff000000000000, 0x0);
+ try test__extendsftf2(makeInf32(), 0x7fff000000000000, 0x0);
// zero
- test__extendsftf2(0.0, 0x0, 0x0);
- test__extendsftf2(0x1.23456p+5, 0x4004234560000000, 0x0);
- test__extendsftf2(0x1.edcbap-9, 0x3ff6edcba0000000, 0x0);
- test__extendsftf2(0x1.23456p+45, 0x402c234560000000, 0x0);
- test__extendsftf2(0x1.edcbap-45, 0x3fd2edcba0000000, 0x0);
+ try test__extendsftf2(0.0, 0x0, 0x0);
+ try test__extendsftf2(0x1.23456p+5, 0x4004234560000000, 0x0);
+ try test__extendsftf2(0x1.edcbap-9, 0x3ff6edcba0000000, 0x0);
+ try test__extendsftf2(0x1.23456p+45, 0x402c234560000000, 0x0);
+ try test__extendsftf2(0x1.edcbap-45, 0x3fd2edcba0000000, 0x0);
}
fn makeQNaN64() f64 {
@@ -163,7 +163,7 @@ fn makeInf32() f32 {
return @bitCast(f32, @as(u32, 0x7f800000));
}
-fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) void {
+fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) !void {
const x = __extendhftf2(a);
const rep = @bitCast(u128, x);
@@ -182,29 +182,29 @@ fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) void {
}
}
- @panic("__extendhftf2 test failure");
+ return error.TestFailure;
}
test "extendhftf2" {
// qNaN
- test__extendhftf2(0x7e00, 0x7fff800000000000, 0x0);
+ try test__extendhftf2(0x7e00, 0x7fff800000000000, 0x0);
// NaN
- test__extendhftf2(0x7d00, 0x7fff400000000000, 0x0);
+ try test__extendhftf2(0x7d00, 0x7fff400000000000, 0x0);
// inf
- test__extendhftf2(0x7c00, 0x7fff000000000000, 0x0);
- test__extendhftf2(0xfc00, 0xffff000000000000, 0x0);
+ try test__extendhftf2(0x7c00, 0x7fff000000000000, 0x0);
+ try test__extendhftf2(0xfc00, 0xffff000000000000, 0x0);
// zero
- test__extendhftf2(0x0000, 0x0000000000000000, 0x0);
- test__extendhftf2(0x8000, 0x8000000000000000, 0x0);
+ try test__extendhftf2(0x0000, 0x0000000000000000, 0x0);
+ try test__extendhftf2(0x8000, 0x8000000000000000, 0x0);
// denormal
- test__extendhftf2(0x0010, 0x3feb000000000000, 0x0);
- test__extendhftf2(0x0001, 0x3fe7000000000000, 0x0);
- test__extendhftf2(0x8001, 0xbfe7000000000000, 0x0);
+ try test__extendhftf2(0x0010, 0x3feb000000000000, 0x0);
+ try test__extendhftf2(0x0001, 0x3fe7000000000000, 0x0);
+ try test__extendhftf2(0x8001, 0xbfe7000000000000, 0x0);
// pi
- test__extendhftf2(0x4248, 0x4000920000000000, 0x0);
- test__extendhftf2(0xc248, 0xc000920000000000, 0x0);
+ try test__extendhftf2(0x4248, 0x4000920000000000, 0x0);
+ try test__extendhftf2(0xc248, 0xc000920000000000, 0x0);
- test__extendhftf2(0x508c, 0x4004230000000000, 0x0);
- test__extendhftf2(0x1bb7, 0x3ff6edc000000000, 0x0);
+ try test__extendhftf2(0x508c, 0x4004230000000000, 0x0);
+ try test__extendhftf2(0x1bb7, 0x3ff6edc000000000, 0x0);
}
diff --git a/lib/std/special/compiler_rt/fixdfdi_test.zig b/lib/std/special/compiler_rt/fixdfdi_test.zig
index f085bdf665..c8220b532d 100644
--- a/lib/std/special/compiler_rt/fixdfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixdfdi_test.zig
@@ -9,62 +9,62 @@ const math = std.math;
const testing = std.testing;
const warn = std.debug.warn;
-fn test__fixdfdi(a: f64, expected: i64) void {
+fn test__fixdfdi(a: f64, expected: i64) !void {
const x = __fixdfdi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixdfdi" {
//warn("\n", .{});
- test__fixdfdi(-math.f64_max, math.minInt(i64));
+ try test__fixdfdi(-math.f64_max, math.minInt(i64));
- test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
- test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
+ try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
+ try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
- test__fixdfdi(-0x1.0000000000000p+127, -0x8000000000000000);
- test__fixdfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
- test__fixdfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
+ try test__fixdfdi(-0x1.0000000000000p+127, -0x8000000000000000);
+ try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
+ try test__fixdfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
- test__fixdfdi(-0x1.0000000000001p+63, -0x8000000000000000);
- test__fixdfdi(-0x1.0000000000000p+63, -0x8000000000000000);
- test__fixdfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
- test__fixdfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
+ try test__fixdfdi(-0x1.0000000000001p+63, -0x8000000000000000);
+ try test__fixdfdi(-0x1.0000000000000p+63, -0x8000000000000000);
+ try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
+ try test__fixdfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
- test__fixdfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);
- test__fixdfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);
+ try test__fixdfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);
+ try test__fixdfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);
- test__fixdfdi(-2.01, -2);
- test__fixdfdi(-2.0, -2);
- test__fixdfdi(-1.99, -1);
- test__fixdfdi(-1.0, -1);
- test__fixdfdi(-0.99, 0);
- test__fixdfdi(-0.5, 0);
- test__fixdfdi(-math.f64_min, 0);
- test__fixdfdi(0.0, 0);
- test__fixdfdi(math.f64_min, 0);
- test__fixdfdi(0.5, 0);
- test__fixdfdi(0.99, 0);
- test__fixdfdi(1.0, 1);
- test__fixdfdi(1.5, 1);
- test__fixdfdi(1.99, 1);
- test__fixdfdi(2.0, 2);
- test__fixdfdi(2.01, 2);
+ try test__fixdfdi(-2.01, -2);
+ try test__fixdfdi(-2.0, -2);
+ try test__fixdfdi(-1.99, -1);
+ try test__fixdfdi(-1.0, -1);
+ try test__fixdfdi(-0.99, 0);
+ try test__fixdfdi(-0.5, 0);
+ try test__fixdfdi(-math.f64_min, 0);
+ try test__fixdfdi(0.0, 0);
+ try test__fixdfdi(math.f64_min, 0);
+ try test__fixdfdi(0.5, 0);
+ try test__fixdfdi(0.99, 0);
+ try test__fixdfdi(1.0, 1);
+ try test__fixdfdi(1.5, 1);
+ try test__fixdfdi(1.99, 1);
+ try test__fixdfdi(2.0, 2);
+ try test__fixdfdi(2.01, 2);
- test__fixdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
- test__fixdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
+ try test__fixdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
+ try test__fixdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
- test__fixdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
- test__fixdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
- test__fixdfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
- test__fixdfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
+ try test__fixdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
+ try test__fixdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
+ try test__fixdfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
+ try test__fixdfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
- test__fixdfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
- test__fixdfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
- test__fixdfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
+ try test__fixdfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
+ try test__fixdfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
+ try test__fixdfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
- test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
- test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
+ try test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
+ try test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
- test__fixdfdi(math.f64_max, math.maxInt(i64));
+ try test__fixdfdi(math.f64_max, math.maxInt(i64));
}
diff --git a/lib/std/special/compiler_rt/fixdfsi_test.zig b/lib/std/special/compiler_rt/fixdfsi_test.zig
index 1445149546..c9ebcbeddc 100644
--- a/lib/std/special/compiler_rt/fixdfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixdfsi_test.zig
@@ -9,70 +9,70 @@ const math = std.math;
const testing = std.testing;
const warn = std.debug.warn;
-fn test__fixdfsi(a: f64, expected: i32) void {
+fn test__fixdfsi(a: f64, expected: i32) !void {
const x = __fixdfsi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixdfsi" {
//warn("\n", .{});
- test__fixdfsi(-math.f64_max, math.minInt(i32));
+ try test__fixdfsi(-math.f64_max, math.minInt(i32));
- test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
- test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
+ try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
+ try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
- test__fixdfsi(-0x1.0000000000000p+127, -0x80000000);
- test__fixdfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
- test__fixdfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
+ try test__fixdfsi(-0x1.0000000000000p+127, -0x80000000);
+ try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
+ try test__fixdfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
- test__fixdfsi(-0x1.0000000000001p+63, -0x80000000);
- test__fixdfsi(-0x1.0000000000000p+63, -0x80000000);
- test__fixdfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
- test__fixdfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
+ try test__fixdfsi(-0x1.0000000000001p+63, -0x80000000);
+ try test__fixdfsi(-0x1.0000000000000p+63, -0x80000000);
+ try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
+ try test__fixdfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
- test__fixdfsi(-0x1.FFFFFEp+62, -0x80000000);
- test__fixdfsi(-0x1.FFFFFCp+62, -0x80000000);
+ try test__fixdfsi(-0x1.FFFFFEp+62, -0x80000000);
+ try test__fixdfsi(-0x1.FFFFFCp+62, -0x80000000);
- test__fixdfsi(-0x1.000000p+31, -0x80000000);
- test__fixdfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
- test__fixdfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
+ try test__fixdfsi(-0x1.000000p+31, -0x80000000);
+ try test__fixdfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
+ try test__fixdfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
- test__fixdfsi(-2.01, -2);
- test__fixdfsi(-2.0, -2);
- test__fixdfsi(-1.99, -1);
- test__fixdfsi(-1.0, -1);
- test__fixdfsi(-0.99, 0);
- test__fixdfsi(-0.5, 0);
- test__fixdfsi(-math.f64_min, 0);
- test__fixdfsi(0.0, 0);
- test__fixdfsi(math.f64_min, 0);
- test__fixdfsi(0.5, 0);
- test__fixdfsi(0.99, 0);
- test__fixdfsi(1.0, 1);
- test__fixdfsi(1.5, 1);
- test__fixdfsi(1.99, 1);
- test__fixdfsi(2.0, 2);
- test__fixdfsi(2.01, 2);
+ try test__fixdfsi(-2.01, -2);
+ try test__fixdfsi(-2.0, -2);
+ try test__fixdfsi(-1.99, -1);
+ try test__fixdfsi(-1.0, -1);
+ try test__fixdfsi(-0.99, 0);
+ try test__fixdfsi(-0.5, 0);
+ try test__fixdfsi(-math.f64_min, 0);
+ try test__fixdfsi(0.0, 0);
+ try test__fixdfsi(math.f64_min, 0);
+ try test__fixdfsi(0.5, 0);
+ try test__fixdfsi(0.99, 0);
+ try test__fixdfsi(1.0, 1);
+ try test__fixdfsi(1.5, 1);
+ try test__fixdfsi(1.99, 1);
+ try test__fixdfsi(2.0, 2);
+ try test__fixdfsi(2.01, 2);
- test__fixdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
- test__fixdfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);
- test__fixdfsi(0x1.000000p+31, 0x7FFFFFFF);
+ try test__fixdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
+ try test__fixdfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);
+ try test__fixdfsi(0x1.000000p+31, 0x7FFFFFFF);
- test__fixdfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
- test__fixdfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
+ try test__fixdfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
+ try test__fixdfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
- test__fixdfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
- test__fixdfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
- test__fixdfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
- test__fixdfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
+ try test__fixdfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
+ try test__fixdfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
+ try test__fixdfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
+ try test__fixdfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
- test__fixdfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
- test__fixdfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
- test__fixdfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
+ try test__fixdfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
+ try test__fixdfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
+ try test__fixdfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
- test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
- test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
+ try test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
+ try test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
- test__fixdfsi(math.f64_max, math.maxInt(i32));
+ try test__fixdfsi(math.f64_max, math.maxInt(i32));
}
diff --git a/lib/std/special/compiler_rt/fixdfti_test.zig b/lib/std/special/compiler_rt/fixdfti_test.zig
index 3b5bac4b4e..76f08f985d 100644
--- a/lib/std/special/compiler_rt/fixdfti_test.zig
+++ b/lib/std/special/compiler_rt/fixdfti_test.zig
@@ -9,62 +9,62 @@ const math = std.math;
const testing = std.testing;
const warn = std.debug.warn;
-fn test__fixdfti(a: f64, expected: i128) void {
+fn test__fixdfti(a: f64, expected: i128) !void {
const x = __fixdfti(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixdfti" {
//warn("\n", .{});
- test__fixdfti(-math.f64_max, math.minInt(i128));
+ try test__fixdfti(-math.f64_max, math.minInt(i128));
- test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
- test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
+ try test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
+ try test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
- test__fixdfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
- test__fixdfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);
- test__fixdfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);
+ try test__fixdfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
+ try test__fixdfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);
+ try test__fixdfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);
- test__fixdfti(-0x1.0000000000001p+63, -0x8000000000000800);
- test__fixdfti(-0x1.0000000000000p+63, -0x8000000000000000);
- test__fixdfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
- test__fixdfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
+ try test__fixdfti(-0x1.0000000000001p+63, -0x8000000000000800);
+ try test__fixdfti(-0x1.0000000000000p+63, -0x8000000000000000);
+ try test__fixdfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
+ try test__fixdfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
- test__fixdfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
- test__fixdfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
+ try test__fixdfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
+ try test__fixdfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
- test__fixdfti(-2.01, -2);
- test__fixdfti(-2.0, -2);
- test__fixdfti(-1.99, -1);
- test__fixdfti(-1.0, -1);
- test__fixdfti(-0.99, 0);
- test__fixdfti(-0.5, 0);
- test__fixdfti(-math.f64_min, 0);
- test__fixdfti(0.0, 0);
- test__fixdfti(math.f64_min, 0);
- test__fixdfti(0.5, 0);
- test__fixdfti(0.99, 0);
- test__fixdfti(1.0, 1);
- test__fixdfti(1.5, 1);
- test__fixdfti(1.99, 1);
- test__fixdfti(2.0, 2);
- test__fixdfti(2.01, 2);
+ try test__fixdfti(-2.01, -2);
+ try test__fixdfti(-2.0, -2);
+ try test__fixdfti(-1.99, -1);
+ try test__fixdfti(-1.0, -1);
+ try test__fixdfti(-0.99, 0);
+ try test__fixdfti(-0.5, 0);
+ try test__fixdfti(-math.f64_min, 0);
+ try test__fixdfti(0.0, 0);
+ try test__fixdfti(math.f64_min, 0);
+ try test__fixdfti(0.5, 0);
+ try test__fixdfti(0.99, 0);
+ try test__fixdfti(1.0, 1);
+ try test__fixdfti(1.5, 1);
+ try test__fixdfti(1.99, 1);
+ try test__fixdfti(2.0, 2);
+ try test__fixdfti(2.01, 2);
- test__fixdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
- test__fixdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
+ try test__fixdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
+ try test__fixdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
- test__fixdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
- test__fixdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
- test__fixdfti(0x1.0000000000000p+63, 0x8000000000000000);
- test__fixdfti(0x1.0000000000001p+63, 0x8000000000000800);
+ try test__fixdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
+ try test__fixdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
+ try test__fixdfti(0x1.0000000000000p+63, 0x8000000000000000);
+ try test__fixdfti(0x1.0000000000001p+63, 0x8000000000000800);
- test__fixdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
- test__fixdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
- test__fixdfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__fixdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
+ try test__fixdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
+ try test__fixdfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
+ try test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
- test__fixdfti(math.f64_max, math.maxInt(i128));
+ try test__fixdfti(math.f64_max, math.maxInt(i128));
}
diff --git a/lib/std/special/compiler_rt/fixint_test.zig b/lib/std/special/compiler_rt/fixint_test.zig
index 139546c52b..86bc32e642 100644
--- a/lib/std/special/compiler_rt/fixint_test.zig
+++ b/lib/std/special/compiler_rt/fixint_test.zig
@@ -11,147 +11,147 @@ const warn = std.debug.warn;
const fixint = @import("fixint.zig").fixint;
-fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void {
+fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) !void {
const x = fixint(fp_t, fixint_t, a);
//warn("a={} x={}:{x} expected={}:{x})\n", .{a, x, x, expected, expected});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixint.i1" {
- test__fixint(f32, i1, -math.inf_f32, -1);
- test__fixint(f32, i1, -math.f32_max, -1);
- test__fixint(f32, i1, -2.0, -1);
- test__fixint(f32, i1, -1.1, -1);
- test__fixint(f32, i1, -1.0, -1);
- test__fixint(f32, i1, -0.9, 0);
- test__fixint(f32, i1, -0.1, 0);
- test__fixint(f32, i1, -math.f32_min, 0);
- test__fixint(f32, i1, -0.0, 0);
- test__fixint(f32, i1, 0.0, 0);
- test__fixint(f32, i1, math.f32_min, 0);
- test__fixint(f32, i1, 0.1, 0);
- test__fixint(f32, i1, 0.9, 0);
- test__fixint(f32, i1, 1.0, 0);
- test__fixint(f32, i1, 2.0, 0);
- test__fixint(f32, i1, math.f32_max, 0);
- test__fixint(f32, i1, math.inf_f32, 0);
+ try test__fixint(f32, i1, -math.inf_f32, -1);
+ try test__fixint(f32, i1, -math.f32_max, -1);
+ try test__fixint(f32, i1, -2.0, -1);
+ try test__fixint(f32, i1, -1.1, -1);
+ try test__fixint(f32, i1, -1.0, -1);
+ try test__fixint(f32, i1, -0.9, 0);
+ try test__fixint(f32, i1, -0.1, 0);
+ try test__fixint(f32, i1, -math.f32_min, 0);
+ try test__fixint(f32, i1, -0.0, 0);
+ try test__fixint(f32, i1, 0.0, 0);
+ try test__fixint(f32, i1, math.f32_min, 0);
+ try test__fixint(f32, i1, 0.1, 0);
+ try test__fixint(f32, i1, 0.9, 0);
+ try test__fixint(f32, i1, 1.0, 0);
+ try test__fixint(f32, i1, 2.0, 0);
+ try test__fixint(f32, i1, math.f32_max, 0);
+ try test__fixint(f32, i1, math.inf_f32, 0);
}
test "fixint.i2" {
- test__fixint(f32, i2, -math.inf_f32, -2);
- test__fixint(f32, i2, -math.f32_max, -2);
- test__fixint(f32, i2, -2.0, -2);
- test__fixint(f32, i2, -1.9, -1);
- test__fixint(f32, i2, -1.1, -1);
- test__fixint(f32, i2, -1.0, -1);
- test__fixint(f32, i2, -0.9, 0);
- test__fixint(f32, i2, -0.1, 0);
- test__fixint(f32, i2, -math.f32_min, 0);
- test__fixint(f32, i2, -0.0, 0);
- test__fixint(f32, i2, 0.0, 0);
- test__fixint(f32, i2, math.f32_min, 0);
- test__fixint(f32, i2, 0.1, 0);
- test__fixint(f32, i2, 0.9, 0);
- test__fixint(f32, i2, 1.0, 1);
- test__fixint(f32, i2, 2.0, 1);
- test__fixint(f32, i2, math.f32_max, 1);
- test__fixint(f32, i2, math.inf_f32, 1);
+ try test__fixint(f32, i2, -math.inf_f32, -2);
+ try test__fixint(f32, i2, -math.f32_max, -2);
+ try test__fixint(f32, i2, -2.0, -2);
+ try test__fixint(f32, i2, -1.9, -1);
+ try test__fixint(f32, i2, -1.1, -1);
+ try test__fixint(f32, i2, -1.0, -1);
+ try test__fixint(f32, i2, -0.9, 0);
+ try test__fixint(f32, i2, -0.1, 0);
+ try test__fixint(f32, i2, -math.f32_min, 0);
+ try test__fixint(f32, i2, -0.0, 0);
+ try test__fixint(f32, i2, 0.0, 0);
+ try test__fixint(f32, i2, math.f32_min, 0);
+ try test__fixint(f32, i2, 0.1, 0);
+ try test__fixint(f32, i2, 0.9, 0);
+ try test__fixint(f32, i2, 1.0, 1);
+ try test__fixint(f32, i2, 2.0, 1);
+ try test__fixint(f32, i2, math.f32_max, 1);
+ try test__fixint(f32, i2, math.inf_f32, 1);
}
test "fixint.i3" {
- test__fixint(f32, i3, -math.inf_f32, -4);
- test__fixint(f32, i3, -math.f32_max, -4);
- test__fixint(f32, i3, -4.0, -4);
- test__fixint(f32, i3, -3.0, -3);
- test__fixint(f32, i3, -2.0, -2);
- test__fixint(f32, i3, -1.9, -1);
- test__fixint(f32, i3, -1.1, -1);
- test__fixint(f32, i3, -1.0, -1);
- test__fixint(f32, i3, -0.9, 0);
- test__fixint(f32, i3, -0.1, 0);
- test__fixint(f32, i3, -math.f32_min, 0);
- test__fixint(f32, i3, -0.0, 0);
- test__fixint(f32, i3, 0.0, 0);
- test__fixint(f32, i3, math.f32_min, 0);
- test__fixint(f32, i3, 0.1, 0);
- test__fixint(f32, i3, 0.9, 0);
- test__fixint(f32, i3, 1.0, 1);
- test__fixint(f32, i3, 2.0, 2);
- test__fixint(f32, i3, 3.0, 3);
- test__fixint(f32, i3, 4.0, 3);
- test__fixint(f32, i3, math.f32_max, 3);
- test__fixint(f32, i3, math.inf_f32, 3);
+ try test__fixint(f32, i3, -math.inf_f32, -4);
+ try test__fixint(f32, i3, -math.f32_max, -4);
+ try test__fixint(f32, i3, -4.0, -4);
+ try test__fixint(f32, i3, -3.0, -3);
+ try test__fixint(f32, i3, -2.0, -2);
+ try test__fixint(f32, i3, -1.9, -1);
+ try test__fixint(f32, i3, -1.1, -1);
+ try test__fixint(f32, i3, -1.0, -1);
+ try test__fixint(f32, i3, -0.9, 0);
+ try test__fixint(f32, i3, -0.1, 0);
+ try test__fixint(f32, i3, -math.f32_min, 0);
+ try test__fixint(f32, i3, -0.0, 0);
+ try test__fixint(f32, i3, 0.0, 0);
+ try test__fixint(f32, i3, math.f32_min, 0);
+ try test__fixint(f32, i3, 0.1, 0);
+ try test__fixint(f32, i3, 0.9, 0);
+ try test__fixint(f32, i3, 1.0, 1);
+ try test__fixint(f32, i3, 2.0, 2);
+ try test__fixint(f32, i3, 3.0, 3);
+ try test__fixint(f32, i3, 4.0, 3);
+ try test__fixint(f32, i3, math.f32_max, 3);
+ try test__fixint(f32, i3, math.inf_f32, 3);
}
test "fixint.i32" {
- test__fixint(f64, i32, -math.inf_f64, math.minInt(i32));
- test__fixint(f64, i32, -math.f64_max, math.minInt(i32));
- test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32));
- test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1);
- test__fixint(f64, i32, -2.0, -2);
- test__fixint(f64, i32, -1.9, -1);
- test__fixint(f64, i32, -1.1, -1);
- test__fixint(f64, i32, -1.0, -1);
- test__fixint(f64, i32, -0.9, 0);
- test__fixint(f64, i32, -0.1, 0);
- test__fixint(f64, i32, -math.f32_min, 0);
- test__fixint(f64, i32, -0.0, 0);
- test__fixint(f64, i32, 0.0, 0);
- test__fixint(f64, i32, math.f32_min, 0);
- test__fixint(f64, i32, 0.1, 0);
- test__fixint(f64, i32, 0.9, 0);
- test__fixint(f64, i32, 1.0, 1);
- test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1);
- test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32));
- test__fixint(f64, i32, math.f64_max, math.maxInt(i32));
- test__fixint(f64, i32, math.inf_f64, math.maxInt(i32));
+ try test__fixint(f64, i32, -math.inf_f64, math.minInt(i32));
+ try test__fixint(f64, i32, -math.f64_max, math.minInt(i32));
+ try test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32));
+ try test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1);
+ try test__fixint(f64, i32, -2.0, -2);
+ try test__fixint(f64, i32, -1.9, -1);
+ try test__fixint(f64, i32, -1.1, -1);
+ try test__fixint(f64, i32, -1.0, -1);
+ try test__fixint(f64, i32, -0.9, 0);
+ try test__fixint(f64, i32, -0.1, 0);
+ try test__fixint(f64, i32, -math.f32_min, 0);
+ try test__fixint(f64, i32, -0.0, 0);
+ try test__fixint(f64, i32, 0.0, 0);
+ try test__fixint(f64, i32, math.f32_min, 0);
+ try test__fixint(f64, i32, 0.1, 0);
+ try test__fixint(f64, i32, 0.9, 0);
+ try test__fixint(f64, i32, 1.0, 1);
+ try test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1);
+ try test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32));
+ try test__fixint(f64, i32, math.f64_max, math.maxInt(i32));
+ try test__fixint(f64, i32, math.inf_f64, math.maxInt(i32));
}
test "fixint.i64" {
- test__fixint(f64, i64, -math.inf_f64, math.minInt(i64));
- test__fixint(f64, i64, -math.f64_max, math.minInt(i64));
- test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64));
- test__fixint(f64, i64, @as(f64, math.minInt(i64)) + 1, math.minInt(i64));
- test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2);
- test__fixint(f64, i64, -2.0, -2);
- test__fixint(f64, i64, -1.9, -1);
- test__fixint(f64, i64, -1.1, -1);
- test__fixint(f64, i64, -1.0, -1);
- test__fixint(f64, i64, -0.9, 0);
- test__fixint(f64, i64, -0.1, 0);
- test__fixint(f64, i64, -math.f32_min, 0);
- test__fixint(f64, i64, -0.0, 0);
- test__fixint(f64, i64, 0.0, 0);
- test__fixint(f64, i64, math.f32_min, 0);
- test__fixint(f64, i64, 0.1, 0);
- test__fixint(f64, i64, 0.9, 0);
- test__fixint(f64, i64, 1.0, 1);
- test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64));
- test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64));
- test__fixint(f64, i64, math.f64_max, math.maxInt(i64));
- test__fixint(f64, i64, math.inf_f64, math.maxInt(i64));
+ try test__fixint(f64, i64, -math.inf_f64, math.minInt(i64));
+ try test__fixint(f64, i64, -math.f64_max, math.minInt(i64));
+ try test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64));
+ try test__fixint(f64, i64, @as(f64, math.minInt(i64)) + 1, math.minInt(i64));
+ try test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2);
+ try test__fixint(f64, i64, -2.0, -2);
+ try test__fixint(f64, i64, -1.9, -1);
+ try test__fixint(f64, i64, -1.1, -1);
+ try test__fixint(f64, i64, -1.0, -1);
+ try test__fixint(f64, i64, -0.9, 0);
+ try test__fixint(f64, i64, -0.1, 0);
+ try test__fixint(f64, i64, -math.f32_min, 0);
+ try test__fixint(f64, i64, -0.0, 0);
+ try test__fixint(f64, i64, 0.0, 0);
+ try test__fixint(f64, i64, math.f32_min, 0);
+ try test__fixint(f64, i64, 0.1, 0);
+ try test__fixint(f64, i64, 0.9, 0);
+ try test__fixint(f64, i64, 1.0, 1);
+ try test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64));
+ try test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64));
+ try test__fixint(f64, i64, math.f64_max, math.maxInt(i64));
+ try test__fixint(f64, i64, math.inf_f64, math.maxInt(i64));
}
test "fixint.i128" {
- test__fixint(f64, i128, -math.inf_f64, math.minInt(i128));
- test__fixint(f64, i128, -math.f64_max, math.minInt(i128));
- test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128));
- test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128));
- test__fixint(f64, i128, -2.0, -2);
- test__fixint(f64, i128, -1.9, -1);
- test__fixint(f64, i128, -1.1, -1);
- test__fixint(f64, i128, -1.0, -1);
- test__fixint(f64, i128, -0.9, 0);
- test__fixint(f64, i128, -0.1, 0);
- test__fixint(f64, i128, -math.f32_min, 0);
- test__fixint(f64, i128, -0.0, 0);
- test__fixint(f64, i128, 0.0, 0);
- test__fixint(f64, i128, math.f32_min, 0);
- test__fixint(f64, i128, 0.1, 0);
- test__fixint(f64, i128, 0.9, 0);
- test__fixint(f64, i128, 1.0, 1);
- test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128));
- test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128));
- test__fixint(f64, i128, math.f64_max, math.maxInt(i128));
- test__fixint(f64, i128, math.inf_f64, math.maxInt(i128));
+ try test__fixint(f64, i128, -math.inf_f64, math.minInt(i128));
+ try test__fixint(f64, i128, -math.f64_max, math.minInt(i128));
+ try test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128));
+ try test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128));
+ try test__fixint(f64, i128, -2.0, -2);
+ try test__fixint(f64, i128, -1.9, -1);
+ try test__fixint(f64, i128, -1.1, -1);
+ try test__fixint(f64, i128, -1.0, -1);
+ try test__fixint(f64, i128, -0.9, 0);
+ try test__fixint(f64, i128, -0.1, 0);
+ try test__fixint(f64, i128, -math.f32_min, 0);
+ try test__fixint(f64, i128, -0.0, 0);
+ try test__fixint(f64, i128, 0.0, 0);
+ try test__fixint(f64, i128, math.f32_min, 0);
+ try test__fixint(f64, i128, 0.1, 0);
+ try test__fixint(f64, i128, 0.9, 0);
+ try test__fixint(f64, i128, 1.0, 1);
+ try test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128));
+ try test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128));
+ try test__fixint(f64, i128, math.f64_max, math.maxInt(i128));
+ try test__fixint(f64, i128, math.inf_f64, math.maxInt(i128));
}
diff --git a/lib/std/special/compiler_rt/fixsfdi_test.zig b/lib/std/special/compiler_rt/fixsfdi_test.zig
index 7c13d83da5..e18a15d9a3 100644
--- a/lib/std/special/compiler_rt/fixsfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixsfdi_test.zig
@@ -9,64 +9,64 @@ const math = std.math;
const testing = std.testing;
const warn = std.debug.warn;
-fn test__fixsfdi(a: f32, expected: i64) void {
+fn test__fixsfdi(a: f32, expected: i64) !void {
const x = __fixsfdi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixsfdi" {
//warn("\n", .{});
- test__fixsfdi(-math.f32_max, math.minInt(i64));
+ try test__fixsfdi(-math.f32_max, math.minInt(i64));
- test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
- test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
+ try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
+ try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
- test__fixsfdi(-0x1.0000000000000p+127, -0x8000000000000000);
- test__fixsfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
- test__fixsfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
+ try test__fixsfdi(-0x1.0000000000000p+127, -0x8000000000000000);
+ try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
+ try test__fixsfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
- test__fixsfdi(-0x1.0000000000001p+63, -0x8000000000000000);
- test__fixsfdi(-0x1.0000000000000p+63, -0x8000000000000000);
- test__fixsfdi(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);
- test__fixsfdi(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);
+ try test__fixsfdi(-0x1.0000000000001p+63, -0x8000000000000000);
+ try test__fixsfdi(-0x1.0000000000000p+63, -0x8000000000000000);
+ try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);
+ try test__fixsfdi(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);
- test__fixsfdi(-0x1.FFFFFFp+62, -0x8000000000000000);
- test__fixsfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);
- test__fixsfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);
+ try test__fixsfdi(-0x1.FFFFFFp+62, -0x8000000000000000);
+ try test__fixsfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);
+ try test__fixsfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);
- test__fixsfdi(-2.01, -2);
- test__fixsfdi(-2.0, -2);
- test__fixsfdi(-1.99, -1);
- test__fixsfdi(-1.0, -1);
- test__fixsfdi(-0.99, 0);
- test__fixsfdi(-0.5, 0);
- test__fixsfdi(-math.f32_min, 0);
- test__fixsfdi(0.0, 0);
- test__fixsfdi(math.f32_min, 0);
- test__fixsfdi(0.5, 0);
- test__fixsfdi(0.99, 0);
- test__fixsfdi(1.0, 1);
- test__fixsfdi(1.5, 1);
- test__fixsfdi(1.99, 1);
- test__fixsfdi(2.0, 2);
- test__fixsfdi(2.01, 2);
+ try test__fixsfdi(-2.01, -2);
+ try test__fixsfdi(-2.0, -2);
+ try test__fixsfdi(-1.99, -1);
+ try test__fixsfdi(-1.0, -1);
+ try test__fixsfdi(-0.99, 0);
+ try test__fixsfdi(-0.5, 0);
+ try test__fixsfdi(-math.f32_min, 0);
+ try test__fixsfdi(0.0, 0);
+ try test__fixsfdi(math.f32_min, 0);
+ try test__fixsfdi(0.5, 0);
+ try test__fixsfdi(0.99, 0);
+ try test__fixsfdi(1.0, 1);
+ try test__fixsfdi(1.5, 1);
+ try test__fixsfdi(1.99, 1);
+ try test__fixsfdi(2.0, 2);
+ try test__fixsfdi(2.01, 2);
- test__fixsfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
- test__fixsfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
- test__fixsfdi(0x1.FFFFFFp+62, 0x7FFFFFFFFFFFFFFF);
+ try test__fixsfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
+ try test__fixsfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
+ try test__fixsfdi(0x1.FFFFFFp+62, 0x7FFFFFFFFFFFFFFF);
- test__fixsfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFFFFF);
- test__fixsfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFFFF);
- test__fixsfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
- test__fixsfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
+ try test__fixsfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFFFFF);
+ try test__fixsfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFFFF);
+ try test__fixsfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
+ try test__fixsfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
- test__fixsfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
- test__fixsfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
- test__fixsfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
+ try test__fixsfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
+ try test__fixsfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
+ try test__fixsfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
- test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
- test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
+ try test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
+ try test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
- test__fixsfdi(math.f64_max, math.maxInt(i64));
+ try test__fixsfdi(math.f64_max, math.maxInt(i64));
}
diff --git a/lib/std/special/compiler_rt/fixsfsi_test.zig b/lib/std/special/compiler_rt/fixsfsi_test.zig
index 07c080470d..6bc451a697 100644
--- a/lib/std/special/compiler_rt/fixsfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixsfsi_test.zig
@@ -9,72 +9,72 @@ const math = std.math;
const testing = std.testing;
const warn = std.debug.warn;
-fn test__fixsfsi(a: f32, expected: i32) void {
+fn test__fixsfsi(a: f32, expected: i32) !void {
const x = __fixsfsi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixsfsi" {
//warn("\n", .{});
- test__fixsfsi(-math.f32_max, math.minInt(i32));
+ try test__fixsfsi(-math.f32_max, math.minInt(i32));
- test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
- test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
+ try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
+ try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
- test__fixsfsi(-0x1.0000000000000p+127, -0x80000000);
- test__fixsfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
- test__fixsfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
+ try test__fixsfsi(-0x1.0000000000000p+127, -0x80000000);
+ try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
+ try test__fixsfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
- test__fixsfsi(-0x1.0000000000001p+63, -0x80000000);
- test__fixsfsi(-0x1.0000000000000p+63, -0x80000000);
- test__fixsfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
- test__fixsfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
+ try test__fixsfsi(-0x1.0000000000001p+63, -0x80000000);
+ try test__fixsfsi(-0x1.0000000000000p+63, -0x80000000);
+ try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
+ try test__fixsfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
- test__fixsfsi(-0x1.FFFFFEp+62, -0x80000000);
- test__fixsfsi(-0x1.FFFFFCp+62, -0x80000000);
+ try test__fixsfsi(-0x1.FFFFFEp+62, -0x80000000);
+ try test__fixsfsi(-0x1.FFFFFCp+62, -0x80000000);
- test__fixsfsi(-0x1.000000p+31, -0x80000000);
- test__fixsfsi(-0x1.FFFFFFp+30, -0x80000000);
- test__fixsfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
- test__fixsfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);
+ try test__fixsfsi(-0x1.000000p+31, -0x80000000);
+ try test__fixsfsi(-0x1.FFFFFFp+30, -0x80000000);
+ try test__fixsfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
+ try test__fixsfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);
- test__fixsfsi(-2.01, -2);
- test__fixsfsi(-2.0, -2);
- test__fixsfsi(-1.99, -1);
- test__fixsfsi(-1.0, -1);
- test__fixsfsi(-0.99, 0);
- test__fixsfsi(-0.5, 0);
- test__fixsfsi(-math.f32_min, 0);
- test__fixsfsi(0.0, 0);
- test__fixsfsi(math.f32_min, 0);
- test__fixsfsi(0.5, 0);
- test__fixsfsi(0.99, 0);
- test__fixsfsi(1.0, 1);
- test__fixsfsi(1.5, 1);
- test__fixsfsi(1.99, 1);
- test__fixsfsi(2.0, 2);
- test__fixsfsi(2.01, 2);
+ try test__fixsfsi(-2.01, -2);
+ try test__fixsfsi(-2.0, -2);
+ try test__fixsfsi(-1.99, -1);
+ try test__fixsfsi(-1.0, -1);
+ try test__fixsfsi(-0.99, 0);
+ try test__fixsfsi(-0.5, 0);
+ try test__fixsfsi(-math.f32_min, 0);
+ try test__fixsfsi(0.0, 0);
+ try test__fixsfsi(math.f32_min, 0);
+ try test__fixsfsi(0.5, 0);
+ try test__fixsfsi(0.99, 0);
+ try test__fixsfsi(1.0, 1);
+ try test__fixsfsi(1.5, 1);
+ try test__fixsfsi(1.99, 1);
+ try test__fixsfsi(2.0, 2);
+ try test__fixsfsi(2.01, 2);
- test__fixsfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
- test__fixsfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
- test__fixsfsi(0x1.FFFFFFp+30, 0x7FFFFFFF);
- test__fixsfsi(0x1.000000p+31, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
+ try test__fixsfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
+ try test__fixsfsi(0x1.FFFFFFp+30, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.000000p+31, 0x7FFFFFFF);
- test__fixsfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
- test__fixsfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
- test__fixsfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
- test__fixsfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
- test__fixsfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
- test__fixsfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
- test__fixsfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
- test__fixsfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
- test__fixsfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
- test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
- test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
+ try test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
+ try test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
- test__fixsfsi(math.f32_max, math.maxInt(i32));
+ try test__fixsfsi(math.f32_max, math.maxInt(i32));
}
diff --git a/lib/std/special/compiler_rt/fixsfti_test.zig b/lib/std/special/compiler_rt/fixsfti_test.zig
index dbc30c5404..792716d5d3 100644
--- a/lib/std/special/compiler_rt/fixsfti_test.zig
+++ b/lib/std/special/compiler_rt/fixsfti_test.zig
@@ -9,80 +9,80 @@ const math = std.math;
const testing = std.testing;
const warn = std.debug.warn;
-fn test__fixsfti(a: f32, expected: i128) void {
+fn test__fixsfti(a: f32, expected: i128) !void {
const x = __fixsfti(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixsfti" {
//warn("\n", .{});
- test__fixsfti(-math.f32_max, math.minInt(i128));
+ try test__fixsfti(-math.f32_max, math.minInt(i128));
- test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
- test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
+ try test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
+ try test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
- test__fixsfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
- test__fixsfti(-0x1.FFFFFFFFFFFFFp+126, -0x80000000000000000000000000000000);
- test__fixsfti(-0x1.FFFFFFFFFFFFEp+126, -0x80000000000000000000000000000000);
- test__fixsfti(-0x1.FFFFFF0000000p+126, -0x80000000000000000000000000000000);
- test__fixsfti(-0x1.FFFFFE0000000p+126, -0x7FFFFF80000000000000000000000000);
- test__fixsfti(-0x1.FFFFFC0000000p+126, -0x7FFFFF00000000000000000000000000);
+ try test__fixsfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
+ try test__fixsfti(-0x1.FFFFFFFFFFFFFp+126, -0x80000000000000000000000000000000);
+ try test__fixsfti(-0x1.FFFFFFFFFFFFEp+126, -0x80000000000000000000000000000000);
+ try test__fixsfti(-0x1.FFFFFF0000000p+126, -0x80000000000000000000000000000000);
+ try test__fixsfti(-0x1.FFFFFE0000000p+126, -0x7FFFFF80000000000000000000000000);
+ try test__fixsfti(-0x1.FFFFFC0000000p+126, -0x7FFFFF00000000000000000000000000);
- test__fixsfti(-0x1.0000000000001p+63, -0x8000000000000000);
- test__fixsfti(-0x1.0000000000000p+63, -0x8000000000000000);
- test__fixsfti(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);
- test__fixsfti(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);
+ try test__fixsfti(-0x1.0000000000001p+63, -0x8000000000000000);
+ try test__fixsfti(-0x1.0000000000000p+63, -0x8000000000000000);
+ try test__fixsfti(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);
+ try test__fixsfti(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);
- test__fixsfti(-0x1.FFFFFFp+62, -0x8000000000000000);
- test__fixsfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
- test__fixsfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
+ try test__fixsfti(-0x1.FFFFFFp+62, -0x8000000000000000);
+ try test__fixsfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
+ try test__fixsfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
- test__fixsfti(-0x1.000000p+31, -0x80000000);
- test__fixsfti(-0x1.FFFFFFp+30, -0x80000000);
- test__fixsfti(-0x1.FFFFFEp+30, -0x7FFFFF80);
- test__fixsfti(-0x1.FFFFFCp+30, -0x7FFFFF00);
+ try test__fixsfti(-0x1.000000p+31, -0x80000000);
+ try test__fixsfti(-0x1.FFFFFFp+30, -0x80000000);
+ try test__fixsfti(-0x1.FFFFFEp+30, -0x7FFFFF80);
+ try test__fixsfti(-0x1.FFFFFCp+30, -0x7FFFFF00);
- test__fixsfti(-2.01, -2);
- test__fixsfti(-2.0, -2);
- test__fixsfti(-1.99, -1);
- test__fixsfti(-1.0, -1);
- test__fixsfti(-0.99, 0);
- test__fixsfti(-0.5, 0);
- test__fixsfti(-math.f32_min, 0);
- test__fixsfti(0.0, 0);
- test__fixsfti(math.f32_min, 0);
- test__fixsfti(0.5, 0);
- test__fixsfti(0.99, 0);
- test__fixsfti(1.0, 1);
- test__fixsfti(1.5, 1);
- test__fixsfti(1.99, 1);
- test__fixsfti(2.0, 2);
- test__fixsfti(2.01, 2);
+ try test__fixsfti(-2.01, -2);
+ try test__fixsfti(-2.0, -2);
+ try test__fixsfti(-1.99, -1);
+ try test__fixsfti(-1.0, -1);
+ try test__fixsfti(-0.99, 0);
+ try test__fixsfti(-0.5, 0);
+ try test__fixsfti(-math.f32_min, 0);
+ try test__fixsfti(0.0, 0);
+ try test__fixsfti(math.f32_min, 0);
+ try test__fixsfti(0.5, 0);
+ try test__fixsfti(0.99, 0);
+ try test__fixsfti(1.0, 1);
+ try test__fixsfti(1.5, 1);
+ try test__fixsfti(1.99, 1);
+ try test__fixsfti(2.0, 2);
+ try test__fixsfti(2.01, 2);
- test__fixsfti(0x1.FFFFFCp+30, 0x7FFFFF00);
- test__fixsfti(0x1.FFFFFEp+30, 0x7FFFFF80);
- test__fixsfti(0x1.FFFFFFp+30, 0x80000000);
- test__fixsfti(0x1.000000p+31, 0x80000000);
+ try test__fixsfti(0x1.FFFFFCp+30, 0x7FFFFF00);
+ try test__fixsfti(0x1.FFFFFEp+30, 0x7FFFFF80);
+ try test__fixsfti(0x1.FFFFFFp+30, 0x80000000);
+ try test__fixsfti(0x1.000000p+31, 0x80000000);
- test__fixsfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
- test__fixsfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
- test__fixsfti(0x1.FFFFFFp+62, 0x8000000000000000);
+ try test__fixsfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
+ try test__fixsfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
+ try test__fixsfti(0x1.FFFFFFp+62, 0x8000000000000000);
- test__fixsfti(0x1.FFFFFFFFFFFFEp+62, 0x8000000000000000);
- test__fixsfti(0x1.FFFFFFFFFFFFFp+62, 0x8000000000000000);
- test__fixsfti(0x1.0000000000000p+63, 0x8000000000000000);
- test__fixsfti(0x1.0000000000001p+63, 0x8000000000000000);
+ try test__fixsfti(0x1.FFFFFFFFFFFFEp+62, 0x8000000000000000);
+ try test__fixsfti(0x1.FFFFFFFFFFFFFp+62, 0x8000000000000000);
+ try test__fixsfti(0x1.0000000000000p+63, 0x8000000000000000);
+ try test__fixsfti(0x1.0000000000001p+63, 0x8000000000000000);
- test__fixsfti(0x1.FFFFFC0000000p+126, 0x7FFFFF00000000000000000000000000);
- test__fixsfti(0x1.FFFFFE0000000p+126, 0x7FFFFF80000000000000000000000000);
- test__fixsfti(0x1.FFFFFF0000000p+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- test__fixsfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- test__fixsfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- test__fixsfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__fixsfti(0x1.FFFFFC0000000p+126, 0x7FFFFF00000000000000000000000000);
+ try test__fixsfti(0x1.FFFFFE0000000p+126, 0x7FFFFF80000000000000000000000000);
+ try test__fixsfti(0x1.FFFFFF0000000p+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__fixsfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__fixsfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__fixsfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
+ try test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
- test__fixsfti(math.f32_max, math.maxInt(i128));
+ try test__fixsfti(math.f32_max, math.maxInt(i128));
}
diff --git a/lib/std/special/compiler_rt/fixtfdi_test.zig b/lib/std/special/compiler_rt/fixtfdi_test.zig
index dfc08f84a3..ef72e6527c 100644
--- a/lib/std/special/compiler_rt/fixtfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixtfdi_test.zig
@@ -9,72 +9,72 @@ const math = std.math;
const testing = std.testing;
const warn = std.debug.warn;
-fn test__fixtfdi(a: f128, expected: i64) void {
+fn test__fixtfdi(a: f128, expected: i64) !void {
const x = __fixtfdi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixtfdi" {
//warn("\n", .{});
- test__fixtfdi(-math.f128_max, math.minInt(i64));
+ try test__fixtfdi(-math.f128_max, math.minInt(i64));
- test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
- test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
+ try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
+ try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
- test__fixtfdi(-0x1.0000000000000p+127, -0x8000000000000000);
- test__fixtfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
- test__fixtfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
+ try test__fixtfdi(-0x1.0000000000000p+127, -0x8000000000000000);
+ try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
+ try test__fixtfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
- test__fixtfdi(-0x1.0000000000001p+63, -0x8000000000000000);
- test__fixtfdi(-0x1.0000000000000p+63, -0x8000000000000000);
- test__fixtfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
- test__fixtfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
+ try test__fixtfdi(-0x1.0000000000001p+63, -0x8000000000000000);
+ try test__fixtfdi(-0x1.0000000000000p+63, -0x8000000000000000);
+ try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
+ try test__fixtfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
- test__fixtfdi(-0x1.FFFFFEp+62, -0x7FFFFF8000000000);
- test__fixtfdi(-0x1.FFFFFCp+62, -0x7FFFFF0000000000);
+ try test__fixtfdi(-0x1.FFFFFEp+62, -0x7FFFFF8000000000);
+ try test__fixtfdi(-0x1.FFFFFCp+62, -0x7FFFFF0000000000);
- test__fixtfdi(-0x1.000000p+31, -0x80000000);
- test__fixtfdi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
- test__fixtfdi(-0x1.FFFFFEp+30, -0x7FFFFF80);
- test__fixtfdi(-0x1.FFFFFCp+30, -0x7FFFFF00);
+ try test__fixtfdi(-0x1.000000p+31, -0x80000000);
+ try test__fixtfdi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
+ try test__fixtfdi(-0x1.FFFFFEp+30, -0x7FFFFF80);
+ try test__fixtfdi(-0x1.FFFFFCp+30, -0x7FFFFF00);
- test__fixtfdi(-2.01, -2);
- test__fixtfdi(-2.0, -2);
- test__fixtfdi(-1.99, -1);
- test__fixtfdi(-1.0, -1);
- test__fixtfdi(-0.99, 0);
- test__fixtfdi(-0.5, 0);
- test__fixtfdi(-math.f64_min, 0);
- test__fixtfdi(0.0, 0);
- test__fixtfdi(math.f64_min, 0);
- test__fixtfdi(0.5, 0);
- test__fixtfdi(0.99, 0);
- test__fixtfdi(1.0, 1);
- test__fixtfdi(1.5, 1);
- test__fixtfdi(1.99, 1);
- test__fixtfdi(2.0, 2);
- test__fixtfdi(2.01, 2);
+ try test__fixtfdi(-2.01, -2);
+ try test__fixtfdi(-2.0, -2);
+ try test__fixtfdi(-1.99, -1);
+ try test__fixtfdi(-1.0, -1);
+ try test__fixtfdi(-0.99, 0);
+ try test__fixtfdi(-0.5, 0);
+ try test__fixtfdi(-math.f64_min, 0);
+ try test__fixtfdi(0.0, 0);
+ try test__fixtfdi(math.f64_min, 0);
+ try test__fixtfdi(0.5, 0);
+ try test__fixtfdi(0.99, 0);
+ try test__fixtfdi(1.0, 1);
+ try test__fixtfdi(1.5, 1);
+ try test__fixtfdi(1.99, 1);
+ try test__fixtfdi(2.0, 2);
+ try test__fixtfdi(2.01, 2);
- test__fixtfdi(0x1.FFFFFCp+30, 0x7FFFFF00);
- test__fixtfdi(0x1.FFFFFEp+30, 0x7FFFFF80);
- test__fixtfdi(0x1.FFFFFFp+30, 0x7FFFFFC0);
- test__fixtfdi(0x1.000000p+31, 0x80000000);
+ try test__fixtfdi(0x1.FFFFFCp+30, 0x7FFFFF00);
+ try test__fixtfdi(0x1.FFFFFEp+30, 0x7FFFFF80);
+ try test__fixtfdi(0x1.FFFFFFp+30, 0x7FFFFFC0);
+ try test__fixtfdi(0x1.000000p+31, 0x80000000);
- test__fixtfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
- test__fixtfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
+ try test__fixtfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
+ try test__fixtfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
- test__fixtfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
- test__fixtfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
- test__fixtfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
- test__fixtfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
+ try test__fixtfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
+ try test__fixtfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
+ try test__fixtfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
+ try test__fixtfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
- test__fixtfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
- test__fixtfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
- test__fixtfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
+ try test__fixtfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
+ try test__fixtfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
+ try test__fixtfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
- test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
- test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
+ try test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
+ try test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
- test__fixtfdi(math.f128_max, math.maxInt(i64));
+ try test__fixtfdi(math.f128_max, math.maxInt(i64));
}
diff --git a/lib/std/special/compiler_rt/fixtfsi_test.zig b/lib/std/special/compiler_rt/fixtfsi_test.zig
index e5605a3936..61a963b07d 100644
--- a/lib/std/special/compiler_rt/fixtfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixtfsi_test.zig
@@ -9,72 +9,72 @@ const math = std.math;
const testing = std.testing;
const warn = std.debug.warn;
-fn test__fixtfsi(a: f128, expected: i32) void {
+fn test__fixtfsi(a: f128, expected: i32) !void {
const x = __fixtfsi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixtfsi" {
//warn("\n", .{});
- test__fixtfsi(-math.f128_max, math.minInt(i32));
+ try test__fixtfsi(-math.f128_max, math.minInt(i32));
- test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
- test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
+ try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
+ try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
- test__fixtfsi(-0x1.0000000000000p+127, -0x80000000);
- test__fixtfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
- test__fixtfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
+ try test__fixtfsi(-0x1.0000000000000p+127, -0x80000000);
+ try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
+ try test__fixtfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
- test__fixtfsi(-0x1.0000000000001p+63, -0x80000000);
- test__fixtfsi(-0x1.0000000000000p+63, -0x80000000);
- test__fixtfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
- test__fixtfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
+ try test__fixtfsi(-0x1.0000000000001p+63, -0x80000000);
+ try test__fixtfsi(-0x1.0000000000000p+63, -0x80000000);
+ try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
+ try test__fixtfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
- test__fixtfsi(-0x1.FFFFFEp+62, -0x80000000);
- test__fixtfsi(-0x1.FFFFFCp+62, -0x80000000);
+ try test__fixtfsi(-0x1.FFFFFEp+62, -0x80000000);
+ try test__fixtfsi(-0x1.FFFFFCp+62, -0x80000000);
- test__fixtfsi(-0x1.000000p+31, -0x80000000);
- test__fixtfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
- test__fixtfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
- test__fixtfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);
+ try test__fixtfsi(-0x1.000000p+31, -0x80000000);
+ try test__fixtfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
+ try test__fixtfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
+ try test__fixtfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);
- test__fixtfsi(-2.01, -2);
- test__fixtfsi(-2.0, -2);
- test__fixtfsi(-1.99, -1);
- test__fixtfsi(-1.0, -1);
- test__fixtfsi(-0.99, 0);
- test__fixtfsi(-0.5, 0);
- test__fixtfsi(-math.f32_min, 0);
- test__fixtfsi(0.0, 0);
- test__fixtfsi(math.f32_min, 0);
- test__fixtfsi(0.5, 0);
- test__fixtfsi(0.99, 0);
- test__fixtfsi(1.0, 1);
- test__fixtfsi(1.5, 1);
- test__fixtfsi(1.99, 1);
- test__fixtfsi(2.0, 2);
- test__fixtfsi(2.01, 2);
+ try test__fixtfsi(-2.01, -2);
+ try test__fixtfsi(-2.0, -2);
+ try test__fixtfsi(-1.99, -1);
+ try test__fixtfsi(-1.0, -1);
+ try test__fixtfsi(-0.99, 0);
+ try test__fixtfsi(-0.5, 0);
+ try test__fixtfsi(-math.f32_min, 0);
+ try test__fixtfsi(0.0, 0);
+ try test__fixtfsi(math.f32_min, 0);
+ try test__fixtfsi(0.5, 0);
+ try test__fixtfsi(0.99, 0);
+ try test__fixtfsi(1.0, 1);
+ try test__fixtfsi(1.5, 1);
+ try test__fixtfsi(1.99, 1);
+ try test__fixtfsi(2.0, 2);
+ try test__fixtfsi(2.01, 2);
- test__fixtfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
- test__fixtfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
- test__fixtfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);
- test__fixtfsi(0x1.000000p+31, 0x7FFFFFFF);
+ try test__fixtfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
+ try test__fixtfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
+ try test__fixtfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);
+ try test__fixtfsi(0x1.000000p+31, 0x7FFFFFFF);
- test__fixtfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
- test__fixtfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
+ try test__fixtfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
+ try test__fixtfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
- test__fixtfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
- test__fixtfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
- test__fixtfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
- test__fixtfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
+ try test__fixtfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
+ try test__fixtfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
+ try test__fixtfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
+ try test__fixtfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
- test__fixtfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
- test__fixtfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
- test__fixtfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
+ try test__fixtfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
+ try test__fixtfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
+ try test__fixtfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
- test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
- test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
+ try test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
+ try test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
- test__fixtfsi(math.f128_max, math.maxInt(i32));
+ try test__fixtfsi(math.f128_max, math.maxInt(i32));
}
diff --git a/lib/std/special/compiler_rt/fixtfti_test.zig b/lib/std/special/compiler_rt/fixtfti_test.zig
index b01e3af9f9..23ec67a737 100644
--- a/lib/std/special/compiler_rt/fixtfti_test.zig
+++ b/lib/std/special/compiler_rt/fixtfti_test.zig
@@ -9,62 +9,62 @@ const math = std.math;
const testing = std.testing;
const warn = std.debug.warn;
-fn test__fixtfti(a: f128, expected: i128) void {
+fn test__fixtfti(a: f128, expected: i128) !void {
const x = __fixtfti(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixtfti" {
//warn("\n", .{});
- test__fixtfti(-math.f128_max, math.minInt(i128));
+ try test__fixtfti(-math.f128_max, math.minInt(i128));
- test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
- test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
+ try test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
+ try test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
- test__fixtfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
- test__fixtfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);
- test__fixtfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);
+ try test__fixtfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
+ try test__fixtfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);
+ try test__fixtfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);
- test__fixtfti(-0x1.0000000000001p+63, -0x8000000000000800);
- test__fixtfti(-0x1.0000000000000p+63, -0x8000000000000000);
- test__fixtfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
- test__fixtfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
+ try test__fixtfti(-0x1.0000000000001p+63, -0x8000000000000800);
+ try test__fixtfti(-0x1.0000000000000p+63, -0x8000000000000000);
+ try test__fixtfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
+ try test__fixtfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
- test__fixtfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
- test__fixtfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
+ try test__fixtfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
+ try test__fixtfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
- test__fixtfti(-2.01, -2);
- test__fixtfti(-2.0, -2);
- test__fixtfti(-1.99, -1);
- test__fixtfti(-1.0, -1);
- test__fixtfti(-0.99, 0);
- test__fixtfti(-0.5, 0);
- test__fixtfti(-math.f128_min, 0);
- test__fixtfti(0.0, 0);
- test__fixtfti(math.f128_min, 0);
- test__fixtfti(0.5, 0);
- test__fixtfti(0.99, 0);
- test__fixtfti(1.0, 1);
- test__fixtfti(1.5, 1);
- test__fixtfti(1.99, 1);
- test__fixtfti(2.0, 2);
- test__fixtfti(2.01, 2);
+ try test__fixtfti(-2.01, -2);
+ try test__fixtfti(-2.0, -2);
+ try test__fixtfti(-1.99, -1);
+ try test__fixtfti(-1.0, -1);
+ try test__fixtfti(-0.99, 0);
+ try test__fixtfti(-0.5, 0);
+ try test__fixtfti(-math.f128_min, 0);
+ try test__fixtfti(0.0, 0);
+ try test__fixtfti(math.f128_min, 0);
+ try test__fixtfti(0.5, 0);
+ try test__fixtfti(0.99, 0);
+ try test__fixtfti(1.0, 1);
+ try test__fixtfti(1.5, 1);
+ try test__fixtfti(1.99, 1);
+ try test__fixtfti(2.0, 2);
+ try test__fixtfti(2.01, 2);
- test__fixtfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
- test__fixtfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
+ try test__fixtfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
+ try test__fixtfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
- test__fixtfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
- test__fixtfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
- test__fixtfti(0x1.0000000000000p+63, 0x8000000000000000);
- test__fixtfti(0x1.0000000000001p+63, 0x8000000000000800);
+ try test__fixtfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
+ try test__fixtfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
+ try test__fixtfti(0x1.0000000000000p+63, 0x8000000000000000);
+ try test__fixtfti(0x1.0000000000001p+63, 0x8000000000000800);
- test__fixtfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
- test__fixtfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
- test__fixtfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__fixtfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
+ try test__fixtfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
+ try test__fixtfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
+ try test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
- test__fixtfti(math.f128_max, math.maxInt(i128));
+ try test__fixtfti(math.f128_max, math.maxInt(i128));
}
diff --git a/lib/std/special/compiler_rt/fixunsdfdi_test.zig b/lib/std/special/compiler_rt/fixunsdfdi_test.zig
index b7bbe42fb9..dcccb076d4 100644
--- a/lib/std/special/compiler_rt/fixunsdfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixunsdfdi_test.zig
@@ -6,39 +6,39 @@
const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi;
const testing = @import("std").testing;
-fn test__fixunsdfdi(a: f64, expected: u64) void {
+fn test__fixunsdfdi(a: f64, expected: u64) !void {
const x = __fixunsdfdi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunsdfdi" {
//test__fixunsdfdi(0.0, 0);
//test__fixunsdfdi(0.5, 0);
//test__fixunsdfdi(0.99, 0);
- test__fixunsdfdi(1.0, 1);
- test__fixunsdfdi(1.5, 1);
- test__fixunsdfdi(1.99, 1);
- test__fixunsdfdi(2.0, 2);
- test__fixunsdfdi(2.01, 2);
- test__fixunsdfdi(-0.5, 0);
- test__fixunsdfdi(-0.99, 0);
- test__fixunsdfdi(-1.0, 0);
- test__fixunsdfdi(-1.5, 0);
- test__fixunsdfdi(-1.99, 0);
- test__fixunsdfdi(-2.0, 0);
- test__fixunsdfdi(-2.01, 0);
+ try test__fixunsdfdi(1.0, 1);
+ try test__fixunsdfdi(1.5, 1);
+ try test__fixunsdfdi(1.99, 1);
+ try test__fixunsdfdi(2.0, 2);
+ try test__fixunsdfdi(2.01, 2);
+ try test__fixunsdfdi(-0.5, 0);
+ try test__fixunsdfdi(-0.99, 0);
+ try test__fixunsdfdi(-1.0, 0);
+ try test__fixunsdfdi(-1.5, 0);
+ try test__fixunsdfdi(-1.99, 0);
+ try test__fixunsdfdi(-2.0, 0);
+ try test__fixunsdfdi(-2.01, 0);
- test__fixunsdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
- test__fixunsdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
+ try test__fixunsdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
+ try test__fixunsdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
- test__fixunsdfdi(-0x1.FFFFFEp+62, 0);
- test__fixunsdfdi(-0x1.FFFFFCp+62, 0);
+ try test__fixunsdfdi(-0x1.FFFFFEp+62, 0);
+ try test__fixunsdfdi(-0x1.FFFFFCp+62, 0);
- test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);
- test__fixunsdfdi(0x1.0000000000000p+63, 0x8000000000000000);
- test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
- test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
+ try test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);
+ try test__fixunsdfdi(0x1.0000000000000p+63, 0x8000000000000000);
+ try test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
+ try test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
- test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0);
- test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp+62, 0);
+ try test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0);
+ try test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp+62, 0);
}
diff --git a/lib/std/special/compiler_rt/fixunsdfsi_test.zig b/lib/std/special/compiler_rt/fixunsdfsi_test.zig
index a083f97f0b..059eb208c7 100644
--- a/lib/std/special/compiler_rt/fixunsdfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixunsdfsi_test.zig
@@ -6,39 +6,39 @@
const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi;
const testing = @import("std").testing;
-fn test__fixunsdfsi(a: f64, expected: u32) void {
+fn test__fixunsdfsi(a: f64, expected: u32) !void {
const x = __fixunsdfsi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunsdfsi" {
- test__fixunsdfsi(0.0, 0);
+ try test__fixunsdfsi(0.0, 0);
- test__fixunsdfsi(0.5, 0);
- test__fixunsdfsi(0.99, 0);
- test__fixunsdfsi(1.0, 1);
- test__fixunsdfsi(1.5, 1);
- test__fixunsdfsi(1.99, 1);
- test__fixunsdfsi(2.0, 2);
- test__fixunsdfsi(2.01, 2);
- test__fixunsdfsi(-0.5, 0);
- test__fixunsdfsi(-0.99, 0);
- test__fixunsdfsi(-1.0, 0);
- test__fixunsdfsi(-1.5, 0);
- test__fixunsdfsi(-1.99, 0);
- test__fixunsdfsi(-2.0, 0);
- test__fixunsdfsi(-2.01, 0);
+ try test__fixunsdfsi(0.5, 0);
+ try test__fixunsdfsi(0.99, 0);
+ try test__fixunsdfsi(1.0, 1);
+ try test__fixunsdfsi(1.5, 1);
+ try test__fixunsdfsi(1.99, 1);
+ try test__fixunsdfsi(2.0, 2);
+ try test__fixunsdfsi(2.01, 2);
+ try test__fixunsdfsi(-0.5, 0);
+ try test__fixunsdfsi(-0.99, 0);
+ try test__fixunsdfsi(-1.0, 0);
+ try test__fixunsdfsi(-1.5, 0);
+ try test__fixunsdfsi(-1.99, 0);
+ try test__fixunsdfsi(-2.0, 0);
+ try test__fixunsdfsi(-2.01, 0);
- test__fixunsdfsi(0x1.000000p+31, 0x80000000);
- test__fixunsdfsi(0x1.000000p+32, 0xFFFFFFFF);
- test__fixunsdfsi(0x1.FFFFFEp+31, 0xFFFFFF00);
- test__fixunsdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
- test__fixunsdfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
+ try test__fixunsdfsi(0x1.000000p+31, 0x80000000);
+ try test__fixunsdfsi(0x1.000000p+32, 0xFFFFFFFF);
+ try test__fixunsdfsi(0x1.FFFFFEp+31, 0xFFFFFF00);
+ try test__fixunsdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
+ try test__fixunsdfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
- test__fixunsdfsi(-0x1.FFFFFEp+30, 0);
- test__fixunsdfsi(-0x1.FFFFFCp+30, 0);
+ try test__fixunsdfsi(-0x1.FFFFFEp+30, 0);
+ try test__fixunsdfsi(-0x1.FFFFFCp+30, 0);
- test__fixunsdfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF);
- test__fixunsdfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF);
- test__fixunsdfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE);
+ try test__fixunsdfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF);
+ try test__fixunsdfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF);
+ try test__fixunsdfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE);
}
diff --git a/lib/std/special/compiler_rt/fixunsdfti_test.zig b/lib/std/special/compiler_rt/fixunsdfti_test.zig
index dbfeb0fc4b..89098afb33 100644
--- a/lib/std/special/compiler_rt/fixunsdfti_test.zig
+++ b/lib/std/special/compiler_rt/fixunsdfti_test.zig
@@ -6,46 +6,46 @@
const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti;
const testing = @import("std").testing;
-fn test__fixunsdfti(a: f64, expected: u128) void {
+fn test__fixunsdfti(a: f64, expected: u128) !void {
const x = __fixunsdfti(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunsdfti" {
- test__fixunsdfti(0.0, 0);
+ try test__fixunsdfti(0.0, 0);
- test__fixunsdfti(0.5, 0);
- test__fixunsdfti(0.99, 0);
- test__fixunsdfti(1.0, 1);
- test__fixunsdfti(1.5, 1);
- test__fixunsdfti(1.99, 1);
- test__fixunsdfti(2.0, 2);
- test__fixunsdfti(2.01, 2);
- test__fixunsdfti(-0.5, 0);
- test__fixunsdfti(-0.99, 0);
- test__fixunsdfti(-1.0, 0);
- test__fixunsdfti(-1.5, 0);
- test__fixunsdfti(-1.99, 0);
- test__fixunsdfti(-2.0, 0);
- test__fixunsdfti(-2.01, 0);
+ try test__fixunsdfti(0.5, 0);
+ try test__fixunsdfti(0.99, 0);
+ try test__fixunsdfti(1.0, 1);
+ try test__fixunsdfti(1.5, 1);
+ try test__fixunsdfti(1.99, 1);
+ try test__fixunsdfti(2.0, 2);
+ try test__fixunsdfti(2.01, 2);
+ try test__fixunsdfti(-0.5, 0);
+ try test__fixunsdfti(-0.99, 0);
+ try test__fixunsdfti(-1.0, 0);
+ try test__fixunsdfti(-1.5, 0);
+ try test__fixunsdfti(-1.99, 0);
+ try test__fixunsdfti(-2.0, 0);
+ try test__fixunsdfti(-2.01, 0);
- test__fixunsdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
- test__fixunsdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
+ try test__fixunsdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
+ try test__fixunsdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
- test__fixunsdfti(-0x1.FFFFFEp+62, 0);
- test__fixunsdfti(-0x1.FFFFFCp+62, 0);
+ try test__fixunsdfti(-0x1.FFFFFEp+62, 0);
+ try test__fixunsdfti(-0x1.FFFFFCp+62, 0);
- test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);
- test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000);
- test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
- test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
+ try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);
+ try test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000);
+ try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
+ try test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
- test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, 0xFFFFFFFFFFFFF8000000000000000000);
- test__fixunsdfti(0x1.0000000000000p+127, 0x80000000000000000000000000000000);
- test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
- test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
- test__fixunsdfti(0x1.0000000000000p+128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, 0xFFFFFFFFFFFFF8000000000000000000);
+ try test__fixunsdfti(0x1.0000000000000p+127, 0x80000000000000000000000000000000);
+ try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
+ try test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
+ try test__fixunsdfti(0x1.0000000000000p+128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0);
- test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0);
+ try test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0);
+ try test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0);
}
diff --git a/lib/std/special/compiler_rt/fixunssfdi_test.zig b/lib/std/special/compiler_rt/fixunssfdi_test.zig
index d5e04292cb..005e005a9b 100644
--- a/lib/std/special/compiler_rt/fixunssfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixunssfdi_test.zig
@@ -6,35 +6,35 @@
const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi;
const testing = @import("std").testing;
-fn test__fixunssfdi(a: f32, expected: u64) void {
+fn test__fixunssfdi(a: f32, expected: u64) !void {
const x = __fixunssfdi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunssfdi" {
- test__fixunssfdi(0.0, 0);
+ try test__fixunssfdi(0.0, 0);
- test__fixunssfdi(0.5, 0);
- test__fixunssfdi(0.99, 0);
- test__fixunssfdi(1.0, 1);
- test__fixunssfdi(1.5, 1);
- test__fixunssfdi(1.99, 1);
- test__fixunssfdi(2.0, 2);
- test__fixunssfdi(2.01, 2);
- test__fixunssfdi(-0.5, 0);
- test__fixunssfdi(-0.99, 0);
+ try test__fixunssfdi(0.5, 0);
+ try test__fixunssfdi(0.99, 0);
+ try test__fixunssfdi(1.0, 1);
+ try test__fixunssfdi(1.5, 1);
+ try test__fixunssfdi(1.99, 1);
+ try test__fixunssfdi(2.0, 2);
+ try test__fixunssfdi(2.01, 2);
+ try test__fixunssfdi(-0.5, 0);
+ try test__fixunssfdi(-0.99, 0);
- test__fixunssfdi(-1.0, 0);
- test__fixunssfdi(-1.5, 0);
- test__fixunssfdi(-1.99, 0);
- test__fixunssfdi(-2.0, 0);
- test__fixunssfdi(-2.01, 0);
+ try test__fixunssfdi(-1.0, 0);
+ try test__fixunssfdi(-1.5, 0);
+ try test__fixunssfdi(-1.99, 0);
+ try test__fixunssfdi(-2.0, 0);
+ try test__fixunssfdi(-2.01, 0);
- test__fixunssfdi(0x1.FFFFFEp+63, 0xFFFFFF0000000000);
- test__fixunssfdi(0x1.000000p+63, 0x8000000000000000);
- test__fixunssfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
- test__fixunssfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
+ try test__fixunssfdi(0x1.FFFFFEp+63, 0xFFFFFF0000000000);
+ try test__fixunssfdi(0x1.000000p+63, 0x8000000000000000);
+ try test__fixunssfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
+ try test__fixunssfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
- test__fixunssfdi(-0x1.FFFFFEp+62, 0x0000000000000000);
- test__fixunssfdi(-0x1.FFFFFCp+62, 0x0000000000000000);
+ try test__fixunssfdi(-0x1.FFFFFEp+62, 0x0000000000000000);
+ try test__fixunssfdi(-0x1.FFFFFCp+62, 0x0000000000000000);
}
diff --git a/lib/std/special/compiler_rt/fixunssfsi_test.zig b/lib/std/special/compiler_rt/fixunssfsi_test.zig
index c30c1d6804..90cb202230 100644
--- a/lib/std/special/compiler_rt/fixunssfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixunssfsi_test.zig
@@ -6,36 +6,36 @@
const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi;
const testing = @import("std").testing;
-fn test__fixunssfsi(a: f32, expected: u32) void {
+fn test__fixunssfsi(a: f32, expected: u32) !void {
const x = __fixunssfsi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunssfsi" {
- test__fixunssfsi(0.0, 0);
+ try test__fixunssfsi(0.0, 0);
- test__fixunssfsi(0.5, 0);
- test__fixunssfsi(0.99, 0);
- test__fixunssfsi(1.0, 1);
- test__fixunssfsi(1.5, 1);
- test__fixunssfsi(1.99, 1);
- test__fixunssfsi(2.0, 2);
- test__fixunssfsi(2.01, 2);
- test__fixunssfsi(-0.5, 0);
- test__fixunssfsi(-0.99, 0);
+ try test__fixunssfsi(0.5, 0);
+ try test__fixunssfsi(0.99, 0);
+ try test__fixunssfsi(1.0, 1);
+ try test__fixunssfsi(1.5, 1);
+ try test__fixunssfsi(1.99, 1);
+ try test__fixunssfsi(2.0, 2);
+ try test__fixunssfsi(2.01, 2);
+ try test__fixunssfsi(-0.5, 0);
+ try test__fixunssfsi(-0.99, 0);
- test__fixunssfsi(-1.0, 0);
- test__fixunssfsi(-1.5, 0);
- test__fixunssfsi(-1.99, 0);
- test__fixunssfsi(-2.0, 0);
- test__fixunssfsi(-2.01, 0);
+ try test__fixunssfsi(-1.0, 0);
+ try test__fixunssfsi(-1.5, 0);
+ try test__fixunssfsi(-1.99, 0);
+ try test__fixunssfsi(-2.0, 0);
+ try test__fixunssfsi(-2.01, 0);
- test__fixunssfsi(0x1.000000p+31, 0x80000000);
- test__fixunssfsi(0x1.000000p+32, 0xFFFFFFFF);
- test__fixunssfsi(0x1.FFFFFEp+31, 0xFFFFFF00);
- test__fixunssfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
- test__fixunssfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
+ try test__fixunssfsi(0x1.000000p+31, 0x80000000);
+ try test__fixunssfsi(0x1.000000p+32, 0xFFFFFFFF);
+ try test__fixunssfsi(0x1.FFFFFEp+31, 0xFFFFFF00);
+ try test__fixunssfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
+ try test__fixunssfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
- test__fixunssfsi(-0x1.FFFFFEp+30, 0);
- test__fixunssfsi(-0x1.FFFFFCp+30, 0);
+ try test__fixunssfsi(-0x1.FFFFFEp+30, 0);
+ try test__fixunssfsi(-0x1.FFFFFCp+30, 0);
}
diff --git a/lib/std/special/compiler_rt/fixunssfti_test.zig b/lib/std/special/compiler_rt/fixunssfti_test.zig
index b148f5a35a..6dabae8ba8 100644
--- a/lib/std/special/compiler_rt/fixunssfti_test.zig
+++ b/lib/std/special/compiler_rt/fixunssfti_test.zig
@@ -6,41 +6,41 @@
const __fixunssfti = @import("fixunssfti.zig").__fixunssfti;
const testing = @import("std").testing;
-fn test__fixunssfti(a: f32, expected: u128) void {
+fn test__fixunssfti(a: f32, expected: u128) !void {
const x = __fixunssfti(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunssfti" {
- test__fixunssfti(0.0, 0);
+ try test__fixunssfti(0.0, 0);
- test__fixunssfti(0.5, 0);
- test__fixunssfti(0.99, 0);
- test__fixunssfti(1.0, 1);
- test__fixunssfti(1.5, 1);
- test__fixunssfti(1.99, 1);
- test__fixunssfti(2.0, 2);
- test__fixunssfti(2.01, 2);
- test__fixunssfti(-0.5, 0);
- test__fixunssfti(-0.99, 0);
+ try test__fixunssfti(0.5, 0);
+ try test__fixunssfti(0.99, 0);
+ try test__fixunssfti(1.0, 1);
+ try test__fixunssfti(1.5, 1);
+ try test__fixunssfti(1.99, 1);
+ try test__fixunssfti(2.0, 2);
+ try test__fixunssfti(2.01, 2);
+ try test__fixunssfti(-0.5, 0);
+ try test__fixunssfti(-0.99, 0);
- test__fixunssfti(-1.0, 0);
- test__fixunssfti(-1.5, 0);
- test__fixunssfti(-1.99, 0);
- test__fixunssfti(-2.0, 0);
- test__fixunssfti(-2.01, 0);
+ try test__fixunssfti(-1.0, 0);
+ try test__fixunssfti(-1.5, 0);
+ try test__fixunssfti(-1.99, 0);
+ try test__fixunssfti(-2.0, 0);
+ try test__fixunssfti(-2.01, 0);
- test__fixunssfti(0x1.FFFFFEp+63, 0xFFFFFF0000000000);
- test__fixunssfti(0x1.000000p+63, 0x8000000000000000);
- test__fixunssfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
- test__fixunssfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
- test__fixunssfti(0x1.FFFFFEp+127, 0xFFFFFF00000000000000000000000000);
- test__fixunssfti(0x1.000000p+127, 0x80000000000000000000000000000000);
- test__fixunssfti(0x1.FFFFFEp+126, 0x7FFFFF80000000000000000000000000);
- test__fixunssfti(0x1.FFFFFCp+126, 0x7FFFFF00000000000000000000000000);
+ try test__fixunssfti(0x1.FFFFFEp+63, 0xFFFFFF0000000000);
+ try test__fixunssfti(0x1.000000p+63, 0x8000000000000000);
+ try test__fixunssfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
+ try test__fixunssfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
+ try test__fixunssfti(0x1.FFFFFEp+127, 0xFFFFFF00000000000000000000000000);
+ try test__fixunssfti(0x1.000000p+127, 0x80000000000000000000000000000000);
+ try test__fixunssfti(0x1.FFFFFEp+126, 0x7FFFFF80000000000000000000000000);
+ try test__fixunssfti(0x1.FFFFFCp+126, 0x7FFFFF00000000000000000000000000);
- test__fixunssfti(-0x1.FFFFFEp+62, 0x0000000000000000);
- test__fixunssfti(-0x1.FFFFFCp+62, 0x0000000000000000);
- test__fixunssfti(-0x1.FFFFFEp+126, 0x0000000000000000);
- test__fixunssfti(-0x1.FFFFFCp+126, 0x0000000000000000);
+ try test__fixunssfti(-0x1.FFFFFEp+62, 0x0000000000000000);
+ try test__fixunssfti(-0x1.FFFFFCp+62, 0x0000000000000000);
+ try test__fixunssfti(-0x1.FFFFFEp+126, 0x0000000000000000);
+ try test__fixunssfti(-0x1.FFFFFCp+126, 0x0000000000000000);
}
diff --git a/lib/std/special/compiler_rt/fixunstfdi_test.zig b/lib/std/special/compiler_rt/fixunstfdi_test.zig
index b0297d4a2f..7102203cc0 100644
--- a/lib/std/special/compiler_rt/fixunstfdi_test.zig
+++ b/lib/std/special/compiler_rt/fixunstfdi_test.zig
@@ -6,49 +6,49 @@
const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi;
const testing = @import("std").testing;
-fn test__fixunstfdi(a: f128, expected: u64) void {
+fn test__fixunstfdi(a: f128, expected: u64) !void {
const x = __fixunstfdi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunstfdi" {
- test__fixunstfdi(0.0, 0);
+ try test__fixunstfdi(0.0, 0);
- test__fixunstfdi(0.5, 0);
- test__fixunstfdi(0.99, 0);
- test__fixunstfdi(1.0, 1);
- test__fixunstfdi(1.5, 1);
- test__fixunstfdi(1.99, 1);
- test__fixunstfdi(2.0, 2);
- test__fixunstfdi(2.01, 2);
- test__fixunstfdi(-0.5, 0);
- test__fixunstfdi(-0.99, 0);
- test__fixunstfdi(-1.0, 0);
- test__fixunstfdi(-1.5, 0);
- test__fixunstfdi(-1.99, 0);
- test__fixunstfdi(-2.0, 0);
- test__fixunstfdi(-2.01, 0);
+ try test__fixunstfdi(0.5, 0);
+ try test__fixunstfdi(0.99, 0);
+ try test__fixunstfdi(1.0, 1);
+ try test__fixunstfdi(1.5, 1);
+ try test__fixunstfdi(1.99, 1);
+ try test__fixunstfdi(2.0, 2);
+ try test__fixunstfdi(2.01, 2);
+ try test__fixunstfdi(-0.5, 0);
+ try test__fixunstfdi(-0.99, 0);
+ try test__fixunstfdi(-1.0, 0);
+ try test__fixunstfdi(-1.5, 0);
+ try test__fixunstfdi(-1.99, 0);
+ try test__fixunstfdi(-2.0, 0);
+ try test__fixunstfdi(-2.01, 0);
- test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
- test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
+ try test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
+ try test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
- test__fixunstfdi(-0x1.FFFFFEp+62, 0);
- test__fixunstfdi(-0x1.FFFFFCp+62, 0);
+ try test__fixunstfdi(-0x1.FFFFFEp+62, 0);
+ try test__fixunstfdi(-0x1.FFFFFCp+62, 0);
- test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
- test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
+ try test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
+ try test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
- test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0);
- test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0);
+ try test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0);
+ try test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0);
- test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63, 0xFFFFFFFFFFFFFFFF);
- test__fixunstfdi(0x1.0000000000000002p+63, 0x8000000000000001);
- test__fixunstfdi(0x1.0000000000000000p+63, 0x8000000000000000);
- test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62, 0x7FFFFFFFFFFFFFFF);
- test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62, 0x7FFFFFFFFFFFFFFE);
- test__fixunstfdi(0x1.p+64, 0xFFFFFFFFFFFFFFFF);
+ try test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63, 0xFFFFFFFFFFFFFFFF);
+ try test__fixunstfdi(0x1.0000000000000002p+63, 0x8000000000000001);
+ try test__fixunstfdi(0x1.0000000000000000p+63, 0x8000000000000000);
+ try test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62, 0x7FFFFFFFFFFFFFFF);
+ try test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62, 0x7FFFFFFFFFFFFFFE);
+ try test__fixunstfdi(0x1.p+64, 0xFFFFFFFFFFFFFFFF);
- test__fixunstfdi(-0x1.0000000000000000p+63, 0);
- test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62, 0);
- test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62, 0);
+ try test__fixunstfdi(-0x1.0000000000000000p+63, 0);
+ try test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62, 0);
+ try test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62, 0);
}
diff --git a/lib/std/special/compiler_rt/fixunstfsi_test.zig b/lib/std/special/compiler_rt/fixunstfsi_test.zig
index f1cb9f6de7..9173b01f46 100644
--- a/lib/std/special/compiler_rt/fixunstfsi_test.zig
+++ b/lib/std/special/compiler_rt/fixunstfsi_test.zig
@@ -6,22 +6,22 @@
const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi;
const testing = @import("std").testing;
-fn test__fixunstfsi(a: f128, expected: u32) void {
+fn test__fixunstfsi(a: f128, expected: u32) !void {
const x = __fixunstfsi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
test "fixunstfsi" {
- test__fixunstfsi(inf128, 0xffffffff);
- test__fixunstfsi(0, 0x0);
- test__fixunstfsi(0x1.23456789abcdefp+5, 0x24);
- test__fixunstfsi(0x1.23456789abcdefp-3, 0x0);
- test__fixunstfsi(0x1.23456789abcdefp+20, 0x123456);
- test__fixunstfsi(0x1.23456789abcdefp+40, 0xffffffff);
- test__fixunstfsi(0x1.23456789abcdefp+256, 0xffffffff);
- test__fixunstfsi(-0x1.23456789abcdefp+3, 0x0);
+ try test__fixunstfsi(inf128, 0xffffffff);
+ try test__fixunstfsi(0, 0x0);
+ try test__fixunstfsi(0x1.23456789abcdefp+5, 0x24);
+ try test__fixunstfsi(0x1.23456789abcdefp-3, 0x0);
+ try test__fixunstfsi(0x1.23456789abcdefp+20, 0x123456);
+ try test__fixunstfsi(0x1.23456789abcdefp+40, 0xffffffff);
+ try test__fixunstfsi(0x1.23456789abcdefp+256, 0xffffffff);
+ try test__fixunstfsi(-0x1.23456789abcdefp+3, 0x0);
- test__fixunstfsi(0x1.p+32, 0xFFFFFFFF);
+ try test__fixunstfsi(0x1.p+32, 0xFFFFFFFF);
}
diff --git a/lib/std/special/compiler_rt/fixunstfti_test.zig b/lib/std/special/compiler_rt/fixunstfti_test.zig
index fcbf9d3b25..450b07b524 100644
--- a/lib/std/special/compiler_rt/fixunstfti_test.zig
+++ b/lib/std/special/compiler_rt/fixunstfti_test.zig
@@ -6,32 +6,32 @@
const __fixunstfti = @import("fixunstfti.zig").__fixunstfti;
const testing = @import("std").testing;
-fn test__fixunstfti(a: f128, expected: u128) void {
+fn test__fixunstfti(a: f128, expected: u128) !void {
const x = __fixunstfti(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
test "fixunstfti" {
- test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff);
+ try test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff);
- test__fixunstfti(0.0, 0);
+ try test__fixunstfti(0.0, 0);
- test__fixunstfti(0.5, 0);
- test__fixunstfti(0.99, 0);
- test__fixunstfti(1.0, 1);
- test__fixunstfti(1.5, 1);
- test__fixunstfti(1.99, 1);
- test__fixunstfti(2.0, 2);
- test__fixunstfti(2.01, 2);
- test__fixunstfti(-0.01, 0);
- test__fixunstfti(-0.99, 0);
+ try test__fixunstfti(0.5, 0);
+ try test__fixunstfti(0.99, 0);
+ try test__fixunstfti(1.0, 1);
+ try test__fixunstfti(1.5, 1);
+ try test__fixunstfti(1.99, 1);
+ try test__fixunstfti(2.0, 2);
+ try test__fixunstfti(2.01, 2);
+ try test__fixunstfti(-0.01, 0);
+ try test__fixunstfti(-0.99, 0);
- test__fixunstfti(0x1.p+128, 0xffffffffffffffffffffffffffffffff);
+ try test__fixunstfti(0x1.p+128, 0xffffffffffffffffffffffffffffffff);
- test__fixunstfti(0x1.FFFFFEp+126, 0x7fffff80000000000000000000000000);
- test__fixunstfti(0x1.FFFFFEp+127, 0xffffff00000000000000000000000000);
- test__fixunstfti(0x1.FFFFFEp+128, 0xffffffffffffffffffffffffffffffff);
- test__fixunstfti(0x1.FFFFFEp+129, 0xffffffffffffffffffffffffffffffff);
+ try test__fixunstfti(0x1.FFFFFEp+126, 0x7fffff80000000000000000000000000);
+ try test__fixunstfti(0x1.FFFFFEp+127, 0xffffff00000000000000000000000000);
+ try test__fixunstfti(0x1.FFFFFEp+128, 0xffffffffffffffffffffffffffffffff);
+ try test__fixunstfti(0x1.FFFFFEp+129, 0xffffffffffffffffffffffffffffffff);
}
diff --git a/lib/std/special/compiler_rt/floatdidf_test.zig b/lib/std/special/compiler_rt/floatdidf_test.zig
index 41b851a306..d20e6b39aa 100644
--- a/lib/std/special/compiler_rt/floatdidf_test.zig
+++ b/lib/std/special/compiler_rt/floatdidf_test.zig
@@ -6,53 +6,53 @@
const __floatdidf = @import("floatdidf.zig").__floatdidf;
const testing = @import("std").testing;
-fn test__floatdidf(a: i64, expected: f64) void {
+fn test__floatdidf(a: i64, expected: f64) !void {
const r = __floatdidf(a);
- testing.expect(r == expected);
+ try testing.expect(r == expected);
}
test "floatdidf" {
- test__floatdidf(0, 0.0);
- test__floatdidf(1, 1.0);
- test__floatdidf(2, 2.0);
- test__floatdidf(20, 20.0);
- test__floatdidf(-1, -1.0);
- test__floatdidf(-2, -2.0);
- test__floatdidf(-20, -20.0);
- test__floatdidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
- test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
- test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
- test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
- test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000008000000000)), -0x1.FFFFFEp+62);
- test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000800)), -0x1.FFFFFFFFFFFFEp+62);
- test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000010000000000)), -0x1.FFFFFCp+62);
- test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000001000)), -0x1.FFFFFFFFFFFFCp+62);
- test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000000)), -0x1.000000p+63);
- test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000001)), -0x1.000000p+63);
- test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
- test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
- test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
- test__floatdidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
- test__floatdidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
- test__floatdidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
- test__floatdidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
- test__floatdidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
- test__floatdidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
- test__floatdidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
- test__floatdidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
- test__floatdidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
- test__floatdidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
- test__floatdidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
- test__floatdidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
- test__floatdidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
- test__floatdidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
- test__floatdidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
- test__floatdidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
- test__floatdidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
- test__floatdidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
- test__floatdidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
- test__floatdidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
- test__floatdidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
- test__floatdidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
- test__floatdidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
+ try test__floatdidf(0, 0.0);
+ try test__floatdidf(1, 1.0);
+ try test__floatdidf(2, 2.0);
+ try test__floatdidf(20, 20.0);
+ try test__floatdidf(-1, -1.0);
+ try test__floatdidf(-2, -2.0);
+ try test__floatdidf(-20, -20.0);
+ try test__floatdidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
+ try test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
+ try test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
+ try test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
+ try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000008000000000)), -0x1.FFFFFEp+62);
+ try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000800)), -0x1.FFFFFFFFFFFFEp+62);
+ try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000010000000000)), -0x1.FFFFFCp+62);
+ try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000001000)), -0x1.FFFFFFFFFFFFCp+62);
+ try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000000)), -0x1.000000p+63);
+ try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000001)), -0x1.000000p+63);
+ try test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
+ try test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
+ try test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
+ try test__floatdidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
+ try test__floatdidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
+ try test__floatdidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
+ try test__floatdidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
+ try test__floatdidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
+ try test__floatdidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
+ try test__floatdidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
+ try test__floatdidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
+ try test__floatdidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
+ try test__floatdidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
+ try test__floatdidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
+ try test__floatdidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
+ try test__floatdidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
+ try test__floatdidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
+ try test__floatdidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
+ try test__floatdidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
+ try test__floatdidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
+ try test__floatdidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
+ try test__floatdidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
+ try test__floatdidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
+ try test__floatdidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
+ try test__floatdidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
+ try test__floatdidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
}
diff --git a/lib/std/special/compiler_rt/floatdisf_test.zig b/lib/std/special/compiler_rt/floatdisf_test.zig
index 845dc7b1ae..a90326e943 100644
--- a/lib/std/special/compiler_rt/floatdisf_test.zig
+++ b/lib/std/special/compiler_rt/floatdisf_test.zig
@@ -6,32 +6,32 @@
const __floatdisf = @import("floatXisf.zig").__floatdisf;
const testing = @import("std").testing;
-fn test__floatdisf(a: i64, expected: f32) void {
+fn test__floatdisf(a: i64, expected: f32) !void {
const x = __floatdisf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floatdisf" {
- test__floatdisf(0, 0.0);
- test__floatdisf(1, 1.0);
- test__floatdisf(2, 2.0);
- test__floatdisf(-1, -1.0);
- test__floatdisf(-2, -2.0);
- test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
- test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
- test__floatdisf(0x8000008000000000, -0x1.FFFFFEp+62);
- test__floatdisf(0x8000010000000000, -0x1.FFFFFCp+62);
- test__floatdisf(0x8000000000000000, -0x1.000000p+63);
- test__floatdisf(0x8000000000000001, -0x1.000000p+63);
- test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
- test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
- test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
- test__floatdisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
- test__floatdisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
- test__floatdisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
- test__floatdisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
- test__floatdisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
- test__floatdisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
- test__floatdisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
- test__floatdisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
+ try test__floatdisf(0, 0.0);
+ try test__floatdisf(1, 1.0);
+ try test__floatdisf(2, 2.0);
+ try test__floatdisf(-1, -1.0);
+ try test__floatdisf(-2, -2.0);
+ try test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
+ try test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
+ try test__floatdisf(0x8000008000000000, -0x1.FFFFFEp+62);
+ try test__floatdisf(0x8000010000000000, -0x1.FFFFFCp+62);
+ try test__floatdisf(0x8000000000000000, -0x1.000000p+63);
+ try test__floatdisf(0x8000000000000001, -0x1.000000p+63);
+ try test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
+ try test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
+ try test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
+ try test__floatdisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
+ try test__floatdisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
+ try test__floatdisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
+ try test__floatdisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
+ try test__floatdisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
+ try test__floatdisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
+ try test__floatdisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
+ try test__floatdisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
}
diff --git a/lib/std/special/compiler_rt/floatditf_test.zig b/lib/std/special/compiler_rt/floatditf_test.zig
index 13796efd69..bec8384dce 100644
--- a/lib/std/special/compiler_rt/floatditf_test.zig
+++ b/lib/std/special/compiler_rt/floatditf_test.zig
@@ -6,21 +6,21 @@
const __floatditf = @import("floatditf.zig").__floatditf;
const testing = @import("std").testing;
-fn test__floatditf(a: i64, expected: f128) void {
+fn test__floatditf(a: i64, expected: f128) !void {
const x = __floatditf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floatditf" {
- test__floatditf(0x7fffffffffffffff, make_ti(0x403dffffffffffff, 0xfffc000000000000));
- test__floatditf(0x123456789abcdef1, make_ti(0x403b23456789abcd, 0xef10000000000000));
- test__floatditf(0x2, make_ti(0x4000000000000000, 0x0));
- test__floatditf(0x1, make_ti(0x3fff000000000000, 0x0));
- test__floatditf(0x0, make_ti(0x0, 0x0));
- test__floatditf(@bitCast(i64, @as(u64, 0xffffffffffffffff)), make_ti(0xbfff000000000000, 0x0));
- test__floatditf(@bitCast(i64, @as(u64, 0xfffffffffffffffe)), make_ti(0xc000000000000000, 0x0));
- test__floatditf(-0x123456789abcdef1, make_ti(0xc03b23456789abcd, 0xef10000000000000));
- test__floatditf(@bitCast(i64, @as(u64, 0x8000000000000000)), make_ti(0xc03e000000000000, 0x0));
+ try test__floatditf(0x7fffffffffffffff, make_ti(0x403dffffffffffff, 0xfffc000000000000));
+ try test__floatditf(0x123456789abcdef1, make_ti(0x403b23456789abcd, 0xef10000000000000));
+ try test__floatditf(0x2, make_ti(0x4000000000000000, 0x0));
+ try test__floatditf(0x1, make_ti(0x3fff000000000000, 0x0));
+ try test__floatditf(0x0, make_ti(0x0, 0x0));
+ try test__floatditf(@bitCast(i64, @as(u64, 0xffffffffffffffff)), make_ti(0xbfff000000000000, 0x0));
+ try test__floatditf(@bitCast(i64, @as(u64, 0xfffffffffffffffe)), make_ti(0xc000000000000000, 0x0));
+ try test__floatditf(-0x123456789abcdef1, make_ti(0xc03b23456789abcd, 0xef10000000000000));
+ try test__floatditf(@bitCast(i64, @as(u64, 0x8000000000000000)), make_ti(0xc03e000000000000, 0x0));
}
fn make_ti(high: u64, low: u64) f128 {
diff --git a/lib/std/special/compiler_rt/floatsiXf.zig b/lib/std/special/compiler_rt/floatsiXf.zig
index 50fcdd748b..91e52ac50a 100644
--- a/lib/std/special/compiler_rt/floatsiXf.zig
+++ b/lib/std/special/compiler_rt/floatsiXf.zig
@@ -84,42 +84,42 @@ pub fn __aeabi_i2f(arg: i32) callconv(.AAPCS) f32 {
return @call(.{ .modifier = .always_inline }, __floatsisf, .{arg});
}
-fn test_one_floatsitf(a: i32, expected: u128) void {
+fn test_one_floatsitf(a: i32, expected: u128) !void {
const r = __floatsitf(a);
- std.testing.expect(@bitCast(u128, r) == expected);
+ try std.testing.expect(@bitCast(u128, r) == expected);
}
-fn test_one_floatsidf(a: i32, expected: u64) void {
+fn test_one_floatsidf(a: i32, expected: u64) !void {
const r = __floatsidf(a);
- std.testing.expect(@bitCast(u64, r) == expected);
+ try std.testing.expect(@bitCast(u64, r) == expected);
}
-fn test_one_floatsisf(a: i32, expected: u32) void {
+fn test_one_floatsisf(a: i32, expected: u32) !void {
const r = __floatsisf(a);
- std.testing.expect(@bitCast(u32, r) == expected);
+ try std.testing.expect(@bitCast(u32, r) == expected);
}
test "floatsidf" {
- test_one_floatsidf(0, 0x0000000000000000);
- test_one_floatsidf(1, 0x3ff0000000000000);
- test_one_floatsidf(-1, 0xbff0000000000000);
- test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000);
- test_one_floatsidf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc1e0000000000000);
+ try test_one_floatsidf(0, 0x0000000000000000);
+ try test_one_floatsidf(1, 0x3ff0000000000000);
+ try test_one_floatsidf(-1, 0xbff0000000000000);
+ try test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000);
+ try test_one_floatsidf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc1e0000000000000);
}
test "floatsisf" {
- test_one_floatsisf(0, 0x00000000);
- test_one_floatsisf(1, 0x3f800000);
- test_one_floatsisf(-1, 0xbf800000);
- test_one_floatsisf(0x7FFFFFFF, 0x4f000000);
- test_one_floatsisf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xcf000000);
+ try test_one_floatsisf(0, 0x00000000);
+ try test_one_floatsisf(1, 0x3f800000);
+ try test_one_floatsisf(-1, 0xbf800000);
+ try test_one_floatsisf(0x7FFFFFFF, 0x4f000000);
+ try test_one_floatsisf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xcf000000);
}
test "floatsitf" {
- test_one_floatsitf(0, 0);
- test_one_floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000);
- test_one_floatsitf(0x12345678, 0x401b2345678000000000000000000000);
- test_one_floatsitf(-0x12345678, 0xc01b2345678000000000000000000000);
- test_one_floatsitf(@bitCast(i32, @intCast(u32, 0xffffffff)), 0xbfff0000000000000000000000000000);
- test_one_floatsitf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc01e0000000000000000000000000000);
+ try test_one_floatsitf(0, 0);
+ try test_one_floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000);
+ try test_one_floatsitf(0x12345678, 0x401b2345678000000000000000000000);
+ try test_one_floatsitf(-0x12345678, 0xc01b2345678000000000000000000000);
+ try test_one_floatsitf(@bitCast(i32, @intCast(u32, 0xffffffff)), 0xbfff0000000000000000000000000000);
+ try test_one_floatsitf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc01e0000000000000000000000000000);
}
diff --git a/lib/std/special/compiler_rt/floattidf_test.zig b/lib/std/special/compiler_rt/floattidf_test.zig
index ab6311c9ff..826b73f8a1 100644
--- a/lib/std/special/compiler_rt/floattidf_test.zig
+++ b/lib/std/special/compiler_rt/floattidf_test.zig
@@ -6,79 +6,79 @@
const __floattidf = @import("floattidf.zig").__floattidf;
const testing = @import("std").testing;
-fn test__floattidf(a: i128, expected: f64) void {
+fn test__floattidf(a: i128, expected: f64) !void {
const x = __floattidf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floattidf" {
- test__floattidf(0, 0.0);
+ try test__floattidf(0, 0.0);
- test__floattidf(1, 1.0);
- test__floattidf(2, 2.0);
- test__floattidf(20, 20.0);
- test__floattidf(-1, -1.0);
- test__floattidf(-2, -2.0);
- test__floattidf(-20, -20.0);
+ try test__floattidf(1, 1.0);
+ try test__floattidf(2, 2.0);
+ try test__floattidf(20, 20.0);
+ try test__floattidf(-1, -1.0);
+ try test__floattidf(-2, -2.0);
+ try test__floattidf(-20, -20.0);
- test__floattidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
- test__floattidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
- test__floattidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
- test__floattidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
+ try test__floattidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
+ try test__floattidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
+ try test__floattidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
+ try test__floattidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
- test__floattidf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);
- test__floattidf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);
- test__floattidf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);
- test__floattidf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);
+ try test__floattidf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);
+ try test__floattidf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);
+ try test__floattidf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);
+ try test__floattidf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);
- test__floattidf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);
- test__floattidf(make_ti(0x8000000000000001, 0), -0x1.000000p+127);
+ try test__floattidf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);
+ try test__floattidf(make_ti(0x8000000000000001, 0), -0x1.000000p+127);
- test__floattidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
+ try test__floattidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
- test__floattidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
- test__floattidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
- test__floattidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
- test__floattidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
- test__floattidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
+ try test__floattidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
+ try test__floattidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
+ try test__floattidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
+ try test__floattidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
+ try test__floattidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
- test__floattidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
- test__floattidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
- test__floattidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
- test__floattidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
- test__floattidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
+ try test__floattidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
+ try test__floattidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
+ try test__floattidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
+ try test__floattidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
+ try test__floattidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
- test__floattidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
- test__floattidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
- test__floattidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
- test__floattidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
- test__floattidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
- test__floattidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
- test__floattidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
- test__floattidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
- test__floattidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
- test__floattidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
- test__floattidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
- test__floattidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
- test__floattidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
- test__floattidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
- test__floattidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
+ try test__floattidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
+ try test__floattidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
+ try test__floattidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
+ try test__floattidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
+ try test__floattidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
+ try test__floattidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
+ try test__floattidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
+ try test__floattidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
+ try test__floattidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
+ try test__floattidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
+ try test__floattidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
+ try test__floattidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
+ try test__floattidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
+ try test__floattidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
+ try test__floattidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
- test__floattidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
- test__floattidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);
- test__floattidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);
- test__floattidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);
- test__floattidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);
- test__floattidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);
- test__floattidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);
- test__floattidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);
- test__floattidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);
- test__floattidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);
- test__floattidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);
- test__floattidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);
- test__floattidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);
- test__floattidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);
- test__floattidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
+ try test__floattidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
+ try test__floattidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);
+ try test__floattidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);
+ try test__floattidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);
+ try test__floattidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);
+ try test__floattidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);
+ try test__floattidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);
+ try test__floattidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);
+ try test__floattidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);
+ try test__floattidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);
+ try test__floattidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);
+ try test__floattidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);
+ try test__floattidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);
+ try test__floattidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);
+ try test__floattidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
}
fn make_ti(high: u64, low: u64) i128 {
diff --git a/lib/std/special/compiler_rt/floattisf_test.zig b/lib/std/special/compiler_rt/floattisf_test.zig
index 2458e4bb76..28df0b54ea 100644
--- a/lib/std/special/compiler_rt/floattisf_test.zig
+++ b/lib/std/special/compiler_rt/floattisf_test.zig
@@ -6,55 +6,55 @@
const __floattisf = @import("floatXisf.zig").__floattisf;
const testing = @import("std").testing;
-fn test__floattisf(a: i128, expected: f32) void {
+fn test__floattisf(a: i128, expected: f32) !void {
const x = __floattisf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floattisf" {
- test__floattisf(0, 0.0);
+ try test__floattisf(0, 0.0);
- test__floattisf(1, 1.0);
- test__floattisf(2, 2.0);
- test__floattisf(-1, -1.0);
- test__floattisf(-2, -2.0);
+ try test__floattisf(1, 1.0);
+ try test__floattisf(2, 2.0);
+ try test__floattisf(-1, -1.0);
+ try test__floattisf(-2, -2.0);
- test__floattisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
- test__floattisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
+ try test__floattisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
+ try test__floattisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
- test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000008000000000), -0x1.FFFFFEp+62);
- test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000010000000000), -0x1.FFFFFCp+62);
+ try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000008000000000), -0x1.FFFFFEp+62);
+ try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000010000000000), -0x1.FFFFFCp+62);
- test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000000), -0x1.000000p+63);
- test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000001), -0x1.000000p+63);
+ try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000000), -0x1.000000p+63);
+ try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000001), -0x1.000000p+63);
- test__floattisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
+ try test__floattisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
- test__floattisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
- test__floattisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
- test__floattisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
- test__floattisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
- test__floattisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
+ try test__floattisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
+ try test__floattisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
+ try test__floattisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
+ try test__floattisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
+ try test__floattisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
- test__floattisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
- test__floattisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
- test__floattisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
- test__floattisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
- test__floattisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
+ try test__floattisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
+ try test__floattisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
+ try test__floattisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
+ try test__floattisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
+ try test__floattisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
- test__floattisf(make_ti(0x0007FB72E8000000, 0), 0x1.FEDCBAp+114);
+ try test__floattisf(make_ti(0x0007FB72E8000000, 0), 0x1.FEDCBAp+114);
- test__floattisf(make_ti(0x0007FB72EA000000, 0), 0x1.FEDCBAp+114);
- test__floattisf(make_ti(0x0007FB72EB000000, 0), 0x1.FEDCBAp+114);
- test__floattisf(make_ti(0x0007FB72EBFFFFFF, 0), 0x1.FEDCBAp+114);
- test__floattisf(make_ti(0x0007FB72EC000000, 0), 0x1.FEDCBCp+114);
- test__floattisf(make_ti(0x0007FB72E8000001, 0), 0x1.FEDCBAp+114);
+ try test__floattisf(make_ti(0x0007FB72EA000000, 0), 0x1.FEDCBAp+114);
+ try test__floattisf(make_ti(0x0007FB72EB000000, 0), 0x1.FEDCBAp+114);
+ try test__floattisf(make_ti(0x0007FB72EBFFFFFF, 0), 0x1.FEDCBAp+114);
+ try test__floattisf(make_ti(0x0007FB72EC000000, 0), 0x1.FEDCBCp+114);
+ try test__floattisf(make_ti(0x0007FB72E8000001, 0), 0x1.FEDCBAp+114);
- test__floattisf(make_ti(0x0007FB72E6000000, 0), 0x1.FEDCBAp+114);
- test__floattisf(make_ti(0x0007FB72E7000000, 0), 0x1.FEDCBAp+114);
- test__floattisf(make_ti(0x0007FB72E7FFFFFF, 0), 0x1.FEDCBAp+114);
- test__floattisf(make_ti(0x0007FB72E4000001, 0), 0x1.FEDCBAp+114);
- test__floattisf(make_ti(0x0007FB72E4000000, 0), 0x1.FEDCB8p+114);
+ try test__floattisf(make_ti(0x0007FB72E6000000, 0), 0x1.FEDCBAp+114);
+ try test__floattisf(make_ti(0x0007FB72E7000000, 0), 0x1.FEDCBAp+114);
+ try test__floattisf(make_ti(0x0007FB72E7FFFFFF, 0), 0x1.FEDCBAp+114);
+ try test__floattisf(make_ti(0x0007FB72E4000001, 0), 0x1.FEDCBAp+114);
+ try test__floattisf(make_ti(0x0007FB72E4000000, 0), 0x1.FEDCB8p+114);
}
fn make_ti(high: u64, low: u64) i128 {
diff --git a/lib/std/special/compiler_rt/floattitf_test.zig b/lib/std/special/compiler_rt/floattitf_test.zig
index 3310875ecc..cf0aa138a9 100644
--- a/lib/std/special/compiler_rt/floattitf_test.zig
+++ b/lib/std/special/compiler_rt/floattitf_test.zig
@@ -6,91 +6,91 @@
const __floattitf = @import("floattitf.zig").__floattitf;
const testing = @import("std").testing;
-fn test__floattitf(a: i128, expected: f128) void {
+fn test__floattitf(a: i128, expected: f128) !void {
const x = __floattitf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floattitf" {
- test__floattitf(0, 0.0);
+ try test__floattitf(0, 0.0);
- test__floattitf(1, 1.0);
- test__floattitf(2, 2.0);
- test__floattitf(20, 20.0);
- test__floattitf(-1, -1.0);
- test__floattitf(-2, -2.0);
- test__floattitf(-20, -20.0);
+ try test__floattitf(1, 1.0);
+ try test__floattitf(2, 2.0);
+ try test__floattitf(20, 20.0);
+ try test__floattitf(-1, -1.0);
+ try test__floattitf(-2, -2.0);
+ try test__floattitf(-20, -20.0);
- test__floattitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
- test__floattitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
- test__floattitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
- test__floattitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
+ try test__floattitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
+ try test__floattitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
+ try test__floattitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
+ try test__floattitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
- test__floattitf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);
- test__floattitf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);
- test__floattitf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);
- test__floattitf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);
+ try test__floattitf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);
+ try test__floattitf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);
+ try test__floattitf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);
+ try test__floattitf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);
- test__floattitf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);
- test__floattitf(make_ti(0x8000000000000001, 0), -0x1.FFFFFFFFFFFFFFFCp+126);
+ try test__floattitf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);
+ try test__floattitf(make_ti(0x8000000000000001, 0), -0x1.FFFFFFFFFFFFFFFCp+126);
- test__floattitf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
+ try test__floattitf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
- test__floattitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
- test__floattitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
- test__floattitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
- test__floattitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
- test__floattitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
+ try test__floattitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
+ try test__floattitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
+ try test__floattitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
+ try test__floattitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
+ try test__floattitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
- test__floattitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
- test__floattitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
- test__floattitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
- test__floattitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
- test__floattitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
+ try test__floattitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
+ try test__floattitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
+ try test__floattitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
+ try test__floattitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
+ try test__floattitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
- test__floattitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
- test__floattitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);
- test__floattitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);
- test__floattitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);
- test__floattitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);
- test__floattitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);
- test__floattitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);
- test__floattitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);
- test__floattitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);
- test__floattitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);
- test__floattitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);
- test__floattitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);
- test__floattitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);
- test__floattitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);
- test__floattitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
+ try test__floattitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
+ try test__floattitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);
+ try test__floattitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);
+ try test__floattitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);
+ try test__floattitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);
+ try test__floattitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);
+ try test__floattitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);
+ try test__floattitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);
+ try test__floattitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);
+ try test__floattitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);
+ try test__floattitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);
+ try test__floattitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);
+ try test__floattitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);
+ try test__floattitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);
+ try test__floattitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
- test__floattitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
- test__floattitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);
- test__floattitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);
- test__floattitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);
- test__floattitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);
- test__floattitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);
- test__floattitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);
- test__floattitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);
- test__floattitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);
- test__floattitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);
- test__floattitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);
- test__floattitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);
- test__floattitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);
- test__floattitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);
- test__floattitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
+ try test__floattitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
+ try test__floattitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);
+ try test__floattitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);
+ try test__floattitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);
+ try test__floattitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);
+ try test__floattitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);
+ try test__floattitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);
+ try test__floattitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);
+ try test__floattitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);
+ try test__floattitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);
+ try test__floattitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);
+ try test__floattitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);
+ try test__floattitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);
+ try test__floattitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);
+ try test__floattitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
- test__floattitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63);
+ try test__floattitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63);
- test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);
- test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);
- test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);
- test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);
- test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);
- test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);
- test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);
- test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);
- test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);
+ try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);
+ try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);
+ try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);
+ try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);
+ try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);
+ try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);
+ try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);
+ try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);
+ try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);
}
fn make_ti(high: u64, low: u64) i128 {
diff --git a/lib/std/special/compiler_rt/floatundidf_test.zig b/lib/std/special/compiler_rt/floatundidf_test.zig
index a0e18c4f5a..3094396326 100644
--- a/lib/std/special/compiler_rt/floatundidf_test.zig
+++ b/lib/std/special/compiler_rt/floatundidf_test.zig
@@ -6,50 +6,50 @@
const __floatundidf = @import("floatundidf.zig").__floatundidf;
const testing = @import("std").testing;
-fn test__floatundidf(a: u64, expected: f64) void {
+fn test__floatundidf(a: u64, expected: f64) !void {
const r = __floatundidf(a);
- testing.expect(r == expected);
+ try testing.expect(r == expected);
}
test "floatundidf" {
- test__floatundidf(0, 0.0);
- test__floatundidf(1, 1.0);
- test__floatundidf(2, 2.0);
- test__floatundidf(20, 20.0);
- test__floatundidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
- test__floatundidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
- test__floatundidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
- test__floatundidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
- test__floatundidf(0x8000008000000000, 0x1.000001p+63);
- test__floatundidf(0x8000000000000800, 0x1.0000000000001p+63);
- test__floatundidf(0x8000010000000000, 0x1.000002p+63);
- test__floatundidf(0x8000000000001000, 0x1.0000000000002p+63);
- test__floatundidf(0x8000000000000000, 0x1p+63);
- test__floatundidf(0x8000000000000001, 0x1p+63);
- test__floatundidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
- test__floatundidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
- test__floatundidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
- test__floatundidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
- test__floatundidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
- test__floatundidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
- test__floatundidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
- test__floatundidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
- test__floatundidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
- test__floatundidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
- test__floatundidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
- test__floatundidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
- test__floatundidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
- test__floatundidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
- test__floatundidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
- test__floatundidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
- test__floatundidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
- test__floatundidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
- test__floatundidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
- test__floatundidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
- test__floatundidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
- test__floatundidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
- test__floatundidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
- test__floatundidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
- test__floatundidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
- test__floatundidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
+ try test__floatundidf(0, 0.0);
+ try test__floatundidf(1, 1.0);
+ try test__floatundidf(2, 2.0);
+ try test__floatundidf(20, 20.0);
+ try test__floatundidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
+ try test__floatundidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
+ try test__floatundidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
+ try test__floatundidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
+ try test__floatundidf(0x8000008000000000, 0x1.000001p+63);
+ try test__floatundidf(0x8000000000000800, 0x1.0000000000001p+63);
+ try test__floatundidf(0x8000010000000000, 0x1.000002p+63);
+ try test__floatundidf(0x8000000000001000, 0x1.0000000000002p+63);
+ try test__floatundidf(0x8000000000000000, 0x1p+63);
+ try test__floatundidf(0x8000000000000001, 0x1p+63);
+ try test__floatundidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
+ try test__floatundidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
+ try test__floatundidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
+ try test__floatundidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
+ try test__floatundidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
+ try test__floatundidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
+ try test__floatundidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
+ try test__floatundidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
+ try test__floatundidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
+ try test__floatundidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
+ try test__floatundidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
+ try test__floatundidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
+ try test__floatundidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
+ try test__floatundidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
+ try test__floatundidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
+ try test__floatundidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
+ try test__floatundidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
+ try test__floatundidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
+ try test__floatundidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
+ try test__floatundidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
+ try test__floatundidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
+ try test__floatundidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
+ try test__floatundidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
+ try test__floatundidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
+ try test__floatundidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
+ try test__floatundidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
}
diff --git a/lib/std/special/compiler_rt/floatundisf.zig b/lib/std/special/compiler_rt/floatundisf.zig
index ac7e576316..2367416847 100644
--- a/lib/std/special/compiler_rt/floatundisf.zig
+++ b/lib/std/special/compiler_rt/floatundisf.zig
@@ -66,31 +66,31 @@ pub fn __aeabi_ul2f(arg: u64) callconv(.AAPCS) f32 {
return @call(.{ .modifier = .always_inline }, __floatundisf, .{arg});
}
-fn test__floatundisf(a: u64, expected: f32) void {
- std.testing.expectEqual(expected, __floatundisf(a));
+fn test__floatundisf(a: u64, expected: f32) !void {
+ try std.testing.expectEqual(expected, __floatundisf(a));
}
test "floatundisf" {
- test__floatundisf(0, 0.0);
- test__floatundisf(1, 1.0);
- test__floatundisf(2, 2.0);
- test__floatundisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
- test__floatundisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
- test__floatundisf(0x8000008000000000, 0x1p+63);
- test__floatundisf(0x8000010000000000, 0x1.000002p+63);
- test__floatundisf(0x8000000000000000, 0x1p+63);
- test__floatundisf(0x8000000000000001, 0x1p+63);
- test__floatundisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
- test__floatundisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);
- test__floatundisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
- test__floatundisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
- test__floatundisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
- test__floatundisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
- test__floatundisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
- test__floatundisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
- test__floatundisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
- test__floatundisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
- test__floatundisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
- test__floatundisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
- test__floatundisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
+ try test__floatundisf(0, 0.0);
+ try test__floatundisf(1, 1.0);
+ try test__floatundisf(2, 2.0);
+ try test__floatundisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
+ try test__floatundisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
+ try test__floatundisf(0x8000008000000000, 0x1p+63);
+ try test__floatundisf(0x8000010000000000, 0x1.000002p+63);
+ try test__floatundisf(0x8000000000000000, 0x1p+63);
+ try test__floatundisf(0x8000000000000001, 0x1p+63);
+ try test__floatundisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
+ try test__floatundisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);
+ try test__floatundisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
+ try test__floatundisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
+ try test__floatundisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
+ try test__floatundisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
+ try test__floatundisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
+ try test__floatundisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
+ try test__floatundisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
+ try test__floatundisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
+ try test__floatundisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
+ try test__floatundisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
+ try test__floatundisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
}
diff --git a/lib/std/special/compiler_rt/floatunditf_test.zig b/lib/std/special/compiler_rt/floatunditf_test.zig
index e734355589..20dca4df4e 100644
--- a/lib/std/special/compiler_rt/floatunditf_test.zig
+++ b/lib/std/special/compiler_rt/floatunditf_test.zig
@@ -5,7 +5,7 @@
// and substantial portions of the software.
const __floatunditf = @import("floatunditf.zig").__floatunditf;
-fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) void {
+fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void {
const x = __floatunditf(a);
const x_repr = @bitCast(u128, x);
@@ -26,12 +26,12 @@ fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) void {
}
test "floatunditf" {
- test__floatunditf(0xffffffffffffffff, 0x403effffffffffff, 0xfffe000000000000);
- test__floatunditf(0xfffffffffffffffe, 0x403effffffffffff, 0xfffc000000000000);
- test__floatunditf(0x8000000000000000, 0x403e000000000000, 0x0);
- test__floatunditf(0x7fffffffffffffff, 0x403dffffffffffff, 0xfffc000000000000);
- test__floatunditf(0x123456789abcdef1, 0x403b23456789abcd, 0xef10000000000000);
- test__floatunditf(0x2, 0x4000000000000000, 0x0);
- test__floatunditf(0x1, 0x3fff000000000000, 0x0);
- test__floatunditf(0x0, 0x0, 0x0);
+ try test__floatunditf(0xffffffffffffffff, 0x403effffffffffff, 0xfffe000000000000);
+ try test__floatunditf(0xfffffffffffffffe, 0x403effffffffffff, 0xfffc000000000000);
+ try test__floatunditf(0x8000000000000000, 0x403e000000000000, 0x0);
+ try test__floatunditf(0x7fffffffffffffff, 0x403dffffffffffff, 0xfffc000000000000);
+ try test__floatunditf(0x123456789abcdef1, 0x403b23456789abcd, 0xef10000000000000);
+ try test__floatunditf(0x2, 0x4000000000000000, 0x0);
+ try test__floatunditf(0x1, 0x3fff000000000000, 0x0);
+ try test__floatunditf(0x0, 0x0, 0x0);
}
diff --git a/lib/std/special/compiler_rt/floatunsidf.zig b/lib/std/special/compiler_rt/floatunsidf.zig
index 1b700b001d..e3f54e8042 100644
--- a/lib/std/special/compiler_rt/floatunsidf.zig
+++ b/lib/std/special/compiler_rt/floatunsidf.zig
@@ -28,16 +28,16 @@ pub fn __aeabi_ui2d(arg: u32) callconv(.AAPCS) f64 {
return @call(.{ .modifier = .always_inline }, __floatunsidf, .{arg});
}
-fn test_one_floatunsidf(a: u32, expected: u64) void {
+fn test_one_floatunsidf(a: u32, expected: u64) !void {
const r = __floatunsidf(a);
- std.testing.expect(@bitCast(u64, r) == expected);
+ try std.testing.expect(@bitCast(u64, r) == expected);
}
test "floatsidf" {
// Test the produced bit pattern
- test_one_floatunsidf(0, 0x0000000000000000);
- test_one_floatunsidf(1, 0x3ff0000000000000);
- test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);
- test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000);
- test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000);
+ try test_one_floatunsidf(0, 0x0000000000000000);
+ try test_one_floatunsidf(1, 0x3ff0000000000000);
+ try test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);
+ try test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000);
+ try test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000);
}
diff --git a/lib/std/special/compiler_rt/floatunsisf.zig b/lib/std/special/compiler_rt/floatunsisf.zig
index 1a0ef47b5c..1ff11c6388 100644
--- a/lib/std/special/compiler_rt/floatunsisf.zig
+++ b/lib/std/special/compiler_rt/floatunsisf.zig
@@ -48,16 +48,16 @@ pub fn __aeabi_ui2f(arg: u32) callconv(.AAPCS) f32 {
return @call(.{ .modifier = .always_inline }, __floatunsisf, .{arg});
}
-fn test_one_floatunsisf(a: u32, expected: u32) void {
+fn test_one_floatunsisf(a: u32, expected: u32) !void {
const r = __floatunsisf(a);
- std.testing.expect(@bitCast(u32, r) == expected);
+ try std.testing.expect(@bitCast(u32, r) == expected);
}
test "floatunsisf" {
// Test the produced bit pattern
- test_one_floatunsisf(0, 0);
- test_one_floatunsisf(1, 0x3f800000);
- test_one_floatunsisf(0x7FFFFFFF, 0x4f000000);
- test_one_floatunsisf(0x80000000, 0x4f000000);
- test_one_floatunsisf(0xFFFFFFFF, 0x4f800000);
+ try test_one_floatunsisf(0, 0);
+ try test_one_floatunsisf(1, 0x3f800000);
+ try test_one_floatunsisf(0x7FFFFFFF, 0x4f000000);
+ try test_one_floatunsisf(0x80000000, 0x4f000000);
+ try test_one_floatunsisf(0xFFFFFFFF, 0x4f800000);
}
diff --git a/lib/std/special/compiler_rt/floatunsitf_test.zig b/lib/std/special/compiler_rt/floatunsitf_test.zig
index 7e7b8b69b9..4e62282422 100644
--- a/lib/std/special/compiler_rt/floatunsitf_test.zig
+++ b/lib/std/special/compiler_rt/floatunsitf_test.zig
@@ -5,7 +5,7 @@
// and substantial portions of the software.
const __floatunsitf = @import("floatunsitf.zig").__floatunsitf;
-fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void {
+fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) !void {
const x = __floatunsitf(a);
const x_repr = @bitCast(u128, x);
@@ -26,8 +26,8 @@ fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void {
}
test "floatunsitf" {
- test__floatunsitf(0x7fffffff, 0x401dfffffffc0000, 0x0);
- test__floatunsitf(0, 0x0, 0x0);
- test__floatunsitf(0xffffffff, 0x401efffffffe0000, 0x0);
- test__floatunsitf(0x12345678, 0x401b234567800000, 0x0);
+ try test__floatunsitf(0x7fffffff, 0x401dfffffffc0000, 0x0);
+ try test__floatunsitf(0, 0x0, 0x0);
+ try test__floatunsitf(0xffffffff, 0x401efffffffe0000, 0x0);
+ try test__floatunsitf(0x12345678, 0x401b234567800000, 0x0);
}
diff --git a/lib/std/special/compiler_rt/floatuntidf_test.zig b/lib/std/special/compiler_rt/floatuntidf_test.zig
index 427c7a08f2..735b5bcdbb 100644
--- a/lib/std/special/compiler_rt/floatuntidf_test.zig
+++ b/lib/std/special/compiler_rt/floatuntidf_test.zig
@@ -6,76 +6,76 @@
const __floatuntidf = @import("floatuntidf.zig").__floatuntidf;
const testing = @import("std").testing;
-fn test__floatuntidf(a: u128, expected: f64) void {
+fn test__floatuntidf(a: u128, expected: f64) !void {
const x = __floatuntidf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floatuntidf" {
- test__floatuntidf(0, 0.0);
+ try test__floatuntidf(0, 0.0);
- test__floatuntidf(1, 1.0);
- test__floatuntidf(2, 2.0);
- test__floatuntidf(20, 20.0);
+ try test__floatuntidf(1, 1.0);
+ try test__floatuntidf(2, 2.0);
+ try test__floatuntidf(20, 20.0);
- test__floatuntidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
- test__floatuntidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
- test__floatuntidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
- test__floatuntidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
+ try test__floatuntidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
+ try test__floatuntidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
+ try test__floatuntidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
+ try test__floatuntidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
- test__floatuntidf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
- test__floatuntidf(make_ti(0x8000000000000800, 0), 0x1.0000000000001p+127);
- test__floatuntidf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);
- test__floatuntidf(make_ti(0x8000000000001000, 0), 0x1.0000000000002p+127);
+ try test__floatuntidf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
+ try test__floatuntidf(make_ti(0x8000000000000800, 0), 0x1.0000000000001p+127);
+ try test__floatuntidf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);
+ try test__floatuntidf(make_ti(0x8000000000001000, 0), 0x1.0000000000002p+127);
- test__floatuntidf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);
- test__floatuntidf(make_ti(0x8000000000000001, 0), 0x1.0000000000000002p+127);
+ try test__floatuntidf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);
+ try test__floatuntidf(make_ti(0x8000000000000001, 0), 0x1.0000000000000002p+127);
- test__floatuntidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
+ try test__floatuntidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
- test__floatuntidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
- test__floatuntidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
- test__floatuntidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
- test__floatuntidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
- test__floatuntidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
+ try test__floatuntidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
+ try test__floatuntidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
+ try test__floatuntidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
+ try test__floatuntidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
+ try test__floatuntidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
- test__floatuntidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
- test__floatuntidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
- test__floatuntidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
- test__floatuntidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
- test__floatuntidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
+ try test__floatuntidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
+ try test__floatuntidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
+ try test__floatuntidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
+ try test__floatuntidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
+ try test__floatuntidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
- test__floatuntidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
- test__floatuntidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
- test__floatuntidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
- test__floatuntidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
- test__floatuntidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
- test__floatuntidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
- test__floatuntidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
- test__floatuntidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
- test__floatuntidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
- test__floatuntidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
- test__floatuntidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
- test__floatuntidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
- test__floatuntidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
- test__floatuntidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
- test__floatuntidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
+ try test__floatuntidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
+ try test__floatuntidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
+ try test__floatuntidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
+ try test__floatuntidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
+ try test__floatuntidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
+ try test__floatuntidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
+ try test__floatuntidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
+ try test__floatuntidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
+ try test__floatuntidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
+ try test__floatuntidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
+ try test__floatuntidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
+ try test__floatuntidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
+ try test__floatuntidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
+ try test__floatuntidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
+ try test__floatuntidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
- test__floatuntidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
- test__floatuntidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);
- test__floatuntidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);
- test__floatuntidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);
- test__floatuntidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);
- test__floatuntidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);
- test__floatuntidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);
- test__floatuntidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);
- test__floatuntidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);
- test__floatuntidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);
- test__floatuntidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);
- test__floatuntidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);
- test__floatuntidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);
- test__floatuntidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);
- test__floatuntidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);
+ try test__floatuntidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
}
fn make_ti(high: u64, low: u64) u128 {
diff --git a/lib/std/special/compiler_rt/floatuntisf_test.zig b/lib/std/special/compiler_rt/floatuntisf_test.zig
index 78d45dc5e0..5657db1c82 100644
--- a/lib/std/special/compiler_rt/floatuntisf_test.zig
+++ b/lib/std/special/compiler_rt/floatuntisf_test.zig
@@ -6,67 +6,67 @@
const __floatuntisf = @import("floatuntisf.zig").__floatuntisf;
const testing = @import("std").testing;
-fn test__floatuntisf(a: u128, expected: f32) void {
+fn test__floatuntisf(a: u128, expected: f32) !void {
const x = __floatuntisf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floatuntisf" {
- test__floatuntisf(0, 0.0);
+ try test__floatuntisf(0, 0.0);
- test__floatuntisf(1, 1.0);
- test__floatuntisf(2, 2.0);
- test__floatuntisf(20, 20.0);
+ try test__floatuntisf(1, 1.0);
+ try test__floatuntisf(2, 2.0);
+ try test__floatuntisf(20, 20.0);
- test__floatuntisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
- test__floatuntisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
+ try test__floatuntisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
+ try test__floatuntisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
- test__floatuntisf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
- test__floatuntisf(make_ti(0x8000000000000800, 0), 0x1.0p+127);
- test__floatuntisf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);
+ try test__floatuntisf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
+ try test__floatuntisf(make_ti(0x8000000000000800, 0), 0x1.0p+127);
+ try test__floatuntisf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);
- test__floatuntisf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);
+ try test__floatuntisf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);
- test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
+ try test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
- test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
- test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
+ try test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
+ try test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
- test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
+ try test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
- test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
- test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
- test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
+ try test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
+ try test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
+ try test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
- test__floatuntisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
- test__floatuntisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);
+ try test__floatuntisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
+ try test__floatuntisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);
- test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
+ try test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
- test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
- test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
- test__floatuntisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
- test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
- test__floatuntisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
+ try test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
+ try test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
+ try test__floatuntisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
+ try test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
+ try test__floatuntisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
- test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
- test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
- test__floatuntisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
- test__floatuntisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
- test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
+ try test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
+ try test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
+ try test__floatuntisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
+ try test__floatuntisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
+ try test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCB90000000000001), 0x1.FEDCBAp+76);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCBA0000000000000), 0x1.FEDCBAp+76);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCBAFFFFFFFFFFFFF), 0x1.FEDCBAp+76);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000000), 0x1.FEDCBCp+76);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000001), 0x1.FEDCBCp+76);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCBBFFFFFFFFFFFFF), 0x1.FEDCBCp+76);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000000), 0x1.FEDCBCp+76);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000001), 0x1.FEDCBCp+76);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000000), 0x1.FEDCBCp+76);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000001), 0x1.FEDCBEp+76);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCBDFFFFFFFFFFFFF), 0x1.FEDCBEp+76);
- test__floatuntisf(make_ti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCB90000000000001), 0x1.FEDCBAp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBA0000000000000), 0x1.FEDCBAp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBAFFFFFFFFFFFFF), 0x1.FEDCBAp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000000), 0x1.FEDCBCp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000001), 0x1.FEDCBCp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBBFFFFFFFFFFFFF), 0x1.FEDCBCp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000000), 0x1.FEDCBCp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000001), 0x1.FEDCBCp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000000), 0x1.FEDCBCp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000001), 0x1.FEDCBEp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBDFFFFFFFFFFFFF), 0x1.FEDCBEp+76);
+ try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);
}
fn make_ti(high: u64, low: u64) u128 {
diff --git a/lib/std/special/compiler_rt/floatuntitf_test.zig b/lib/std/special/compiler_rt/floatuntitf_test.zig
index fd57be51e6..41057aa38c 100644
--- a/lib/std/special/compiler_rt/floatuntitf_test.zig
+++ b/lib/std/special/compiler_rt/floatuntitf_test.zig
@@ -6,94 +6,94 @@
const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;
const testing = @import("std").testing;
-fn test__floatuntitf(a: u128, expected: f128) void {
+fn test__floatuntitf(a: u128, expected: f128) !void {
const x = __floatuntitf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floatuntitf" {
- test__floatuntitf(0, 0.0);
+ try test__floatuntitf(0, 0.0);
- test__floatuntitf(1, 1.0);
- test__floatuntitf(2, 2.0);
- test__floatuntitf(20, 20.0);
+ try test__floatuntitf(1, 1.0);
+ try test__floatuntitf(2, 2.0);
+ try test__floatuntitf(20, 20.0);
- test__floatuntitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
- test__floatuntitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
- test__floatuntitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
- test__floatuntitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
- test__floatuntitf(0x7FFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFEp+59);
- test__floatuntitf(0xFFFFFFFFFFFFFFFE, 0xF.FFFFFFFFFFFFFFEp+60);
- test__floatuntitf(0xFFFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFFp+60);
+ try test__floatuntitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
+ try test__floatuntitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
+ try test__floatuntitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
+ try test__floatuntitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
+ try test__floatuntitf(0x7FFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFEp+59);
+ try test__floatuntitf(0xFFFFFFFFFFFFFFFE, 0xF.FFFFFFFFFFFFFFEp+60);
+ try test__floatuntitf(0xFFFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFFp+60);
- test__floatuntitf(0x8000008000000000, 0x8.000008p+60);
- test__floatuntitf(0x8000000000000800, 0x8.0000000000008p+60);
- test__floatuntitf(0x8000010000000000, 0x8.00001p+60);
- test__floatuntitf(0x8000000000001000, 0x8.000000000001p+60);
+ try test__floatuntitf(0x8000008000000000, 0x8.000008p+60);
+ try test__floatuntitf(0x8000000000000800, 0x8.0000000000008p+60);
+ try test__floatuntitf(0x8000010000000000, 0x8.00001p+60);
+ try test__floatuntitf(0x8000000000001000, 0x8.000000000001p+60);
- test__floatuntitf(0x8000000000000000, 0x8p+60);
- test__floatuntitf(0x8000000000000001, 0x8.000000000000001p+60);
+ try test__floatuntitf(0x8000000000000000, 0x8p+60);
+ try test__floatuntitf(0x8000000000000001, 0x8.000000000000001p+60);
- test__floatuntitf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
+ try test__floatuntitf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
- test__floatuntitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
- test__floatuntitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
- test__floatuntitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
- test__floatuntitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
- test__floatuntitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
+ try test__floatuntitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
+ try test__floatuntitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
+ try test__floatuntitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
+ try test__floatuntitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
+ try test__floatuntitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
- test__floatuntitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
- test__floatuntitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
- test__floatuntitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
- test__floatuntitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
- test__floatuntitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
+ try test__floatuntitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
+ try test__floatuntitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
+ try test__floatuntitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
+ try test__floatuntitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
+ try test__floatuntitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
- test__floatuntitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
- test__floatuntitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);
- test__floatuntitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);
- test__floatuntitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);
- test__floatuntitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);
- test__floatuntitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);
- test__floatuntitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);
- test__floatuntitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);
- test__floatuntitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);
- test__floatuntitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);
- test__floatuntitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);
- test__floatuntitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);
- test__floatuntitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);
- test__floatuntitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);
- test__floatuntitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
+ try test__floatuntitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
+ try test__floatuntitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);
+ try test__floatuntitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);
+ try test__floatuntitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);
+ try test__floatuntitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);
+ try test__floatuntitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);
+ try test__floatuntitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);
+ try test__floatuntitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);
+ try test__floatuntitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);
+ try test__floatuntitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);
+ try test__floatuntitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);
+ try test__floatuntitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);
+ try test__floatuntitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);
+ try test__floatuntitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);
+ try test__floatuntitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
- test__floatuntitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
- test__floatuntitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);
- test__floatuntitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);
- test__floatuntitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);
- test__floatuntitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);
- test__floatuntitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);
- test__floatuntitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);
- test__floatuntitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);
- test__floatuntitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);
- test__floatuntitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);
- test__floatuntitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);
- test__floatuntitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);
- test__floatuntitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);
- test__floatuntitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);
- test__floatuntitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);
+ try test__floatuntitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
- test__floatuntitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63);
+ try test__floatuntitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63);
- test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0x0000000000000000), 0x1.FFFFFFFFFFFFFFFEp+127);
- test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0x1.0000000000000000p+128);
+ try test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0x0000000000000000), 0x1.FFFFFFFFFFFFFFFEp+127);
+ try test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0x1.0000000000000000p+128);
- test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);
- test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);
- test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);
- test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);
- test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);
- test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);
- test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);
- test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);
- test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);
+ try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);
+ try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);
+ try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);
+ try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);
+ try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);
+ try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);
+ try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);
+ try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);
+ try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);
}
fn make_ti(high: u64, low: u64) u128 {
diff --git a/lib/std/special/compiler_rt/int.zig b/lib/std/special/compiler_rt/int.zig
index b852139516..4533d10ab9 100644
--- a/lib/std/special/compiler_rt/int.zig
+++ b/lib/std/special/compiler_rt/int.zig
@@ -58,13 +58,13 @@ test "test_divdi3" {
};
for (cases) |case| {
- test_one_divdi3(case[0], case[1], case[2]);
+ try test_one_divdi3(case[0], case[1], case[2]);
}
}
-fn test_one_divdi3(a: i64, b: i64, expected_q: i64) void {
+fn test_one_divdi3(a: i64, b: i64, expected_q: i64) !void {
const q: i64 = __divdi3(a, b);
- testing.expect(q == expected_q);
+ try testing.expect(q == expected_q);
}
pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
@@ -98,13 +98,13 @@ test "test_moddi3" {
};
for (cases) |case| {
- test_one_moddi3(case[0], case[1], case[2]);
+ try test_one_moddi3(case[0], case[1], case[2]);
}
}
-fn test_one_moddi3(a: i64, b: i64, expected_r: i64) void {
+fn test_one_moddi3(a: i64, b: i64, expected_r: i64) !void {
const r: i64 = __moddi3(a, b);
- testing.expect(r == expected_r);
+ try testing.expect(r == expected_r);
}
pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {
@@ -121,16 +121,16 @@ pub fn __umoddi3(a: u64, b: u64) callconv(.C) u64 {
}
test "test_umoddi3" {
- test_one_umoddi3(0, 1, 0);
- test_one_umoddi3(2, 1, 0);
- test_one_umoddi3(0x8000000000000000, 1, 0x0);
- test_one_umoddi3(0x8000000000000000, 2, 0x0);
- test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1);
+ try test_one_umoddi3(0, 1, 0);
+ try test_one_umoddi3(2, 1, 0);
+ try test_one_umoddi3(0x8000000000000000, 1, 0x0);
+ try test_one_umoddi3(0x8000000000000000, 2, 0x0);
+ try test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1);
}
-fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {
+fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) !void {
const r = __umoddi3(a, b);
- testing.expect(r == expected_r);
+ try testing.expect(r == expected_r);
}
pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {
@@ -159,14 +159,14 @@ test "test_divmodsi4" {
};
for (cases) |case| {
- test_one_divmodsi4(case[0], case[1], case[2], case[3]);
+ try test_one_divmodsi4(case[0], case[1], case[2], case[3]);
}
}
-fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) void {
+fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {
var r: i32 = undefined;
const q: i32 = __divmodsi4(a, b, &r);
- testing.expect(q == expected_q and r == expected_r);
+ try testing.expect(q == expected_q and r == expected_r);
}
pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
@@ -207,13 +207,13 @@ test "test_divsi3" {
};
for (cases) |case| {
- test_one_divsi3(case[0], case[1], case[2]);
+ try test_one_divsi3(case[0], case[1], case[2]);
}
}
-fn test_one_divsi3(a: i32, b: i32, expected_q: i32) void {
+fn test_one_divsi3(a: i32, b: i32, expected_q: i32) !void {
const q: i32 = __divsi3(a, b);
- testing.expect(q == expected_q);
+ try testing.expect(q == expected_q);
}
pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
@@ -394,13 +394,13 @@ test "test_udivsi3" {
};
for (cases) |case| {
- test_one_udivsi3(case[0], case[1], case[2]);
+ try test_one_udivsi3(case[0], case[1], case[2]);
}
}
-fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void {
+fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) !void {
const q: u32 = __udivsi3(a, b);
- testing.expect(q == expected_q);
+ try testing.expect(q == expected_q);
}
pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {
@@ -425,13 +425,13 @@ test "test_modsi3" {
};
for (cases) |case| {
- test_one_modsi3(case[0], case[1], case[2]);
+ try test_one_modsi3(case[0], case[1], case[2]);
}
}
-fn test_one_modsi3(a: i32, b: i32, expected_r: i32) void {
+fn test_one_modsi3(a: i32, b: i32, expected_r: i32) !void {
const r: i32 = __modsi3(a, b);
- testing.expect(r == expected_r);
+ try testing.expect(r == expected_r);
}
pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {
@@ -577,13 +577,13 @@ test "test_umodsi3" {
};
for (cases) |case| {
- test_one_umodsi3(case[0], case[1], case[2]);
+ try test_one_umodsi3(case[0], case[1], case[2]);
}
}
-fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void {
+fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) !void {
const r: u32 = __umodsi3(a, b);
- testing.expect(r == expected_r);
+ try testing.expect(r == expected_r);
}
pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
@@ -602,44 +602,44 @@ pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
return @bitCast(i32, r);
}
-fn test_one_mulsi3(a: i32, b: i32, result: i32) void {
- testing.expectEqual(result, __mulsi3(a, b));
+fn test_one_mulsi3(a: i32, b: i32, result: i32) !void {
+ try testing.expectEqual(result, __mulsi3(a, b));
}
test "mulsi3" {
- test_one_mulsi3(0, 0, 0);
- test_one_mulsi3(0, 1, 0);
- test_one_mulsi3(1, 0, 0);
- test_one_mulsi3(0, 10, 0);
- test_one_mulsi3(10, 0, 0);
- test_one_mulsi3(0, maxInt(i32), 0);
- test_one_mulsi3(maxInt(i32), 0, 0);
- test_one_mulsi3(0, -1, 0);
- test_one_mulsi3(-1, 0, 0);
- test_one_mulsi3(0, -10, 0);
- test_one_mulsi3(-10, 0, 0);
- test_one_mulsi3(0, minInt(i32), 0);
- test_one_mulsi3(minInt(i32), 0, 0);
- test_one_mulsi3(1, 1, 1);
- test_one_mulsi3(1, 10, 10);
- test_one_mulsi3(10, 1, 10);
- test_one_mulsi3(1, maxInt(i32), maxInt(i32));
- test_one_mulsi3(maxInt(i32), 1, maxInt(i32));
- test_one_mulsi3(1, -1, -1);
- test_one_mulsi3(1, -10, -10);
- test_one_mulsi3(-10, 1, -10);
- test_one_mulsi3(1, minInt(i32), minInt(i32));
- test_one_mulsi3(minInt(i32), 1, minInt(i32));
- test_one_mulsi3(46340, 46340, 2147395600);
- test_one_mulsi3(-46340, 46340, -2147395600);
- test_one_mulsi3(46340, -46340, -2147395600);
- test_one_mulsi3(-46340, -46340, 2147395600);
- test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176));
- test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176));
- test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176));
- test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176));
- test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176));
- test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176));
- test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176));
- test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176));
+ try test_one_mulsi3(0, 0, 0);
+ try test_one_mulsi3(0, 1, 0);
+ try test_one_mulsi3(1, 0, 0);
+ try test_one_mulsi3(0, 10, 0);
+ try test_one_mulsi3(10, 0, 0);
+ try test_one_mulsi3(0, maxInt(i32), 0);
+ try test_one_mulsi3(maxInt(i32), 0, 0);
+ try test_one_mulsi3(0, -1, 0);
+ try test_one_mulsi3(-1, 0, 0);
+ try test_one_mulsi3(0, -10, 0);
+ try test_one_mulsi3(-10, 0, 0);
+ try test_one_mulsi3(0, minInt(i32), 0);
+ try test_one_mulsi3(minInt(i32), 0, 0);
+ try test_one_mulsi3(1, 1, 1);
+ try test_one_mulsi3(1, 10, 10);
+ try test_one_mulsi3(10, 1, 10);
+ try test_one_mulsi3(1, maxInt(i32), maxInt(i32));
+ try test_one_mulsi3(maxInt(i32), 1, maxInt(i32));
+ try test_one_mulsi3(1, -1, -1);
+ try test_one_mulsi3(1, -10, -10);
+ try test_one_mulsi3(-10, 1, -10);
+ try test_one_mulsi3(1, minInt(i32), minInt(i32));
+ try test_one_mulsi3(minInt(i32), 1, minInt(i32));
+ try test_one_mulsi3(46340, 46340, 2147395600);
+ try test_one_mulsi3(-46340, 46340, -2147395600);
+ try test_one_mulsi3(46340, -46340, -2147395600);
+ try test_one_mulsi3(-46340, -46340, 2147395600);
+ try test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176));
+ try test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176));
+ try test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176));
+ try test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176));
+ try test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176));
+ try test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176));
+ try test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176));
+ try test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176));
}
diff --git a/lib/std/special/compiler_rt/lshrdi3_test.zig b/lib/std/special/compiler_rt/lshrdi3_test.zig
index 5443fd9bce..1e3270711e 100644
--- a/lib/std/special/compiler_rt/lshrdi3_test.zig
+++ b/lib/std/special/compiler_rt/lshrdi3_test.zig
@@ -6,55 +6,55 @@
const __lshrdi3 = @import("shift.zig").__lshrdi3;
const testing = @import("std").testing;
-fn test__lshrdi3(a: i64, b: i32, expected: u64) void {
+fn test__lshrdi3(a: i64, b: i32, expected: u64) !void {
const x = __lshrdi3(a, b);
- testing.expectEqual(@bitCast(i64, expected), x);
+ try testing.expectEqual(@bitCast(i64, expected), x);
}
test "lshrdi3" {
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
- test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2);
- test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1);
}
diff --git a/lib/std/special/compiler_rt/lshrti3_test.zig b/lib/std/special/compiler_rt/lshrti3_test.zig
index bfd812f028..3cb134f777 100644
--- a/lib/std/special/compiler_rt/lshrti3_test.zig
+++ b/lib/std/special/compiler_rt/lshrti3_test.zig
@@ -6,46 +6,46 @@
const __lshrti3 = @import("shift.zig").__lshrti3;
const testing = @import("std").testing;
-fn test__lshrti3(a: i128, b: i32, expected: i128) void {
+fn test__lshrti3(a: i128, b: i32, expected: i128) !void {
const x = __lshrti3(a, b);
- testing.expectEqual(expected, x);
+ try testing.expectEqual(expected, x);
}
test "lshrti3" {
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190A)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0x3FB72EA61D950C857FB72EA61D950C85)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0x1FDB97530ECA8642BFDB97530ECA8642)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0x0FEDCBA9876543215FEDCBA987654321)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x0000000FEDCBA9876543215FEDCBA987)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x00000007F6E5D4C3B2A190AFF6E5D4C3)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x00000003FB72EA61D950C857FB72EA61)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x00000001FDB97530ECA8642BFDB97530)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x00000000FEDCBA9876543215FEDCBA98)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0x000000007F6E5D4C3B2A190AFF6E5D4C)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0x000000003FB72EA61D950C857FB72EA6)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0x000000001FDB97530ECA8642BFDB9753)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x000000000FEDCBA9876543215FEDCBA9)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x000000000000000FEDCBA9876543215F)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0x0000000000000007F6E5D4C3B2A190AF)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x0000000000000003FB72EA61D950C857)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0x0000000000000001FDB97530ECA8642B)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0x0000000000000000FEDCBA9876543215)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0x00000000000000007F6E5D4C3B2A190A)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0x00000000000000003FB72EA61D950C85)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0x00000000000000001FDB97530ECA8642)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0x00000000000000000FEDCBA987654321)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x00000000000000000000000FEDCBA987)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x000000000000000000000007F6E5D4C3)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x000000000000000000000003FB72EA61)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x000000000000000000000001FDB97530)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x000000000000000000000000FEDCBA98)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0x0000000000000000000000007F6E5D4C)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0x0000000000000000000000003FB72EA6)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0x0000000000000000000000001FDB9753)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000FEDCBA9)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000000000F)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000007)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000003)));
- test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000001)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190A)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0x3FB72EA61D950C857FB72EA61D950C85)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0x1FDB97530ECA8642BFDB97530ECA8642)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0x0FEDCBA9876543215FEDCBA987654321)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x0000000FEDCBA9876543215FEDCBA987)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x00000007F6E5D4C3B2A190AFF6E5D4C3)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x00000003FB72EA61D950C857FB72EA61)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x00000001FDB97530ECA8642BFDB97530)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x00000000FEDCBA9876543215FEDCBA98)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0x000000007F6E5D4C3B2A190AFF6E5D4C)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0x000000003FB72EA61D950C857FB72EA6)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0x000000001FDB97530ECA8642BFDB9753)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x000000000FEDCBA9876543215FEDCBA9)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x000000000000000FEDCBA9876543215F)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0x0000000000000007F6E5D4C3B2A190AF)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x0000000000000003FB72EA61D950C857)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0x0000000000000001FDB97530ECA8642B)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0x0000000000000000FEDCBA9876543215)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0x00000000000000007F6E5D4C3B2A190A)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0x00000000000000003FB72EA61D950C85)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0x00000000000000001FDB97530ECA8642)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0x00000000000000000FEDCBA987654321)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x00000000000000000000000FEDCBA987)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x000000000000000000000007F6E5D4C3)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x000000000000000000000003FB72EA61)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x000000000000000000000001FDB97530)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x000000000000000000000000FEDCBA98)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0x0000000000000000000000007F6E5D4C)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0x0000000000000000000000003FB72EA6)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0x0000000000000000000000001FDB9753)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000FEDCBA9)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000000000F)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000007)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000003)));
+ try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000001)));
}
diff --git a/lib/std/special/compiler_rt/modti3_test.zig b/lib/std/special/compiler_rt/modti3_test.zig
index 644c9027b7..e053941730 100644
--- a/lib/std/special/compiler_rt/modti3_test.zig
+++ b/lib/std/special/compiler_rt/modti3_test.zig
@@ -6,32 +6,32 @@
const __modti3 = @import("modti3.zig").__modti3;
const testing = @import("std").testing;
-fn test__modti3(a: i128, b: i128, expected: i128) void {
+fn test__modti3(a: i128, b: i128, expected: i128) !void {
const x = __modti3(a, b);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "modti3" {
- test__modti3(0, 1, 0);
- test__modti3(0, -1, 0);
- test__modti3(5, 3, 2);
- test__modti3(5, -3, 2);
- test__modti3(-5, 3, -2);
- test__modti3(-5, -3, -2);
+ try test__modti3(0, 1, 0);
+ try test__modti3(0, -1, 0);
+ try test__modti3(5, 3, 2);
+ try test__modti3(5, -3, 2);
+ try test__modti3(-5, 3, -2);
+ try test__modti3(-5, -3, -2);
- test__modti3(0x8000000000000000, 1, 0x0);
- test__modti3(0x8000000000000000, -1, 0x0);
- test__modti3(0x8000000000000000, 2, 0x0);
- test__modti3(0x8000000000000000, -2, 0x0);
- test__modti3(0x8000000000000000, 3, 2);
- test__modti3(0x8000000000000000, -3, 2);
+ try test__modti3(0x8000000000000000, 1, 0x0);
+ try test__modti3(0x8000000000000000, -1, 0x0);
+ try test__modti3(0x8000000000000000, 2, 0x0);
+ try test__modti3(0x8000000000000000, -2, 0x0);
+ try test__modti3(0x8000000000000000, 3, 2);
+ try test__modti3(0x8000000000000000, -3, 2);
- test__modti3(make_ti(0x8000000000000000, 0), 1, 0x0);
- test__modti3(make_ti(0x8000000000000000, 0), -1, 0x0);
- test__modti3(make_ti(0x8000000000000000, 0), 2, 0x0);
- test__modti3(make_ti(0x8000000000000000, 0), -2, 0x0);
- test__modti3(make_ti(0x8000000000000000, 0), 3, -2);
- test__modti3(make_ti(0x8000000000000000, 0), -3, -2);
+ try test__modti3(make_ti(0x8000000000000000, 0), 1, 0x0);
+ try test__modti3(make_ti(0x8000000000000000, 0), -1, 0x0);
+ try test__modti3(make_ti(0x8000000000000000, 0), 2, 0x0);
+ try test__modti3(make_ti(0x8000000000000000, 0), -2, 0x0);
+ try test__modti3(make_ti(0x8000000000000000, 0), 3, -2);
+ try test__modti3(make_ti(0x8000000000000000, 0), -3, -2);
}
fn make_ti(high: u64, low: u64) i128 {
diff --git a/lib/std/special/compiler_rt/mulXf3_test.zig b/lib/std/special/compiler_rt/mulXf3_test.zig
index 272c96522d..b73f03d6c1 100644
--- a/lib/std/special/compiler_rt/mulXf3_test.zig
+++ b/lib/std/special/compiler_rt/mulXf3_test.zig
@@ -34,7 +34,7 @@ fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
return false;
}
-fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
+fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
const x = __multf3(a, b);
if (compareResultLD(x, expected_hi, expected_lo))
@@ -50,42 +50,42 @@ fn makeNaN128(rand: u64) f128 {
}
test "multf3" {
// qNaN * any = qNaN
- test__multf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
+ try test__multf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
// NaN * any = NaN
const a = makeNaN128(0x800030000000);
- test__multf3(a, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
+ try test__multf3(a, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
// inf * any = inf
- test__multf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
+ try test__multf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
// any * any
- test__multf3(
+ try test__multf3(
@bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)),
@bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)),
0x400423e7f9e3c9fc,
0xd906c2c2a85777c4,
);
- test__multf3(
+ try test__multf3(
@bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)),
@bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)),
0x3fc52a163c6223fc,
0xc94c4bf0430768b4,
);
- test__multf3(
+ try test__multf3(
0x1.234425696abcad34a35eeffefdcbap+456,
0x451.ed98d76e5d46e5f24323dff21ffp+600,
0x44293a91de5e0e94,
0xe8ed17cc2cdf64ac,
);
- test__multf3(
+ try test__multf3(
@bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)),
@bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)),
0x3d4f37c1a3137cae,
0xfc6807048bc2836a,
);
- test__multf3(0x1.23456734245345p-10000, 0x1.edcba524498724p-6497, 0x0, 0x0);
+ try test__multf3(0x1.23456734245345p-10000, 0x1.edcba524498724p-6497, 0x0, 0x0);
}
diff --git a/lib/std/special/compiler_rt/muldi3_test.zig b/lib/std/special/compiler_rt/muldi3_test.zig
index 78023f514b..914e42bd15 100644
--- a/lib/std/special/compiler_rt/muldi3_test.zig
+++ b/lib/std/special/compiler_rt/muldi3_test.zig
@@ -6,51 +6,51 @@
const __muldi3 = @import("muldi3.zig").__muldi3;
const testing = @import("std").testing;
-fn test__muldi3(a: i64, b: i64, expected: i64) void {
+fn test__muldi3(a: i64, b: i64, expected: i64) !void {
const x = __muldi3(a, b);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "muldi3" {
- test__muldi3(0, 0, 0);
- test__muldi3(0, 1, 0);
- test__muldi3(1, 0, 0);
- test__muldi3(0, 10, 0);
- test__muldi3(10, 0, 0);
- test__muldi3(0, 81985529216486895, 0);
- test__muldi3(81985529216486895, 0, 0);
+ try test__muldi3(0, 0, 0);
+ try test__muldi3(0, 1, 0);
+ try test__muldi3(1, 0, 0);
+ try test__muldi3(0, 10, 0);
+ try test__muldi3(10, 0, 0);
+ try test__muldi3(0, 81985529216486895, 0);
+ try test__muldi3(81985529216486895, 0, 0);
- test__muldi3(0, -1, 0);
- test__muldi3(-1, 0, 0);
- test__muldi3(0, -10, 0);
- test__muldi3(-10, 0, 0);
- test__muldi3(0, -81985529216486895, 0);
- test__muldi3(-81985529216486895, 0, 0);
+ try test__muldi3(0, -1, 0);
+ try test__muldi3(-1, 0, 0);
+ try test__muldi3(0, -10, 0);
+ try test__muldi3(-10, 0, 0);
+ try test__muldi3(0, -81985529216486895, 0);
+ try test__muldi3(-81985529216486895, 0, 0);
- test__muldi3(1, 1, 1);
- test__muldi3(1, 10, 10);
- test__muldi3(10, 1, 10);
- test__muldi3(1, 81985529216486895, 81985529216486895);
- test__muldi3(81985529216486895, 1, 81985529216486895);
+ try test__muldi3(1, 1, 1);
+ try test__muldi3(1, 10, 10);
+ try test__muldi3(10, 1, 10);
+ try test__muldi3(1, 81985529216486895, 81985529216486895);
+ try test__muldi3(81985529216486895, 1, 81985529216486895);
- test__muldi3(1, -1, -1);
- test__muldi3(1, -10, -10);
- test__muldi3(-10, 1, -10);
- test__muldi3(1, -81985529216486895, -81985529216486895);
- test__muldi3(-81985529216486895, 1, -81985529216486895);
+ try test__muldi3(1, -1, -1);
+ try test__muldi3(1, -10, -10);
+ try test__muldi3(-10, 1, -10);
+ try test__muldi3(1, -81985529216486895, -81985529216486895);
+ try test__muldi3(-81985529216486895, 1, -81985529216486895);
- test__muldi3(3037000499, 3037000499, 9223372030926249001);
- test__muldi3(-3037000499, 3037000499, -9223372030926249001);
- test__muldi3(3037000499, -3037000499, -9223372030926249001);
- test__muldi3(-3037000499, -3037000499, 9223372030926249001);
+ try test__muldi3(3037000499, 3037000499, 9223372030926249001);
+ try test__muldi3(-3037000499, 3037000499, -9223372030926249001);
+ try test__muldi3(3037000499, -3037000499, -9223372030926249001);
+ try test__muldi3(-3037000499, -3037000499, 9223372030926249001);
- test__muldi3(4398046511103, 2097152, 9223372036852678656);
- test__muldi3(-4398046511103, 2097152, -9223372036852678656);
- test__muldi3(4398046511103, -2097152, -9223372036852678656);
- test__muldi3(-4398046511103, -2097152, 9223372036852678656);
+ try test__muldi3(4398046511103, 2097152, 9223372036852678656);
+ try test__muldi3(-4398046511103, 2097152, -9223372036852678656);
+ try test__muldi3(4398046511103, -2097152, -9223372036852678656);
+ try test__muldi3(-4398046511103, -2097152, 9223372036852678656);
- test__muldi3(2097152, 4398046511103, 9223372036852678656);
- test__muldi3(-2097152, 4398046511103, -9223372036852678656);
- test__muldi3(2097152, -4398046511103, -9223372036852678656);
- test__muldi3(-2097152, -4398046511103, 9223372036852678656);
+ try test__muldi3(2097152, 4398046511103, 9223372036852678656);
+ try test__muldi3(-2097152, 4398046511103, -9223372036852678656);
+ try test__muldi3(2097152, -4398046511103, -9223372036852678656);
+ try test__muldi3(-2097152, -4398046511103, 9223372036852678656);
}
diff --git a/lib/std/special/compiler_rt/mulodi4_test.zig b/lib/std/special/compiler_rt/mulodi4_test.zig
index 7d7658e192..c865b7a0c5 100644
--- a/lib/std/special/compiler_rt/mulodi4_test.zig
+++ b/lib/std/special/compiler_rt/mulodi4_test.zig
@@ -6,85 +6,85 @@
const __mulodi4 = @import("mulodi4.zig").__mulodi4;
const testing = @import("std").testing;
-fn test__mulodi4(a: i64, b: i64, expected: i64, expected_overflow: c_int) void {
+fn test__mulodi4(a: i64, b: i64, expected: i64, expected_overflow: c_int) !void {
var overflow: c_int = undefined;
const x = __mulodi4(a, b, &overflow);
- testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
+ try testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
}
test "mulodi4" {
- test__mulodi4(0, 0, 0, 0);
- test__mulodi4(0, 1, 0, 0);
- test__mulodi4(1, 0, 0, 0);
- test__mulodi4(0, 10, 0, 0);
- test__mulodi4(10, 0, 0, 0);
- test__mulodi4(0, 81985529216486895, 0, 0);
- test__mulodi4(81985529216486895, 0, 0, 0);
+ try test__mulodi4(0, 0, 0, 0);
+ try test__mulodi4(0, 1, 0, 0);
+ try test__mulodi4(1, 0, 0, 0);
+ try test__mulodi4(0, 10, 0, 0);
+ try test__mulodi4(10, 0, 0, 0);
+ try test__mulodi4(0, 81985529216486895, 0, 0);
+ try test__mulodi4(81985529216486895, 0, 0, 0);
- test__mulodi4(0, -1, 0, 0);
- test__mulodi4(-1, 0, 0, 0);
- test__mulodi4(0, -10, 0, 0);
- test__mulodi4(-10, 0, 0, 0);
- test__mulodi4(0, -81985529216486895, 0, 0);
- test__mulodi4(-81985529216486895, 0, 0, 0);
+ try test__mulodi4(0, -1, 0, 0);
+ try test__mulodi4(-1, 0, 0, 0);
+ try test__mulodi4(0, -10, 0, 0);
+ try test__mulodi4(-10, 0, 0, 0);
+ try test__mulodi4(0, -81985529216486895, 0, 0);
+ try test__mulodi4(-81985529216486895, 0, 0, 0);
- test__mulodi4(1, 1, 1, 0);
- test__mulodi4(1, 10, 10, 0);
- test__mulodi4(10, 1, 10, 0);
- test__mulodi4(1, 81985529216486895, 81985529216486895, 0);
- test__mulodi4(81985529216486895, 1, 81985529216486895, 0);
+ try test__mulodi4(1, 1, 1, 0);
+ try test__mulodi4(1, 10, 10, 0);
+ try test__mulodi4(10, 1, 10, 0);
+ try test__mulodi4(1, 81985529216486895, 81985529216486895, 0);
+ try test__mulodi4(81985529216486895, 1, 81985529216486895, 0);
- test__mulodi4(1, -1, -1, 0);
- test__mulodi4(1, -10, -10, 0);
- test__mulodi4(-10, 1, -10, 0);
- test__mulodi4(1, -81985529216486895, -81985529216486895, 0);
- test__mulodi4(-81985529216486895, 1, -81985529216486895, 0);
+ try test__mulodi4(1, -1, -1, 0);
+ try test__mulodi4(1, -10, -10, 0);
+ try test__mulodi4(-10, 1, -10, 0);
+ try test__mulodi4(1, -81985529216486895, -81985529216486895, 0);
+ try test__mulodi4(-81985529216486895, 1, -81985529216486895, 0);
- test__mulodi4(3037000499, 3037000499, 9223372030926249001, 0);
- test__mulodi4(-3037000499, 3037000499, -9223372030926249001, 0);
- test__mulodi4(3037000499, -3037000499, -9223372030926249001, 0);
- test__mulodi4(-3037000499, -3037000499, 9223372030926249001, 0);
+ try test__mulodi4(3037000499, 3037000499, 9223372030926249001, 0);
+ try test__mulodi4(-3037000499, 3037000499, -9223372030926249001, 0);
+ try test__mulodi4(3037000499, -3037000499, -9223372030926249001, 0);
+ try test__mulodi4(-3037000499, -3037000499, 9223372030926249001, 0);
- test__mulodi4(4398046511103, 2097152, 9223372036852678656, 0);
- test__mulodi4(-4398046511103, 2097152, -9223372036852678656, 0);
- test__mulodi4(4398046511103, -2097152, -9223372036852678656, 0);
- test__mulodi4(-4398046511103, -2097152, 9223372036852678656, 0);
+ try test__mulodi4(4398046511103, 2097152, 9223372036852678656, 0);
+ try test__mulodi4(-4398046511103, 2097152, -9223372036852678656, 0);
+ try test__mulodi4(4398046511103, -2097152, -9223372036852678656, 0);
+ try test__mulodi4(-4398046511103, -2097152, 9223372036852678656, 0);
- test__mulodi4(2097152, 4398046511103, 9223372036852678656, 0);
- test__mulodi4(-2097152, 4398046511103, -9223372036852678656, 0);
- test__mulodi4(2097152, -4398046511103, -9223372036852678656, 0);
- test__mulodi4(-2097152, -4398046511103, 9223372036852678656, 0);
+ try test__mulodi4(2097152, 4398046511103, 9223372036852678656, 0);
+ try test__mulodi4(-2097152, 4398046511103, -9223372036852678656, 0);
+ try test__mulodi4(2097152, -4398046511103, -9223372036852678656, 0);
+ try test__mulodi4(-2097152, -4398046511103, 9223372036852678656, 0);
- test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);
- test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);
- test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
- test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
- test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);
- test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);
- test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);
- test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);
- test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
- test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
+ try test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);
+ try test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);
+ try test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
+ try test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
+ try test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);
+ try test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);
+ try test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);
+ try test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);
+ try test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
+ try test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
- test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
- test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
- test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
- test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
- test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0);
- test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0);
- test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
- test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
- test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
- test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
+ try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
+ try test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
+ try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
+ try test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
+ try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0);
+ try test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0);
+ try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
+ try test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
+ try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
+ try test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
- test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
- test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
- test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);
- test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);
- test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0);
- test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0);
- test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
- test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
- test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
- test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
+ try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
+ try test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
+ try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);
+ try test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);
+ try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0);
+ try test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0);
+ try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
+ try test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
+ try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
+ try test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
}
diff --git a/lib/std/special/compiler_rt/muloti4_test.zig b/lib/std/special/compiler_rt/muloti4_test.zig
index 83722df6a5..34c1d2daab 100644
--- a/lib/std/special/compiler_rt/muloti4_test.zig
+++ b/lib/std/special/compiler_rt/muloti4_test.zig
@@ -6,76 +6,76 @@
const __muloti4 = @import("muloti4.zig").__muloti4;
const testing = @import("std").testing;
-fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void {
+fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) !void {
var overflow: c_int = undefined;
const x = __muloti4(a, b, &overflow);
- testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
+ try testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
}
test "muloti4" {
- test__muloti4(0, 0, 0, 0);
- test__muloti4(0, 1, 0, 0);
- test__muloti4(1, 0, 0, 0);
- test__muloti4(0, 10, 0, 0);
- test__muloti4(10, 0, 0, 0);
+ try test__muloti4(0, 0, 0, 0);
+ try test__muloti4(0, 1, 0, 0);
+ try test__muloti4(1, 0, 0, 0);
+ try test__muloti4(0, 10, 0, 0);
+ try test__muloti4(10, 0, 0, 0);
- test__muloti4(0, 81985529216486895, 0, 0);
- test__muloti4(81985529216486895, 0, 0, 0);
+ try test__muloti4(0, 81985529216486895, 0, 0);
+ try test__muloti4(81985529216486895, 0, 0, 0);
- test__muloti4(0, -1, 0, 0);
- test__muloti4(-1, 0, 0, 0);
- test__muloti4(0, -10, 0, 0);
- test__muloti4(-10, 0, 0, 0);
- test__muloti4(0, -81985529216486895, 0, 0);
- test__muloti4(-81985529216486895, 0, 0, 0);
+ try test__muloti4(0, -1, 0, 0);
+ try test__muloti4(-1, 0, 0, 0);
+ try test__muloti4(0, -10, 0, 0);
+ try test__muloti4(-10, 0, 0, 0);
+ try test__muloti4(0, -81985529216486895, 0, 0);
+ try test__muloti4(-81985529216486895, 0, 0, 0);
- test__muloti4(3037000499, 3037000499, 9223372030926249001, 0);
- test__muloti4(-3037000499, 3037000499, -9223372030926249001, 0);
- test__muloti4(3037000499, -3037000499, -9223372030926249001, 0);
- test__muloti4(-3037000499, -3037000499, 9223372030926249001, 0);
+ try test__muloti4(3037000499, 3037000499, 9223372030926249001, 0);
+ try test__muloti4(-3037000499, 3037000499, -9223372030926249001, 0);
+ try test__muloti4(3037000499, -3037000499, -9223372030926249001, 0);
+ try test__muloti4(-3037000499, -3037000499, 9223372030926249001, 0);
- test__muloti4(4398046511103, 2097152, 9223372036852678656, 0);
- test__muloti4(-4398046511103, 2097152, -9223372036852678656, 0);
- test__muloti4(4398046511103, -2097152, -9223372036852678656, 0);
- test__muloti4(-4398046511103, -2097152, 9223372036852678656, 0);
+ try test__muloti4(4398046511103, 2097152, 9223372036852678656, 0);
+ try test__muloti4(-4398046511103, 2097152, -9223372036852678656, 0);
+ try test__muloti4(4398046511103, -2097152, -9223372036852678656, 0);
+ try test__muloti4(-4398046511103, -2097152, 9223372036852678656, 0);
- test__muloti4(2097152, 4398046511103, 9223372036852678656, 0);
- test__muloti4(-2097152, 4398046511103, -9223372036852678656, 0);
- test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);
- test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0);
+ try test__muloti4(2097152, 4398046511103, 9223372036852678656, 0);
+ try test__muloti4(-2097152, 4398046511103, -9223372036852678656, 0);
+ try test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);
+ try test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0);
- test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0);
- test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
- test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
+ try test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
- test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
- test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
- test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);
- test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);
- test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
- test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
- test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
- test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
+ try test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);
+ try test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
+ try test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
+ try test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
- test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
- test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
- test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
- test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
- test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0);
- test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0);
- test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
- test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
- test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
- test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
+ try test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
+ try test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0);
+ try test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
+ try test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
+ try test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
- test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
- test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
- test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
- test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
- test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0);
- test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0);
- test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
- test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
- test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
- test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
+ try test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
+ try test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0);
+ try test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
+ try test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
+ try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
+ try test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
}
diff --git a/lib/std/special/compiler_rt/multi3_test.zig b/lib/std/special/compiler_rt/multi3_test.zig
index 674cf1cb9b..a9ac760099 100644
--- a/lib/std/special/compiler_rt/multi3_test.zig
+++ b/lib/std/special/compiler_rt/multi3_test.zig
@@ -6,53 +6,53 @@
const __multi3 = @import("multi3.zig").__multi3;
const testing = @import("std").testing;
-fn test__multi3(a: i128, b: i128, expected: i128) void {
+fn test__multi3(a: i128, b: i128, expected: i128) !void {
const x = __multi3(a, b);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "multi3" {
- test__multi3(0, 0, 0);
- test__multi3(0, 1, 0);
- test__multi3(1, 0, 0);
- test__multi3(0, 10, 0);
- test__multi3(10, 0, 0);
- test__multi3(0, 81985529216486895, 0);
- test__multi3(81985529216486895, 0, 0);
+ try test__multi3(0, 0, 0);
+ try test__multi3(0, 1, 0);
+ try test__multi3(1, 0, 0);
+ try test__multi3(0, 10, 0);
+ try test__multi3(10, 0, 0);
+ try test__multi3(0, 81985529216486895, 0);
+ try test__multi3(81985529216486895, 0, 0);
- test__multi3(0, -1, 0);
- test__multi3(-1, 0, 0);
- test__multi3(0, -10, 0);
- test__multi3(-10, 0, 0);
- test__multi3(0, -81985529216486895, 0);
- test__multi3(-81985529216486895, 0, 0);
+ try test__multi3(0, -1, 0);
+ try test__multi3(-1, 0, 0);
+ try test__multi3(0, -10, 0);
+ try test__multi3(-10, 0, 0);
+ try test__multi3(0, -81985529216486895, 0);
+ try test__multi3(-81985529216486895, 0, 0);
- test__multi3(1, 1, 1);
- test__multi3(1, 10, 10);
- test__multi3(10, 1, 10);
- test__multi3(1, 81985529216486895, 81985529216486895);
- test__multi3(81985529216486895, 1, 81985529216486895);
+ try test__multi3(1, 1, 1);
+ try test__multi3(1, 10, 10);
+ try test__multi3(10, 1, 10);
+ try test__multi3(1, 81985529216486895, 81985529216486895);
+ try test__multi3(81985529216486895, 1, 81985529216486895);
- test__multi3(1, -1, -1);
- test__multi3(1, -10, -10);
- test__multi3(-10, 1, -10);
- test__multi3(1, -81985529216486895, -81985529216486895);
- test__multi3(-81985529216486895, 1, -81985529216486895);
+ try test__multi3(1, -1, -1);
+ try test__multi3(1, -10, -10);
+ try test__multi3(-10, 1, -10);
+ try test__multi3(1, -81985529216486895, -81985529216486895);
+ try test__multi3(-81985529216486895, 1, -81985529216486895);
- test__multi3(3037000499, 3037000499, 9223372030926249001);
- test__multi3(-3037000499, 3037000499, -9223372030926249001);
- test__multi3(3037000499, -3037000499, -9223372030926249001);
- test__multi3(-3037000499, -3037000499, 9223372030926249001);
+ try test__multi3(3037000499, 3037000499, 9223372030926249001);
+ try test__multi3(-3037000499, 3037000499, -9223372030926249001);
+ try test__multi3(3037000499, -3037000499, -9223372030926249001);
+ try test__multi3(-3037000499, -3037000499, 9223372030926249001);
- test__multi3(4398046511103, 2097152, 9223372036852678656);
- test__multi3(-4398046511103, 2097152, -9223372036852678656);
- test__multi3(4398046511103, -2097152, -9223372036852678656);
- test__multi3(-4398046511103, -2097152, 9223372036852678656);
+ try test__multi3(4398046511103, 2097152, 9223372036852678656);
+ try test__multi3(-4398046511103, 2097152, -9223372036852678656);
+ try test__multi3(4398046511103, -2097152, -9223372036852678656);
+ try test__multi3(-4398046511103, -2097152, 9223372036852678656);
- test__multi3(2097152, 4398046511103, 9223372036852678656);
- test__multi3(-2097152, 4398046511103, -9223372036852678656);
- test__multi3(2097152, -4398046511103, -9223372036852678656);
- test__multi3(-2097152, -4398046511103, 9223372036852678656);
+ try test__multi3(2097152, 4398046511103, 9223372036852678656);
+ try test__multi3(-2097152, 4398046511103, -9223372036852678656);
+ try test__multi3(2097152, -4398046511103, -9223372036852678656);
+ try test__multi3(-2097152, -4398046511103, 9223372036852678656);
- test__multi3(0x00000000000000B504F333F9DE5BE000, 0x000000000000000000B504F333F9DE5B, 0x7FFFFFFFFFFFF328DF915DA296E8A000);
+ try test__multi3(0x00000000000000B504F333F9DE5BE000, 0x000000000000000000B504F333F9DE5B, 0x7FFFFFFFFFFFF328DF915DA296E8A000);
}
diff --git a/lib/std/special/compiler_rt/popcountdi2_test.zig b/lib/std/special/compiler_rt/popcountdi2_test.zig
index d0665bf278..056b9827ef 100644
--- a/lib/std/special/compiler_rt/popcountdi2_test.zig
+++ b/lib/std/special/compiler_rt/popcountdi2_test.zig
@@ -15,18 +15,18 @@ fn naive_popcount(a_param: i64) i32 {
return r;
}
-fn test__popcountdi2(a: i64) void {
+fn test__popcountdi2(a: i64) !void {
const x = __popcountdi2(a);
const expected = naive_popcount(a);
- testing.expect(expected == x);
+ try testing.expect(expected == x);
}
test "popcountdi2" {
- test__popcountdi2(0);
- test__popcountdi2(1);
- test__popcountdi2(2);
- test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD)));
- test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE)));
- test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF)));
+ try test__popcountdi2(0);
+ try test__popcountdi2(1);
+ try test__popcountdi2(2);
+ try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD)));
+ try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE)));
+ try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF)));
// TODO some fuzz testing
}
diff --git a/lib/std/special/compiler_rt/truncXfYf2_test.zig b/lib/std/special/compiler_rt/truncXfYf2_test.zig
index 4fae5d1fc0..9e581fd636 100644
--- a/lib/std/special/compiler_rt/truncXfYf2_test.zig
+++ b/lib/std/special/compiler_rt/truncXfYf2_test.zig
@@ -5,67 +5,67 @@
// and substantial portions of the software.
const __truncsfhf2 = @import("truncXfYf2.zig").__truncsfhf2;
-fn test__truncsfhf2(a: u32, expected: u16) void {
+fn test__truncsfhf2(a: u32, expected: u16) !void {
const actual = __truncsfhf2(@bitCast(f32, a));
if (actual == expected) {
return;
}
- @panic("__truncsfhf2 test failure");
+ return error.TestFailure;
}
test "truncsfhf2" {
- test__truncsfhf2(0x7fc00000, 0x7e00); // qNaN
- test__truncsfhf2(0x7fe00000, 0x7f00); // sNaN
+ try test__truncsfhf2(0x7fc00000, 0x7e00); // qNaN
+ try test__truncsfhf2(0x7fe00000, 0x7f00); // sNaN
- test__truncsfhf2(0, 0); // 0
- test__truncsfhf2(0x80000000, 0x8000); // -0
+ try test__truncsfhf2(0, 0); // 0
+ try test__truncsfhf2(0x80000000, 0x8000); // -0
- test__truncsfhf2(0x7f800000, 0x7c00); // inf
- test__truncsfhf2(0xff800000, 0xfc00); // -inf
+ try test__truncsfhf2(0x7f800000, 0x7c00); // inf
+ try test__truncsfhf2(0xff800000, 0xfc00); // -inf
- test__truncsfhf2(0x477ff000, 0x7c00); // 65520 -> inf
- test__truncsfhf2(0xc77ff000, 0xfc00); // -65520 -> -inf
+ try test__truncsfhf2(0x477ff000, 0x7c00); // 65520 -> inf
+ try test__truncsfhf2(0xc77ff000, 0xfc00); // -65520 -> -inf
- test__truncsfhf2(0x71cc3892, 0x7c00); // 0x1.987124876876324p+100 -> inf
- test__truncsfhf2(0xf1cc3892, 0xfc00); // -0x1.987124876876324p+100 -> -inf
+ try test__truncsfhf2(0x71cc3892, 0x7c00); // 0x1.987124876876324p+100 -> inf
+ try test__truncsfhf2(0xf1cc3892, 0xfc00); // -0x1.987124876876324p+100 -> -inf
- test__truncsfhf2(0x38800000, 0x0400); // normal (min), 2**-14
- test__truncsfhf2(0xb8800000, 0x8400); // normal (min), -2**-14
+ try test__truncsfhf2(0x38800000, 0x0400); // normal (min), 2**-14
+ try test__truncsfhf2(0xb8800000, 0x8400); // normal (min), -2**-14
- test__truncsfhf2(0x477fe000, 0x7bff); // normal (max), 65504
- test__truncsfhf2(0xc77fe000, 0xfbff); // normal (max), -65504
+ try test__truncsfhf2(0x477fe000, 0x7bff); // normal (max), 65504
+ try test__truncsfhf2(0xc77fe000, 0xfbff); // normal (max), -65504
- test__truncsfhf2(0x477fe100, 0x7bff); // normal, 65505 -> 65504
- test__truncsfhf2(0xc77fe100, 0xfbff); // normal, -65505 -> -65504
+ try test__truncsfhf2(0x477fe100, 0x7bff); // normal, 65505 -> 65504
+ try test__truncsfhf2(0xc77fe100, 0xfbff); // normal, -65505 -> -65504
- test__truncsfhf2(0x477fef00, 0x7bff); // normal, 65519 -> 65504
- test__truncsfhf2(0xc77fef00, 0xfbff); // normal, -65519 -> -65504
+ try test__truncsfhf2(0x477fef00, 0x7bff); // normal, 65519 -> 65504
+ try test__truncsfhf2(0xc77fef00, 0xfbff); // normal, -65519 -> -65504
- test__truncsfhf2(0x3f802000, 0x3c01); // normal, 1 + 2**-10
- test__truncsfhf2(0xbf802000, 0xbc01); // normal, -1 - 2**-10
+ try test__truncsfhf2(0x3f802000, 0x3c01); // normal, 1 + 2**-10
+ try test__truncsfhf2(0xbf802000, 0xbc01); // normal, -1 - 2**-10
- test__truncsfhf2(0x3eaaa000, 0x3555); // normal, approx. 1/3
- test__truncsfhf2(0xbeaaa000, 0xb555); // normal, approx. -1/3
+ try test__truncsfhf2(0x3eaaa000, 0x3555); // normal, approx. 1/3
+ try test__truncsfhf2(0xbeaaa000, 0xb555); // normal, approx. -1/3
- test__truncsfhf2(0x40490fdb, 0x4248); // normal, 3.1415926535
- test__truncsfhf2(0xc0490fdb, 0xc248); // normal, -3.1415926535
+ try test__truncsfhf2(0x40490fdb, 0x4248); // normal, 3.1415926535
+ try test__truncsfhf2(0xc0490fdb, 0xc248); // normal, -3.1415926535
- test__truncsfhf2(0x45cc3892, 0x6e62); // normal, 0x1.987124876876324p+12
+ try test__truncsfhf2(0x45cc3892, 0x6e62); // normal, 0x1.987124876876324p+12
- test__truncsfhf2(0x3f800000, 0x3c00); // normal, 1
- test__truncsfhf2(0x38800000, 0x0400); // normal, 0x1.0p-14
+ try test__truncsfhf2(0x3f800000, 0x3c00); // normal, 1
+ try test__truncsfhf2(0x38800000, 0x0400); // normal, 0x1.0p-14
- test__truncsfhf2(0x33800000, 0x0001); // denormal (min), 2**-24
- test__truncsfhf2(0xb3800000, 0x8001); // denormal (min), -2**-24
+ try test__truncsfhf2(0x33800000, 0x0001); // denormal (min), 2**-24
+ try test__truncsfhf2(0xb3800000, 0x8001); // denormal (min), -2**-24
- test__truncsfhf2(0x387fc000, 0x03ff); // denormal (max), 2**-14 - 2**-24
- test__truncsfhf2(0xb87fc000, 0x83ff); // denormal (max), -2**-14 + 2**-24
+ try test__truncsfhf2(0x387fc000, 0x03ff); // denormal (max), 2**-14 - 2**-24
+ try test__truncsfhf2(0xb87fc000, 0x83ff); // denormal (max), -2**-14 + 2**-24
- test__truncsfhf2(0x35800000, 0x0010); // denormal, 0x1.0p-20
- test__truncsfhf2(0x33280000, 0x0001); // denormal, 0x1.5p-25 -> 0x1.0p-24
- test__truncsfhf2(0x33000000, 0x0000); // 0x1.0p-25 -> zero
+ try test__truncsfhf2(0x35800000, 0x0010); // denormal, 0x1.0p-20
+ try test__truncsfhf2(0x33280000, 0x0001); // denormal, 0x1.5p-25 -> 0x1.0p-24
+ try test__truncsfhf2(0x33000000, 0x0000); // 0x1.0p-25 -> zero
}
const __truncdfhf2 = @import("truncXfYf2.zig").__truncdfhf2;
diff --git a/lib/std/special/compiler_rt/udivmoddi4_test.zig b/lib/std/special/compiler_rt/udivmoddi4_test.zig
index d3f39a0589..edc07bc1db 100644
--- a/lib/std/special/compiler_rt/udivmoddi4_test.zig
+++ b/lib/std/special/compiler_rt/udivmoddi4_test.zig
@@ -8,16 +8,16 @@
const __udivmoddi4 = @import("int.zig").__udivmoddi4;
const testing = @import("std").testing;
-fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void {
+fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) !void {
var r: u64 = undefined;
const q = __udivmoddi4(a, b, &r);
- testing.expect(q == expected_q);
- testing.expect(r == expected_r);
+ try testing.expect(q == expected_q);
+ try testing.expect(r == expected_r);
}
test "udivmoddi4" {
for (cases) |case| {
- test__udivmoddi4(case[0], case[1], case[2], case[3]);
+ try test__udivmoddi4(case[0], case[1], case[2], case[3]);
}
}
diff --git a/lib/std/special/compiler_rt/udivmodti4_test.zig b/lib/std/special/compiler_rt/udivmodti4_test.zig
index 667b27f0aa..5d39470f53 100644
--- a/lib/std/special/compiler_rt/udivmodti4_test.zig
+++ b/lib/std/special/compiler_rt/udivmodti4_test.zig
@@ -8,16 +8,16 @@
const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
const testing = @import("std").testing;
-fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void {
+fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) !void {
var r: u128 = undefined;
const q = __udivmodti4(a, b, &r);
- testing.expect(q == expected_q);
- testing.expect(r == expected_r);
+ try testing.expect(q == expected_q);
+ try testing.expect(r == expected_r);
}
test "udivmodti4" {
for (cases) |case| {
- test__udivmodti4(case[0], case[1], case[2], case[3]);
+ try test__udivmodti4(case[0], case[1], case[2], case[3]);
}
}
diff --git a/lib/std/special/init-lib/src/main.zig b/lib/std/special/init-lib/src/main.zig
index 747bb08573..ecfeade1a3 100644
--- a/lib/std/special/init-lib/src/main.zig
+++ b/lib/std/special/init-lib/src/main.zig
@@ -6,5 +6,5 @@ export fn add(a: i32, b: i32) i32 {
}
test "basic add functionality" {
- testing.expect(add(3, 7) == 10);
+ try testing.expect(add(3, 7) == 10);
}
diff --git a/lib/std/special/test_runner.zig b/lib/std/special/test_runner.zig
index f5a93298b5..3c66c64b4b 100644
--- a/lib/std/special/test_runner.zig
+++ b/lib/std/special/test_runner.zig
@@ -23,6 +23,7 @@ pub fn main() anyerror!void {
const test_fn_list = builtin.test_functions;
var ok_count: usize = 0;
var skip_count: usize = 0;
+ var fail_count: usize = 0;
var progress = std.Progress{};
const root_node = progress.start("Test", test_fn_list.len) catch |err| switch (err) {
// TODO still run tests in this case
@@ -62,7 +63,7 @@ pub fn main() anyerror!void {
.blocking => {
skip_count += 1;
test_node.end();
- progress.log("{s}...SKIP (async test)\n", .{test_fn.name});
+ progress.log("{s}... SKIP (async test)\n", .{test_fn.name});
if (progress.terminal == null) std.debug.print("SKIP (async test)\n", .{});
continue;
},
@@ -75,12 +76,14 @@ pub fn main() anyerror!void {
error.SkipZigTest => {
skip_count += 1;
test_node.end();
- progress.log("{s}...SKIP\n", .{test_fn.name});
+ progress.log("{s}... SKIP\n", .{test_fn.name});
if (progress.terminal == null) std.debug.print("SKIP\n", .{});
},
else => {
- progress.log("", .{});
- return err;
+ fail_count += 1;
+ test_node.end();
+ progress.log("{s}... FAIL ({s})\n", .{ test_fn.name, @errorName(err) });
+ if (progress.terminal == null) std.debug.print("FAIL ({s})\n", .{@errorName(err)});
},
}
}
@@ -88,7 +91,7 @@ pub fn main() anyerror!void {
if (ok_count == test_fn_list.len) {
std.debug.print("All {d} tests passed.\n", .{ok_count});
} else {
- std.debug.print("{d} passed; {d} skipped.\n", .{ ok_count, skip_count });
+ std.debug.print("{d} passed; {d} skipped; {d} failed.\n", .{ ok_count, skip_count, fail_count });
}
if (log_err_count != 0) {
std.debug.print("{d} errors were logged.\n", .{log_err_count});
@@ -96,7 +99,7 @@ pub fn main() anyerror!void {
if (leaks != 0) {
std.debug.print("{d} tests leaked memory.\n", .{leaks});
}
- if (leaks != 0 or log_err_count != 0) {
+ if (leaks != 0 or log_err_count != 0 or fail_count != 0) {
std.process.exit(1);
}
}
diff --git a/lib/std/testing.zig b/lib/std/testing.zig
index ac1aa3bf6d..22df9c9b66 100644
--- a/lib/std/testing.zig
+++ b/lib/std/testing.zig
@@ -27,15 +27,17 @@ pub var zig_exe_path: []const u8 = undefined;
/// This function is intended to be used only in tests. It prints diagnostics to stderr
/// and then aborts when actual_error_union is not expected_error.
-pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void {
+pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void {
if (actual_error_union) |actual_payload| {
- std.debug.panic("expected error.{s}, found {any}", .{ @errorName(expected_error), actual_payload });
+ std.debug.print("expected error.{s}, found {any}", .{ @errorName(expected_error), actual_payload });
+ return error.TestUnexpectedError;
} else |actual_error| {
if (expected_error != actual_error) {
- std.debug.panic("expected error.{s}, found error.{s}", .{
+ std.debug.print("expected error.{s}, found error.{s}", .{
@errorName(expected_error),
@errorName(actual_error),
});
+ return error.TestExpectedError;
}
}
}
@@ -44,7 +46,7 @@ pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void {
/// equal, prints diagnostics to stderr to show exactly how they are not equal,
/// then aborts.
/// `actual` is casted to the type of `expected`.
-pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
+pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void {
switch (@typeInfo(@TypeOf(actual))) {
.NoReturn,
.BoundFn,
@@ -60,7 +62,8 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
.Type => {
if (actual != expected) {
- std.debug.panic("expected type {s}, found type {s}", .{ @typeName(expected), @typeName(actual) });
+ std.debug.print("expected type {s}, found type {s}", .{ @typeName(expected), @typeName(actual) });
+ return error.TestExpectedEqual;
}
},
@@ -75,7 +78,8 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
.ErrorSet,
=> {
if (actual != expected) {
- std.debug.panic("expected {}, found {}", .{ expected, actual });
+ std.debug.print("expected {}, found {}", .{ expected, actual });
+ return error.TestExpectedEqual;
}
},
@@ -83,34 +87,38 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
switch (pointer.size) {
.One, .Many, .C => {
if (actual != expected) {
- std.debug.panic("expected {*}, found {*}", .{ expected, actual });
+ std.debug.print("expected {*}, found {*}", .{ expected, actual });
+ return error.TestExpectedEqual;
}
},
.Slice => {
if (actual.ptr != expected.ptr) {
- std.debug.panic("expected slice ptr {*}, found {*}", .{ expected.ptr, actual.ptr });
+ std.debug.print("expected slice ptr {*}, found {*}", .{ expected.ptr, actual.ptr });
+ return error.TestExpectedEqual;
}
if (actual.len != expected.len) {
- std.debug.panic("expected slice len {}, found {}", .{ expected.len, actual.len });
+ std.debug.print("expected slice len {}, found {}", .{ expected.len, actual.len });
+ return error.TestExpectedEqual;
}
},
}
},
- .Array => |array| expectEqualSlices(array.child, &expected, &actual),
+ .Array => |array| try expectEqualSlices(array.child, &expected, &actual),
.Vector => |vectorType| {
var i: usize = 0;
while (i < vectorType.len) : (i += 1) {
if (!std.meta.eql(expected[i], actual[i])) {
- std.debug.panic("index {} incorrect. expected {}, found {}", .{ i, expected[i], actual[i] });
+ std.debug.print("index {} incorrect. expected {}, found {}", .{ i, expected[i], actual[i] });
+ return error.TestExpectedEqual;
}
}
},
.Struct => |structType| {
inline for (structType.fields) |field| {
- expectEqual(@field(expected, field.name), @field(actual, field.name));
+ try expectEqual(@field(expected, field.name), @field(actual, field.name));
}
},
@@ -124,12 +132,12 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
const expectedTag = @as(Tag, expected);
const actualTag = @as(Tag, actual);
- expectEqual(expectedTag, actualTag);
+ try expectEqual(expectedTag, actualTag);
// we only reach this loop if the tags are equal
inline for (std.meta.fields(@TypeOf(actual))) |fld| {
if (std.mem.eql(u8, fld.name, @tagName(actualTag))) {
- expectEqual(@field(expected, fld.name), @field(actual, fld.name));
+ try expectEqual(@field(expected, fld.name), @field(actual, fld.name));
return;
}
}
@@ -143,13 +151,15 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
.Optional => {
if (expected) |expected_payload| {
if (actual) |actual_payload| {
- expectEqual(expected_payload, actual_payload);
+ try expectEqual(expected_payload, actual_payload);
} else {
- std.debug.panic("expected {any}, found null", .{expected_payload});
+ std.debug.print("expected {any}, found null", .{expected_payload});
+ return error.TestExpectedEqual;
}
} else {
if (actual) |actual_payload| {
- std.debug.panic("expected null, found {any}", .{actual_payload});
+ std.debug.print("expected null, found {any}", .{actual_payload});
+ return error.TestExpectedEqual;
}
}
},
@@ -157,15 +167,17 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
.ErrorUnion => {
if (expected) |expected_payload| {
if (actual) |actual_payload| {
- expectEqual(expected_payload, actual_payload);
+ try expectEqual(expected_payload, actual_payload);
} else |actual_err| {
- std.debug.panic("expected {any}, found {}", .{ expected_payload, actual_err });
+ std.debug.print("expected {any}, found {}", .{ expected_payload, actual_err });
+ return error.TestExpectedEqual;
}
} else |expected_err| {
if (actual) |actual_payload| {
- std.debug.panic("expected {}, found {any}", .{ expected_err, actual_payload });
+ std.debug.print("expected {}, found {any}", .{ expected_err, actual_payload });
+ return error.TestExpectedEqual;
} else |actual_err| {
- expectEqual(expected_err, actual_err);
+ try expectEqual(expected_err, actual_err);
}
}
},
@@ -181,7 +193,7 @@ test "expectEqual.union(enum)" {
const a10 = T{ .a = 10 };
const a20 = T{ .a = 20 };
- expectEqual(a10, a10);
+ try expectEqual(a10, a10);
}
/// This function is intended to be used only in tests. When the formatted result of the template
@@ -197,7 +209,7 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt
print("\n======== instead found this: =========\n", .{});
print("{s}", .{result});
print("\n======================================\n", .{});
- return error.TestFailed;
+ return error.TestExpectedFmt;
}
pub const expectWithinMargin = @compileError("expectWithinMargin is deprecated, use expectApproxEqAbs or expectApproxEqRel");
@@ -208,12 +220,14 @@ pub const expectWithinEpsilon = @compileError("expectWithinEpsilon is deprecated
/// to show exactly how they are not equal, then aborts.
/// See `math.approxEqAbs` for more informations on the tolerance parameter.
/// The types must be floating point
-pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) void {
+pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {
const T = @TypeOf(expected);
switch (@typeInfo(T)) {
- .Float => if (!math.approxEqAbs(T, expected, actual, tolerance))
- std.debug.panic("actual {}, not within absolute tolerance {} of expected {}", .{ actual, tolerance, expected }),
+ .Float => if (!math.approxEqAbs(T, expected, actual, tolerance)) {
+ std.debug.print("actual {}, not within absolute tolerance {} of expected {}", .{ actual, tolerance, expected });
+ return error.TestExpectedApproxEqAbs;
+ },
.ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"),
@@ -228,8 +242,8 @@ test "expectApproxEqAbs" {
const neg_x: T = -12.0;
const neg_y: T = -12.06;
- expectApproxEqAbs(pos_x, pos_y, 0.1);
- expectApproxEqAbs(neg_x, neg_y, 0.1);
+ try expectApproxEqAbs(pos_x, pos_y, 0.1);
+ try expectApproxEqAbs(neg_x, neg_y, 0.1);
}
}
@@ -238,12 +252,14 @@ test "expectApproxEqAbs" {
/// to show exactly how they are not equal, then aborts.
/// See `math.approxEqRel` for more informations on the tolerance parameter.
/// The types must be floating point
-pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) void {
+pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {
const T = @TypeOf(expected);
switch (@typeInfo(T)) {
- .Float => if (!math.approxEqRel(T, expected, actual, tolerance))
- std.debug.panic("actual {}, not within relative tolerance {} of expected {}", .{ actual, tolerance, expected }),
+ .Float => if (!math.approxEqRel(T, expected, actual, tolerance)) {
+ std.debug.print("actual {}, not within relative tolerance {} of expected {}", .{ actual, tolerance, expected });
+ return error.TestExpectedApproxEqRel;
+ },
.ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"),
@@ -261,8 +277,8 @@ test "expectApproxEqRel" {
const neg_x: T = -12.0;
const neg_y: T = neg_x - 2 * eps_value;
- expectApproxEqRel(pos_x, pos_y, sqrt_eps_value);
- expectApproxEqRel(neg_x, neg_y, sqrt_eps_value);
+ try expectApproxEqRel(pos_x, pos_y, sqrt_eps_value);
+ try expectApproxEqRel(neg_x, neg_y, sqrt_eps_value);
}
}
@@ -270,26 +286,28 @@ test "expectApproxEqRel" {
/// equal, prints diagnostics to stderr to show exactly how they are not equal,
/// then aborts.
/// If your inputs are UTF-8 encoded strings, consider calling `expectEqualStrings` instead.
-pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) void {
+pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void {
// TODO better printing of the difference
// If the arrays are small enough we could print the whole thing
// If the child type is u8 and no weird bytes, we could print it as strings
// Even for the length difference, it would be useful to see the values of the slices probably.
if (expected.len != actual.len) {
- std.debug.panic("slice lengths differ. expected {d}, found {d}", .{ expected.len, actual.len });
+ std.debug.print("slice lengths differ. expected {d}, found {d}", .{ expected.len, actual.len });
+ return error.TestExpectedEqual;
}
var i: usize = 0;
while (i < expected.len) : (i += 1) {
if (!std.meta.eql(expected[i], actual[i])) {
- std.debug.panic("index {} incorrect. expected {any}, found {any}", .{ i, expected[i], actual[i] });
+ std.debug.print("index {} incorrect. expected {any}, found {any}", .{ i, expected[i], actual[i] });
+ return error.TestExpectedEqual;
}
}
}
/// This function is intended to be used only in tests. When `ok` is false, the test fails.
/// A message is printed to stderr and then abort is called.
-pub fn expect(ok: bool) void {
- if (!ok) @panic("test failure");
+pub fn expect(ok: bool) !void {
+ if (!ok) return error.TestUnexpectedResult;
}
pub const TmpDir = struct {
@@ -356,17 +374,17 @@ test "expectEqual nested array" {
[_]f32{ 0.0, 1.0 },
};
- expectEqual(a, b);
+ try expectEqual(a, b);
}
test "expectEqual vector" {
var a = @splat(4, @as(u32, 4));
var b = @splat(4, @as(u32, 4));
- expectEqual(a, b);
+ try expectEqual(a, b);
}
-pub fn expectEqualStrings(expected: []const u8, actual: []const u8) void {
+pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void {
if (std.mem.indexOfDiff(u8, actual, expected)) |diff_index| {
print("\n====== expected this output: =========\n", .{});
printWithVisibleNewlines(expected);
@@ -386,11 +404,11 @@ pub fn expectEqualStrings(expected: []const u8, actual: []const u8) void {
print("found:\n", .{});
printIndicatorLine(actual, diff_index);
- @panic("test failure");
+ return error.TestExpectedEqual;
}
}
-pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8) void {
+pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8) !void {
if (std.mem.endsWith(u8, actual, expected_ends_with))
return;
@@ -407,7 +425,7 @@ pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8)
printWithVisibleNewlines(actual);
print("\n======================================\n", .{});
- @panic("test failure");
+ return error.TestExpectedEndsWith;
}
fn printIndicatorLine(source: []const u8, indicator_index: usize) void {
@@ -446,7 +464,7 @@ fn printLine(line: []const u8) void {
}
test {
- expectEqualStrings("foo", "foo");
+ try expectEqualStrings("foo", "foo");
}
/// Given a type, reference all the declarations inside, so that the semantic analyzer sees them.
diff --git a/lib/std/time.zig b/lib/std/time.zig
index f0118d2642..99304af46a 100644
--- a/lib/std/time.zig
+++ b/lib/std/time.zig
@@ -271,7 +271,7 @@ test "timestamp" {
sleep(ns_per_ms);
const time_1 = milliTimestamp();
const interval = time_1 - time_0;
- testing.expect(interval > 0);
+ try testing.expect(interval > 0);
// Tests should not depend on timings: skip test if outside margin.
if (!(interval < margin)) return error.SkipZigTest;
}
@@ -282,13 +282,13 @@ test "Timer" {
var timer = try Timer.start();
sleep(10 * ns_per_ms);
const time_0 = timer.read();
- testing.expect(time_0 > 0);
+ try testing.expect(time_0 > 0);
// Tests should not depend on timings: skip test if outside margin.
if (!(time_0 < margin)) return error.SkipZigTest;
const time_1 = timer.lap();
- testing.expect(time_1 >= time_0);
+ try testing.expect(time_1 >= time_0);
timer.reset();
- testing.expect(timer.read() < time_1);
+ try testing.expect(timer.read() < time_1);
}
diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig
index 9eed0f466f..ca666097bb 100644
--- a/lib/std/unicode.zig
+++ b/lib/std/unicode.zig
@@ -336,224 +336,224 @@ pub const Utf16LeIterator = struct {
};
test "utf8 encode" {
- comptime testUtf8Encode() catch unreachable;
+ comptime try testUtf8Encode();
try testUtf8Encode();
}
fn testUtf8Encode() !void {
// A few taken from wikipedia a few taken elsewhere
var array: [4]u8 = undefined;
- testing.expect((try utf8Encode(try utf8Decode("β¬"), array[0..])) == 3);
- testing.expect(array[0] == 0b11100010);
- testing.expect(array[1] == 0b10000010);
- testing.expect(array[2] == 0b10101100);
+ try testing.expect((try utf8Encode(try utf8Decode("β¬"), array[0..])) == 3);
+ try testing.expect(array[0] == 0b11100010);
+ try testing.expect(array[1] == 0b10000010);
+ try testing.expect(array[2] == 0b10101100);
- testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
- testing.expect(array[0] == 0b00100100);
+ try testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
+ try testing.expect(array[0] == 0b00100100);
- testing.expect((try utf8Encode(try utf8Decode("Β’"), array[0..])) == 2);
- testing.expect(array[0] == 0b11000010);
- testing.expect(array[1] == 0b10100010);
+ try testing.expect((try utf8Encode(try utf8Decode("Β’"), array[0..])) == 2);
+ try testing.expect(array[0] == 0b11000010);
+ try testing.expect(array[1] == 0b10100010);
- testing.expect((try utf8Encode(try utf8Decode("π"), array[0..])) == 4);
- testing.expect(array[0] == 0b11110000);
- testing.expect(array[1] == 0b10010000);
- testing.expect(array[2] == 0b10001101);
- testing.expect(array[3] == 0b10001000);
+ try testing.expect((try utf8Encode(try utf8Decode("π"), array[0..])) == 4);
+ try testing.expect(array[0] == 0b11110000);
+ try testing.expect(array[1] == 0b10010000);
+ try testing.expect(array[2] == 0b10001101);
+ try testing.expect(array[3] == 0b10001000);
}
test "utf8 encode error" {
- comptime testUtf8EncodeError();
- testUtf8EncodeError();
+ comptime try testUtf8EncodeError();
+ try testUtf8EncodeError();
}
-fn testUtf8EncodeError() void {
+fn testUtf8EncodeError() !void {
var array: [4]u8 = undefined;
- testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);
- testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);
- testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);
- testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);
+ try testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);
+ try testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);
+ try testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);
+ try testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);
}
-fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) void {
- testing.expectError(expectedErr, utf8Encode(codePoint, array));
+fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) !void {
+ try testing.expectError(expectedErr, utf8Encode(codePoint, array));
}
test "utf8 iterator on ascii" {
- comptime testUtf8IteratorOnAscii();
- testUtf8IteratorOnAscii();
+ comptime try testUtf8IteratorOnAscii();
+ try testUtf8IteratorOnAscii();
}
-fn testUtf8IteratorOnAscii() void {
+fn testUtf8IteratorOnAscii() !void {
const s = Utf8View.initComptime("abc");
var it1 = s.iterator();
- testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
- testing.expect(it1.nextCodepointSlice() == null);
+ try testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
+ try testing.expect(it1.nextCodepointSlice() == null);
var it2 = s.iterator();
- testing.expect(it2.nextCodepoint().? == 'a');
- testing.expect(it2.nextCodepoint().? == 'b');
- testing.expect(it2.nextCodepoint().? == 'c');
- testing.expect(it2.nextCodepoint() == null);
+ try testing.expect(it2.nextCodepoint().? == 'a');
+ try testing.expect(it2.nextCodepoint().? == 'b');
+ try testing.expect(it2.nextCodepoint().? == 'c');
+ try testing.expect(it2.nextCodepoint() == null);
}
test "utf8 view bad" {
- comptime testUtf8ViewBad();
- testUtf8ViewBad();
+ comptime try testUtf8ViewBad();
+ try testUtf8ViewBad();
}
-fn testUtf8ViewBad() void {
+fn testUtf8ViewBad() !void {
// Compile-time error.
// const s3 = Utf8View.initComptime("\xfe\xf2");
- testing.expectError(error.InvalidUtf8, Utf8View.init("hel\xadlo"));
+ try testing.expectError(error.InvalidUtf8, Utf8View.init("hel\xadlo"));
}
test "utf8 view ok" {
- comptime testUtf8ViewOk();
- testUtf8ViewOk();
+ comptime try testUtf8ViewOk();
+ try testUtf8ViewOk();
}
-fn testUtf8ViewOk() void {
+fn testUtf8ViewOk() !void {
const s = Utf8View.initComptime("ζ±δΊ¬εΈ");
var it1 = s.iterator();
- testing.expect(std.mem.eql(u8, "ζ±", it1.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "δΊ¬", it1.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "εΈ", it1.nextCodepointSlice().?));
- testing.expect(it1.nextCodepointSlice() == null);
+ try testing.expect(std.mem.eql(u8, "ζ±", it1.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "δΊ¬", it1.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "εΈ", it1.nextCodepointSlice().?));
+ try testing.expect(it1.nextCodepointSlice() == null);
var it2 = s.iterator();
- testing.expect(it2.nextCodepoint().? == 0x6771);
- testing.expect(it2.nextCodepoint().? == 0x4eac);
- testing.expect(it2.nextCodepoint().? == 0x5e02);
- testing.expect(it2.nextCodepoint() == null);
+ try testing.expect(it2.nextCodepoint().? == 0x6771);
+ try testing.expect(it2.nextCodepoint().? == 0x4eac);
+ try testing.expect(it2.nextCodepoint().? == 0x5e02);
+ try testing.expect(it2.nextCodepoint() == null);
}
test "bad utf8 slice" {
- comptime testBadUtf8Slice();
- testBadUtf8Slice();
+ comptime try testBadUtf8Slice();
+ try testBadUtf8Slice();
}
-fn testBadUtf8Slice() void {
- testing.expect(utf8ValidateSlice("abc"));
- testing.expect(!utf8ValidateSlice("abc\xc0"));
- testing.expect(!utf8ValidateSlice("abc\xc0abc"));
- testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
+fn testBadUtf8Slice() !void {
+ try testing.expect(utf8ValidateSlice("abc"));
+ try testing.expect(!utf8ValidateSlice("abc\xc0"));
+ try testing.expect(!utf8ValidateSlice("abc\xc0abc"));
+ try testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
}
test "valid utf8" {
- comptime testValidUtf8();
- testValidUtf8();
+ comptime try testValidUtf8();
+ try testValidUtf8();
}
-fn testValidUtf8() void {
- testValid("\x00", 0x0);
- testValid("\x20", 0x20);
- testValid("\x7f", 0x7f);
- testValid("\xc2\x80", 0x80);
- testValid("\xdf\xbf", 0x7ff);
- testValid("\xe0\xa0\x80", 0x800);
- testValid("\xe1\x80\x80", 0x1000);
- testValid("\xef\xbf\xbf", 0xffff);
- testValid("\xf0\x90\x80\x80", 0x10000);
- testValid("\xf1\x80\x80\x80", 0x40000);
- testValid("\xf3\xbf\xbf\xbf", 0xfffff);
- testValid("\xf4\x8f\xbf\xbf", 0x10ffff);
+fn testValidUtf8() !void {
+ try testValid("\x00", 0x0);
+ try testValid("\x20", 0x20);
+ try testValid("\x7f", 0x7f);
+ try testValid("\xc2\x80", 0x80);
+ try testValid("\xdf\xbf", 0x7ff);
+ try testValid("\xe0\xa0\x80", 0x800);
+ try testValid("\xe1\x80\x80", 0x1000);
+ try testValid("\xef\xbf\xbf", 0xffff);
+ try testValid("\xf0\x90\x80\x80", 0x10000);
+ try testValid("\xf1\x80\x80\x80", 0x40000);
+ try testValid("\xf3\xbf\xbf\xbf", 0xfffff);
+ try testValid("\xf4\x8f\xbf\xbf", 0x10ffff);
}
test "invalid utf8 continuation bytes" {
- comptime testInvalidUtf8ContinuationBytes();
- testInvalidUtf8ContinuationBytes();
+ comptime try testInvalidUtf8ContinuationBytes();
+ try testInvalidUtf8ContinuationBytes();
}
-fn testInvalidUtf8ContinuationBytes() void {
+fn testInvalidUtf8ContinuationBytes() !void {
// unexpected continuation
- testError("\x80", error.Utf8InvalidStartByte);
- testError("\xbf", error.Utf8InvalidStartByte);
+ try testError("\x80", error.Utf8InvalidStartByte);
+ try testError("\xbf", error.Utf8InvalidStartByte);
// too many leading 1's
- testError("\xf8", error.Utf8InvalidStartByte);
- testError("\xff", error.Utf8InvalidStartByte);
+ try testError("\xf8", error.Utf8InvalidStartByte);
+ try testError("\xff", error.Utf8InvalidStartByte);
// expected continuation for 2 byte sequences
- testError("\xc2", error.UnexpectedEof);
- testError("\xc2\x00", error.Utf8ExpectedContinuation);
- testError("\xc2\xc0", error.Utf8ExpectedContinuation);
+ try testError("\xc2", error.UnexpectedEof);
+ try testError("\xc2\x00", error.Utf8ExpectedContinuation);
+ try testError("\xc2\xc0", error.Utf8ExpectedContinuation);
// expected continuation for 3 byte sequences
- testError("\xe0", error.UnexpectedEof);
- testError("\xe0\x00", error.UnexpectedEof);
- testError("\xe0\xc0", error.UnexpectedEof);
- testError("\xe0\xa0", error.UnexpectedEof);
- testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);
- testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);
+ try testError("\xe0", error.UnexpectedEof);
+ try testError("\xe0\x00", error.UnexpectedEof);
+ try testError("\xe0\xc0", error.UnexpectedEof);
+ try testError("\xe0\xa0", error.UnexpectedEof);
+ try testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);
+ try testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);
// expected continuation for 4 byte sequences
- testError("\xf0", error.UnexpectedEof);
- testError("\xf0\x00", error.UnexpectedEof);
- testError("\xf0\xc0", error.UnexpectedEof);
- testError("\xf0\x90\x00", error.UnexpectedEof);
- testError("\xf0\x90\xc0", error.UnexpectedEof);
- testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);
- testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);
+ try testError("\xf0", error.UnexpectedEof);
+ try testError("\xf0\x00", error.UnexpectedEof);
+ try testError("\xf0\xc0", error.UnexpectedEof);
+ try testError("\xf0\x90\x00", error.UnexpectedEof);
+ try testError("\xf0\x90\xc0", error.UnexpectedEof);
+ try testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);
+ try testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);
}
test "overlong utf8 codepoint" {
- comptime testOverlongUtf8Codepoint();
- testOverlongUtf8Codepoint();
+ comptime try testOverlongUtf8Codepoint();
+ try testOverlongUtf8Codepoint();
}
-fn testOverlongUtf8Codepoint() void {
- testError("\xc0\x80", error.Utf8OverlongEncoding);
- testError("\xc1\xbf", error.Utf8OverlongEncoding);
- testError("\xe0\x80\x80", error.Utf8OverlongEncoding);
- testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);
- testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);
- testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);
+fn testOverlongUtf8Codepoint() !void {
+ try testError("\xc0\x80", error.Utf8OverlongEncoding);
+ try testError("\xc1\xbf", error.Utf8OverlongEncoding);
+ try testError("\xe0\x80\x80", error.Utf8OverlongEncoding);
+ try testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);
+ try testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);
+ try testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);
}
test "misc invalid utf8" {
- comptime testMiscInvalidUtf8();
- testMiscInvalidUtf8();
+ comptime try testMiscInvalidUtf8();
+ try testMiscInvalidUtf8();
}
-fn testMiscInvalidUtf8() void {
+fn testMiscInvalidUtf8() !void {
// codepoint out of bounds
- testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);
- testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);
+ try testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);
+ try testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);
// surrogate halves
- testValid("\xed\x9f\xbf", 0xd7ff);
- testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);
- testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);
- testValid("\xee\x80\x80", 0xe000);
+ try testValid("\xed\x9f\xbf", 0xd7ff);
+ try testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);
+ try testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);
+ try testValid("\xee\x80\x80", 0xe000);
}
test "utf8 iterator peeking" {
- comptime testUtf8Peeking();
- testUtf8Peeking();
+ comptime try testUtf8Peeking();
+ try testUtf8Peeking();
}
-fn testUtf8Peeking() void {
+fn testUtf8Peeking() !void {
const s = Utf8View.initComptime("noΓ«l");
var it = s.iterator();
- testing.expect(std.mem.eql(u8, "n", it.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "n", it.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "o", it.peek(1)));
- testing.expect(std.mem.eql(u8, "oΓ«", it.peek(2)));
- testing.expect(std.mem.eql(u8, "oΓ«l", it.peek(3)));
- testing.expect(std.mem.eql(u8, "oΓ«l", it.peek(4)));
- testing.expect(std.mem.eql(u8, "oΓ«l", it.peek(10)));
+ try testing.expect(std.mem.eql(u8, "o", it.peek(1)));
+ try testing.expect(std.mem.eql(u8, "oΓ«", it.peek(2)));
+ try testing.expect(std.mem.eql(u8, "oΓ«l", it.peek(3)));
+ try testing.expect(std.mem.eql(u8, "oΓ«l", it.peek(4)));
+ try testing.expect(std.mem.eql(u8, "oΓ«l", it.peek(10)));
- testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "Γ«", it.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));
- testing.expect(it.nextCodepointSlice() == null);
+ try testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "Γ«", it.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));
+ try testing.expect(it.nextCodepointSlice() == null);
- testing.expect(std.mem.eql(u8, &[_]u8{}, it.peek(1)));
+ try testing.expect(std.mem.eql(u8, &[_]u8{}, it.peek(1)));
}
-fn testError(bytes: []const u8, expected_err: anyerror) void {
- testing.expectError(expected_err, testDecode(bytes));
+fn testError(bytes: []const u8, expected_err: anyerror) !void {
+ try testing.expectError(expected_err, testDecode(bytes));
}
-fn testValid(bytes: []const u8, expected_codepoint: u21) void {
- testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);
+fn testValid(bytes: []const u8, expected_codepoint: u21) !void {
+ try testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);
}
fn testDecode(bytes: []const u8) !u21 {
const length = try utf8ByteSequenceLength(bytes[0]);
if (bytes.len < length) return error.UnexpectedEof;
- testing.expect(bytes.len == length);
+ try testing.expect(bytes.len == length);
return utf8Decode(bytes);
}
@@ -615,7 +615,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "Aa"));
+ try testing.expect(mem.eql(u8, utf8, "Aa"));
}
{
@@ -623,7 +623,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
+ try testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
}
{
@@ -632,7 +632,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
+ try testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
}
{
@@ -641,7 +641,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
+ try testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
}
{
@@ -650,7 +650,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
+ try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
}
{
@@ -658,7 +658,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
+ try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
}
}
@@ -717,13 +717,13 @@ test "utf8ToUtf16Le" {
var utf16le: [2]u16 = [_]u16{0} ** 2;
{
const length = try utf8ToUtf16Le(utf16le[0..], "π·");
- testing.expectEqual(@as(usize, 2), length);
- testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));
+ try testing.expectEqual(@as(usize, 2), length);
+ try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));
}
{
const length = try utf8ToUtf16Le(utf16le[0..], "\u{10FFFF}");
- testing.expectEqual(@as(usize, 2), length);
- testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));
+ try testing.expectEqual(@as(usize, 2), length);
+ try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));
}
}
@@ -731,14 +731,14 @@ test "utf8ToUtf16LeWithNull" {
{
const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "π·");
defer testing.allocator.free(utf16);
- testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));
- testing.expect(utf16[2] == 0);
+ try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));
+ try testing.expect(utf16[2] == 0);
}
{
const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "\u{10FFFF}");
defer testing.allocator.free(utf16);
- testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));
- testing.expect(utf16[2] == 0);
+ try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));
+ try testing.expect(utf16[2] == 0);
}
}
@@ -776,8 +776,8 @@ test "utf8ToUtf16LeStringLiteral" {
mem.nativeToLittle(u16, 0x41),
};
const utf16 = utf8ToUtf16LeStringLiteral("A");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[1] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[1] == 0);
}
{
const bytes = [_:0]u16{
@@ -785,32 +785,32 @@ test "utf8ToUtf16LeStringLiteral" {
mem.nativeToLittle(u16, 0xDC37),
};
const utf16 = utf8ToUtf16LeStringLiteral("π·");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[2] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[2] == 0);
}
{
const bytes = [_:0]u16{
mem.nativeToLittle(u16, 0x02FF),
};
const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[1] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[1] == 0);
}
{
const bytes = [_:0]u16{
mem.nativeToLittle(u16, 0x7FF),
};
const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[1] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[1] == 0);
}
{
const bytes = [_:0]u16{
mem.nativeToLittle(u16, 0x801),
};
const utf16 = utf8ToUtf16LeStringLiteral("\u{801}");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[1] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[1] == 0);
}
{
const bytes = [_:0]u16{
@@ -818,35 +818,35 @@ test "utf8ToUtf16LeStringLiteral" {
mem.nativeToLittle(u16, 0xDFFF),
};
const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[2] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[2] == 0);
}
}
fn testUtf8CountCodepoints() !void {
- testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));
- testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("Γ€Γ₯éëþüúΓΓ³ΓΆ"));
- testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("γγγ«γ‘γ―"));
+ try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));
+ try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("Γ€Γ₯éëþüúΓΓ³ΓΆ"));
+ try testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("γγγ«γ‘γ―"));
// testing.expectError(error.Utf8EncodesSurrogateHalf, utf8CountCodepoints("\xED\xA0\x80"));
}
test "utf8 count codepoints" {
try testUtf8CountCodepoints();
- comptime testUtf8CountCodepoints() catch unreachable;
+ comptime try testUtf8CountCodepoints();
}
fn testUtf8ValidCodepoint() !void {
- testing.expect(utf8ValidCodepoint('e'));
- testing.expect(utf8ValidCodepoint('Γ«'));
- testing.expect(utf8ValidCodepoint('γ―'));
- testing.expect(utf8ValidCodepoint(0xe000));
- testing.expect(utf8ValidCodepoint(0x10ffff));
- testing.expect(!utf8ValidCodepoint(0xd800));
- testing.expect(!utf8ValidCodepoint(0xdfff));
- testing.expect(!utf8ValidCodepoint(0x110000));
+ try testing.expect(utf8ValidCodepoint('e'));
+ try testing.expect(utf8ValidCodepoint('Γ«'));
+ try testing.expect(utf8ValidCodepoint('γ―'));
+ try testing.expect(utf8ValidCodepoint(0xe000));
+ try testing.expect(utf8ValidCodepoint(0x10ffff));
+ try testing.expect(!utf8ValidCodepoint(0xd800));
+ try testing.expect(!utf8ValidCodepoint(0xdfff));
+ try testing.expect(!utf8ValidCodepoint(0x110000));
}
test "utf8 valid codepoint" {
try testUtf8ValidCodepoint();
- comptime testUtf8ValidCodepoint() catch unreachable;
+ comptime try testUtf8ValidCodepoint();
}
diff --git a/lib/std/valgrind/memcheck.zig b/lib/std/valgrind/memcheck.zig
index 3226beec53..8262e39fe9 100644
--- a/lib/std/valgrind/memcheck.zig
+++ b/lib/std/valgrind/memcheck.zig
@@ -149,7 +149,7 @@ pub fn countLeaks() CountResult {
}
test "countLeaks" {
- testing.expectEqual(
+ try testing.expectEqual(
@as(CountResult, .{
.leaked = 0,
.dubious = 0,
@@ -179,7 +179,7 @@ pub fn countLeakBlocks() CountResult {
}
test "countLeakBlocks" {
- testing.expectEqual(
+ try testing.expectEqual(
@as(CountResult, .{
.leaked = 0,
.dubious = 0,
diff --git a/lib/std/wasm.zig b/lib/std/wasm.zig
index ad6b947f67..8922b3c83e 100644
--- a/lib/std/wasm.zig
+++ b/lib/std/wasm.zig
@@ -200,11 +200,11 @@ test "Wasm - opcodes" {
const local_get = opcode(.local_get);
const i64_extend32_s = opcode(.i64_extend32_s);
- testing.expectEqual(@as(u16, 0x41), i32_const);
- testing.expectEqual(@as(u16, 0x0B), end);
- testing.expectEqual(@as(u16, 0x1A), drop);
- testing.expectEqual(@as(u16, 0x20), local_get);
- testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);
+ try testing.expectEqual(@as(u16, 0x41), i32_const);
+ try testing.expectEqual(@as(u16, 0x0B), end);
+ try testing.expectEqual(@as(u16, 0x1A), drop);
+ try testing.expectEqual(@as(u16, 0x20), local_get);
+ try testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);
}
/// Enum representing all Wasm value types as per spec:
@@ -227,10 +227,10 @@ test "Wasm - valtypes" {
const _f32 = valtype(.f32);
const _f64 = valtype(.f64);
- testing.expectEqual(@as(u8, 0x7F), _i32);
- testing.expectEqual(@as(u8, 0x7E), _i64);
- testing.expectEqual(@as(u8, 0x7D), _f32);
- testing.expectEqual(@as(u8, 0x7C), _f64);
+ try testing.expectEqual(@as(u8, 0x7F), _i32);
+ try testing.expectEqual(@as(u8, 0x7E), _i64);
+ try testing.expectEqual(@as(u8, 0x7D), _f32);
+ try testing.expectEqual(@as(u8, 0x7C), _f64);
}
/// Wasm module sections as per spec:
diff --git a/lib/std/x/net/tcp.zig b/lib/std/x/net/tcp.zig
index a4cc4a288c..0740e3ab4f 100644
--- a/lib/std/x/net/tcp.zig
+++ b/lib/std/x/net/tcp.zig
@@ -322,7 +322,7 @@ test "tcp/client: set read timeout of 1 millisecond on blocking client" {
defer conn.deinit();
var buf: [1]u8 = undefined;
- testing.expectError(error.WouldBlock, client.read(&buf));
+ try testing.expectError(error.WouldBlock, client.read(&buf));
}
test "tcp/listener: bind to unspecified ipv4 address" {
@@ -335,7 +335,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {
try listener.listen(128);
const address = try listener.getLocalAddress();
- testing.expect(address == .ipv4);
+ try testing.expect(address == .ipv4);
}
test "tcp/listener: bind to unspecified ipv6 address" {
@@ -348,5 +348,5 @@ test "tcp/listener: bind to unspecified ipv6 address" {
try listener.listen(128);
const address = try listener.getLocalAddress();
- testing.expect(address == .ipv6);
+ try testing.expect(address == .ipv6);
}
diff --git a/lib/std/x/os/net.zig b/lib/std/x/os/net.zig
index a8d9f095d3..7cd400cc0a 100644
--- a/lib/std/x/os/net.zig
+++ b/lib/std/x/os/net.zig
@@ -499,12 +499,12 @@ test {
test "ip: convert to and from ipv6" {
try testing.expectFmt("::7f00:1", "{}", .{IPv4.localhost.toIPv6()});
- testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());
+ try testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());
try testing.expectFmt("::ffff:127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6()});
- testing.expect(IPv4.localhost.mapToIPv6().mapsToIPv4());
+ try testing.expect(IPv4.localhost.mapToIPv6().mapsToIPv4());
- testing.expect(IPv4.localhost.toIPv6().toIPv4() == null);
+ try testing.expect(IPv4.localhost.toIPv6().toIPv4() == null);
try testing.expectFmt("127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6().toIPv4()});
}
diff --git a/lib/std/zig.zig b/lib/std/zig.zig
index a06249dd4f..daf440c796 100644
--- a/lib/std/zig.zig
+++ b/lib/std/zig.zig
@@ -253,26 +253,26 @@ pub fn parseCharLiteral(
test "parseCharLiteral" {
var bad_index: usize = undefined;
- std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');
- std.testing.expectEqual(try parseCharLiteral("'Γ€'", &bad_index), 'Γ€');
- std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);
- std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);
- std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);
- std.testing.expectEqual(try parseCharLiteral("'γ'", &bad_index), 0x3041);
- std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);
- std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);
- std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);
- std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);
+ try std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');
+ try std.testing.expectEqual(try parseCharLiteral("'Γ€'", &bad_index), 'Γ€');
+ try std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);
+ try std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);
+ try std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);
+ try std.testing.expectEqual(try parseCharLiteral("'γ'", &bad_index), 0x3041);
+ try std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);
+ try std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);
+ try std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);
+ try std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));
}
test {
diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig
index 8d6f63f5e3..bf62a49ef6 100644
--- a/lib/std/zig/cross_target.zig
+++ b/lib/std/zig/cross_target.zig
@@ -800,7 +800,7 @@ test "CrossTarget.parse" {
.{@tagName(std.Target.current.abi)},
) catch unreachable;
- std.testing.expectEqualSlices(u8, triple, text);
+ try std.testing.expectEqualSlices(u8, triple, text);
}
{
const cross_target = try CrossTarget.parse(.{
@@ -808,18 +808,18 @@ test "CrossTarget.parse" {
.cpu_features = "native",
});
- std.testing.expect(cross_target.cpu_arch.? == .aarch64);
- std.testing.expect(cross_target.cpu_model == .native);
+ try std.testing.expect(cross_target.cpu_arch.? == .aarch64);
+ try std.testing.expect(cross_target.cpu_model == .native);
}
{
const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
- std.testing.expect(cross_target.cpu_arch == null);
- std.testing.expect(cross_target.isNative());
+ try std.testing.expect(cross_target.cpu_arch == null);
+ try std.testing.expect(cross_target.isNative());
const text = try cross_target.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text);
- std.testing.expectEqualSlices(u8, "native", text);
+ try std.testing.expectEqualSlices(u8, "native", text);
}
{
const cross_target = try CrossTarget.parse(.{
@@ -828,23 +828,23 @@ test "CrossTarget.parse" {
});
const target = cross_target.toTarget();
- std.testing.expect(target.os.tag == .linux);
- std.testing.expect(target.abi == .gnu);
- std.testing.expect(target.cpu.arch == .x86_64);
- std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
- std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
- std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
- std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
- std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));
+ try std.testing.expect(target.os.tag == .linux);
+ try std.testing.expect(target.abi == .gnu);
+ try std.testing.expect(target.cpu.arch == .x86_64);
+ try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
+ try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
+ try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
+ try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
+ try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));
- std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));
- std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
- std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
- std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
+ try std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));
+ try std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
+ try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
+ try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
const text = try cross_target.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text);
- std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text);
+ try std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text);
}
{
const cross_target = try CrossTarget.parse(.{
@@ -853,15 +853,15 @@ test "CrossTarget.parse" {
});
const target = cross_target.toTarget();
- std.testing.expect(target.os.tag == .linux);
- std.testing.expect(target.abi == .musleabihf);
- std.testing.expect(target.cpu.arch == .arm);
- std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
- std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
+ try std.testing.expect(target.os.tag == .linux);
+ try std.testing.expect(target.abi == .musleabihf);
+ try std.testing.expect(target.cpu.arch == .arm);
+ try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
+ try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
const text = try cross_target.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text);
- std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text);
+ try std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text);
}
{
const cross_target = try CrossTarget.parse(.{
@@ -870,21 +870,21 @@ test "CrossTarget.parse" {
});
const target = cross_target.toTarget();
- std.testing.expect(target.cpu.arch == .aarch64);
- std.testing.expect(target.os.tag == .linux);
- std.testing.expect(target.os.version_range.linux.range.min.major == 3);
- std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
- std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
- std.testing.expect(target.os.version_range.linux.range.max.major == 4);
- std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
- std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
- std.testing.expect(target.os.version_range.linux.glibc.major == 2);
- std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
- std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
- std.testing.expect(target.abi == .gnu);
+ try std.testing.expect(target.cpu.arch == .aarch64);
+ try std.testing.expect(target.os.tag == .linux);
+ try std.testing.expect(target.os.version_range.linux.range.min.major == 3);
+ try std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
+ try std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
+ try std.testing.expect(target.os.version_range.linux.range.max.major == 4);
+ try std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
+ try std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
+ try std.testing.expect(target.os.version_range.linux.glibc.major == 2);
+ try std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
+ try std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
+ try std.testing.expect(target.abi == .gnu);
const text = try cross_target.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text);
- std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text);
+ try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text);
}
}
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
index fe119a5d27..9cc350b1ad 100644
--- a/lib/std/zig/parser_test.zig
+++ b/lib/std/zig/parser_test.zig
@@ -988,7 +988,7 @@ test "zig fmt: while else err prong with no block" {
\\ const result = while (returnError()) |value| {
\\ break value;
\\ } else |err| @as(i32, 2);
- \\ expect(result == 2);
+ \\ try expect(result == 2);
\\}
\\
);
@@ -5135,7 +5135,7 @@ test "recovery: missing while rbrace" {
const std = @import("std");
const mem = std.mem;
-const warn = std.debug.warn;
+const print = std.debug.print;
const io = std.io;
const maxInt = std.math.maxInt;
@@ -5177,13 +5177,13 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize));
var anything_changed: bool = undefined;
const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);
- std.testing.expectEqualStrings(expected_source, result_source);
+ try std.testing.expectEqualStrings(expected_source, result_source);
const changes_expected = source.ptr != expected_source.ptr;
if (anything_changed != changes_expected) {
- warn("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected });
+ print("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected });
return error.TestFailed;
}
- std.testing.expect(anything_changed == changes_expected);
+ try std.testing.expect(anything_changed == changes_expected);
failing_allocator.allocator.free(result_source);
break :x failing_allocator.index;
};
@@ -5198,7 +5198,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
} else |err| switch (err) {
error.OutOfMemory => {
if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
- warn(
+ print(
"\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\n",
.{
fail_index,
@@ -5212,8 +5212,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
return error.MemoryLeakDetected;
}
},
- error.ParseError => @panic("test failed"),
- else => @panic("test failed"),
+ else => return err,
}
}
}
@@ -5227,8 +5226,8 @@ fn testError(source: []const u8, expected_errors: []const Error) !void {
var tree = try std.zig.parse(std.testing.allocator, source);
defer tree.deinit(std.testing.allocator);
- std.testing.expectEqual(expected_errors.len, tree.errors.len);
+ try std.testing.expectEqual(expected_errors.len, tree.errors.len);
for (expected_errors) |expected, i| {
- std.testing.expectEqual(expected, tree.errors[i].tag);
+ try std.testing.expectEqual(expected, tree.errors[i].tag);
}
}
diff --git a/lib/std/zig/string_literal.zig b/lib/std/zig/string_literal.zig
index e1fa799954..992affc829 100644
--- a/lib/std/zig/string_literal.zig
+++ b/lib/std/zig/string_literal.zig
@@ -153,7 +153,7 @@ test "parse" {
var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buf_mem[0..]);
var alloc = &fixed_buf_alloc.allocator;
- expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));
- expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));
- expect(eql(u8, "fπ―", try parseAlloc(alloc, "\"f\u{1f4af}\"")));
+ try expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));
+ try expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));
+ try expect(eql(u8, "fπ―", try parseAlloc(alloc, "\"f\u{1f4af}\"")));
}
diff --git a/lib/std/zig/system/linux.zig b/lib/std/zig/system/linux.zig
index c2cf7b009d..e7737dfd70 100644
--- a/lib/std/zig/system/linux.zig
+++ b/lib/std/zig/system/linux.zig
@@ -414,8 +414,8 @@ fn testParser(
) !void {
var fbs = io.fixedBufferStream(input);
const result = try parser.parse(arch, fbs.reader());
- testing.expectEqual(expected_model, result.?.model);
- testing.expect(expected_model.features.eql(result.?.features));
+ try testing.expectEqual(expected_model, result.?.model);
+ try testing.expect(expected_model.features.eql(result.?.features));
}
// The generic implementation of a /proc/cpuinfo parser.
diff --git a/lib/std/zig/system/macos.zig b/lib/std/zig/system/macos.zig
index abe844d2c4..be892b4834 100644
--- a/lib/std/zig/system/macos.zig
+++ b/lib/std/zig/system/macos.zig
@@ -402,7 +402,7 @@ fn testVersionEquality(expected: std.builtin.Version, got: std.builtin.Version)
var b_got: [64]u8 = undefined;
const s_got: []const u8 = try std.fmt.bufPrint(b_got[0..], "{}", .{got});
- testing.expectEqualStrings(s_expected, s_got);
+ try testing.expectEqualStrings(s_expected, s_got);
}
/// Detect SDK path on Darwin.
diff --git a/lib/std/zig/tokenizer.zig b/lib/std/zig/tokenizer.zig
index 88feabd021..edb6b5ffc3 100644
--- a/lib/std/zig/tokenizer.zig
+++ b/lib/std/zig/tokenizer.zig
@@ -1503,11 +1503,11 @@ pub const Tokenizer = struct {
};
test "tokenizer" {
- testTokenize("test", &.{.keyword_test});
+ try testTokenize("test", &.{.keyword_test});
}
test "line comment followed by top-level comptime" {
- testTokenize(
+ try testTokenize(
\\// line comment
\\comptime {}
\\
@@ -1519,7 +1519,7 @@ test "line comment followed by top-level comptime" {
}
test "tokenizer - unknown length pointer and then c pointer" {
- testTokenize(
+ try testTokenize(
\\[*]u8
\\[*c]u8
, &.{
@@ -1536,72 +1536,72 @@ test "tokenizer - unknown length pointer and then c pointer" {
}
test "tokenizer - code point literal with hex escape" {
- testTokenize(
+ try testTokenize(
\\'\x1b'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\'\x1'
, &.{ .invalid, .invalid });
}
test "tokenizer - code point literal with unicode escapes" {
// Valid unicode escapes
- testTokenize(
+ try testTokenize(
\\'\u{3}'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\'\u{01}'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\'\u{2a}'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\'\u{3f9}'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\'\u{6E09aBc1523}'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\"\u{440}"
, &.{.string_literal});
// Invalid unicode escapes
- testTokenize(
+ try testTokenize(
\\'\u'
, &.{.invalid});
- testTokenize(
+ try testTokenize(
\\'\u{{'
, &.{ .invalid, .invalid });
- testTokenize(
+ try testTokenize(
\\'\u{}'
, &.{ .invalid, .invalid });
- testTokenize(
+ try testTokenize(
\\'\u{s}'
, &.{ .invalid, .invalid });
- testTokenize(
+ try testTokenize(
\\'\u{2z}'
, &.{ .invalid, .invalid });
- testTokenize(
+ try testTokenize(
\\'\u{4a'
, &.{.invalid});
// Test old-style unicode literals
- testTokenize(
+ try testTokenize(
\\'\u0333'
, &.{ .invalid, .invalid });
- testTokenize(
+ try testTokenize(
\\'\U0333'
, &.{ .invalid, .integer_literal, .invalid });
}
test "tokenizer - code point literal with unicode code point" {
- testTokenize(
+ try testTokenize(
\\'π©'
, &.{.char_literal});
}
test "tokenizer - float literal e exponent" {
- testTokenize("a = 4.94065645841246544177e-324;\n", &.{
+ try testTokenize("a = 4.94065645841246544177e-324;\n", &.{
.identifier,
.equal,
.float_literal,
@@ -1610,7 +1610,7 @@ test "tokenizer - float literal e exponent" {
}
test "tokenizer - float literal p exponent" {
- testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{
+ try testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{
.identifier,
.equal,
.float_literal,
@@ -1619,84 +1619,84 @@ test "tokenizer - float literal p exponent" {
}
test "tokenizer - chars" {
- testTokenize("'c'", &.{.char_literal});
+ try testTokenize("'c'", &.{.char_literal});
}
test "tokenizer - invalid token characters" {
- testTokenize("#", &.{.invalid});
- testTokenize("`", &.{.invalid});
- testTokenize("'c", &.{.invalid});
- testTokenize("'", &.{.invalid});
- testTokenize("''", &.{ .invalid, .invalid });
+ try testTokenize("#", &.{.invalid});
+ try testTokenize("`", &.{.invalid});
+ try testTokenize("'c", &.{.invalid});
+ try testTokenize("'", &.{.invalid});
+ try testTokenize("''", &.{ .invalid, .invalid });
}
test "tokenizer - invalid literal/comment characters" {
- testTokenize("\"\x00\"", &.{
+ try testTokenize("\"\x00\"", &.{
.string_literal,
.invalid,
});
- testTokenize("//\x00", &.{
+ try testTokenize("//\x00", &.{
.invalid,
});
- testTokenize("//\x1f", &.{
+ try testTokenize("//\x1f", &.{
.invalid,
});
- testTokenize("//\x7f", &.{
+ try testTokenize("//\x7f", &.{
.invalid,
});
}
test "tokenizer - utf8" {
- testTokenize("//\xc2\x80", &.{});
- testTokenize("//\xf4\x8f\xbf\xbf", &.{});
+ try testTokenize("//\xc2\x80", &.{});
+ try testTokenize("//\xf4\x8f\xbf\xbf", &.{});
}
test "tokenizer - invalid utf8" {
- testTokenize("//\x80", &.{
+ try testTokenize("//\x80", &.{
.invalid,
});
- testTokenize("//\xbf", &.{
+ try testTokenize("//\xbf", &.{
.invalid,
});
- testTokenize("//\xf8", &.{
+ try testTokenize("//\xf8", &.{
.invalid,
});
- testTokenize("//\xff", &.{
+ try testTokenize("//\xff", &.{
.invalid,
});
- testTokenize("//\xc2\xc0", &.{
+ try testTokenize("//\xc2\xc0", &.{
.invalid,
});
- testTokenize("//\xe0", &.{
+ try testTokenize("//\xe0", &.{
.invalid,
});
- testTokenize("//\xf0", &.{
+ try testTokenize("//\xf0", &.{
.invalid,
});
- testTokenize("//\xf0\x90\x80\xc0", &.{
+ try testTokenize("//\xf0\x90\x80\xc0", &.{
.invalid,
});
}
test "tokenizer - illegal unicode codepoints" {
// unicode newline characters.U+0085, U+2028, U+2029
- testTokenize("//\xc2\x84", &.{});
- testTokenize("//\xc2\x85", &.{
+ try testTokenize("//\xc2\x84", &.{});
+ try testTokenize("//\xc2\x85", &.{
.invalid,
});
- testTokenize("//\xc2\x86", &.{});
- testTokenize("//\xe2\x80\xa7", &.{});
- testTokenize("//\xe2\x80\xa8", &.{
+ try testTokenize("//\xc2\x86", &.{});
+ try testTokenize("//\xe2\x80\xa7", &.{});
+ try testTokenize("//\xe2\x80\xa8", &.{
.invalid,
});
- testTokenize("//\xe2\x80\xa9", &.{
+ try testTokenize("//\xe2\x80\xa9", &.{
.invalid,
});
- testTokenize("//\xe2\x80\xaa", &.{});
+ try testTokenize("//\xe2\x80\xaa", &.{});
}
test "tokenizer - string identifier and builtin fns" {
- testTokenize(
+ try testTokenize(
\\const @"if" = @import("std");
, &.{
.keyword_const,
@@ -1711,7 +1711,7 @@ test "tokenizer - string identifier and builtin fns" {
}
test "tokenizer - multiline string literal with literal tab" {
- testTokenize(
+ try testTokenize(
\\\\foo bar
, &.{
.multiline_string_literal_line,
@@ -1719,7 +1719,7 @@ test "tokenizer - multiline string literal with literal tab" {
}
test "tokenizer - comments with literal tab" {
- testTokenize(
+ try testTokenize(
\\//foo bar
\\//!foo bar
\\///foo bar
@@ -1735,25 +1735,25 @@ test "tokenizer - comments with literal tab" {
}
test "tokenizer - pipe and then invalid" {
- testTokenize("||=", &.{
+ try testTokenize("||=", &.{
.pipe_pipe,
.equal,
});
}
test "tokenizer - line comment and doc comment" {
- testTokenize("//", &.{});
- testTokenize("// a / b", &.{});
- testTokenize("// /", &.{});
- testTokenize("/// a", &.{.doc_comment});
- testTokenize("///", &.{.doc_comment});
- testTokenize("////", &.{});
- testTokenize("//!", &.{.container_doc_comment});
- testTokenize("//!!", &.{.container_doc_comment});
+ try testTokenize("//", &.{});
+ try testTokenize("// a / b", &.{});
+ try testTokenize("// /", &.{});
+ try testTokenize("/// a", &.{.doc_comment});
+ try testTokenize("///", &.{.doc_comment});
+ try testTokenize("////", &.{});
+ try testTokenize("//!", &.{.container_doc_comment});
+ try testTokenize("//!!", &.{.container_doc_comment});
}
test "tokenizer - line comment followed by identifier" {
- testTokenize(
+ try testTokenize(
\\ Unexpected,
\\ // another
\\ Another,
@@ -1766,14 +1766,14 @@ test "tokenizer - line comment followed by identifier" {
}
test "tokenizer - UTF-8 BOM is recognized and skipped" {
- testTokenize("\xEF\xBB\xBFa;\n", &.{
+ try testTokenize("\xEF\xBB\xBFa;\n", &.{
.identifier,
.semicolon,
});
}
test "correctly parse pointer assignment" {
- testTokenize("b.*=3;\n", &.{
+ try testTokenize("b.*=3;\n", &.{
.identifier,
.period_asterisk,
.equal,
@@ -1783,14 +1783,14 @@ test "correctly parse pointer assignment" {
}
test "correctly parse pointer dereference followed by asterisk" {
- testTokenize("\"b\".* ** 10", &.{
+ try testTokenize("\"b\".* ** 10", &.{
.string_literal,
.period_asterisk,
.asterisk_asterisk,
.integer_literal,
});
- testTokenize("(\"b\".*)** 10", &.{
+ try testTokenize("(\"b\".*)** 10", &.{
.l_paren,
.string_literal,
.period_asterisk,
@@ -1799,7 +1799,7 @@ test "correctly parse pointer dereference followed by asterisk" {
.integer_literal,
});
- testTokenize("\"b\".*** 10", &.{
+ try testTokenize("\"b\".*** 10", &.{
.string_literal,
.invalid_periodasterisks,
.asterisk_asterisk,
@@ -1808,245 +1808,245 @@ test "correctly parse pointer dereference followed by asterisk" {
}
test "tokenizer - range literals" {
- testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });
- testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });
- testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });
- testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });
- testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });
+ try testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });
+ try testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });
+ try testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });
+ try testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });
+ try testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });
}
test "tokenizer - number literals decimal" {
- testTokenize("0", &.{.integer_literal});
- testTokenize("1", &.{.integer_literal});
- testTokenize("2", &.{.integer_literal});
- testTokenize("3", &.{.integer_literal});
- testTokenize("4", &.{.integer_literal});
- testTokenize("5", &.{.integer_literal});
- testTokenize("6", &.{.integer_literal});
- testTokenize("7", &.{.integer_literal});
- testTokenize("8", &.{.integer_literal});
- testTokenize("9", &.{.integer_literal});
- testTokenize("1..", &.{ .integer_literal, .ellipsis2 });
- testTokenize("0a", &.{ .invalid, .identifier });
- testTokenize("9b", &.{ .invalid, .identifier });
- testTokenize("1z", &.{ .invalid, .identifier });
- testTokenize("1z_1", &.{ .invalid, .identifier });
- testTokenize("9z3", &.{ .invalid, .identifier });
+ try testTokenize("0", &.{.integer_literal});
+ try testTokenize("1", &.{.integer_literal});
+ try testTokenize("2", &.{.integer_literal});
+ try testTokenize("3", &.{.integer_literal});
+ try testTokenize("4", &.{.integer_literal});
+ try testTokenize("5", &.{.integer_literal});
+ try testTokenize("6", &.{.integer_literal});
+ try testTokenize("7", &.{.integer_literal});
+ try testTokenize("8", &.{.integer_literal});
+ try testTokenize("9", &.{.integer_literal});
+ try testTokenize("1..", &.{ .integer_literal, .ellipsis2 });
+ try testTokenize("0a", &.{ .invalid, .identifier });
+ try testTokenize("9b", &.{ .invalid, .identifier });
+ try testTokenize("1z", &.{ .invalid, .identifier });
+ try testTokenize("1z_1", &.{ .invalid, .identifier });
+ try testTokenize("9z3", &.{ .invalid, .identifier });
- testTokenize("0_0", &.{.integer_literal});
- testTokenize("0001", &.{.integer_literal});
- testTokenize("01234567890", &.{.integer_literal});
- testTokenize("012_345_6789_0", &.{.integer_literal});
- testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});
+ try testTokenize("0_0", &.{.integer_literal});
+ try testTokenize("0001", &.{.integer_literal});
+ try testTokenize("01234567890", &.{.integer_literal});
+ try testTokenize("012_345_6789_0", &.{.integer_literal});
+ try testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});
- testTokenize("00_", &.{.invalid});
- testTokenize("0_0_", &.{.invalid});
- testTokenize("0__0", &.{ .invalid, .identifier });
- testTokenize("0_0f", &.{ .invalid, .identifier });
- testTokenize("0_0_f", &.{ .invalid, .identifier });
- testTokenize("0_0_f_00", &.{ .invalid, .identifier });
- testTokenize("1_,", &.{ .invalid, .comma });
+ try testTokenize("00_", &.{.invalid});
+ try testTokenize("0_0_", &.{.invalid});
+ try testTokenize("0__0", &.{ .invalid, .identifier });
+ try testTokenize("0_0f", &.{ .invalid, .identifier });
+ try testTokenize("0_0_f", &.{ .invalid, .identifier });
+ try testTokenize("0_0_f_00", &.{ .invalid, .identifier });
+ try testTokenize("1_,", &.{ .invalid, .comma });
- testTokenize("1.", &.{.float_literal});
- testTokenize("0.0", &.{.float_literal});
- testTokenize("1.0", &.{.float_literal});
- testTokenize("10.0", &.{.float_literal});
- testTokenize("0e0", &.{.float_literal});
- testTokenize("1e0", &.{.float_literal});
- testTokenize("1e100", &.{.float_literal});
- testTokenize("1.e100", &.{.float_literal});
- testTokenize("1.0e100", &.{.float_literal});
- testTokenize("1.0e+100", &.{.float_literal});
- testTokenize("1.0e-100", &.{.float_literal});
- testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});
- testTokenize("1.+", &.{ .float_literal, .plus });
+ try testTokenize("1.", &.{.float_literal});
+ try testTokenize("0.0", &.{.float_literal});
+ try testTokenize("1.0", &.{.float_literal});
+ try testTokenize("10.0", &.{.float_literal});
+ try testTokenize("0e0", &.{.float_literal});
+ try testTokenize("1e0", &.{.float_literal});
+ try testTokenize("1e100", &.{.float_literal});
+ try testTokenize("1.e100", &.{.float_literal});
+ try testTokenize("1.0e100", &.{.float_literal});
+ try testTokenize("1.0e+100", &.{.float_literal});
+ try testTokenize("1.0e-100", &.{.float_literal});
+ try testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});
+ try testTokenize("1.+", &.{ .float_literal, .plus });
- testTokenize("1e", &.{.invalid});
- testTokenize("1.0e1f0", &.{ .invalid, .identifier });
- testTokenize("1.0p100", &.{ .invalid, .identifier });
- testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });
- testTokenize("1.0p1f0", &.{ .invalid, .identifier });
- testTokenize("1.0_,", &.{ .invalid, .comma });
- testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });
- testTokenize("1._", &.{ .invalid, .identifier });
- testTokenize("1.a", &.{ .invalid, .identifier });
- testTokenize("1.z", &.{ .invalid, .identifier });
- testTokenize("1._0", &.{ .invalid, .identifier });
- testTokenize("1._+", &.{ .invalid, .identifier, .plus });
- testTokenize("1._e", &.{ .invalid, .identifier });
- testTokenize("1.0e", &.{.invalid});
- testTokenize("1.0e,", &.{ .invalid, .comma });
- testTokenize("1.0e_", &.{ .invalid, .identifier });
- testTokenize("1.0e+_", &.{ .invalid, .identifier });
- testTokenize("1.0e-_", &.{ .invalid, .identifier });
- testTokenize("1.0e0_+", &.{ .invalid, .plus });
+ try testTokenize("1e", &.{.invalid});
+ try testTokenize("1.0e1f0", &.{ .invalid, .identifier });
+ try testTokenize("1.0p100", &.{ .invalid, .identifier });
+ try testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });
+ try testTokenize("1.0p1f0", &.{ .invalid, .identifier });
+ try testTokenize("1.0_,", &.{ .invalid, .comma });
+ try testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });
+ try testTokenize("1._", &.{ .invalid, .identifier });
+ try testTokenize("1.a", &.{ .invalid, .identifier });
+ try testTokenize("1.z", &.{ .invalid, .identifier });
+ try testTokenize("1._0", &.{ .invalid, .identifier });
+ try testTokenize("1._+", &.{ .invalid, .identifier, .plus });
+ try testTokenize("1._e", &.{ .invalid, .identifier });
+ try testTokenize("1.0e", &.{.invalid});
+ try testTokenize("1.0e,", &.{ .invalid, .comma });
+ try testTokenize("1.0e_", &.{ .invalid, .identifier });
+ try testTokenize("1.0e+_", &.{ .invalid, .identifier });
+ try testTokenize("1.0e-_", &.{ .invalid, .identifier });
+ try testTokenize("1.0e0_+", &.{ .invalid, .plus });
}
test "tokenizer - number literals binary" {
- testTokenize("0b0", &.{.integer_literal});
- testTokenize("0b1", &.{.integer_literal});
- testTokenize("0b2", &.{ .invalid, .integer_literal });
- testTokenize("0b3", &.{ .invalid, .integer_literal });
- testTokenize("0b4", &.{ .invalid, .integer_literal });
- testTokenize("0b5", &.{ .invalid, .integer_literal });
- testTokenize("0b6", &.{ .invalid, .integer_literal });
- testTokenize("0b7", &.{ .invalid, .integer_literal });
- testTokenize("0b8", &.{ .invalid, .integer_literal });
- testTokenize("0b9", &.{ .invalid, .integer_literal });
- testTokenize("0ba", &.{ .invalid, .identifier });
- testTokenize("0bb", &.{ .invalid, .identifier });
- testTokenize("0bc", &.{ .invalid, .identifier });
- testTokenize("0bd", &.{ .invalid, .identifier });
- testTokenize("0be", &.{ .invalid, .identifier });
- testTokenize("0bf", &.{ .invalid, .identifier });
- testTokenize("0bz", &.{ .invalid, .identifier });
+ try testTokenize("0b0", &.{.integer_literal});
+ try testTokenize("0b1", &.{.integer_literal});
+ try testTokenize("0b2", &.{ .invalid, .integer_literal });
+ try testTokenize("0b3", &.{ .invalid, .integer_literal });
+ try testTokenize("0b4", &.{ .invalid, .integer_literal });
+ try testTokenize("0b5", &.{ .invalid, .integer_literal });
+ try testTokenize("0b6", &.{ .invalid, .integer_literal });
+ try testTokenize("0b7", &.{ .invalid, .integer_literal });
+ try testTokenize("0b8", &.{ .invalid, .integer_literal });
+ try testTokenize("0b9", &.{ .invalid, .integer_literal });
+ try testTokenize("0ba", &.{ .invalid, .identifier });
+ try testTokenize("0bb", &.{ .invalid, .identifier });
+ try testTokenize("0bc", &.{ .invalid, .identifier });
+ try testTokenize("0bd", &.{ .invalid, .identifier });
+ try testTokenize("0be", &.{ .invalid, .identifier });
+ try testTokenize("0bf", &.{ .invalid, .identifier });
+ try testTokenize("0bz", &.{ .invalid, .identifier });
- testTokenize("0b0000_0000", &.{.integer_literal});
- testTokenize("0b1111_1111", &.{.integer_literal});
- testTokenize("0b10_10_10_10", &.{.integer_literal});
- testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});
- testTokenize("0b1.", &.{ .integer_literal, .period });
- testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });
+ try testTokenize("0b0000_0000", &.{.integer_literal});
+ try testTokenize("0b1111_1111", &.{.integer_literal});
+ try testTokenize("0b10_10_10_10", &.{.integer_literal});
+ try testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});
+ try testTokenize("0b1.", &.{ .integer_literal, .period });
+ try testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });
- testTokenize("0B0", &.{ .invalid, .identifier });
- testTokenize("0b_", &.{ .invalid, .identifier });
- testTokenize("0b_0", &.{ .invalid, .identifier });
- testTokenize("0b1_", &.{.invalid});
- testTokenize("0b0__1", &.{ .invalid, .identifier });
- testTokenize("0b0_1_", &.{.invalid});
- testTokenize("0b1e", &.{ .invalid, .identifier });
- testTokenize("0b1p", &.{ .invalid, .identifier });
- testTokenize("0b1e0", &.{ .invalid, .identifier });
- testTokenize("0b1p0", &.{ .invalid, .identifier });
- testTokenize("0b1_,", &.{ .invalid, .comma });
+ try testTokenize("0B0", &.{ .invalid, .identifier });
+ try testTokenize("0b_", &.{ .invalid, .identifier });
+ try testTokenize("0b_0", &.{ .invalid, .identifier });
+ try testTokenize("0b1_", &.{.invalid});
+ try testTokenize("0b0__1", &.{ .invalid, .identifier });
+ try testTokenize("0b0_1_", &.{.invalid});
+ try testTokenize("0b1e", &.{ .invalid, .identifier });
+ try testTokenize("0b1p", &.{ .invalid, .identifier });
+ try testTokenize("0b1e0", &.{ .invalid, .identifier });
+ try testTokenize("0b1p0", &.{ .invalid, .identifier });
+ try testTokenize("0b1_,", &.{ .invalid, .comma });
}
test "tokenizer - number literals octal" {
- testTokenize("0o0", &.{.integer_literal});
- testTokenize("0o1", &.{.integer_literal});
- testTokenize("0o2", &.{.integer_literal});
- testTokenize("0o3", &.{.integer_literal});
- testTokenize("0o4", &.{.integer_literal});
- testTokenize("0o5", &.{.integer_literal});
- testTokenize("0o6", &.{.integer_literal});
- testTokenize("0o7", &.{.integer_literal});
- testTokenize("0o8", &.{ .invalid, .integer_literal });
- testTokenize("0o9", &.{ .invalid, .integer_literal });
- testTokenize("0oa", &.{ .invalid, .identifier });
- testTokenize("0ob", &.{ .invalid, .identifier });
- testTokenize("0oc", &.{ .invalid, .identifier });
- testTokenize("0od", &.{ .invalid, .identifier });
- testTokenize("0oe", &.{ .invalid, .identifier });
- testTokenize("0of", &.{ .invalid, .identifier });
- testTokenize("0oz", &.{ .invalid, .identifier });
+ try testTokenize("0o0", &.{.integer_literal});
+ try testTokenize("0o1", &.{.integer_literal});
+ try testTokenize("0o2", &.{.integer_literal});
+ try testTokenize("0o3", &.{.integer_literal});
+ try testTokenize("0o4", &.{.integer_literal});
+ try testTokenize("0o5", &.{.integer_literal});
+ try testTokenize("0o6", &.{.integer_literal});
+ try testTokenize("0o7", &.{.integer_literal});
+ try testTokenize("0o8", &.{ .invalid, .integer_literal });
+ try testTokenize("0o9", &.{ .invalid, .integer_literal });
+ try testTokenize("0oa", &.{ .invalid, .identifier });
+ try testTokenize("0ob", &.{ .invalid, .identifier });
+ try testTokenize("0oc", &.{ .invalid, .identifier });
+ try testTokenize("0od", &.{ .invalid, .identifier });
+ try testTokenize("0oe", &.{ .invalid, .identifier });
+ try testTokenize("0of", &.{ .invalid, .identifier });
+ try testTokenize("0oz", &.{ .invalid, .identifier });
- testTokenize("0o01234567", &.{.integer_literal});
- testTokenize("0o0123_4567", &.{.integer_literal});
- testTokenize("0o01_23_45_67", &.{.integer_literal});
- testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});
- testTokenize("0o7.", &.{ .integer_literal, .period });
- testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });
+ try testTokenize("0o01234567", &.{.integer_literal});
+ try testTokenize("0o0123_4567", &.{.integer_literal});
+ try testTokenize("0o01_23_45_67", &.{.integer_literal});
+ try testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});
+ try testTokenize("0o7.", &.{ .integer_literal, .period });
+ try testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });
- testTokenize("0O0", &.{ .invalid, .identifier });
- testTokenize("0o_", &.{ .invalid, .identifier });
- testTokenize("0o_0", &.{ .invalid, .identifier });
- testTokenize("0o1_", &.{.invalid});
- testTokenize("0o0__1", &.{ .invalid, .identifier });
- testTokenize("0o0_1_", &.{.invalid});
- testTokenize("0o1e", &.{ .invalid, .identifier });
- testTokenize("0o1p", &.{ .invalid, .identifier });
- testTokenize("0o1e0", &.{ .invalid, .identifier });
- testTokenize("0o1p0", &.{ .invalid, .identifier });
- testTokenize("0o_,", &.{ .invalid, .identifier, .comma });
+ try testTokenize("0O0", &.{ .invalid, .identifier });
+ try testTokenize("0o_", &.{ .invalid, .identifier });
+ try testTokenize("0o_0", &.{ .invalid, .identifier });
+ try testTokenize("0o1_", &.{.invalid});
+ try testTokenize("0o0__1", &.{ .invalid, .identifier });
+ try testTokenize("0o0_1_", &.{.invalid});
+ try testTokenize("0o1e", &.{ .invalid, .identifier });
+ try testTokenize("0o1p", &.{ .invalid, .identifier });
+ try testTokenize("0o1e0", &.{ .invalid, .identifier });
+ try testTokenize("0o1p0", &.{ .invalid, .identifier });
+ try testTokenize("0o_,", &.{ .invalid, .identifier, .comma });
}
test "tokenizer - number literals hexadeciaml" {
- testTokenize("0x0", &.{.integer_literal});
- testTokenize("0x1", &.{.integer_literal});
- testTokenize("0x2", &.{.integer_literal});
- testTokenize("0x3", &.{.integer_literal});
- testTokenize("0x4", &.{.integer_literal});
- testTokenize("0x5", &.{.integer_literal});
- testTokenize("0x6", &.{.integer_literal});
- testTokenize("0x7", &.{.integer_literal});
- testTokenize("0x8", &.{.integer_literal});
- testTokenize("0x9", &.{.integer_literal});
- testTokenize("0xa", &.{.integer_literal});
- testTokenize("0xb", &.{.integer_literal});
- testTokenize("0xc", &.{.integer_literal});
- testTokenize("0xd", &.{.integer_literal});
- testTokenize("0xe", &.{.integer_literal});
- testTokenize("0xf", &.{.integer_literal});
- testTokenize("0xA", &.{.integer_literal});
- testTokenize("0xB", &.{.integer_literal});
- testTokenize("0xC", &.{.integer_literal});
- testTokenize("0xD", &.{.integer_literal});
- testTokenize("0xE", &.{.integer_literal});
- testTokenize("0xF", &.{.integer_literal});
- testTokenize("0x0z", &.{ .invalid, .identifier });
- testTokenize("0xz", &.{ .invalid, .identifier });
+ try testTokenize("0x0", &.{.integer_literal});
+ try testTokenize("0x1", &.{.integer_literal});
+ try testTokenize("0x2", &.{.integer_literal});
+ try testTokenize("0x3", &.{.integer_literal});
+ try testTokenize("0x4", &.{.integer_literal});
+ try testTokenize("0x5", &.{.integer_literal});
+ try testTokenize("0x6", &.{.integer_literal});
+ try testTokenize("0x7", &.{.integer_literal});
+ try testTokenize("0x8", &.{.integer_literal});
+ try testTokenize("0x9", &.{.integer_literal});
+ try testTokenize("0xa", &.{.integer_literal});
+ try testTokenize("0xb", &.{.integer_literal});
+ try testTokenize("0xc", &.{.integer_literal});
+ try testTokenize("0xd", &.{.integer_literal});
+ try testTokenize("0xe", &.{.integer_literal});
+ try testTokenize("0xf", &.{.integer_literal});
+ try testTokenize("0xA", &.{.integer_literal});
+ try testTokenize("0xB", &.{.integer_literal});
+ try testTokenize("0xC", &.{.integer_literal});
+ try testTokenize("0xD", &.{.integer_literal});
+ try testTokenize("0xE", &.{.integer_literal});
+ try testTokenize("0xF", &.{.integer_literal});
+ try testTokenize("0x0z", &.{ .invalid, .identifier });
+ try testTokenize("0xz", &.{ .invalid, .identifier });
- testTokenize("0x0123456789ABCDEF", &.{.integer_literal});
- testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});
- testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal});
- testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal});
+ try testTokenize("0x0123456789ABCDEF", &.{.integer_literal});
+ try testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});
+ try testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal});
+ try testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal});
- testTokenize("0X0", &.{ .invalid, .identifier });
- testTokenize("0x_", &.{ .invalid, .identifier });
- testTokenize("0x_1", &.{ .invalid, .identifier });
- testTokenize("0x1_", &.{.invalid});
- testTokenize("0x0__1", &.{ .invalid, .identifier });
- testTokenize("0x0_1_", &.{.invalid});
- testTokenize("0x_,", &.{ .invalid, .identifier, .comma });
+ try testTokenize("0X0", &.{ .invalid, .identifier });
+ try testTokenize("0x_", &.{ .invalid, .identifier });
+ try testTokenize("0x_1", &.{ .invalid, .identifier });
+ try testTokenize("0x1_", &.{.invalid});
+ try testTokenize("0x0__1", &.{ .invalid, .identifier });
+ try testTokenize("0x0_1_", &.{.invalid});
+ try testTokenize("0x_,", &.{ .invalid, .identifier, .comma });
- testTokenize("0x1.", &.{.float_literal});
- testTokenize("0x1.0", &.{.float_literal});
- testTokenize("0xF.", &.{.float_literal});
- testTokenize("0xF.0", &.{.float_literal});
- testTokenize("0xF.F", &.{.float_literal});
- testTokenize("0xF.Fp0", &.{.float_literal});
- testTokenize("0xF.FP0", &.{.float_literal});
- testTokenize("0x1p0", &.{.float_literal});
- testTokenize("0xfp0", &.{.float_literal});
- testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });
+ try testTokenize("0x1.", &.{.float_literal});
+ try testTokenize("0x1.0", &.{.float_literal});
+ try testTokenize("0xF.", &.{.float_literal});
+ try testTokenize("0xF.0", &.{.float_literal});
+ try testTokenize("0xF.F", &.{.float_literal});
+ try testTokenize("0xF.Fp0", &.{.float_literal});
+ try testTokenize("0xF.FP0", &.{.float_literal});
+ try testTokenize("0x1p0", &.{.float_literal});
+ try testTokenize("0xfp0", &.{.float_literal});
+ try testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });
- testTokenize("0x0123456.789ABCDEF", &.{.float_literal});
- testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal});
- testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal});
- testTokenize("0x0p0", &.{.float_literal});
- testTokenize("0x0.0p0", &.{.float_literal});
- testTokenize("0xff.ffp10", &.{.float_literal});
- testTokenize("0xff.ffP10", &.{.float_literal});
- testTokenize("0xff.p10", &.{.float_literal});
- testTokenize("0xffp10", &.{.float_literal});
- testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});
- testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal});
- testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal});
+ try testTokenize("0x0123456.789ABCDEF", &.{.float_literal});
+ try testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal});
+ try testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal});
+ try testTokenize("0x0p0", &.{.float_literal});
+ try testTokenize("0x0.0p0", &.{.float_literal});
+ try testTokenize("0xff.ffp10", &.{.float_literal});
+ try testTokenize("0xff.ffP10", &.{.float_literal});
+ try testTokenize("0xff.p10", &.{.float_literal});
+ try testTokenize("0xffp10", &.{.float_literal});
+ try testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});
+ try testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal});
+ try testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal});
- testTokenize("0x1e", &.{.integer_literal});
- testTokenize("0x1e0", &.{.integer_literal});
- testTokenize("0x1p", &.{.invalid});
- testTokenize("0xfp0z1", &.{ .invalid, .identifier });
- testTokenize("0xff.ffpff", &.{ .invalid, .identifier });
- testTokenize("0x0.p", &.{.invalid});
- testTokenize("0x0.z", &.{ .invalid, .identifier });
- testTokenize("0x0._", &.{ .invalid, .identifier });
- testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });
- testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });
- testTokenize("0x0._0", &.{ .invalid, .identifier });
- testTokenize("0x0.0_", &.{.invalid});
- testTokenize("0x0_p0", &.{ .invalid, .identifier });
- testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });
- testTokenize("0x0._p0", &.{ .invalid, .identifier });
- testTokenize("0x0.0_p0", &.{ .invalid, .identifier });
- testTokenize("0x0._0p0", &.{ .invalid, .identifier });
- testTokenize("0x0.0p_0", &.{ .invalid, .identifier });
- testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });
- testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });
- testTokenize("0x0.0p0_", &.{ .invalid, .eof });
+ try testTokenize("0x1e", &.{.integer_literal});
+ try testTokenize("0x1e0", &.{.integer_literal});
+ try testTokenize("0x1p", &.{.invalid});
+ try testTokenize("0xfp0z1", &.{ .invalid, .identifier });
+ try testTokenize("0xff.ffpff", &.{ .invalid, .identifier });
+ try testTokenize("0x0.p", &.{.invalid});
+ try testTokenize("0x0.z", &.{ .invalid, .identifier });
+ try testTokenize("0x0._", &.{ .invalid, .identifier });
+ try testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });
+ try testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });
+ try testTokenize("0x0._0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0_", &.{.invalid});
+ try testTokenize("0x0_p0", &.{ .invalid, .identifier });
+ try testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });
+ try testTokenize("0x0._p0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0_p0", &.{ .invalid, .identifier });
+ try testTokenize("0x0._0p0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0p_0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0p0_", &.{ .invalid, .eof });
}
-fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {
+fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) !void {
var tokenizer = Tokenizer.init(source);
for (expected_tokens) |expected_token_id| {
const token = tokenizer.next();
@@ -2055,6 +2055,6 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {
}
}
const last_token = tokenizer.next();
- std.testing.expect(last_token.tag == .eof);
- std.testing.expect(last_token.loc.start == source.len);
+ try std.testing.expect(last_token.tag == .eof);
+ try std.testing.expect(last_token.loc.start == source.len);
}
diff --git a/src/Cache.zig b/src/Cache.zig
index f2fdafff9b..5bc32b4b68 100644
--- a/src/Cache.zig
+++ b/src/Cache.zig
@@ -727,7 +727,7 @@ test "cache file and then recall it" {
_ = try ch.addFile(temp_file, null);
// There should be nothing in the cache
- testing.expectEqual(false, try ch.hit());
+ try testing.expectEqual(false, try ch.hit());
digest1 = ch.final();
try ch.writeManifest();
@@ -742,13 +742,13 @@ test "cache file and then recall it" {
_ = try ch.addFile(temp_file, null);
// Cache hit! We just "built" the same file
- testing.expect(try ch.hit());
+ try testing.expect(try ch.hit());
digest2 = ch.final();
try ch.writeManifest();
}
- testing.expectEqual(digest1, digest2);
+ try testing.expectEqual(digest1, digest2);
}
try cwd.deleteTree(temp_manifest_dir);
@@ -760,11 +760,11 @@ test "give problematic timestamp" {
// to make it problematic, we make it only accurate to the second
fs_clock = @divTrunc(fs_clock, std.time.ns_per_s);
fs_clock *= std.time.ns_per_s;
- testing.expect(isProblematicTimestamp(fs_clock));
+ try testing.expect(isProblematicTimestamp(fs_clock));
}
test "give nonproblematic timestamp" {
- testing.expect(!isProblematicTimestamp(std.time.nanoTimestamp() - std.time.ns_per_s));
+ try testing.expect(!isProblematicTimestamp(std.time.nanoTimestamp() - std.time.ns_per_s));
}
test "check that changing a file makes cache fail" {
@@ -807,9 +807,9 @@ test "check that changing a file makes cache fail" {
const temp_file_idx = try ch.addFile(temp_file, 100);
// There should be nothing in the cache
- testing.expectEqual(false, try ch.hit());
+ try testing.expectEqual(false, try ch.hit());
- testing.expect(mem.eql(u8, original_temp_file_contents, ch.files.items[temp_file_idx].contents.?));
+ try testing.expect(mem.eql(u8, original_temp_file_contents, ch.files.items[temp_file_idx].contents.?));
digest1 = ch.final();
@@ -826,17 +826,17 @@ test "check that changing a file makes cache fail" {
const temp_file_idx = try ch.addFile(temp_file, 100);
// A file that we depend on has been updated, so the cache should not contain an entry for it
- testing.expectEqual(false, try ch.hit());
+ try testing.expectEqual(false, try ch.hit());
// The cache system does not keep the contents of re-hashed input files.
- testing.expect(ch.files.items[temp_file_idx].contents == null);
+ try testing.expect(ch.files.items[temp_file_idx].contents == null);
digest2 = ch.final();
try ch.writeManifest();
}
- testing.expect(!mem.eql(u8, digest1[0..], digest2[0..]));
+ try testing.expect(!mem.eql(u8, digest1[0..], digest2[0..]));
}
try cwd.deleteTree(temp_manifest_dir);
@@ -868,7 +868,7 @@ test "no file inputs" {
ch.hash.addBytes("1234");
// There should be nothing in the cache
- testing.expectEqual(false, try ch.hit());
+ try testing.expectEqual(false, try ch.hit());
digest1 = ch.final();
@@ -880,12 +880,12 @@ test "no file inputs" {
ch.hash.addBytes("1234");
- testing.expect(try ch.hit());
+ try testing.expect(try ch.hit());
digest2 = ch.final();
try ch.writeManifest();
}
- testing.expectEqual(digest1, digest2);
+ try testing.expectEqual(digest1, digest2);
}
test "Manifest with files added after initial hash work" {
@@ -926,7 +926,7 @@ test "Manifest with files added after initial hash work" {
_ = try ch.addFile(temp_file1, null);
// There should be nothing in the cache
- testing.expectEqual(false, try ch.hit());
+ try testing.expectEqual(false, try ch.hit());
_ = try ch.addFilePost(temp_file2);
@@ -940,12 +940,12 @@ test "Manifest with files added after initial hash work" {
ch.hash.addBytes("1234");
_ = try ch.addFile(temp_file1, null);
- testing.expect(try ch.hit());
+ try testing.expect(try ch.hit());
digest2 = ch.final();
try ch.writeManifest();
}
- testing.expect(mem.eql(u8, &digest1, &digest2));
+ try testing.expect(mem.eql(u8, &digest1, &digest2));
// Modify the file added after initial hash
const ts2 = std.time.nanoTimestamp();
@@ -963,7 +963,7 @@ test "Manifest with files added after initial hash work" {
_ = try ch.addFile(temp_file1, null);
// A file that we depend on has been updated, so the cache should not contain an entry for it
- testing.expectEqual(false, try ch.hit());
+ try testing.expectEqual(false, try ch.hit());
_ = try ch.addFilePost(temp_file2);
@@ -972,7 +972,7 @@ test "Manifest with files added after initial hash work" {
try ch.writeManifest();
}
- testing.expect(!mem.eql(u8, &digest1, &digest3));
+ try testing.expect(!mem.eql(u8, &digest1, &digest3));
}
try cwd.deleteTree(temp_manifest_dir);
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 58d6f41858..c779398b31 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -2852,14 +2852,14 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
}
test "classifyFileExt" {
- std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc"));
- std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim"));
- std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so"));
- std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1"));
- std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2"));
- std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2.3"));
- std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.so.1.2.3~"));
- std.testing.expectEqual(FileExt.zig, classifyFileExt("foo.zig"));
+ try std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc"));
+ try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim"));
+ try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so"));
+ try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1"));
+ try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2"));
+ try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2.3"));
+ try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.so.1.2.3~"));
+ try std.testing.expectEqual(FileExt.zig, classifyFileExt("foo.zig"));
}
fn haveFramePointer(comp: *const Compilation) bool {
diff --git a/src/DepTokenizer.zig b/src/DepTokenizer.zig
index 0bd2999719..c8417f2df1 100644
--- a/src/DepTokenizer.zig
+++ b/src/DepTokenizer.zig
@@ -918,7 +918,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void {
}
if (std.mem.eql(u8, expect, buffer.items)) {
- testing.expect(true);
+ try testing.expect(true);
return;
}
@@ -930,7 +930,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void {
try printSection(out, ">>>> got", buffer.items);
try printRuler(out);
- testing.expect(false);
+ try testing.expect(false);
}
fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void {
diff --git a/src/codegen/aarch64.zig b/src/codegen/aarch64.zig
index b456465075..1c176df017 100644
--- a/src/codegen/aarch64.zig
+++ b/src/codegen/aarch64.zig
@@ -67,27 +67,27 @@ pub const c_abi_int_param_regs = [_]Register{ .x0, .x1, .x2, .x3, .x4, .x5, .x6,
pub const c_abi_int_return_regs = [_]Register{ .x0, .x1, .x2, .x3, .x4, .x5, .x6, .x7 };
test "Register.id" {
- testing.expectEqual(@as(u5, 0), Register.x0.id());
- testing.expectEqual(@as(u5, 0), Register.w0.id());
+ try testing.expectEqual(@as(u5, 0), Register.x0.id());
+ try testing.expectEqual(@as(u5, 0), Register.w0.id());
- testing.expectEqual(@as(u5, 31), Register.xzr.id());
- testing.expectEqual(@as(u5, 31), Register.wzr.id());
+ try testing.expectEqual(@as(u5, 31), Register.xzr.id());
+ try testing.expectEqual(@as(u5, 31), Register.wzr.id());
- testing.expectEqual(@as(u5, 31), Register.sp.id());
- testing.expectEqual(@as(u5, 31), Register.sp.id());
+ try testing.expectEqual(@as(u5, 31), Register.sp.id());
+ try testing.expectEqual(@as(u5, 31), Register.sp.id());
}
test "Register.size" {
- testing.expectEqual(@as(u7, 64), Register.x19.size());
- testing.expectEqual(@as(u7, 32), Register.w3.size());
+ try testing.expectEqual(@as(u7, 64), Register.x19.size());
+ try testing.expectEqual(@as(u7, 32), Register.w3.size());
}
test "Register.to64/to32" {
- testing.expectEqual(Register.x0, Register.w0.to64());
- testing.expectEqual(Register.x0, Register.x0.to64());
+ try testing.expectEqual(Register.x0, Register.w0.to64());
+ try testing.expectEqual(Register.x0, Register.x0.to64());
- testing.expectEqual(Register.w3, Register.w3.to32());
- testing.expectEqual(Register.w3, Register.x3.to32());
+ try testing.expectEqual(Register.w3, Register.w3.to32());
+ try testing.expectEqual(Register.w3, Register.x3.to32());
}
// zig fmt: off
@@ -169,33 +169,33 @@ pub const FloatingPointRegister = enum(u8) {
// zig fmt: on
test "FloatingPointRegister.id" {
- testing.expectEqual(@as(u5, 0), FloatingPointRegister.b0.id());
- testing.expectEqual(@as(u5, 0), FloatingPointRegister.h0.id());
- testing.expectEqual(@as(u5, 0), FloatingPointRegister.s0.id());
- testing.expectEqual(@as(u5, 0), FloatingPointRegister.d0.id());
- testing.expectEqual(@as(u5, 0), FloatingPointRegister.q0.id());
+ try testing.expectEqual(@as(u5, 0), FloatingPointRegister.b0.id());
+ try testing.expectEqual(@as(u5, 0), FloatingPointRegister.h0.id());
+ try testing.expectEqual(@as(u5, 0), FloatingPointRegister.s0.id());
+ try testing.expectEqual(@as(u5, 0), FloatingPointRegister.d0.id());
+ try testing.expectEqual(@as(u5, 0), FloatingPointRegister.q0.id());
- testing.expectEqual(@as(u5, 2), FloatingPointRegister.q2.id());
- testing.expectEqual(@as(u5, 31), FloatingPointRegister.d31.id());
+ try testing.expectEqual(@as(u5, 2), FloatingPointRegister.q2.id());
+ try testing.expectEqual(@as(u5, 31), FloatingPointRegister.d31.id());
}
test "FloatingPointRegister.size" {
- testing.expectEqual(@as(u8, 128), FloatingPointRegister.q1.size());
- testing.expectEqual(@as(u8, 64), FloatingPointRegister.d2.size());
- testing.expectEqual(@as(u8, 32), FloatingPointRegister.s3.size());
- testing.expectEqual(@as(u8, 16), FloatingPointRegister.h4.size());
- testing.expectEqual(@as(u8, 8), FloatingPointRegister.b5.size());
+ try testing.expectEqual(@as(u8, 128), FloatingPointRegister.q1.size());
+ try testing.expectEqual(@as(u8, 64), FloatingPointRegister.d2.size());
+ try testing.expectEqual(@as(u8, 32), FloatingPointRegister.s3.size());
+ try testing.expectEqual(@as(u8, 16), FloatingPointRegister.h4.size());
+ try testing.expectEqual(@as(u8, 8), FloatingPointRegister.b5.size());
}
test "FloatingPointRegister.toX" {
- testing.expectEqual(FloatingPointRegister.q1, FloatingPointRegister.q1.to128());
- testing.expectEqual(FloatingPointRegister.q2, FloatingPointRegister.b2.to128());
- testing.expectEqual(FloatingPointRegister.q3, FloatingPointRegister.h3.to128());
+ try testing.expectEqual(FloatingPointRegister.q1, FloatingPointRegister.q1.to128());
+ try testing.expectEqual(FloatingPointRegister.q2, FloatingPointRegister.b2.to128());
+ try testing.expectEqual(FloatingPointRegister.q3, FloatingPointRegister.h3.to128());
- testing.expectEqual(FloatingPointRegister.d0, FloatingPointRegister.q0.to64());
- testing.expectEqual(FloatingPointRegister.s1, FloatingPointRegister.d1.to32());
- testing.expectEqual(FloatingPointRegister.h2, FloatingPointRegister.s2.to16());
- testing.expectEqual(FloatingPointRegister.b3, FloatingPointRegister.h3.to8());
+ try testing.expectEqual(FloatingPointRegister.d0, FloatingPointRegister.q0.to64());
+ try testing.expectEqual(FloatingPointRegister.s1, FloatingPointRegister.d1.to32());
+ try testing.expectEqual(FloatingPointRegister.h2, FloatingPointRegister.s2.to16());
+ try testing.expectEqual(FloatingPointRegister.b3, FloatingPointRegister.h3.to8());
}
/// Represents an instruction in the AArch64 instruction set
@@ -1225,6 +1225,6 @@ test "serialize instructions" {
for (testcases) |case| {
const actual = case.inst.toU32();
- testing.expectEqual(case.expected, actual);
+ try testing.expectEqual(case.expected, actual);
}
}
diff --git a/src/codegen/arm.zig b/src/codegen/arm.zig
index d538d28c50..cc6abe2e52 100644
--- a/src/codegen/arm.zig
+++ b/src/codegen/arm.zig
@@ -88,19 +88,19 @@ pub const Condition = enum(u4) {
};
test "condition from CompareOperator" {
- testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorSigned(.eq));
- testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorUnsigned(.eq));
+ try testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorSigned(.eq));
+ try testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorUnsigned(.eq));
- testing.expectEqual(@as(Condition, .gt), Condition.fromCompareOperatorSigned(.gt));
- testing.expectEqual(@as(Condition, .hi), Condition.fromCompareOperatorUnsigned(.gt));
+ try testing.expectEqual(@as(Condition, .gt), Condition.fromCompareOperatorSigned(.gt));
+ try testing.expectEqual(@as(Condition, .hi), Condition.fromCompareOperatorUnsigned(.gt));
- testing.expectEqual(@as(Condition, .le), Condition.fromCompareOperatorSigned(.lte));
- testing.expectEqual(@as(Condition, .ls), Condition.fromCompareOperatorUnsigned(.lte));
+ try testing.expectEqual(@as(Condition, .le), Condition.fromCompareOperatorSigned(.lte));
+ try testing.expectEqual(@as(Condition, .ls), Condition.fromCompareOperatorUnsigned(.lte));
}
test "negate condition" {
- testing.expectEqual(@as(Condition, .eq), Condition.ne.negate());
- testing.expectEqual(@as(Condition, .ne), Condition.eq.negate());
+ try testing.expectEqual(@as(Condition, .eq), Condition.ne.negate());
+ try testing.expectEqual(@as(Condition, .ne), Condition.eq.negate());
}
/// Represents a register in the ARM instruction set architecture
@@ -175,8 +175,8 @@ pub const Register = enum(u5) {
};
test "Register.id" {
- testing.expectEqual(@as(u4, 15), Register.r15.id());
- testing.expectEqual(@as(u4, 15), Register.pc.id());
+ try testing.expectEqual(@as(u4, 15), Register.r15.id());
+ try testing.expectEqual(@as(u4, 15), Register.pc.id());
}
/// Program status registers containing flags, mode bits and other
@@ -1225,7 +1225,7 @@ test "serialize instructions" {
for (testcases) |case| {
const actual = case.inst.toU32();
- testing.expectEqual(case.expected, actual);
+ try testing.expectEqual(case.expected, actual);
}
}
@@ -1265,6 +1265,6 @@ test "aliases" {
};
for (testcases) |case| {
- testing.expectEqual(case.expected.toU32(), case.actual.toU32());
+ try testing.expectEqual(case.expected.toU32(), case.actual.toU32());
}
}
diff --git a/src/codegen/riscv64.zig b/src/codegen/riscv64.zig
index a01f38289a..831f74b1b7 100644
--- a/src/codegen/riscv64.zig
+++ b/src/codegen/riscv64.zig
@@ -465,6 +465,6 @@ test "serialize instructions" {
for (testcases) |case| {
const actual = case.inst.toU32();
- testing.expectEqual(case.expected, actual);
+ try testing.expectEqual(case.expected, actual);
}
}
diff --git a/src/codegen/wasm.zig b/src/codegen/wasm.zig
index 400a5cd1a3..759afa1047 100644
--- a/src/codegen/wasm.zig
+++ b/src/codegen/wasm.zig
@@ -463,11 +463,11 @@ test "Wasm - buildOpcode" {
const i64_extend32_s = buildOpcode(.{ .op = .extend, .valtype1 = .i64, .width = 32, .signedness = .signed });
const f64_reinterpret_i64 = buildOpcode(.{ .op = .reinterpret, .valtype1 = .f64, .valtype2 = .i64 });
- testing.expectEqual(@as(wasm.Opcode, .i32_const), i32_const);
- testing.expectEqual(@as(wasm.Opcode, .end), end);
- testing.expectEqual(@as(wasm.Opcode, .local_get), local_get);
- testing.expectEqual(@as(wasm.Opcode, .i64_extend32_s), i64_extend32_s);
- testing.expectEqual(@as(wasm.Opcode, .f64_reinterpret_i64), f64_reinterpret_i64);
+ try testing.expectEqual(@as(wasm.Opcode, .i32_const), i32_const);
+ try testing.expectEqual(@as(wasm.Opcode, .end), end);
+ try testing.expectEqual(@as(wasm.Opcode, .local_get), local_get);
+ try testing.expectEqual(@as(wasm.Opcode, .i64_extend32_s), i64_extend32_s);
+ try testing.expectEqual(@as(wasm.Opcode, .f64_reinterpret_i64), f64_reinterpret_i64);
}
pub const Result = union(enum) {
diff --git a/src/link/MachO/CodeSignature.zig b/src/link/MachO/CodeSignature.zig
index ef0fc6c3e2..d0dd47be92 100644
--- a/src/link/MachO/CodeSignature.zig
+++ b/src/link/MachO/CodeSignature.zig
@@ -182,7 +182,7 @@ test "CodeSignature header" {
try code_sig.writeHeader(stream.writer());
const expected = &[_]u8{ 0xfa, 0xde, 0x0c, 0xc0, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x0 };
- testing.expect(mem.eql(u8, expected, &buffer));
+ try testing.expect(mem.eql(u8, expected, &buffer));
}
pub fn calcCodeSignaturePaddingSize(id: []const u8, file_size: u64, page_size: u16) u32 {
diff --git a/src/link/MachO/Trie.zig b/src/link/MachO/Trie.zig
index f7d54cf578..379b10e2d8 100644
--- a/src/link/MachO/Trie.zig
+++ b/src/link/MachO/Trie.zig
@@ -404,15 +404,15 @@ test "Trie node count" {
var trie = Trie.init(gpa);
defer trie.deinit();
- testing.expectEqual(trie.node_count, 0);
- testing.expect(trie.root == null);
+ try testing.expectEqual(trie.node_count, 0);
+ try testing.expect(trie.root == null);
try trie.put(.{
.name = "_main",
.vmaddr_offset = 0,
.export_flags = 0,
});
- testing.expectEqual(trie.node_count, 2);
+ try testing.expectEqual(trie.node_count, 2);
// Inserting the same node shouldn't update the trie.
try trie.put(.{
@@ -420,14 +420,14 @@ test "Trie node count" {
.vmaddr_offset = 0,
.export_flags = 0,
});
- testing.expectEqual(trie.node_count, 2);
+ try testing.expectEqual(trie.node_count, 2);
try trie.put(.{
.name = "__mh_execute_header",
.vmaddr_offset = 0x1000,
.export_flags = 0,
});
- testing.expectEqual(trie.node_count, 4);
+ try testing.expectEqual(trie.node_count, 4);
// Inserting the same node shouldn't update the trie.
try trie.put(.{
@@ -435,13 +435,13 @@ test "Trie node count" {
.vmaddr_offset = 0x1000,
.export_flags = 0,
});
- testing.expectEqual(trie.node_count, 4);
+ try testing.expectEqual(trie.node_count, 4);
try trie.put(.{
.name = "_main",
.vmaddr_offset = 0,
.export_flags = 0,
});
- testing.expectEqual(trie.node_count, 4);
+ try testing.expectEqual(trie.node_count, 4);
}
test "Trie basic" {
@@ -455,8 +455,8 @@ test "Trie basic" {
.vmaddr_offset = 0,
.export_flags = 0,
});
- testing.expect(trie.root.?.edges.items.len == 1);
- testing.expect(mem.eql(u8, trie.root.?.edges.items[0].label, "_st"));
+ try testing.expect(trie.root.?.edges.items.len == 1);
+ try testing.expect(mem.eql(u8, trie.root.?.edges.items[0].label, "_st"));
{
// root --- _st ---> node --- art ---> node
@@ -465,12 +465,12 @@ test "Trie basic" {
.vmaddr_offset = 0,
.export_flags = 0,
});
- testing.expect(trie.root.?.edges.items.len == 1);
+ try testing.expect(trie.root.?.edges.items.len == 1);
const nextEdge = &trie.root.?.edges.items[0];
- testing.expect(mem.eql(u8, nextEdge.label, "_st"));
- testing.expect(nextEdge.to.edges.items.len == 1);
- testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "art"));
+ try testing.expect(mem.eql(u8, nextEdge.label, "_st"));
+ try testing.expect(nextEdge.to.edges.items.len == 1);
+ try testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "art"));
}
{
// root --- _ ---> node --- st ---> node --- art ---> node
@@ -481,16 +481,16 @@ test "Trie basic" {
.vmaddr_offset = 0,
.export_flags = 0,
});
- testing.expect(trie.root.?.edges.items.len == 1);
+ try testing.expect(trie.root.?.edges.items.len == 1);
const nextEdge = &trie.root.?.edges.items[0];
- testing.expect(mem.eql(u8, nextEdge.label, "_"));
- testing.expect(nextEdge.to.edges.items.len == 2);
- testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "st"));
- testing.expect(mem.eql(u8, nextEdge.to.edges.items[1].label, "main"));
+ try testing.expect(mem.eql(u8, nextEdge.label, "_"));
+ try testing.expect(nextEdge.to.edges.items.len == 2);
+ try testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "st"));
+ try testing.expect(mem.eql(u8, nextEdge.to.edges.items[1].label, "main"));
const nextNextEdge = &nextEdge.to.edges.items[0];
- testing.expect(mem.eql(u8, nextNextEdge.to.edges.items[0].label, "art"));
+ try testing.expect(mem.eql(u8, nextNextEdge.to.edges.items[0].label, "art"));
}
}
@@ -529,15 +529,15 @@ test "write Trie to a byte stream" {
var stream = std.io.fixedBufferStream(buffer);
{
const nwritten = try trie.write(stream.writer());
- testing.expect(nwritten == trie.size);
- testing.expect(mem.eql(u8, buffer, &exp_buffer));
+ try testing.expect(nwritten == trie.size);
+ try testing.expect(mem.eql(u8, buffer, &exp_buffer));
}
{
// Writing finalized trie again should yield the same result.
try stream.seekTo(0);
const nwritten = try trie.write(stream.writer());
- testing.expect(nwritten == trie.size);
- testing.expect(mem.eql(u8, buffer, &exp_buffer));
+ try testing.expect(nwritten == trie.size);
+ try testing.expect(mem.eql(u8, buffer, &exp_buffer));
}
}
@@ -560,7 +560,7 @@ test "parse Trie from byte stream" {
defer trie.deinit();
const nread = try trie.read(in_stream.reader());
- testing.expect(nread == in_buffer.len);
+ try testing.expect(nread == in_buffer.len);
try trie.finalize();
@@ -569,6 +569,6 @@ test "parse Trie from byte stream" {
var out_stream = std.io.fixedBufferStream(out_buffer);
const nwritten = try trie.write(out_stream.writer());
- testing.expect(nwritten == trie.size);
- testing.expect(mem.eql(u8, &in_buffer, out_buffer));
+ try testing.expect(nwritten == trie.size);
+ try testing.expect(mem.eql(u8, &in_buffer, out_buffer));
}
diff --git a/src/link/MachO/commands.zig b/src/link/MachO/commands.zig
index 67b808d856..f81e5c757d 100644
--- a/src/link/MachO/commands.zig
+++ b/src/link/MachO/commands.zig
@@ -286,13 +286,13 @@ fn testRead(allocator: *Allocator, buffer: []const u8, expected: anytype) !void
var stream = io.fixedBufferStream(buffer);
var given = try LoadCommand.read(allocator, stream.reader());
defer given.deinit(allocator);
- testing.expect(expected.eql(given));
+ try testing.expect(expected.eql(given));
}
fn testWrite(buffer: []u8, cmd: LoadCommand, expected: []const u8) !void {
var stream = io.fixedBufferStream(buffer);
try cmd.write(stream.writer());
- testing.expect(mem.eql(u8, expected, buffer[0..expected.len]));
+ try testing.expect(mem.eql(u8, expected, buffer[0..expected.len]));
}
test "read-write segment command" {
diff --git a/src/register_manager.zig b/src/register_manager.zig
index 270c762887..2c812cef89 100644
--- a/src/register_manager.zig
+++ b/src/register_manager.zig
@@ -267,21 +267,21 @@ test "tryAllocReg: no spilling" {
.src = .unneeded,
};
- std.testing.expect(!function.register_manager.isRegAllocated(.r2));
- std.testing.expect(!function.register_manager.isRegAllocated(.r3));
+ try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
+ try std.testing.expect(!function.register_manager.isRegAllocated(.r3));
- std.testing.expectEqual(@as(?MockRegister, .r2), function.register_manager.tryAllocReg(&mock_instruction));
- std.testing.expectEqual(@as(?MockRegister, .r3), function.register_manager.tryAllocReg(&mock_instruction));
- std.testing.expectEqual(@as(?MockRegister, null), function.register_manager.tryAllocReg(&mock_instruction));
+ try std.testing.expectEqual(@as(?MockRegister, .r2), function.register_manager.tryAllocReg(&mock_instruction));
+ try std.testing.expectEqual(@as(?MockRegister, .r3), function.register_manager.tryAllocReg(&mock_instruction));
+ try std.testing.expectEqual(@as(?MockRegister, null), function.register_manager.tryAllocReg(&mock_instruction));
- std.testing.expect(function.register_manager.isRegAllocated(.r2));
- std.testing.expect(function.register_manager.isRegAllocated(.r3));
+ try std.testing.expect(function.register_manager.isRegAllocated(.r2));
+ try std.testing.expect(function.register_manager.isRegAllocated(.r3));
function.register_manager.freeReg(.r2);
function.register_manager.freeReg(.r3);
- std.testing.expect(function.register_manager.isRegAllocated(.r2));
- std.testing.expect(function.register_manager.isRegAllocated(.r3));
+ try std.testing.expect(function.register_manager.isRegAllocated(.r2));
+ try std.testing.expect(function.register_manager.isRegAllocated(.r3));
}
test "allocReg: spilling" {
@@ -298,20 +298,20 @@ test "allocReg: spilling" {
.src = .unneeded,
};
- std.testing.expect(!function.register_manager.isRegAllocated(.r2));
- std.testing.expect(!function.register_manager.isRegAllocated(.r3));
+ try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
+ try std.testing.expect(!function.register_manager.isRegAllocated(.r3));
- std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction));
- std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction));
+ try std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction));
+ try std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction));
// Spill a register
- std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction));
- std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);
+ try std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction));
+ try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);
// No spilling necessary
function.register_manager.freeReg(.r3);
- std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction));
- std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);
+ try std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction));
+ try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);
}
test "getReg" {
@@ -328,18 +328,18 @@ test "getReg" {
.src = .unneeded,
};
- std.testing.expect(!function.register_manager.isRegAllocated(.r2));
- std.testing.expect(!function.register_manager.isRegAllocated(.r3));
+ try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
+ try std.testing.expect(!function.register_manager.isRegAllocated(.r3));
try function.register_manager.getReg(.r3, &mock_instruction);
- std.testing.expect(!function.register_manager.isRegAllocated(.r2));
- std.testing.expect(function.register_manager.isRegAllocated(.r3));
+ try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
+ try std.testing.expect(function.register_manager.isRegAllocated(.r3));
// Spill r3
try function.register_manager.getReg(.r3, &mock_instruction);
- std.testing.expect(!function.register_manager.isRegAllocated(.r2));
- std.testing.expect(function.register_manager.isRegAllocated(.r3));
- std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r3}, function.spilled.items);
+ try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
+ try std.testing.expect(function.register_manager.isRegAllocated(.r3));
+ try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r3}, function.spilled.items);
}
diff --git a/src/test.zig b/src/test.zig
index ca3f073e14..f1cf543252 100644
--- a/src/test.zig
+++ b/src/test.zig
@@ -705,14 +705,14 @@ pub const TestContext = struct {
defer file.close();
const out = try file.reader().readAllAlloc(arena, 5 * 1024 * 1024);
- std.testing.expectEqualStrings(expected_output, out);
+ try std.testing.expectEqualStrings(expected_output, out);
},
.CompareObjectFile => |expected_output| {
var file = try tmp.dir.openFile(bin_name, .{ .read = true });
defer file.close();
const out = try file.reader().readAllAlloc(arena, 5 * 1024 * 1024);
- std.testing.expectEqualStrings(expected_output, out);
+ try std.testing.expectEqualStrings(expected_output, out);
},
.Error => |case_error_list| {
var test_node = update_node.start("assert", 0);
@@ -939,7 +939,7 @@ pub const TestContext = struct {
return error.ZigTestFailed;
},
}
- std.testing.expectEqualStrings(expected_stdout, exec_result.stdout);
+ try std.testing.expectEqualStrings(expected_stdout, exec_result.stdout);
// We allow stderr to have garbage in it because wasmtime prints a
// warning about --invoke even though we don't pass it.
//std.testing.expectEqualStrings("", exec_result.stderr);
diff --git a/src/value.zig b/src/value.zig
index 66a23692c1..6501e788c3 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -1456,19 +1456,19 @@ test "hash same value different representation" {
.data = 0,
};
const zero_2 = Value.initPayload(&payload_1.base);
- std.testing.expectEqual(zero_1.hash(), zero_2.hash());
+ try std.testing.expectEqual(zero_1.hash(), zero_2.hash());
var payload_2 = Value.Payload.I64{
.base = .{ .tag = .int_i64 },
.data = 0,
};
const zero_3 = Value.initPayload(&payload_2.base);
- std.testing.expectEqual(zero_2.hash(), zero_3.hash());
+ try std.testing.expectEqual(zero_2.hash(), zero_3.hash());
var payload_3 = Value.Payload.BigInt{
.base = .{ .tag = .int_big_negative },
.data = &[_]std.math.big.Limb{0},
};
const zero_4 = Value.initPayload(&payload_3.base);
- std.testing.expectEqual(zero_3.hash(), zero_4.hash());
+ try std.testing.expectEqual(zero_3.hash(), zero_4.hash());
}
diff --git a/test/cli.zig b/test/cli.zig
index dedea67a59..a00d76d5e7 100644
--- a/test/cli.zig
+++ b/test/cli.zig
@@ -29,7 +29,7 @@ pub fn main() !void {
const dir_path = try fs.path.join(a, &[_][]const u8{ cache_root, "clitest" });
defer fs.cwd().deleteTree(dir_path) catch {};
-
+
const TestFn = fn ([]const u8, []const u8) anyerror!void;
const test_fns = [_]TestFn{
testZigInitLib,
@@ -94,13 +94,13 @@ fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess
fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {
_ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-lib" });
const test_result = try exec(dir_path, true, &[_][]const u8{ zig_exe, "build", "test" });
- testing.expectStringEndsWith(test_result.stderr, "All 1 tests passed.\n");
+ try testing.expectStringEndsWith(test_result.stderr, "All 1 tests passed.\n");
}
fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
_ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-exe" });
const run_result = try exec(dir_path, true, &[_][]const u8{ zig_exe, "build", "run" });
- testing.expectEqualStrings("info: All your codebase are belong to us.\n", run_result.stderr);
+ try testing.expectEqualStrings("info: All your codebase are belong to us.\n", run_result.stderr);
}
fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
@@ -136,9 +136,9 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
_ = try exec(dir_path, true, args.items);
const out_asm = try std.fs.cwd().readFileAlloc(a, example_s_path, std.math.maxInt(usize));
- testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
- testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null);
- testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null);
+ try testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
+ try testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null);
+ try testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null);
}
fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void {
@@ -149,7 +149,7 @@ fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void {
const result = try exec(dir_path, false, &[_][]const u8{ zig_exe, "build-exe", source_path, output_arg });
const s = std.fs.path.sep_str;
const expected: []const u8 = "error: unable to open output directory 'does" ++ s ++ "not" ++ s ++ "exist': FileNotFound\n";
- testing.expectEqualStrings(expected, result.stderr);
+ try testing.expectEqualStrings(expected, result.stderr);
}
fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
@@ -162,20 +162,20 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
const run_result1 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path });
// stderr should be file path + \n
- testing.expect(std.mem.startsWith(u8, run_result1.stdout, fmt1_zig_path));
- testing.expect(run_result1.stdout.len == fmt1_zig_path.len + 1 and run_result1.stdout[run_result1.stdout.len - 1] == '\n');
+ try testing.expect(std.mem.startsWith(u8, run_result1.stdout, fmt1_zig_path));
+ try testing.expect(run_result1.stdout.len == fmt1_zig_path.len + 1 and run_result1.stdout[run_result1.stdout.len - 1] == '\n');
const fmt2_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt2.zig" });
try fs.cwd().writeFile(fmt2_zig_path, unformatted_code);
const run_result2 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
// running it on the dir, only the new file should be changed
- testing.expect(std.mem.startsWith(u8, run_result2.stdout, fmt2_zig_path));
- testing.expect(run_result2.stdout.len == fmt2_zig_path.len + 1 and run_result2.stdout[run_result2.stdout.len - 1] == '\n');
+ try testing.expect(std.mem.startsWith(u8, run_result2.stdout, fmt2_zig_path));
+ try testing.expect(run_result2.stdout.len == fmt2_zig_path.len + 1 and run_result2.stdout[run_result2.stdout.len - 1] == '\n');
const run_result3 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
// both files have been formatted, nothing should change now
- testing.expect(run_result3.stdout.len == 0);
+ try testing.expect(run_result3.stdout.len == 0);
// Check UTF-16 decoding
const fmt4_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt4.zig" });
@@ -183,6 +183,6 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
try fs.cwd().writeFile(fmt4_zig_path, unformatted_code_utf16);
const run_result4 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
- testing.expect(std.mem.startsWith(u8, run_result4.stdout, fmt4_zig_path));
- testing.expect(run_result4.stdout.len == fmt4_zig_path.len + 1 and run_result4.stdout[run_result4.stdout.len - 1] == '\n');
+ try testing.expect(std.mem.startsWith(u8, run_result4.stdout, fmt4_zig_path));
+ try testing.expect(run_result4.stdout.len == fmt4_zig_path.len + 1 and run_result4.stdout[run_result4.stdout.len - 1] == '\n');
}
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 5b36027248..a1a9fbf460 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -230,7 +230,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("array in c exported function",
\\export fn zig_array(x: [10]u8) void {
- \\ expect(std.mem.eql(u8, &x, "1234567890"));
+ \\try expect(std.mem.eql(u8, &x, "1234567890"));
\\}
\\
\\export fn zig_return_array() [10]u8 {
diff --git a/test/stack_traces.zig b/test/stack_traces.zig
index cb2cf94b70..4b2d6bebfd 100644
--- a/test/stack_traces.zig
+++ b/test/stack_traces.zig
@@ -5,13 +5,13 @@ const tests = @import("tests.zig");
pub fn addCases(cases: *tests.StackTracesContext) void {
cases.addCase(.{
.name = "return",
- .source =
+ .source =
\\pub fn main() !void {
\\ return error.TheSkyIsFalling;
\\}
,
.Debug = .{
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\source.zig:2:5: [address] in main (test)
\\ return error.TheSkyIsFalling;
@@ -23,7 +23,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
.exclude_os = .{
.windows, // segfault
},
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\source.zig:2:5: [address] in [function]
\\ return error.TheSkyIsFalling;
@@ -32,13 +32,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
,
},
.ReleaseFast = .{
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\
,
},
.ReleaseSmall = .{
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\
,
@@ -47,7 +47,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
cases.addCase(.{
.name = "try return",
- .source =
+ .source =
\\fn foo() !void {
\\ return error.TheSkyIsFalling;
\\}
@@ -57,7 +57,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
\\}
,
.Debug = .{
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\source.zig:2:5: [address] in foo (test)
\\ return error.TheSkyIsFalling;
@@ -72,7 +72,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
.exclude_os = .{
.windows, // segfault
},
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\source.zig:2:5: [address] in [function]
\\ return error.TheSkyIsFalling;
@@ -84,13 +84,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
,
},
.ReleaseFast = .{
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\
,
},
.ReleaseSmall = .{
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\
,
@@ -99,7 +99,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
cases.addCase(.{
.name = "try try return return",
- .source =
+ .source =
\\fn foo() !void {
\\ try bar();
\\}
@@ -117,7 +117,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
\\}
,
.Debug = .{
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\source.zig:10:5: [address] in make_error (test)
\\ return error.TheSkyIsFalling;
@@ -138,7 +138,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
.exclude_os = .{
.windows, // segfault
},
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\source.zig:10:5: [address] in [function]
\\ return error.TheSkyIsFalling;
@@ -156,13 +156,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
,
},
.ReleaseFast = .{
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\
,
},
.ReleaseSmall = .{
- .expect =
+ .expect =
\\error: TheSkyIsFalling
\\
,
@@ -174,7 +174,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
.windows,
},
.name = "dumpCurrentStackTrace",
- .source =
+ .source =
\\const std = @import("std");
\\
\\fn bar() void {
@@ -189,7 +189,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
\\}
,
.Debug = .{
- .expect =
+ .expect =
\\source.zig:7:8: [address] in foo (test)
\\ bar();
\\ ^
diff --git a/test/stage1/behavior/align.zig b/test/stage1/behavior/align.zig
index 38f5df0176..30a460e324 100644
--- a/test/stage1/behavior/align.zig
+++ b/test/stage1/behavior/align.zig
@@ -5,16 +5,16 @@ const builtin = @import("builtin");
var foo: u8 align(4) = 100;
test "global variable alignment" {
- comptime expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
- comptime expect(@TypeOf(&foo) == *align(4) u8);
+ comptime try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
+ comptime try expect(@TypeOf(&foo) == *align(4) u8);
{
const slice = @as(*[1]u8, &foo)[0..];
- comptime expect(@TypeOf(slice) == *align(4) [1]u8);
+ comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
}
{
var runtime_zero: usize = 0;
const slice = @as(*[1]u8, &foo)[runtime_zero..];
- comptime expect(@TypeOf(slice) == []align(4) u8);
+ comptime try expect(@TypeOf(slice) == []align(4) u8);
}
}
@@ -28,9 +28,9 @@ test "function alignment" {
// function alignment is a compile error on wasm32/wasm64
if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest;
- expect(derp() == 1234);
- expect(@TypeOf(noop1) == fn () align(1) void);
- expect(@TypeOf(noop4) == fn () align(4) void);
+ try expect(derp() == 1234);
+ try expect(@TypeOf(noop1) == fn () align(1) void);
+ try expect(@TypeOf(noop4) == fn () align(4) void);
noop1();
noop4();
}
@@ -41,7 +41,7 @@ var baz: packed struct {
} = undefined;
test "packed struct alignment" {
- expect(@TypeOf(&baz.b) == *align(1) u32);
+ try expect(@TypeOf(&baz.b) == *align(1) u32);
}
const blah: packed struct {
@@ -51,17 +51,17 @@ const blah: packed struct {
} = undefined;
test "bit field alignment" {
- expect(@TypeOf(&blah.b) == *align(1:3:1) const u3);
+ try expect(@TypeOf(&blah.b) == *align(1:3:1) const u3);
}
test "default alignment allows unspecified in type syntax" {
- expect(*u32 == *align(@alignOf(u32)) u32);
+ try expect(*u32 == *align(@alignOf(u32)) u32);
}
test "implicitly decreasing pointer alignment" {
const a: u32 align(4) = 3;
const b: u32 align(8) = 4;
- expect(addUnaligned(&a, &b) == 7);
+ try expect(addUnaligned(&a, &b) == 7);
}
fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
@@ -71,16 +71,16 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
test "implicitly decreasing slice alignment" {
const a: u32 align(4) = 3;
const b: u32 align(8) = 4;
- expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7);
+ try expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7);
}
fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {
return a[0] + b[0];
}
test "specifying alignment allows pointer cast" {
- testBytesAlign(0x33);
+ try testBytesAlign(0x33);
}
-fn testBytesAlign(b: u8) void {
+fn testBytesAlign(b: u8) !void {
var bytes align(4) = [_]u8{
b,
b,
@@ -88,13 +88,13 @@ fn testBytesAlign(b: u8) void {
b,
};
const ptr = @ptrCast(*u32, &bytes[0]);
- expect(ptr.* == 0x33333333);
+ try expect(ptr.* == 0x33333333);
}
test "@alignCast pointers" {
var x: u32 align(4) = 1;
expectsOnly1(&x);
- expect(x == 2);
+ try expect(x == 2);
}
fn expectsOnly1(x: *align(1) u32) void {
expects4(@alignCast(4, x));
@@ -110,7 +110,7 @@ test "@alignCast slices" {
};
const slice = array[0..];
sliceExpectsOnly1(slice);
- expect(slice[0] == 2);
+ try expect(slice[0] == 2);
}
fn sliceExpectsOnly1(slice: []align(1) u32) void {
sliceExpects4(@alignCast(4, slice));
@@ -123,12 +123,12 @@ test "implicitly decreasing fn alignment" {
// function alignment is a compile error on wasm32/wasm64
if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest;
- testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
- testImplicitlyDecreaseFnAlign(alignedBig, 5678);
+ try testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
+ try testImplicitlyDecreaseFnAlign(alignedBig, 5678);
}
-fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void {
- expect(ptr() == answer);
+fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) !void {
+ try expect(ptr() == answer);
}
fn alignedSmall() align(8) i32 {
@@ -143,7 +143,7 @@ test "@alignCast functions" {
if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest;
if (builtin.arch == .thumb) return error.SkipZigTest;
- expect(fnExpectsOnly1(simple4) == 0x19);
+ try expect(fnExpectsOnly1(simple4) == 0x19);
}
fn fnExpectsOnly1(ptr: fn () align(1) i32) i32 {
return fnExpects4(@alignCast(4, ptr));
@@ -160,9 +160,9 @@ test "generic function with align param" {
if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest;
if (builtin.arch == .thumb) return error.SkipZigTest;
- expect(whyWouldYouEverDoThis(1) == 0x1);
- expect(whyWouldYouEverDoThis(4) == 0x1);
- expect(whyWouldYouEverDoThis(8) == 0x1);
+ try expect(whyWouldYouEverDoThis(1) == 0x1);
+ try expect(whyWouldYouEverDoThis(4) == 0x1);
+ try expect(whyWouldYouEverDoThis(8) == 0x1);
}
fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
@@ -172,49 +172,49 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
test "@ptrCast preserves alignment of bigger source" {
var x: u32 align(16) = 1234;
const ptr = @ptrCast(*u8, &x);
- expect(@TypeOf(ptr) == *align(16) u8);
+ try expect(@TypeOf(ptr) == *align(16) u8);
}
test "runtime known array index has best alignment possible" {
// take full advantage of over-alignment
var array align(4) = [_]u8{ 1, 2, 3, 4 };
- expect(@TypeOf(&array[0]) == *align(4) u8);
- expect(@TypeOf(&array[1]) == *u8);
- expect(@TypeOf(&array[2]) == *align(2) u8);
- expect(@TypeOf(&array[3]) == *u8);
+ try expect(@TypeOf(&array[0]) == *align(4) u8);
+ try expect(@TypeOf(&array[1]) == *u8);
+ try expect(@TypeOf(&array[2]) == *align(2) u8);
+ try expect(@TypeOf(&array[3]) == *u8);
// because align is too small but we still figure out to use 2
var bigger align(2) = [_]u64{ 1, 2, 3, 4 };
- expect(@TypeOf(&bigger[0]) == *align(2) u64);
- expect(@TypeOf(&bigger[1]) == *align(2) u64);
- expect(@TypeOf(&bigger[2]) == *align(2) u64);
- expect(@TypeOf(&bigger[3]) == *align(2) u64);
+ try expect(@TypeOf(&bigger[0]) == *align(2) u64);
+ try expect(@TypeOf(&bigger[1]) == *align(2) u64);
+ try expect(@TypeOf(&bigger[2]) == *align(2) u64);
+ try expect(@TypeOf(&bigger[3]) == *align(2) u64);
// because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
var smaller align(2) = [_]u32{ 1, 2, 3, 4 };
var runtime_zero: usize = 0;
- comptime expect(@TypeOf(smaller[runtime_zero..]) == []align(2) u32);
- comptime expect(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32);
- testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32);
- testIndex(smaller[runtime_zero..].ptr, 1, *align(2) u32);
- testIndex(smaller[runtime_zero..].ptr, 2, *align(2) u32);
- testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32);
+ comptime try expect(@TypeOf(smaller[runtime_zero..]) == []align(2) u32);
+ comptime try expect(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32);
+ try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32);
+ try testIndex(smaller[runtime_zero..].ptr, 1, *align(2) u32);
+ try testIndex(smaller[runtime_zero..].ptr, 2, *align(2) u32);
+ try testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32);
// has to use ABI alignment because index known at runtime only
- testIndex2(array[runtime_zero..].ptr, 0, *u8);
- testIndex2(array[runtime_zero..].ptr, 1, *u8);
- testIndex2(array[runtime_zero..].ptr, 2, *u8);
- testIndex2(array[runtime_zero..].ptr, 3, *u8);
+ try testIndex2(array[runtime_zero..].ptr, 0, *u8);
+ try testIndex2(array[runtime_zero..].ptr, 1, *u8);
+ try testIndex2(array[runtime_zero..].ptr, 2, *u8);
+ try testIndex2(array[runtime_zero..].ptr, 3, *u8);
}
-fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void {
- comptime expect(@TypeOf(&smaller[index]) == T);
+fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void {
+ comptime try expect(@TypeOf(&smaller[index]) == T);
}
-fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void {
- comptime expect(@TypeOf(&ptr[index]) == T);
+fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void {
+ comptime try expect(@TypeOf(&ptr[index]) == T);
}
test "alignstack" {
- expect(fnWithAlignedStack() == 1234);
+ try expect(fnWithAlignedStack() == 1234);
}
fn fnWithAlignedStack() i32 {
@@ -223,7 +223,7 @@ fn fnWithAlignedStack() i32 {
}
test "alignment of structs" {
- expect(@alignOf(struct {
+ try expect(@alignOf(struct {
a: i32,
b: *i32,
}) == @alignOf(usize));
@@ -239,37 +239,37 @@ test "alignment of function with c calling convention" {
fn nothing() callconv(.C) void {}
test "return error union with 128-bit integer" {
- expect(3 == try give());
+ try expect(3 == try give());
}
fn give() anyerror!u128 {
return 3;
}
test "alignment of >= 128-bit integer type" {
- expect(@alignOf(u128) == 16);
- expect(@alignOf(u129) == 16);
+ try expect(@alignOf(u128) == 16);
+ try expect(@alignOf(u129) == 16);
}
test "alignment of struct with 128-bit field" {
- expect(@alignOf(struct {
+ try expect(@alignOf(struct {
x: u128,
}) == 16);
comptime {
- expect(@alignOf(struct {
+ try expect(@alignOf(struct {
x: u128,
}) == 16);
}
}
test "size of extern struct with 128-bit field" {
- expect(@sizeOf(extern struct {
+ try expect(@sizeOf(extern struct {
x: u128,
y: u8,
}) == 32);
comptime {
- expect(@sizeOf(extern struct {
+ try expect(@sizeOf(extern struct {
x: u128,
y: u8,
}) == 32);
@@ -286,8 +286,8 @@ test "read 128-bit field from default aligned struct in stack memory" {
.nevermind = 1,
.badguy = 12,
};
- expect((@ptrToInt(&default_aligned.badguy) % 16) == 0);
- expect(12 == default_aligned.badguy);
+ try expect((@ptrToInt(&default_aligned.badguy) % 16) == 0);
+ try expect(12 == default_aligned.badguy);
}
var default_aligned_global = DefaultAligned{
@@ -296,8 +296,8 @@ var default_aligned_global = DefaultAligned{
};
test "read 128-bit field from default aligned struct in global memory" {
- expect((@ptrToInt(&default_aligned_global.badguy) % 16) == 0);
- expect(12 == default_aligned_global.badguy);
+ try expect((@ptrToInt(&default_aligned_global.badguy) % 16) == 0);
+ try expect(12 == default_aligned_global.badguy);
}
test "struct field explicit alignment" {
@@ -310,9 +310,9 @@ test "struct field explicit alignment" {
var node: S.Node = undefined;
node.massive_byte = 100;
- expect(node.massive_byte == 100);
- comptime expect(@TypeOf(&node.massive_byte) == *align(64) u8);
- expect(@ptrToInt(&node.massive_byte) % 64 == 0);
+ try expect(node.massive_byte == 100);
+ comptime try expect(@TypeOf(&node.massive_byte) == *align(64) u8);
+ try expect(@ptrToInt(&node.massive_byte) % 64 == 0);
}
test "align(@alignOf(T)) T does not force resolution of T" {
@@ -334,7 +334,7 @@ test "align(@alignOf(T)) T does not force resolution of T" {
var ok = false;
};
_ = async S.doTheTest();
- expect(S.ok);
+ try expect(S.ok);
}
test "align(N) on functions" {
@@ -342,7 +342,7 @@ test "align(N) on functions" {
if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest;
if (builtin.arch == .thumb) return error.SkipZigTest;
- expect((@ptrToInt(overaligned_fn) & (0x1000 - 1)) == 0);
+ try expect((@ptrToInt(overaligned_fn) & (0x1000 - 1)) == 0);
}
fn overaligned_fn() align(0x1000) i32 {
return 42;
diff --git a/test/stage1/behavior/alignof.zig b/test/stage1/behavior/alignof.zig
index 96114ed560..775c831cff 100644
--- a/test/stage1/behavior/alignof.zig
+++ b/test/stage1/behavior/alignof.zig
@@ -10,29 +10,29 @@ const Foo = struct {
};
test "@alignOf(T) before referencing T" {
- comptime expect(@alignOf(Foo) != maxInt(usize));
+ comptime try expect(@alignOf(Foo) != maxInt(usize));
if (builtin.arch == builtin.Arch.x86_64) {
- comptime expect(@alignOf(Foo) == 4);
+ comptime try expect(@alignOf(Foo) == 4);
}
}
test "comparison of @alignOf(T) against zero" {
{
const T = struct { x: u32 };
- expect(!(@alignOf(T) == 0));
- expect(@alignOf(T) != 0);
- expect(!(@alignOf(T) < 0));
- expect(!(@alignOf(T) <= 0));
- expect(@alignOf(T) > 0);
- expect(@alignOf(T) >= 0);
+ try expect(!(@alignOf(T) == 0));
+ try expect(@alignOf(T) != 0);
+ try expect(!(@alignOf(T) < 0));
+ try expect(!(@alignOf(T) <= 0));
+ try expect(@alignOf(T) > 0);
+ try expect(@alignOf(T) >= 0);
}
{
const T = struct {};
- expect(@alignOf(T) == 0);
- expect(!(@alignOf(T) != 0));
- expect(!(@alignOf(T) < 0));
- expect(@alignOf(T) <= 0);
- expect(!(@alignOf(T) > 0));
- expect(@alignOf(T) >= 0);
+ try expect(@alignOf(T) == 0);
+ try expect(!(@alignOf(T) != 0));
+ try expect(!(@alignOf(T) < 0));
+ try expect(@alignOf(T) <= 0);
+ try expect(!(@alignOf(T) > 0));
+ try expect(@alignOf(T) >= 0);
}
}
diff --git a/test/stage1/behavior/array.zig b/test/stage1/behavior/array.zig
index 39ccc72960..84a2cdb36c 100644
--- a/test/stage1/behavior/array.zig
+++ b/test/stage1/behavior/array.zig
@@ -21,8 +21,8 @@ test "arrays" {
i += 1;
}
- expect(accumulator == 15);
- expect(getArrayLen(&array) == 5);
+ try expect(accumulator == 15);
+ try expect(getArrayLen(&array) == 5);
}
fn getArrayLen(a: []const u32) usize {
return a.len;
@@ -30,37 +30,37 @@ fn getArrayLen(a: []const u32) usize {
test "array with sentinels" {
const S = struct {
- fn doTheTest(is_ct: bool) void {
+ fn doTheTest(is_ct: bool) !void {
if (is_ct) {
var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
// Disabled at runtime because of
// https://github.com/ziglang/zig/issues/4372
- expectEqual(@as(u8, 0xde), zero_sized[0]);
+ try expectEqual(@as(u8, 0xde), zero_sized[0]);
var reinterpreted = @ptrCast(*[1]u8, &zero_sized);
- expectEqual(@as(u8, 0xde), reinterpreted[0]);
+ try expectEqual(@as(u8, 0xde), reinterpreted[0]);
}
var arr: [3:0x55]u8 = undefined;
// Make sure the sentinel pointer is pointing after the last element
if (!is_ct) {
const sentinel_ptr = @ptrToInt(&arr[3]);
const last_elem_ptr = @ptrToInt(&arr[2]);
- expectEqual(@as(usize, 1), sentinel_ptr - last_elem_ptr);
+ try expectEqual(@as(usize, 1), sentinel_ptr - last_elem_ptr);
}
// Make sure the sentinel is writeable
arr[3] = 0x55;
}
};
- S.doTheTest(false);
- comptime S.doTheTest(true);
+ try S.doTheTest(false);
+ comptime try S.doTheTest(true);
}
test "void arrays" {
var array: [4]void = undefined;
array[0] = void{};
array[1] = array[2];
- expect(@sizeOf(@TypeOf(array)) == 0);
- expect(array.len == 4);
+ try expect(@sizeOf(@TypeOf(array)) == 0);
+ try expect(array.len == 4);
}
test "array literal" {
@@ -71,12 +71,12 @@ test "array literal" {
1,
};
- expect(hex_mult.len == 4);
- expect(hex_mult[1] == 256);
+ try expect(hex_mult.len == 4);
+ try expect(hex_mult[1] == 256);
}
test "array dot len const expr" {
- expect(comptime x: {
+ try expect(comptime x: {
break :x some_array.len == 4;
});
}
@@ -100,11 +100,11 @@ test "nested arrays" {
"thing",
};
for (array_of_strings) |s, i| {
- if (i == 0) expect(mem.eql(u8, s, "hello"));
- if (i == 1) expect(mem.eql(u8, s, "this"));
- if (i == 2) expect(mem.eql(u8, s, "is"));
- if (i == 3) expect(mem.eql(u8, s, "my"));
- if (i == 4) expect(mem.eql(u8, s, "thing"));
+ if (i == 0) try expect(mem.eql(u8, s, "hello"));
+ if (i == 1) try expect(mem.eql(u8, s, "this"));
+ if (i == 2) try expect(mem.eql(u8, s, "is"));
+ if (i == 3) try expect(mem.eql(u8, s, "my"));
+ if (i == 4) try expect(mem.eql(u8, s, "thing"));
}
}
@@ -122,9 +122,9 @@ test "set global var array via slice embedded in struct" {
s.a[1].b = 2;
s.a[2].b = 3;
- expect(s_array[0].b == 1);
- expect(s_array[1].b == 2);
- expect(s_array[2].b == 3);
+ try expect(s_array[0].b == 1);
+ try expect(s_array[1].b == 2);
+ try expect(s_array[2].b == 3);
}
test "array literal with specified size" {
@@ -132,34 +132,34 @@ test "array literal with specified size" {
1,
2,
};
- expect(array[0] == 1);
- expect(array[1] == 2);
+ try expect(array[0] == 1);
+ try expect(array[1] == 2);
}
test "array len field" {
var arr = [4]u8{ 0, 0, 0, 0 };
var ptr = &arr;
- expect(arr.len == 4);
- comptime expect(arr.len == 4);
- expect(ptr.len == 4);
- comptime expect(ptr.len == 4);
+ try expect(arr.len == 4);
+ comptime try expect(arr.len == 4);
+ try expect(ptr.len == 4);
+ comptime try expect(ptr.len == 4);
}
test "single-item pointer to array indexing and slicing" {
- testSingleItemPtrArrayIndexSlice();
- comptime testSingleItemPtrArrayIndexSlice();
+ try testSingleItemPtrArrayIndexSlice();
+ comptime try testSingleItemPtrArrayIndexSlice();
}
-fn testSingleItemPtrArrayIndexSlice() void {
+fn testSingleItemPtrArrayIndexSlice() !void {
{
var array: [4]u8 = "aaaa".*;
doSomeMangling(&array);
- expect(mem.eql(u8, "azya", &array));
+ try expect(mem.eql(u8, "azya", &array));
}
{
var array = "aaaa".*;
doSomeMangling(&array);
- expect(mem.eql(u8, "azya", &array));
+ try expect(mem.eql(u8, "azya", &array));
}
}
@@ -169,15 +169,15 @@ fn doSomeMangling(array: *[4]u8) void {
}
test "implicit cast single-item pointer" {
- testImplicitCastSingleItemPtr();
- comptime testImplicitCastSingleItemPtr();
+ try testImplicitCastSingleItemPtr();
+ comptime try testImplicitCastSingleItemPtr();
}
-fn testImplicitCastSingleItemPtr() void {
+fn testImplicitCastSingleItemPtr() !void {
var byte: u8 = 100;
const slice = @as(*[1]u8, &byte)[0..];
slice[0] += 1;
- expect(byte == 101);
+ try expect(byte == 101);
}
fn testArrayByValAtComptime(b: [2]u8) u8 {
@@ -192,7 +192,7 @@ test "comptime evalutating function that takes array by value" {
test "implicit comptime in array type size" {
var arr: [plusOne(10)]bool = undefined;
- expect(arr.len == 11);
+ try expect(arr.len == 11);
}
fn plusOne(x: u32) u32 {
@@ -202,52 +202,52 @@ fn plusOne(x: u32) u32 {
test "runtime initialize array elem and then implicit cast to slice" {
var two: i32 = 2;
const x: []const i32 = &[_]i32{two};
- expect(x[0] == 2);
+ try expect(x[0] == 2);
}
test "array literal as argument to function" {
const S = struct {
- fn entry(two: i32) void {
- foo(&[_]i32{
+ fn entry(two: i32) !void {
+ try foo(&[_]i32{
1,
2,
3,
});
- foo(&[_]i32{
+ try foo(&[_]i32{
1,
two,
3,
});
- foo2(true, &[_]i32{
+ try foo2(true, &[_]i32{
1,
2,
3,
});
- foo2(true, &[_]i32{
+ try foo2(true, &[_]i32{
1,
two,
3,
});
}
- fn foo(x: []const i32) void {
- expect(x[0] == 1);
- expect(x[1] == 2);
- expect(x[2] == 3);
+ fn foo(x: []const i32) !void {
+ try expect(x[0] == 1);
+ try expect(x[1] == 2);
+ try expect(x[2] == 3);
}
- fn foo2(trash: bool, x: []const i32) void {
- expect(trash);
- expect(x[0] == 1);
- expect(x[1] == 2);
- expect(x[2] == 3);
+ fn foo2(trash: bool, x: []const i32) !void {
+ try expect(trash);
+ try expect(x[0] == 1);
+ try expect(x[1] == 2);
+ try expect(x[2] == 3);
}
};
- S.entry(2);
- comptime S.entry(2);
+ try S.entry(2);
+ comptime try S.entry(2);
}
test "double nested array to const slice cast in array literal" {
const S = struct {
- fn entry(two: i32) void {
+ fn entry(two: i32) !void {
const cases = [_][]const []const i32{
&[_][]const i32{&[_]i32{1}},
&[_][]const i32{&[_]i32{ 2, 3 }},
@@ -256,18 +256,18 @@ test "double nested array to const slice cast in array literal" {
&[_]i32{ 5, 6, 7 },
},
};
- check(&cases);
+ try check(&cases);
const cases2 = [_][]const i32{
&[_]i32{1},
&[_]i32{ two, 3 },
};
- expect(cases2.len == 2);
- expect(cases2[0].len == 1);
- expect(cases2[0][0] == 1);
- expect(cases2[1].len == 2);
- expect(cases2[1][0] == 2);
- expect(cases2[1][1] == 3);
+ try expect(cases2.len == 2);
+ try expect(cases2[0].len == 1);
+ try expect(cases2[0][0] == 1);
+ try expect(cases2[1].len == 2);
+ try expect(cases2[1][0] == 2);
+ try expect(cases2[1][1] == 3);
const cases3 = [_][]const []const i32{
&[_][]const i32{&[_]i32{1}},
@@ -277,37 +277,37 @@ test "double nested array to const slice cast in array literal" {
&[_]i32{ 5, 6, 7 },
},
};
- check(&cases3);
+ try check(&cases3);
}
- fn check(cases: []const []const []const i32) void {
- expect(cases.len == 3);
- expect(cases[0].len == 1);
- expect(cases[0][0].len == 1);
- expect(cases[0][0][0] == 1);
- expect(cases[1].len == 1);
- expect(cases[1][0].len == 2);
- expect(cases[1][0][0] == 2);
- expect(cases[1][0][1] == 3);
- expect(cases[2].len == 2);
- expect(cases[2][0].len == 1);
- expect(cases[2][0][0] == 4);
- expect(cases[2][1].len == 3);
- expect(cases[2][1][0] == 5);
- expect(cases[2][1][1] == 6);
- expect(cases[2][1][2] == 7);
+ fn check(cases: []const []const []const i32) !void {
+ try expect(cases.len == 3);
+ try expect(cases[0].len == 1);
+ try expect(cases[0][0].len == 1);
+ try expect(cases[0][0][0] == 1);
+ try expect(cases[1].len == 1);
+ try expect(cases[1][0].len == 2);
+ try expect(cases[1][0][0] == 2);
+ try expect(cases[1][0][1] == 3);
+ try expect(cases[2].len == 2);
+ try expect(cases[2][0].len == 1);
+ try expect(cases[2][0][0] == 4);
+ try expect(cases[2][1].len == 3);
+ try expect(cases[2][1][0] == 5);
+ try expect(cases[2][1][1] == 6);
+ try expect(cases[2][1][2] == 7);
}
};
- S.entry(2);
- comptime S.entry(2);
+ try S.entry(2);
+ comptime try S.entry(2);
}
test "read/write through global variable array of struct fields initialized via array mult" {
const S = struct {
- fn doTheTest() void {
- expect(storage[0].term == 1);
+ fn doTheTest() !void {
+ try expect(storage[0].term == 1);
storage[0] = MyStruct{ .term = 123 };
- expect(storage[0].term == 123);
+ try expect(storage[0].term == 123);
}
pub const MyStruct = struct {
@@ -316,34 +316,34 @@ test "read/write through global variable array of struct fields initialized via
var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1;
};
- S.doTheTest();
+ try S.doTheTest();
}
test "implicit cast zero sized array ptr to slice" {
{
var b = "".*;
const c: []const u8 = &b;
- expect(c.len == 0);
+ try expect(c.len == 0);
}
{
var b: [0]u8 = "".*;
const c: []const u8 = &b;
- expect(c.len == 0);
+ try expect(c.len == 0);
}
}
test "anonymous list literal syntax" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var array: [4]u8 = .{ 1, 2, 3, 4 };
- expect(array[0] == 1);
- expect(array[1] == 2);
- expect(array[2] == 3);
- expect(array[3] == 4);
+ try expect(array[0] == 1);
+ try expect(array[1] == 2);
+ try expect(array[2] == 3);
+ try expect(array[3] == 4);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "anonymous literal in array" {
@@ -352,51 +352,51 @@ test "anonymous literal in array" {
a: usize = 2,
b: usize = 4,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var array: [2]Foo = .{
.{ .a = 3 },
.{ .b = 3 },
};
- expect(array[0].a == 3);
- expect(array[0].b == 4);
- expect(array[1].a == 2);
- expect(array[1].b == 3);
+ try expect(array[0].a == 3);
+ try expect(array[0].b == 4);
+ try expect(array[1].a == 2);
+ try expect(array[1].b == 3);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "access the null element of a null terminated array" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
- expect(array[4] == 0);
+ try expect(array[4] == 0);
var len: usize = 4;
- expect(array[len] == 0);
+ try expect(array[len] == 0);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "type deduction for array subscript expression" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var array = [_]u8{ 0x55, 0xAA };
var v0 = true;
- expectEqual(@as(u8, 0xAA), array[if (v0) 1 else 0]);
+ try expectEqual(@as(u8, 0xAA), array[if (v0) 1 else 0]);
var v1 = false;
- expectEqual(@as(u8, 0x55), array[if (v1) 1 else 0]);
+ try expectEqual(@as(u8, 0x55), array[if (v1) 1 else 0]);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "sentinel element count towards the ABI size calculation" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
const T = packed struct {
fill_pre: u8 = 0x55,
data: [0:0]u8 = undefined,
@@ -404,14 +404,14 @@ test "sentinel element count towards the ABI size calculation" {
};
var x = T{};
var as_slice = mem.asBytes(&x);
- expectEqual(@as(usize, 3), as_slice.len);
- expectEqual(@as(u8, 0x55), as_slice[0]);
- expectEqual(@as(u8, 0xAA), as_slice[2]);
+ try expectEqual(@as(usize, 3), as_slice.len);
+ try expectEqual(@as(u8, 0x55), as_slice[0]);
+ try expectEqual(@as(u8, 0xAA), as_slice[2]);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "zero-sized array with recursive type definition" {
@@ -429,61 +429,61 @@ test "zero-sized array with recursive type definition" {
};
var t: S = .{ .list = .{ .s = undefined } };
- expectEqual(@as(usize, 0), t.list.x);
+ try expectEqual(@as(usize, 0), t.list.x);
}
test "type coercion of anon struct literal to array" {
const S = struct {
- const U = union{
+ const U = union {
a: u32,
b: bool,
c: []const u8,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var x1: u8 = 42;
const t1 = .{ x1, 56, 54 };
var arr1: [3]u8 = t1;
- expect(arr1[0] == 42);
- expect(arr1[1] == 56);
- expect(arr1[2] == 54);
-
+ try expect(arr1[0] == 42);
+ try expect(arr1[1] == 56);
+ try expect(arr1[2] == 54);
+
var x2: U = .{ .a = 42 };
const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };
var arr2: [3]U = t2;
- expect(arr2[0].a == 42);
- expect(arr2[1].b == true);
- expect(mem.eql(u8, arr2[2].c, "hello"));
+ try expect(arr2[0].a == 42);
+ try expect(arr2[1].b == true);
+ try expect(mem.eql(u8, arr2[2].c, "hello"));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "type coercion of pointer to anon struct literal to pointer to array" {
const S = struct {
- const U = union{
+ const U = union {
a: u32,
b: bool,
c: []const u8,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var x1: u8 = 42;
const t1 = &.{ x1, 56, 54 };
- var arr1: *const[3]u8 = t1;
- expect(arr1[0] == 42);
- expect(arr1[1] == 56);
- expect(arr1[2] == 54);
-
+ var arr1: *const [3]u8 = t1;
+ try expect(arr1[0] == 42);
+ try expect(arr1[1] == 56);
+ try expect(arr1[2] == 54);
+
var x2: U = .{ .a = 42 };
const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } };
var arr2: *const [3]U = t2;
- expect(arr2[0].a == 42);
- expect(arr2[1].b == true);
- expect(mem.eql(u8, arr2[2].c, "hello"));
+ try expect(arr2[0].a == 42);
+ try expect(arr2[1].b == true);
+ try expect(mem.eql(u8, arr2[2].c, "hello"));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
diff --git a/test/stage1/behavior/asm.zig b/test/stage1/behavior/asm.zig
index ade774910d..c9bffa806d 100644
--- a/test/stage1/behavior/asm.zig
+++ b/test/stage1/behavior/asm.zig
@@ -15,7 +15,7 @@ comptime {
test "module level assembly" {
if (is_x86_64_linux) {
- expect(this_is_my_alias() == 1234);
+ try expect(this_is_my_alias() == 1234);
}
}
diff --git a/test/stage1/behavior/async_fn.zig b/test/stage1/behavior/async_fn.zig
index 09db0eeb29..d222f378bb 100644
--- a/test/stage1/behavior/async_fn.zig
+++ b/test/stage1/behavior/async_fn.zig
@@ -9,12 +9,12 @@ var global_x: i32 = 1;
test "simple coroutine suspend and resume" {
var frame = async simpleAsyncFn();
- expect(global_x == 2);
+ try expect(global_x == 2);
resume frame;
- expect(global_x == 3);
+ try expect(global_x == 3);
const af: anyframe->void = &frame;
resume frame;
- expect(global_x == 4);
+ try expect(global_x == 4);
}
fn simpleAsyncFn() void {
global_x += 1;
@@ -28,9 +28,9 @@ var global_y: i32 = 1;
test "pass parameter to coroutine" {
var p = async simpleAsyncFnWithArg(2);
- expect(global_y == 3);
+ try expect(global_y == 3);
resume p;
- expect(global_y == 5);
+ try expect(global_y == 5);
}
fn simpleAsyncFnWithArg(delta: i32) void {
global_y += delta;
@@ -42,10 +42,10 @@ test "suspend at end of function" {
const S = struct {
var x: i32 = 1;
- fn doTheTest() void {
- expect(x == 1);
+ fn doTheTest() !void {
+ try expect(x == 1);
const p = async suspendAtEnd();
- expect(x == 2);
+ try expect(x == 2);
}
fn suspendAtEnd() void {
@@ -53,23 +53,23 @@ test "suspend at end of function" {
suspend {}
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "local variable in async function" {
const S = struct {
var x: i32 = 0;
- fn doTheTest() void {
- expect(x == 0);
+ fn doTheTest() !void {
+ try expect(x == 0);
var p = async add(1, 2);
- expect(x == 0);
+ try expect(x == 0);
resume p;
- expect(x == 0);
+ try expect(x == 0);
resume p;
- expect(x == 0);
+ try expect(x == 0);
resume p;
- expect(x == 3);
+ try expect(x == 3);
}
fn add(a: i32, b: i32) void {
@@ -82,7 +82,7 @@ test "local variable in async function" {
x = accum;
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "calling an inferred async function" {
@@ -90,11 +90,11 @@ test "calling an inferred async function" {
var x: i32 = 1;
var other_frame: *@Frame(other) = undefined;
- fn doTheTest() void {
+ fn doTheTest() !void {
_ = async first();
- expect(x == 1);
+ try expect(x == 1);
resume other_frame.*;
- expect(x == 2);
+ try expect(x == 2);
}
fn first() void {
@@ -106,7 +106,7 @@ test "calling an inferred async function" {
x += 1;
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "@frameSize" {
@@ -114,16 +114,16 @@ test "@frameSize" {
return error.SkipZigTest;
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
{
var ptr = @ptrCast(fn (i32) callconv(.Async) void, other);
const size = @frameSize(ptr);
- expect(size == @sizeOf(@Frame(other)));
+ try expect(size == @sizeOf(@Frame(other)));
}
{
var ptr = @ptrCast(fn () callconv(.Async) void, first);
const size = @frameSize(ptr);
- expect(size == @sizeOf(@Frame(first)));
+ try expect(size == @sizeOf(@Frame(first)));
}
}
@@ -135,20 +135,20 @@ test "@frameSize" {
suspend {}
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "coroutine suspend, resume" {
const S = struct {
var frame: anyframe = undefined;
- fn doTheTest() void {
+ fn doTheTest() !void {
_ = async amain();
seq('d');
resume frame;
seq('h');
- expect(std.mem.eql(u8, &points, "abcdefgh"));
+ try expect(std.mem.eql(u8, &points, "abcdefgh"));
}
fn amain() void {
@@ -176,27 +176,27 @@ test "coroutine suspend, resume" {
index += 1;
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "coroutine suspend with block" {
const p = async testSuspendBlock();
- expect(!global_result);
+ try expect(!global_result);
resume a_promise;
- expect(global_result);
+ try expect(global_result);
}
var a_promise: anyframe = undefined;
var global_result = false;
fn testSuspendBlock() callconv(.Async) void {
suspend {
- comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
+ comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable;
a_promise = @frame();
}
// Test to make sure that @frame() works as advertised (issue #1296)
// var our_handle: anyframe = @frame();
- expect(a_promise == @as(anyframe, @frame()));
+ expect(a_promise == @as(anyframe, @frame())) catch @panic("test failed");
global_result = true;
}
@@ -210,8 +210,8 @@ test "coroutine await" {
await_seq('f');
resume await_a_promise;
await_seq('i');
- expect(await_final_result == 1234);
- expect(std.mem.eql(u8, &await_points, "abcdefghi"));
+ try expect(await_final_result == 1234);
+ try expect(std.mem.eql(u8, &await_points, "abcdefghi"));
}
fn await_amain() callconv(.Async) void {
await_seq('b');
@@ -244,8 +244,8 @@ test "coroutine await early return" {
early_seq('a');
var p = async early_amain();
early_seq('f');
- expect(early_final_result == 1234);
- expect(std.mem.eql(u8, &early_points, "abcdef"));
+ try expect(early_final_result == 1234);
+ try expect(std.mem.eql(u8, &early_points, "abcdef"));
}
fn early_amain() callconv(.Async) void {
early_seq('b');
@@ -276,7 +276,7 @@ test "async function with dot syntax" {
}
};
const p = async S.foo();
- expect(S.y == 2);
+ try expect(S.y == 2);
}
test "async fn pointer in a struct field" {
@@ -287,12 +287,12 @@ test "async fn pointer in a struct field" {
var foo = Foo{ .bar = simpleAsyncFn2 };
var bytes: [64]u8 align(16) = undefined;
const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
- comptime expect(@TypeOf(f) == anyframe->void);
- expect(data == 2);
+ comptime try expect(@TypeOf(f) == anyframe->void);
+ try expect(data == 2);
resume f;
- expect(data == 4);
+ try expect(data == 4);
_ = async doTheAwait(f);
- expect(data == 4);
+ try expect(data == 4);
}
fn doTheAwait(f: anyframe->void) void {
@@ -323,22 +323,22 @@ test "@asyncCall with return type" {
var bytes: [150]u8 align(16) = undefined;
var aresult: i32 = 0;
_ = @asyncCall(&bytes, &aresult, foo.bar, .{});
- expect(aresult == 0);
+ try expect(aresult == 0);
resume Foo.global_frame;
- expect(aresult == 1234);
+ try expect(aresult == 1234);
}
test "async fn with inferred error set" {
const S = struct {
var global_frame: anyframe = undefined;
- fn doTheTest() void {
+ fn doTheTest() !void {
var frame: [1]@Frame(middle) = undefined;
var fn_ptr = middle;
var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;
_ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{});
resume global_frame;
- std.testing.expectError(error.Fail, result);
+ try std.testing.expectError(error.Fail, result);
}
fn middle() callconv(.Async) !void {
var f = async middle2();
@@ -355,7 +355,7 @@ test "async fn with inferred error set" {
return error.Fail;
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "error return trace across suspend points - early return" {
@@ -383,9 +383,9 @@ fn suspendThenFail() callconv(.Async) anyerror!void {
}
fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void {
(await p) catch |e| {
- std.testing.expect(e == error.Fail);
+ std.testing.expect(e == error.Fail) catch @panic("test failure");
if (@errorReturnTrace()) |trace| {
- expect(trace.index == 1);
+ expect(trace.index == 1) catch @panic("test failure");
} else switch (builtin.mode) {
.Debug, .ReleaseSafe => @panic("expected return trace"),
.ReleaseFast, .ReleaseSmall => {},
@@ -396,7 +396,7 @@ fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void {
test "break from suspend" {
var my_result: i32 = 1;
const p = async testBreakFromSuspend(&my_result);
- std.testing.expect(my_result == 2);
+ try std.testing.expect(my_result == 2);
}
fn testBreakFromSuspend(my_result: *i32) callconv(.Async) void {
suspend {
@@ -415,11 +415,11 @@ test "heap allocated async function frame" {
const frame = try std.testing.allocator.create(@Frame(someFunc));
defer std.testing.allocator.destroy(frame);
- expect(x == 42);
+ try expect(x == 42);
frame.* = async someFunc();
- expect(x == 43);
+ try expect(x == 43);
resume frame;
- expect(x == 44);
+ try expect(x == 44);
}
fn someFunc() void {
@@ -436,15 +436,15 @@ test "async function call return value" {
var frame: anyframe = undefined;
var pt = Point{ .x = 10, .y = 11 };
- fn doTheTest() void {
- expectEqual(pt.x, 10);
- expectEqual(pt.y, 11);
+ fn doTheTest() !void {
+ try expectEqual(pt.x, 10);
+ try expectEqual(pt.y, 11);
_ = async first();
- expectEqual(pt.x, 10);
- expectEqual(pt.y, 11);
+ try expectEqual(pt.x, 10);
+ try expectEqual(pt.y, 11);
resume frame;
- expectEqual(pt.x, 1);
- expectEqual(pt.y, 2);
+ try expectEqual(pt.x, 1);
+ try expectEqual(pt.y, 2);
}
fn first() void {
@@ -469,23 +469,23 @@ test "async function call return value" {
y: i32,
};
};
- S.doTheTest();
+ try S.doTheTest();
}
test "suspension points inside branching control flow" {
const S = struct {
var result: i32 = 10;
- fn doTheTest() void {
- expect(10 == result);
+ fn doTheTest() !void {
+ try expect(10 == result);
var frame = async func(true);
- expect(10 == result);
+ try expect(10 == result);
resume frame;
- expect(11 == result);
+ try expect(11 == result);
resume frame;
- expect(12 == result);
+ try expect(12 == result);
resume frame;
- expect(13 == result);
+ try expect(13 == result);
}
fn func(b: bool) void {
@@ -495,7 +495,7 @@ test "suspension points inside branching control flow" {
}
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "call async function which has struct return type" {
@@ -509,8 +509,8 @@ test "call async function which has struct return type" {
fn atest() void {
const result = func();
- expect(result.x == 5);
- expect(result.y == 6);
+ expect(result.x == 5) catch @panic("test failed");
+ expect(result.y == 6) catch @panic("test failed");
}
const Point = struct {
@@ -536,27 +536,27 @@ test "pass string literal to async function" {
var frame: anyframe = undefined;
var ok: bool = false;
- fn doTheTest() void {
+ fn doTheTest() !void {
_ = async hello("hello");
resume frame;
- expect(ok);
+ try expect(ok);
}
fn hello(msg: []const u8) void {
frame = @frame();
suspend {}
- expectEqualStrings("hello", msg);
+ expectEqualStrings("hello", msg) catch @panic("test failed");
ok = true;
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "await inside an errdefer" {
const S = struct {
var frame: anyframe = undefined;
- fn doTheTest() void {
+ fn doTheTest() !void {
_ = async amainWrap();
resume frame;
}
@@ -572,7 +572,7 @@ test "await inside an errdefer" {
suspend {}
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "try in an async function with error union and non-zero-bit payload" {
@@ -580,14 +580,14 @@ test "try in an async function with error union and non-zero-bit payload" {
var frame: anyframe = undefined;
var ok = false;
- fn doTheTest() void {
+ fn doTheTest() !void {
_ = async amain();
resume frame;
- expect(ok);
+ try expect(ok);
}
fn amain() void {
- std.testing.expectError(error.Bad, theProblem());
+ std.testing.expectError(error.Bad, theProblem()) catch @panic("test failed");
ok = true;
}
@@ -602,7 +602,7 @@ test "try in an async function with error union and non-zero-bit payload" {
return error.Bad;
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "returning a const error from async function" {
@@ -610,10 +610,10 @@ test "returning a const error from async function" {
var frame: anyframe = undefined;
var ok = false;
- fn doTheTest() void {
+ fn doTheTest() !void {
_ = async amain();
resume frame;
- expect(ok);
+ try expect(ok);
}
fn amain() !void {
@@ -630,7 +630,7 @@ test "returning a const error from async function" {
return error.OutOfMemory;
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "async/await typical usage" {
@@ -663,11 +663,11 @@ fn testAsyncAwaitTypicalUsage(
}
fn amainWrap() void {
if (amain()) |_| {
- expect(!simulate_fail_download);
- expect(!simulate_fail_file);
+ expect(!simulate_fail_download) catch @panic("test failure");
+ expect(!simulate_fail_file) catch @panic("test failure");
} else |e| switch (e) {
- error.NoResponse => expect(simulate_fail_download),
- error.FileNotFound => expect(simulate_fail_file),
+ error.NoResponse => expect(simulate_fail_download) catch @panic("test failure"),
+ error.FileNotFound => expect(simulate_fail_file) catch @panic("test failure"),
else => @panic("test failure"),
}
}
@@ -694,8 +694,8 @@ fn testAsyncAwaitTypicalUsage(
const file_text = try await file_frame;
defer allocator.free(file_text);
- expect(std.mem.eql(u8, "expected download text", download_text));
- expect(std.mem.eql(u8, "expected file text", file_text));
+ try expect(std.mem.eql(u8, "expected download text", download_text));
+ try expect(std.mem.eql(u8, "expected file text", file_text));
}
var global_download_frame: anyframe = undefined;
@@ -728,13 +728,13 @@ fn testAsyncAwaitTypicalUsage(
test "alignment of local variables in async functions" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var y: u8 = 123;
var x: u8 align(128) = 1;
- expect(@ptrToInt(&x) % 128 == 0);
+ try expect(@ptrToInt(&x) % 128 == 0);
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "no reason to resolve frame still works" {
@@ -746,10 +746,10 @@ fn simpleNothing() void {
test "async call a generic function" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var f = async func(i32, 2);
const result = await f;
- expect(result == 3);
+ try expect(result == 3);
}
fn func(comptime T: type, inc: T) T {
@@ -766,8 +766,8 @@ test "async call a generic function" {
test "return from suspend block" {
const S = struct {
- fn doTheTest() void {
- expect(func() == 1234);
+ fn doTheTest() !void {
+ expect(func() == 1234) catch @panic("test failure");
}
fn func() i32 {
suspend {
@@ -808,7 +808,7 @@ test "struct parameter to async function is copied to the frame" {
var pt = Point{ .x = 1, .y = 2 };
f.* = async foo(pt);
var result = await f;
- expect(result == 1);
+ expect(result == 1) catch @panic("test failure");
}
fn foo(point: Point) i32 {
@@ -833,7 +833,7 @@ test "cast fn to async fn when it is inferred to be async" {
var result: i32 = undefined;
const f = @asyncCall(&buf, &result, ptr, .{});
_ = await f;
- expect(result == 1234);
+ expect(result == 1234) catch @panic("test failure");
ok = true;
}
@@ -846,7 +846,7 @@ test "cast fn to async fn when it is inferred to be async" {
};
_ = async S.doTheTest();
resume S.frame;
- expect(S.ok);
+ try expect(S.ok);
}
test "cast fn to async fn when it is inferred to be async, awaited directly" {
@@ -860,7 +860,7 @@ test "cast fn to async fn when it is inferred to be async, awaited directly" {
var buf: [100]u8 align(16) = undefined;
var result: i32 = undefined;
_ = await @asyncCall(&buf, &result, ptr, .{});
- expect(result == 1234);
+ expect(result == 1234) catch @panic("test failure");
ok = true;
}
@@ -873,7 +873,7 @@ test "cast fn to async fn when it is inferred to be async, awaited directly" {
};
_ = async S.doTheTest();
resume S.frame;
- expect(S.ok);
+ try expect(S.ok);
}
test "await does not force async if callee is blocking" {
@@ -883,12 +883,12 @@ test "await does not force async if callee is blocking" {
}
};
var x = async S.simple();
- expect(await x == 1234);
+ try expect(await x == 1234);
}
test "recursive async function" {
- expect(recursiveAsyncFunctionTest(false).doTheTest() == 55);
- expect(recursiveAsyncFunctionTest(true).doTheTest() == 55);
+ try expect(recursiveAsyncFunctionTest(false).doTheTest() == 55);
+ try expect(recursiveAsyncFunctionTest(true).doTheTest() == 55);
}
fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type {
@@ -952,12 +952,12 @@ test "@asyncCall with comptime-known function, but not awaited directly" {
const S = struct {
var global_frame: anyframe = undefined;
- fn doTheTest() void {
+ fn doTheTest() !void {
var frame: [1]@Frame(middle) = undefined;
var result: @typeInfo(@typeInfo(@TypeOf(middle)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;
_ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, middle, .{});
resume global_frame;
- std.testing.expectError(error.Fail, result);
+ try std.testing.expectError(error.Fail, result);
}
fn middle() callconv(.Async) !void {
var f = async middle2();
@@ -974,7 +974,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" {
return error.Fail;
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "@asyncCall with actual frame instead of byte buffer" {
@@ -988,7 +988,7 @@ test "@asyncCall with actual frame instead of byte buffer" {
var result: i32 = undefined;
const ptr = @asyncCall(&frame, &result, S.func, .{});
resume ptr;
- expect(result == 1234);
+ try expect(result == 1234);
}
test "@asyncCall using the result location inside the frame" {
@@ -1010,19 +1010,19 @@ test "@asyncCall using the result location inside the frame" {
var foo = Foo{ .bar = S.simple2 };
var bytes: [64]u8 align(16) = undefined;
const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
- comptime expect(@TypeOf(f) == anyframe->i32);
- expect(data == 2);
+ comptime try expect(@TypeOf(f) == anyframe->i32);
+ try expect(data == 2);
resume f;
- expect(data == 4);
+ try expect(data == 4);
_ = async S.getAnswer(f, &data);
- expect(data == 1234);
+ try expect(data == 1234);
}
test "@TypeOf an async function call of generic fn with error union type" {
const S = struct {
fn func(comptime x: anytype) anyerror!i32 {
const T = @TypeOf(async func(x));
- comptime expect(T == @typeInfo(@TypeOf(@frame())).Pointer.child);
+ comptime try expect(T == @typeInfo(@TypeOf(@frame())).Pointer.child);
return undefined;
}
};
@@ -1051,7 +1051,7 @@ test "using @TypeOf on a generic function call" {
};
_ = async S.amain(@as(u32, 1));
resume S.global_frame;
- expect(S.global_ok);
+ try expect(S.global_ok);
}
test "recursive call of await @asyncCall with struct return type" {
@@ -1084,17 +1084,17 @@ test "recursive call of await @asyncCall with struct return type" {
var frame: @TypeOf(async S.amain(@as(u32, 1))) = undefined;
_ = @asyncCall(&frame, &res, S.amain, .{@as(u32, 1)});
resume S.global_frame;
- expect(S.global_ok);
- expect(res.x == 1);
- expect(res.y == 2);
- expect(res.z == 3);
+ try expect(S.global_ok);
+ try expect(res.x == 1);
+ try expect(res.y == 2);
+ try expect(res.z == 3);
}
test "nosuspend function call" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
const result = nosuspend add(50, 100);
- expect(result == 150);
+ try expect(result == 150);
}
fn add(a: i32, b: i32) i32 {
if (a > 100) {
@@ -1103,7 +1103,7 @@ test "nosuspend function call" {
return a + b;
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "await used in expression and awaiting fn with no suspend but async calling convention" {
@@ -1113,7 +1113,7 @@ test "await used in expression and awaiting fn with no suspend but async calling
var f2 = async add(3, 4);
const sum = (await f1) + (await f2);
- expect(sum == 10);
+ expect(sum == 10) catch @panic("test failure");
}
fn add(a: i32, b: i32) callconv(.Async) i32 {
return a + b;
@@ -1128,7 +1128,7 @@ test "await used in expression after a fn call" {
var f1 = async add(3, 4);
var sum: i32 = 0;
sum = foo() + await f1;
- expect(sum == 8);
+ expect(sum == 8) catch @panic("test failure");
}
fn add(a: i32, b: i32) callconv(.Async) i32 {
return a + b;
@@ -1145,7 +1145,7 @@ test "async fn call used in expression after a fn call" {
fn atest() void {
var sum: i32 = 0;
sum = foo() + add(3, 4);
- expect(sum == 8);
+ expect(sum == 8) catch @panic("test failure");
}
fn add(a: i32, b: i32) callconv(.Async) i32 {
return a + b;
@@ -1167,7 +1167,7 @@ test "suspend in for loop" {
}
fn atest() void {
- expect(func(&[_]u8{ 1, 2, 3 }) == 6);
+ expect(func(&[_]u8{ 1, 2, 3 }) == 6) catch @panic("test failure");
}
fn func(stuff: []const u8) u32 {
global_frame = @frame();
@@ -1193,8 +1193,8 @@ test "suspend in while loop" {
}
fn atest() void {
- expect(optional(6) == 6);
- expect(errunion(6) == 6);
+ expect(optional(6) == 6) catch @panic("test failure");
+ expect(errunion(6) == 6) catch @panic("test failure");
}
fn optional(stuff: ?u32) u32 {
global_frame = @frame();
@@ -1223,8 +1223,8 @@ test "correctly spill when returning the error union result of another async fn"
const S = struct {
var global_frame: anyframe = undefined;
- fn doTheTest() void {
- expect((atest() catch unreachable) == 1234);
+ fn doTheTest() !void {
+ expect((atest() catch unreachable) == 1234) catch @panic("test failure");
}
fn atest() !i32 {
@@ -1246,11 +1246,11 @@ test "spill target expr in a for loop" {
const S = struct {
var global_frame: anyframe = undefined;
- fn doTheTest() void {
+ fn doTheTest() !void {
var foo = Foo{
.slice = &[_]i32{ 1, 2 },
};
- expect(atest(&foo) == 3);
+ expect(atest(&foo) == 3) catch @panic("test failure");
}
const Foo = struct {
@@ -1277,11 +1277,11 @@ test "spill target expr in a for loop, with a var decl in the loop body" {
const S = struct {
var global_frame: anyframe = undefined;
- fn doTheTest() void {
+ fn doTheTest() !void {
var foo = Foo{
.slice = &[_]i32{ 1, 2 },
};
- expect(atest(&foo) == 3);
+ expect(atest(&foo) == 3) catch @panic("test failure");
}
const Foo = struct {
@@ -1319,7 +1319,7 @@ test "async call with @call" {
fn atest() void {
var frame = @call(.{ .modifier = .async_kw }, afoo, .{});
const res = await frame;
- expect(res == 42);
+ expect(res == 42) catch @panic("test failure");
}
fn afoo() i32 {
suspend {
@@ -1348,7 +1348,7 @@ test "async function passed 0-bit arg after non-0-bit arg" {
};
_ = async S.foo();
resume S.global_frame;
- expect(S.global_int == 1);
+ try expect(S.global_int == 1);
}
test "async function passed align(16) arg after align(8) arg" {
@@ -1362,7 +1362,7 @@ test "async function passed align(16) arg after align(8) arg" {
}
fn bar(x: u64, args: anytype) anyerror!void {
- expect(x == 10);
+ try expect(x == 10);
global_frame = @frame();
suspend {}
global_int = args[0];
@@ -1370,7 +1370,7 @@ test "async function passed align(16) arg after align(8) arg" {
};
_ = async S.foo();
resume S.global_frame;
- expect(S.global_int == 99);
+ try expect(S.global_int == 99);
}
test "async function call resolves target fn frame, comptime func" {
@@ -1392,7 +1392,7 @@ test "async function call resolves target fn frame, comptime func" {
};
_ = async S.foo();
resume S.global_frame;
- expect(S.global_int == 10);
+ try expect(S.global_int == 10);
}
test "async function call resolves target fn frame, runtime func" {
@@ -1415,7 +1415,7 @@ test "async function call resolves target fn frame, runtime func" {
};
_ = async S.foo();
resume S.global_frame;
- expect(S.global_int == 10);
+ try expect(S.global_int == 10);
}
test "properly spill optional payload capture value" {
@@ -1439,7 +1439,7 @@ test "properly spill optional payload capture value" {
};
_ = async S.foo();
resume S.global_frame;
- expect(S.global_int == 1237);
+ try expect(S.global_int == 1237);
}
test "handle defer interfering with return value spill" {
@@ -1449,16 +1449,16 @@ test "handle defer interfering with return value spill" {
var finished = false;
var baz_happened = false;
- fn doTheTest() void {
+ fn doTheTest() !void {
_ = async testFoo();
resume global_frame1;
resume global_frame2;
- expect(baz_happened);
- expect(finished);
+ try expect(baz_happened);
+ try expect(finished);
}
fn testFoo() void {
- expectError(error.Bad, foo());
+ expectError(error.Bad, foo()) catch @panic("test failure");
finished = true;
}
@@ -1479,7 +1479,7 @@ test "handle defer interfering with return value spill" {
baz_happened = true;
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "take address of temporary async frame" {
@@ -1487,14 +1487,14 @@ test "take address of temporary async frame" {
var global_frame: anyframe = undefined;
var finished = false;
- fn doTheTest() void {
+ fn doTheTest() !void {
_ = async asyncDoTheTest();
resume global_frame;
- expect(finished);
+ try expect(finished);
}
fn asyncDoTheTest() void {
- expect(finishIt(&async foo(10)) == 1245);
+ expect(finishIt(&async foo(10)) == 1245) catch @panic("test failure");
finished = true;
}
@@ -1508,16 +1508,16 @@ test "take address of temporary async frame" {
return (await frame) + 1;
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "nosuspend await" {
const S = struct {
var finished = false;
- fn doTheTest() void {
+ fn doTheTest() !void {
var frame = async foo(false);
- expect(nosuspend await frame == 42);
+ try expect(nosuspend await frame == 42);
finished = true;
}
@@ -1528,8 +1528,8 @@ test "nosuspend await" {
return 42;
}
};
- S.doTheTest();
- expect(S.finished);
+ try S.doTheTest();
+ try expect(S.finished);
}
test "nosuspend on function calls" {
@@ -1544,8 +1544,8 @@ test "nosuspend on function calls" {
return S0{};
}
};
- expectEqual(@as(i32, 42), nosuspend S1.c().b);
- expectEqual(@as(i32, 42), (try nosuspend S1.d()).b);
+ try expectEqual(@as(i32, 42), nosuspend S1.c().b);
+ try expectEqual(@as(i32, 42), (try nosuspend S1.d()).b);
}
test "nosuspend on async function calls" {
@@ -1561,9 +1561,9 @@ test "nosuspend on async function calls" {
}
};
var frame_c = nosuspend async S1.c();
- expectEqual(@as(i32, 42), (await frame_c).b);
+ try expectEqual(@as(i32, 42), (await frame_c).b);
var frame_d = nosuspend async S1.d();
- expectEqual(@as(i32, 42), (try await frame_d).b);
+ try expectEqual(@as(i32, 42), (try await frame_d).b);
}
// test "resume nosuspend async function calls" {
@@ -1582,10 +1582,10 @@ test "nosuspend on async function calls" {
// };
// var frame_c = nosuspend async S1.c();
// resume frame_c;
-// expectEqual(@as(i32, 42), (await frame_c).b);
+// try expectEqual(@as(i32, 42), (await frame_c).b);
// var frame_d = nosuspend async S1.d();
// resume frame_d;
-// expectEqual(@as(i32, 42), (try await frame_d).b);
+// try expectEqual(@as(i32, 42), (try await frame_d).b);
// }
test "nosuspend resume async function calls" {
@@ -1604,10 +1604,10 @@ test "nosuspend resume async function calls" {
};
var frame_c = async S1.c();
nosuspend resume frame_c;
- expectEqual(@as(i32, 42), (await frame_c).b);
+ try expectEqual(@as(i32, 42), (await frame_c).b);
var frame_d = async S1.d();
nosuspend resume frame_d;
- expectEqual(@as(i32, 42), (try await frame_d).b);
+ try expectEqual(@as(i32, 42), (try await frame_d).b);
}
test "avoid forcing frame alignment resolution implicit cast to *c_void" {
@@ -1623,7 +1623,7 @@ test "avoid forcing frame alignment resolution implicit cast to *c_void" {
};
var frame = async S.foo();
resume @ptrCast(anyframe->bool, @alignCast(@alignOf(@Frame(S.foo)), S.x));
- expect(nosuspend await frame);
+ try expect(nosuspend await frame);
}
test "@asyncCall with pass-by-value arguments" {
@@ -1638,9 +1638,9 @@ test "@asyncCall with pass-by-value arguments" {
pub fn f(_fill0: u64, s: ST, _fill1: u64, a: AT, _fill2: u64) callconv(.Async) void {
// Check that the array and struct arguments passed by value don't
// end up overflowing the adjacent fields in the frame structure.
- expectEqual(F0, _fill0);
- expectEqual(F1, _fill1);
- expectEqual(F2, _fill2);
+ expectEqual(F0, _fill0) catch @panic("test failure");
+ expectEqual(F1, _fill1) catch @panic("test failure");
+ expectEqual(F2, _fill2) catch @panic("test failure");
}
};
@@ -1664,8 +1664,8 @@ test "@asyncCall with arguments having non-standard alignment" {
pub fn f(_fill0: u32, s: struct { x: u64 align(16) }, _fill1: u64) callconv(.Async) void {
// The compiler inserts extra alignment for s, check that the
// generated code picks the right slot for fill1.
- expectEqual(F0, _fill0);
- expectEqual(F1, _fill1);
+ expectEqual(F0, _fill0) catch @panic("test failure");
+ expectEqual(F1, _fill1) catch @panic("test failure");
}
};
diff --git a/test/stage1/behavior/atomics.zig b/test/stage1/behavior/atomics.zig
index d49ca730e6..74a161b6fc 100644
--- a/test/stage1/behavior/atomics.zig
+++ b/test/stage1/behavior/atomics.zig
@@ -4,25 +4,25 @@ const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");
test "cmpxchg" {
- testCmpxchg();
- comptime testCmpxchg();
+ try testCmpxchg();
+ comptime try testCmpxchg();
}
-fn testCmpxchg() void {
+fn testCmpxchg() !void {
var x: i32 = 1234;
if (@cmpxchgWeak(i32, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
- expect(x1 == 1234);
+ try expect(x1 == 1234);
} else {
@panic("cmpxchg should have failed");
}
while (@cmpxchgWeak(i32, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
- expect(x1 == 1234);
+ try expect(x1 == 1234);
}
- expect(x == 5678);
+ try expect(x == 5678);
- expect(@cmpxchgStrong(i32, &x, 5678, 42, .SeqCst, .SeqCst) == null);
- expect(x == 42);
+ try expect(@cmpxchgStrong(i32, &x, 5678, 42, .SeqCst, .SeqCst) == null);
+ try expect(x == 42);
}
test "fence" {
@@ -33,25 +33,25 @@ test "fence" {
test "atomicrmw and atomicload" {
var data: u8 = 200;
- testAtomicRmw(&data);
- expect(data == 42);
- testAtomicLoad(&data);
+ try testAtomicRmw(&data);
+ try expect(data == 42);
+ try testAtomicLoad(&data);
}
-fn testAtomicRmw(ptr: *u8) void {
+fn testAtomicRmw(ptr: *u8) !void {
const prev_value = @atomicRmw(u8, ptr, .Xchg, 42, .SeqCst);
- expect(prev_value == 200);
+ try expect(prev_value == 200);
comptime {
var x: i32 = 1234;
const y: i32 = 12345;
- expect(@atomicLoad(i32, &x, .SeqCst) == 1234);
- expect(@atomicLoad(i32, &y, .SeqCst) == 12345);
+ try expect(@atomicLoad(i32, &x, .SeqCst) == 1234);
+ try expect(@atomicLoad(i32, &y, .SeqCst) == 12345);
}
}
-fn testAtomicLoad(ptr: *u8) void {
+fn testAtomicLoad(ptr: *u8) !void {
const x = @atomicLoad(u8, ptr, .SeqCst);
- expect(x == 42);
+ try expect(x == 42);
}
test "cmpxchg with ptr" {
@@ -60,18 +60,18 @@ test "cmpxchg with ptr" {
var data3: i32 = 9101;
var x: *i32 = &data1;
if (@cmpxchgWeak(*i32, &x, &data2, &data3, .SeqCst, .SeqCst)) |x1| {
- expect(x1 == &data1);
+ try expect(x1 == &data1);
} else {
@panic("cmpxchg should have failed");
}
while (@cmpxchgWeak(*i32, &x, &data1, &data3, .SeqCst, .SeqCst)) |x1| {
- expect(x1 == &data1);
+ try expect(x1 == &data1);
}
- expect(x == &data3);
+ try expect(x == &data3);
- expect(@cmpxchgStrong(*i32, &x, &data3, &data2, .SeqCst, .SeqCst) == null);
- expect(x == &data2);
+ try expect(@cmpxchgStrong(*i32, &x, &data3, &data2, .SeqCst, .SeqCst) == null);
+ try expect(x == &data2);
}
// TODO this test is disabled until this issue is resolved:
@@ -81,18 +81,18 @@ test "cmpxchg with ptr" {
//test "128-bit cmpxchg" {
// var x: u128 align(16) = 1234; // TODO: https://github.com/ziglang/zig/issues/2987
// if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
-// expect(x1 == 1234);
+// try expect(x1 == 1234);
// } else {
// @panic("cmpxchg should have failed");
// }
//
// while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
-// expect(x1 == 1234);
+// try expect(x1 == 1234);
// }
-// expect(x == 5678);
+// try expect(x == 5678);
//
-// expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null);
-// expect(x == 42);
+// try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null);
+// try expect(x == 42);
//}
test "cmpxchg with ignored result" {
@@ -101,14 +101,14 @@ test "cmpxchg with ignored result" {
_ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);
- expectEqual(@as(i32, 5678), x);
+ try expectEqual(@as(i32, 5678), x);
}
var a_global_variable = @as(u32, 1234);
test "cmpxchg on a global variable" {
_ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);
- expectEqual(@as(u32, 42), a_global_variable);
+ try expectEqual(@as(u32, 42), a_global_variable);
}
test "atomic load and rmw with enum" {
@@ -119,33 +119,33 @@ test "atomic load and rmw with enum" {
};
var x = Value.a;
- expect(@atomicLoad(Value, &x, .SeqCst) != .b);
+ try expect(@atomicLoad(Value, &x, .SeqCst) != .b);
_ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst);
- expect(@atomicLoad(Value, &x, .SeqCst) == .c);
- expect(@atomicLoad(Value, &x, .SeqCst) != .a);
- expect(@atomicLoad(Value, &x, .SeqCst) != .b);
+ try expect(@atomicLoad(Value, &x, .SeqCst) == .c);
+ try expect(@atomicLoad(Value, &x, .SeqCst) != .a);
+ try expect(@atomicLoad(Value, &x, .SeqCst) != .b);
}
test "atomic store" {
var x: u32 = 0;
@atomicStore(u32, &x, 1, .SeqCst);
- expect(@atomicLoad(u32, &x, .SeqCst) == 1);
+ try expect(@atomicLoad(u32, &x, .SeqCst) == 1);
@atomicStore(u32, &x, 12345678, .SeqCst);
- expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
+ try expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
}
test "atomic store comptime" {
- comptime testAtomicStore();
- testAtomicStore();
+ comptime try testAtomicStore();
+ try testAtomicStore();
}
-fn testAtomicStore() void {
+fn testAtomicStore() !void {
var x: u32 = 0;
@atomicStore(u32, &x, 1, .SeqCst);
- expect(@atomicLoad(u32, &x, .SeqCst) == 1);
+ try expect(@atomicLoad(u32, &x, .SeqCst) == 1);
@atomicStore(u32, &x, 12345678, .SeqCst);
- expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
+ try expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
}
test "atomicrmw with floats" {
@@ -154,66 +154,66 @@ test "atomicrmw with floats" {
.aarch64, .arm, .thumb, .riscv64 => return error.SkipZigTest,
else => {},
}
- testAtomicRmwFloat();
- comptime testAtomicRmwFloat();
+ try testAtomicRmwFloat();
+ comptime try testAtomicRmwFloat();
}
-fn testAtomicRmwFloat() void {
+fn testAtomicRmwFloat() !void {
var x: f32 = 0;
- expect(x == 0);
+ try expect(x == 0);
_ = @atomicRmw(f32, &x, .Xchg, 1, .SeqCst);
- expect(x == 1);
+ try expect(x == 1);
_ = @atomicRmw(f32, &x, .Add, 5, .SeqCst);
- expect(x == 6);
+ try expect(x == 6);
_ = @atomicRmw(f32, &x, .Sub, 2, .SeqCst);
- expect(x == 4);
+ try expect(x == 4);
}
test "atomicrmw with ints" {
- testAtomicRmwInt();
- comptime testAtomicRmwInt();
+ try testAtomicRmwInt();
+ comptime try testAtomicRmwInt();
}
-fn testAtomicRmwInt() void {
+fn testAtomicRmwInt() !void {
var x: u8 = 1;
var res = @atomicRmw(u8, &x, .Xchg, 3, .SeqCst);
- expect(x == 3 and res == 1);
+ try expect(x == 3 and res == 1);
_ = @atomicRmw(u8, &x, .Add, 3, .SeqCst);
- expect(x == 6);
+ try expect(x == 6);
_ = @atomicRmw(u8, &x, .Sub, 1, .SeqCst);
- expect(x == 5);
+ try expect(x == 5);
_ = @atomicRmw(u8, &x, .And, 4, .SeqCst);
- expect(x == 4);
+ try expect(x == 4);
_ = @atomicRmw(u8, &x, .Nand, 4, .SeqCst);
- expect(x == 0xfb);
+ try expect(x == 0xfb);
_ = @atomicRmw(u8, &x, .Or, 6, .SeqCst);
- expect(x == 0xff);
+ try expect(x == 0xff);
_ = @atomicRmw(u8, &x, .Xor, 2, .SeqCst);
- expect(x == 0xfd);
+ try expect(x == 0xfd);
_ = @atomicRmw(u8, &x, .Max, 1, .SeqCst);
- expect(x == 0xfd);
+ try expect(x == 0xfd);
_ = @atomicRmw(u8, &x, .Min, 1, .SeqCst);
- expect(x == 1);
+ try expect(x == 1);
}
test "atomics with different types" {
- testAtomicsWithType(bool, true, false);
+ try testAtomicsWithType(bool, true, false);
inline for (.{ u1, i5, u15 }) |T| {
var x: T = 0;
- testAtomicsWithType(T, 0, 1);
+ try testAtomicsWithType(T, 0, 1);
}
- testAtomicsWithType(u0, 0, 0);
- testAtomicsWithType(i0, 0, 0);
+ try testAtomicsWithType(u0, 0, 0);
+ try testAtomicsWithType(i0, 0, 0);
}
-fn testAtomicsWithType(comptime T: type, a: T, b: T) void {
+fn testAtomicsWithType(comptime T: type, a: T, b: T) !void {
var x: T = b;
@atomicStore(T, &x, a, .SeqCst);
- expect(x == a);
- expect(@atomicLoad(T, &x, .SeqCst) == a);
- expect(@atomicRmw(T, &x, .Xchg, b, .SeqCst) == a);
- expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst) == null);
+ try expect(x == a);
+ try expect(@atomicLoad(T, &x, .SeqCst) == a);
+ try expect(@atomicRmw(T, &x, .Xchg, b, .SeqCst) == a);
+ try expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst) == null);
if (@sizeOf(T) != 0)
- expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst).? == a);
+ try expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst).? == a);
}
diff --git a/test/stage1/behavior/await_struct.zig b/test/stage1/behavior/await_struct.zig
index 328f8f87fd..9e01aecc8c 100644
--- a/test/stage1/behavior/await_struct.zig
+++ b/test/stage1/behavior/await_struct.zig
@@ -15,8 +15,8 @@ test "coroutine await struct" {
await_seq('f');
resume await_a_promise;
await_seq('i');
- expect(await_final_result.x == 1234);
- expect(std.mem.eql(u8, &await_points, "abcdefghi"));
+ try expect(await_final_result.x == 1234);
+ try expect(std.mem.eql(u8, &await_points, "abcdefghi"));
}
fn await_amain() callconv(.Async) void {
await_seq('b');
diff --git a/test/stage1/behavior/bit_shifting.zig b/test/stage1/behavior/bit_shifting.zig
index 746d598237..a58026e88d 100644
--- a/test/stage1/behavior/bit_shifting.zig
+++ b/test/stage1/behavior/bit_shifting.zig
@@ -3,8 +3,8 @@ const expect = std.testing.expect;
fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
const key_bits = @typeInfo(Key).Int.bits;
- expect(Key == std.meta.Int(.unsigned, key_bits));
- expect(key_bits >= mask_bit_count);
+ std.debug.assert(Key == std.meta.Int(.unsigned, key_bits));
+ std.debug.assert(key_bits >= mask_bit_count);
const shard_key_bits = mask_bit_count;
const ShardKey = std.meta.Int(.unsigned, mask_bit_count);
const shift_amount = key_bits - shard_key_bits;
@@ -61,31 +61,31 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt
test "sharded table" {
// realistic 16-way sharding
- testShardedTable(u32, 4, 8);
+ try testShardedTable(u32, 4, 8);
- testShardedTable(u5, 0, 32); // ShardKey == u0
- testShardedTable(u5, 2, 32);
- testShardedTable(u5, 5, 32);
+ try testShardedTable(u5, 0, 32); // ShardKey == u0
+ try testShardedTable(u5, 2, 32);
+ try testShardedTable(u5, 5, 32);
- testShardedTable(u1, 0, 2);
- testShardedTable(u1, 1, 2); // this does u1 >> u0
+ try testShardedTable(u1, 0, 2);
+ try testShardedTable(u1, 1, 2); // this does u1 >> u0
- testShardedTable(u0, 0, 1);
+ try testShardedTable(u0, 0, 1);
}
-fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime node_count: comptime_int) void {
+fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime node_count: comptime_int) !void {
const Table = ShardedTable(Key, mask_bit_count, void);
var table = Table.create();
var node_buffer: [node_count]Table.Node = undefined;
for (node_buffer) |*node, i| {
const key = @intCast(Key, i);
- expect(table.get(key) == null);
+ try expect(table.get(key) == null);
node.init(key, {});
table.put(node);
}
for (node_buffer) |*node, i| {
- expect(table.get(@intCast(Key, i)) == node);
+ try expect(table.get(@intCast(Key, i)) == node);
}
}
@@ -93,9 +93,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c
test "comptime shr of BigInt" {
comptime {
var n0 = 0xdeadbeef0000000000000000;
- std.debug.assert(n0 >> 64 == 0xdeadbeef);
+ try expect(n0 >> 64 == 0xdeadbeef);
var n1 = 17908056155735594659;
- std.debug.assert(n1 >> 64 == 0);
+ try expect(n1 >> 64 == 0);
}
}
diff --git a/test/stage1/behavior/bitcast.zig b/test/stage1/behavior/bitcast.zig
index 2a86044dc1..a725d5cc8b 100644
--- a/test/stage1/behavior/bitcast.zig
+++ b/test/stage1/behavior/bitcast.zig
@@ -5,13 +5,13 @@ const expectEqual = std.testing.expectEqual;
const maxInt = std.math.maxInt;
test "@bitCast i32 -> u32" {
- testBitCast_i32_u32();
- comptime testBitCast_i32_u32();
+ try testBitCast_i32_u32();
+ comptime try testBitCast_i32_u32();
}
-fn testBitCast_i32_u32() void {
- expect(conv(-1) == maxInt(u32));
- expect(conv2(maxInt(u32)) == -1);
+fn testBitCast_i32_u32() !void {
+ try expect(conv(-1) == maxInt(u32));
+ try expect(conv2(maxInt(u32)) == -1);
}
fn conv(x: i32) u32 {
@@ -26,15 +26,15 @@ test "@bitCast extern enum to its integer type" {
A,
B,
- fn testBitCastExternEnum() void {
+ fn testBitCastExternEnum() !void {
var SOCK_DGRAM = @This().B;
var sock_dgram = @bitCast(c_int, SOCK_DGRAM);
- expect(sock_dgram == 1);
+ try expect(sock_dgram == 1);
}
};
- SOCK.testBitCastExternEnum();
- comptime SOCK.testBitCastExternEnum();
+ try SOCK.testBitCastExternEnum();
+ comptime try SOCK.testBitCastExternEnum();
}
test "@bitCast packed structs at runtime and comptime" {
@@ -47,25 +47,25 @@ test "@bitCast packed structs at runtime and comptime" {
quarter4: u4,
};
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var full = Full{ .number = 0x1234 };
var two_halves = @bitCast(Divided, full);
switch (builtin.endian) {
builtin.Endian.Big => {
- expect(two_halves.half1 == 0x12);
- expect(two_halves.quarter3 == 0x3);
- expect(two_halves.quarter4 == 0x4);
+ try expect(two_halves.half1 == 0x12);
+ try expect(two_halves.quarter3 == 0x3);
+ try expect(two_halves.quarter4 == 0x4);
},
builtin.Endian.Little => {
- expect(two_halves.half1 == 0x34);
- expect(two_halves.quarter3 == 0x2);
- expect(two_halves.quarter4 == 0x1);
+ try expect(two_halves.half1 == 0x34);
+ try expect(two_halves.quarter3 == 0x2);
+ try expect(two_halves.quarter4 == 0x1);
},
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "@bitCast extern structs at runtime and comptime" {
@@ -77,23 +77,23 @@ test "@bitCast extern structs at runtime and comptime" {
half2: u8,
};
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var full = Full{ .number = 0x1234 };
var two_halves = @bitCast(TwoHalves, full);
switch (builtin.endian) {
builtin.Endian.Big => {
- expect(two_halves.half1 == 0x12);
- expect(two_halves.half2 == 0x34);
+ try expect(two_halves.half1 == 0x12);
+ try expect(two_halves.half2 == 0x34);
},
builtin.Endian.Little => {
- expect(two_halves.half1 == 0x34);
- expect(two_halves.half2 == 0x12);
+ try expect(two_halves.half1 == 0x34);
+ try expect(two_halves.half2 == 0x12);
},
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "bitcast packed struct to integer and back" {
@@ -102,35 +102,35 @@ test "bitcast packed struct to integer and back" {
level: u7,
};
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var move = LevelUpMove{ .move_id = 1, .level = 2 };
var v = @bitCast(u16, move);
var back_to_a_move = @bitCast(LevelUpMove, v);
- expect(back_to_a_move.move_id == 1);
- expect(back_to_a_move.level == 2);
+ try expect(back_to_a_move.move_id == 1);
+ try expect(back_to_a_move.level == 2);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "implicit cast to error union by returning" {
const S = struct {
- fn entry() void {
- expect((func(-1) catch unreachable) == maxInt(u64));
+ fn entry() !void {
+ try expect((func(-1) catch unreachable) == maxInt(u64));
}
pub fn func(sz: i64) anyerror!u64 {
return @bitCast(u64, sz);
}
};
- S.entry();
- comptime S.entry();
+ try S.entry();
+ comptime try S.entry();
}
// issue #3010: compiler segfault
test "bitcast literal [4]u8 param to u32" {
const ip = @bitCast(u32, [_]u8{ 255, 255, 255, 255 });
- expect(ip == maxInt(u32));
+ try expect(ip == maxInt(u32));
}
test "bitcast packed struct literal to byte" {
@@ -138,14 +138,14 @@ test "bitcast packed struct literal to byte" {
value: u8,
};
const casted = @bitCast(u8, Foo{ .value = 0xF });
- expect(casted == 0xf);
+ try expect(casted == 0xf);
}
test "comptime bitcast used in expression has the correct type" {
const Foo = packed struct {
value: u8,
};
- expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf);
+ try expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf);
}
test "bitcast result to _" {
@@ -154,43 +154,43 @@ test "bitcast result to _" {
test "nested bitcast" {
const S = struct {
- fn moo(x: isize) void {
- @import("std").testing.expectEqual(@intCast(isize, 42), x);
+ fn moo(x: isize) !void {
+ try @import("std").testing.expectEqual(@intCast(isize, 42), x);
}
- fn foo(x: isize) void {
- @This().moo(
+ fn foo(x: isize) !void {
+ try @This().moo(
@bitCast(isize, if (x != 0) @bitCast(usize, x) else @bitCast(usize, x)),
);
}
};
- S.foo(42);
- comptime S.foo(42);
+ try S.foo(42);
+ comptime try S.foo(42);
}
test "bitcast passed as tuple element" {
const S = struct {
- fn foo(args: anytype) void {
- comptime expect(@TypeOf(args[0]) == f32);
- expect(args[0] == 12.34);
+ fn foo(args: anytype) !void {
+ comptime try expect(@TypeOf(args[0]) == f32);
+ try expect(args[0] == 12.34);
}
};
- S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))});
+ try S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))});
}
test "triple level result location with bitcast sandwich passed as tuple element" {
const S = struct {
- fn foo(args: anytype) void {
- comptime expect(@TypeOf(args[0]) == f64);
- expect(args[0] > 12.33 and args[0] < 12.35);
+ fn foo(args: anytype) !void {
+ comptime try expect(@TypeOf(args[0]) == f64);
+ try expect(args[0] > 12.33 and args[0] < 12.35);
}
};
- S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))});
+ try S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))});
}
test "bitcast generates a temporary value" {
var y = @as(u16, 0x55AA);
const x = @bitCast(u16, @bitCast([2]u8, y));
- expectEqual(y, x);
+ try expectEqual(y, x);
}
diff --git a/test/stage1/behavior/bitreverse.zig b/test/stage1/behavior/bitreverse.zig
index 8de2d5d2ca..14a7d1cdbe 100644
--- a/test/stage1/behavior/bitreverse.zig
+++ b/test/stage1/behavior/bitreverse.zig
@@ -3,67 +3,67 @@ const expect = std.testing.expect;
const minInt = std.math.minInt;
test "@bitReverse" {
- comptime testBitReverse();
- testBitReverse();
+ comptime try testBitReverse();
+ try testBitReverse();
}
-fn testBitReverse() void {
+fn testBitReverse() !void {
// using comptime_ints, unsigned
- expect(@bitReverse(u0, 0) == 0);
- expect(@bitReverse(u5, 0x12) == 0x9);
- expect(@bitReverse(u8, 0x12) == 0x48);
- expect(@bitReverse(u16, 0x1234) == 0x2c48);
- expect(@bitReverse(u24, 0x123456) == 0x6a2c48);
- expect(@bitReverse(u32, 0x12345678) == 0x1e6a2c48);
- expect(@bitReverse(u40, 0x123456789a) == 0x591e6a2c48);
- expect(@bitReverse(u48, 0x123456789abc) == 0x3d591e6a2c48);
- expect(@bitReverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48);
- expect(@bitReverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48);
- expect(@bitReverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48);
+ try expect(@bitReverse(u0, 0) == 0);
+ try expect(@bitReverse(u5, 0x12) == 0x9);
+ try expect(@bitReverse(u8, 0x12) == 0x48);
+ try expect(@bitReverse(u16, 0x1234) == 0x2c48);
+ try expect(@bitReverse(u24, 0x123456) == 0x6a2c48);
+ try expect(@bitReverse(u32, 0x12345678) == 0x1e6a2c48);
+ try expect(@bitReverse(u40, 0x123456789a) == 0x591e6a2c48);
+ try expect(@bitReverse(u48, 0x123456789abc) == 0x3d591e6a2c48);
+ try expect(@bitReverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48);
+ try expect(@bitReverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48);
+ try expect(@bitReverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48);
// using runtime uints, unsigned
var num0: u0 = 0;
- expect(@bitReverse(u0, num0) == 0);
+ try expect(@bitReverse(u0, num0) == 0);
var num5: u5 = 0x12;
- expect(@bitReverse(u5, num5) == 0x9);
+ try expect(@bitReverse(u5, num5) == 0x9);
var num8: u8 = 0x12;
- expect(@bitReverse(u8, num8) == 0x48);
+ try expect(@bitReverse(u8, num8) == 0x48);
var num16: u16 = 0x1234;
- expect(@bitReverse(u16, num16) == 0x2c48);
+ try expect(@bitReverse(u16, num16) == 0x2c48);
var num24: u24 = 0x123456;
- expect(@bitReverse(u24, num24) == 0x6a2c48);
+ try expect(@bitReverse(u24, num24) == 0x6a2c48);
var num32: u32 = 0x12345678;
- expect(@bitReverse(u32, num32) == 0x1e6a2c48);
+ try expect(@bitReverse(u32, num32) == 0x1e6a2c48);
var num40: u40 = 0x123456789a;
- expect(@bitReverse(u40, num40) == 0x591e6a2c48);
+ try expect(@bitReverse(u40, num40) == 0x591e6a2c48);
var num48: u48 = 0x123456789abc;
- expect(@bitReverse(u48, num48) == 0x3d591e6a2c48);
+ try expect(@bitReverse(u48, num48) == 0x3d591e6a2c48);
var num56: u56 = 0x123456789abcde;
- expect(@bitReverse(u56, num56) == 0x7b3d591e6a2c48);
+ try expect(@bitReverse(u56, num56) == 0x7b3d591e6a2c48);
var num64: u64 = 0x123456789abcdef1;
- expect(@bitReverse(u64, num64) == 0x8f7b3d591e6a2c48);
+ try expect(@bitReverse(u64, num64) == 0x8f7b3d591e6a2c48);
var num128: u128 = 0x123456789abcdef11121314151617181;
- expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
+ try expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
// using comptime_ints, signed, positive
- expect(@bitReverse(u8, @as(u8, 0)) == 0);
- expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));
- expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48)));
- expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48)));
- expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48)));
- expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48)));
- expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48)));
- expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));
- expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));
- expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
+ try expect(@bitReverse(u8, @as(u8, 0)) == 0);
+ try expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));
+ try expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48)));
+ try expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48)));
+ try expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48)));
+ try expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48)));
+ try expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48)));
+ try expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));
+ try expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));
+ try expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
// using signed, negative. Compare to runtime ints returned from llvm.
var neg8: i8 = -18;
- expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8));
+ try expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8));
var neg16: i16 = -32694;
- expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16));
+ try expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16));
var neg24: i24 = -6773785;
- expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24));
+ try expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24));
var neg32: i32 = -16773785;
- expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32));
+ try expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32));
}
diff --git a/test/stage1/behavior/bool.zig b/test/stage1/behavior/bool.zig
index ef9383244e..dfa02a6bfd 100644
--- a/test/stage1/behavior/bool.zig
+++ b/test/stage1/behavior/bool.zig
@@ -1,25 +1,25 @@
const expect = @import("std").testing.expect;
test "bool literals" {
- expect(true);
- expect(!false);
+ try expect(true);
+ try expect(!false);
}
test "cast bool to int" {
const t = true;
const f = false;
- expect(@boolToInt(t) == @as(u32, 1));
- expect(@boolToInt(f) == @as(u32, 0));
- nonConstCastBoolToInt(t, f);
+ try expect(@boolToInt(t) == @as(u32, 1));
+ try expect(@boolToInt(f) == @as(u32, 0));
+ try nonConstCastBoolToInt(t, f);
}
-fn nonConstCastBoolToInt(t: bool, f: bool) void {
- expect(@boolToInt(t) == @as(u32, 1));
- expect(@boolToInt(f) == @as(u32, 0));
+fn nonConstCastBoolToInt(t: bool, f: bool) !void {
+ try expect(@boolToInt(t) == @as(u32, 1));
+ try expect(@boolToInt(f) == @as(u32, 0));
}
test "bool cmp" {
- expect(testBoolCmp(true, false) == false);
+ try expect(testBoolCmp(true, false) == false);
}
fn testBoolCmp(a: bool, b: bool) bool {
return a == b;
@@ -30,6 +30,6 @@ const global_t = true;
const not_global_f = !global_f;
const not_global_t = !global_t;
test "compile time bool not" {
- expect(not_global_f);
- expect(!not_global_t);
+ try expect(not_global_f);
+ try expect(!not_global_t);
}
diff --git a/test/stage1/behavior/bugs/1025.zig b/test/stage1/behavior/bugs/1025.zig
index 66e1a2be54..69ee77eea1 100644
--- a/test/stage1/behavior/bugs/1025.zig
+++ b/test/stage1/behavior/bugs/1025.zig
@@ -8,5 +8,5 @@ fn getA() A {
test "bug 1025" {
const a = getA();
- @import("std").testing.expect(a.B == u8);
+ try @import("std").testing.expect(a.B == u8);
}
diff --git a/test/stage1/behavior/bugs/1076.zig b/test/stage1/behavior/bugs/1076.zig
index fa3caf0df8..ab7d468a7b 100644
--- a/test/stage1/behavior/bugs/1076.zig
+++ b/test/stage1/behavior/bugs/1076.zig
@@ -3,21 +3,21 @@ const mem = std.mem;
const expect = std.testing.expect;
test "comptime code should not modify constant data" {
- testCastPtrOfArrayToSliceAndPtr();
- comptime testCastPtrOfArrayToSliceAndPtr();
+ try testCastPtrOfArrayToSliceAndPtr();
+ comptime try testCastPtrOfArrayToSliceAndPtr();
}
-fn testCastPtrOfArrayToSliceAndPtr() void {
+fn testCastPtrOfArrayToSliceAndPtr() !void {
{
var array = "aoeu".*;
const x: [*]u8 = &array;
x[0] += 1;
- expect(mem.eql(u8, array[0..], "boeu"));
+ try expect(mem.eql(u8, array[0..], "boeu"));
}
{
var array: [4]u8 = "aoeu".*;
const x: [*]u8 = &array;
x[0] += 1;
- expect(mem.eql(u8, array[0..], "boeu"));
+ try expect(mem.eql(u8, array[0..], "boeu"));
}
}
diff --git a/test/stage1/behavior/bugs/1120.zig b/test/stage1/behavior/bugs/1120.zig
index dda46e8e1c..cb68f87e8d 100644
--- a/test/stage1/behavior/bugs/1120.zig
+++ b/test/stage1/behavior/bugs/1120.zig
@@ -19,5 +19,5 @@ test "bug 1120" {
1 => &b.a,
else => unreachable,
};
- expect(ptr.* == 2);
+ try expect(ptr.* == 2);
}
diff --git a/test/stage1/behavior/bugs/1277.zig b/test/stage1/behavior/bugs/1277.zig
index 3aa1db2ea0..18e3592a80 100644
--- a/test/stage1/behavior/bugs/1277.zig
+++ b/test/stage1/behavior/bugs/1277.zig
@@ -11,5 +11,5 @@ fn f() i32 {
}
test "don't emit an LLVM global for a const function when it's in an optional in a struct" {
- std.testing.expect(s.f.?() == 1234);
+ try std.testing.expect(s.f.?() == 1234);
}
diff --git a/test/stage1/behavior/bugs/1310.zig b/test/stage1/behavior/bugs/1310.zig
index 788cba5756..a291b217ec 100644
--- a/test/stage1/behavior/bugs/1310.zig
+++ b/test/stage1/behavior/bugs/1310.zig
@@ -20,5 +20,5 @@ fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {
}
test "fixed" {
- expect(agent_callback(undefined, undefined) == 11);
+ try expect(agent_callback(undefined, undefined) == 11);
}
diff --git a/test/stage1/behavior/bugs/1322.zig b/test/stage1/behavior/bugs/1322.zig
index 02ead6afff..e0220a1719 100644
--- a/test/stage1/behavior/bugs/1322.zig
+++ b/test/stage1/behavior/bugs/1322.zig
@@ -13,7 +13,7 @@ const C = struct {};
test "tagged union with all void fields but a meaningful tag" {
var a: A = A{ .b = B{ .c = C{} } };
- std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).c);
+ try std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).c);
a = A{ .b = B.None };
- std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).None);
+ try std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).None);
}
diff --git a/test/stage1/behavior/bugs/1381.zig b/test/stage1/behavior/bugs/1381.zig
index 1d44593990..6a63e8cc5b 100644
--- a/test/stage1/behavior/bugs/1381.zig
+++ b/test/stage1/behavior/bugs/1381.zig
@@ -17,5 +17,5 @@ test "union that needs padding bytes inside an array" {
};
const a = as[0].B;
- std.testing.expect(a.D == 1);
+ try std.testing.expect(a.D == 1);
}
diff --git a/test/stage1/behavior/bugs/1421.zig b/test/stage1/behavior/bugs/1421.zig
index da0ba41680..449ff17cc8 100644
--- a/test/stage1/behavior/bugs/1421.zig
+++ b/test/stage1/behavior/bugs/1421.zig
@@ -10,5 +10,5 @@ const S = struct {
test "functions with return type required to be comptime are generic" {
const ti = S.method();
- expect(@as(builtin.TypeId, ti) == builtin.TypeId.Struct);
+ try expect(@as(builtin.TypeId, ti) == builtin.TypeId.Struct);
}
diff --git a/test/stage1/behavior/bugs/1442.zig b/test/stage1/behavior/bugs/1442.zig
index d5ea3f66fe..5298d34acb 100644
--- a/test/stage1/behavior/bugs/1442.zig
+++ b/test/stage1/behavior/bugs/1442.zig
@@ -7,5 +7,5 @@ const Union = union(enum) {
test "const error union field alignment" {
var union_or_err: anyerror!Union = Union{ .Color = 1234 };
- std.testing.expect((union_or_err catch unreachable).Color == 1234);
+ try std.testing.expect((union_or_err catch unreachable).Color == 1234);
}
diff --git a/test/stage1/behavior/bugs/1486.zig b/test/stage1/behavior/bugs/1486.zig
index 1b8e5ca4a1..cae181a3b9 100644
--- a/test/stage1/behavior/bugs/1486.zig
+++ b/test/stage1/behavior/bugs/1486.zig
@@ -5,6 +5,6 @@ var global: u64 = 123;
test "constant pointer to global variable causes runtime load" {
global = 1234;
- expect(&global == ptr);
- expect(ptr.* == 1234);
+ try expect(&global == ptr);
+ try expect(ptr.* == 1234);
}
diff --git a/test/stage1/behavior/bugs/1607.zig b/test/stage1/behavior/bugs/1607.zig
index ffc1aa85dc..a60905b070 100644
--- a/test/stage1/behavior/bugs/1607.zig
+++ b/test/stage1/behavior/bugs/1607.zig
@@ -3,13 +3,13 @@ const testing = std.testing;
const a = [_]u8{ 1, 2, 3 };
-fn checkAddress(s: []const u8) void {
+fn checkAddress(s: []const u8) !void {
for (s) |*i, j| {
- testing.expect(i == &a[j]);
+ try testing.expect(i == &a[j]);
}
}
test "slices pointing at the same address as global array." {
- checkAddress(&a);
- comptime checkAddress(&a);
+ try checkAddress(&a);
+ comptime try checkAddress(&a);
}
diff --git a/test/stage1/behavior/bugs/1735.zig b/test/stage1/behavior/bugs/1735.zig
index e757b5157c..f3aa6eb9ec 100644
--- a/test/stage1/behavior/bugs/1735.zig
+++ b/test/stage1/behavior/bugs/1735.zig
@@ -42,5 +42,5 @@ const a = struct {
test "intialization" {
var t = a.init();
- std.testing.expect(t.foo.len == 0);
+ try std.testing.expect(t.foo.len == 0);
}
diff --git a/test/stage1/behavior/bugs/1741.zig b/test/stage1/behavior/bugs/1741.zig
index 9882536d38..8873de9b49 100644
--- a/test/stage1/behavior/bugs/1741.zig
+++ b/test/stage1/behavior/bugs/1741.zig
@@ -2,5 +2,5 @@ const std = @import("std");
test "fixed" {
const x: f32 align(128) = 12.34;
- std.testing.expect(@ptrToInt(&x) % 128 == 0);
+ try std.testing.expect(@ptrToInt(&x) % 128 == 0);
}
diff --git a/test/stage1/behavior/bugs/1851.zig b/test/stage1/behavior/bugs/1851.zig
index d6cf17651d..58b23d71d6 100644
--- a/test/stage1/behavior/bugs/1851.zig
+++ b/test/stage1/behavior/bugs/1851.zig
@@ -2,25 +2,25 @@ const std = @import("std");
const expect = std.testing.expect;
test "allocation and looping over 3-byte integer" {
- expect(@sizeOf(u24) == 4);
- expect(@sizeOf([1]u24) == 4);
- expect(@alignOf(u24) == 4);
- expect(@alignOf([1]u24) == 4);
+ try expect(@sizeOf(u24) == 4);
+ try expect(@sizeOf([1]u24) == 4);
+ try expect(@alignOf(u24) == 4);
+ try expect(@alignOf([1]u24) == 4);
var x = try std.testing.allocator.alloc(u24, 2);
defer std.testing.allocator.free(x);
- expect(x.len == 2);
+ try expect(x.len == 2);
x[0] = 0xFFFFFF;
x[1] = 0xFFFFFF;
const bytes = std.mem.sliceAsBytes(x);
- expect(@TypeOf(bytes) == []align(4) u8);
- expect(bytes.len == 8);
+ try expect(@TypeOf(bytes) == []align(4) u8);
+ try expect(bytes.len == 8);
for (bytes) |*b| {
b.* = 0x00;
}
- expect(x[0] == 0x00);
- expect(x[1] == 0x00);
+ try expect(x[0] == 0x00);
+ try expect(x[1] == 0x00);
}
diff --git a/test/stage1/behavior/bugs/2006.zig b/test/stage1/behavior/bugs/2006.zig
index dad78a9ba0..86dab326e0 100644
--- a/test/stage1/behavior/bugs/2006.zig
+++ b/test/stage1/behavior/bugs/2006.zig
@@ -7,6 +7,6 @@ const S = struct {
test "bug 2006" {
var a: S = undefined;
a = S{ .p = undefined };
- expect(@sizeOf(S) != 0);
- expect(@sizeOf(*void) == 0);
+ try expect(@sizeOf(S) != 0);
+ try expect(@sizeOf(*void) == 0);
}
diff --git a/test/stage1/behavior/bugs/2114.zig b/test/stage1/behavior/bugs/2114.zig
index 1034a256d3..1fc7016f44 100644
--- a/test/stage1/behavior/bugs/2114.zig
+++ b/test/stage1/behavior/bugs/2114.zig
@@ -7,13 +7,13 @@ fn ctz(x: anytype) usize {
}
test "fixed" {
- testClz();
- comptime testClz();
+ try testClz();
+ comptime try testClz();
}
-fn testClz() void {
- expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
- expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
- expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
- expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
+fn testClz() !void {
+ try expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
+ try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
+ try expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
+ try expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
}
diff --git a/test/stage1/behavior/bugs/2889.zig b/test/stage1/behavior/bugs/2889.zig
index 4991b56510..473f6c615d 100644
--- a/test/stage1/behavior/bugs/2889.zig
+++ b/test/stage1/behavior/bugs/2889.zig
@@ -27,5 +27,5 @@ fn parseNote() ?i32 {
test "fixed" {
const result = parseNote();
- std.testing.expect(result.? == 9);
+ try std.testing.expect(result.? == 9);
}
diff --git a/test/stage1/behavior/bugs/3007.zig b/test/stage1/behavior/bugs/3007.zig
index b723ebc097..c08be3676a 100644
--- a/test/stage1/behavior/bugs/3007.zig
+++ b/test/stage1/behavior/bugs/3007.zig
@@ -19,5 +19,5 @@ fn get_foo() Foo.FooError!*Foo {
test "fixed" {
default_foo = get_foo() catch null; // This Line
- std.testing.expect(!default_foo.?.free);
+ try std.testing.expect(!default_foo.?.free);
}
diff --git a/test/stage1/behavior/bugs/3046.zig b/test/stage1/behavior/bugs/3046.zig
index b62474f9ba..8ff95f3b96 100644
--- a/test/stage1/behavior/bugs/3046.zig
+++ b/test/stage1/behavior/bugs/3046.zig
@@ -15,5 +15,5 @@ test "fixed" {
some_struct = SomeStruct{
.field = couldFail() catch |_| @as(i32, 0),
};
- expect(some_struct.field == 1);
+ try expect(some_struct.field == 1);
}
diff --git a/test/stage1/behavior/bugs/3112.zig b/test/stage1/behavior/bugs/3112.zig
index 1dfe359d4a..68e86c7fcb 100644
--- a/test/stage1/behavior/bugs/3112.zig
+++ b/test/stage1/behavior/bugs/3112.zig
@@ -7,7 +7,7 @@ const State = struct {
};
fn prev(p: ?State) void {
- expect(p == null);
+ expect(p == null) catch @panic("test failure");
}
test "zig test crash" {
diff --git a/test/stage1/behavior/bugs/3384.zig b/test/stage1/behavior/bugs/3384.zig
index 789b0be516..c45aae5180 100644
--- a/test/stage1/behavior/bugs/3384.zig
+++ b/test/stage1/behavior/bugs/3384.zig
@@ -2,10 +2,10 @@ const std = @import("std");
const expect = std.testing.expect;
test "resolve array slice using builtin" {
- expect(@hasDecl(@This(), "std") == true);
- expect(@hasDecl(@This(), "std"[0..0]) == false);
- expect(@hasDecl(@This(), "std"[0..1]) == false);
- expect(@hasDecl(@This(), "std"[0..2]) == false);
- expect(@hasDecl(@This(), "std"[0..3]) == true);
- expect(@hasDecl(@This(), "std"[0..]) == true);
+ try expect(@hasDecl(@This(), "std") == true);
+ try expect(@hasDecl(@This(), "std"[0..0]) == false);
+ try expect(@hasDecl(@This(), "std"[0..1]) == false);
+ try expect(@hasDecl(@This(), "std"[0..2]) == false);
+ try expect(@hasDecl(@This(), "std"[0..3]) == true);
+ try expect(@hasDecl(@This(), "std"[0..]) == true);
}
diff --git a/test/stage1/behavior/bugs/394.zig b/test/stage1/behavior/bugs/394.zig
index b1f0b6b605..55fec53ea1 100644
--- a/test/stage1/behavior/bugs/394.zig
+++ b/test/stage1/behavior/bugs/394.zig
@@ -14,5 +14,5 @@ test "bug 394 fixed" {
.x = 3,
.y = E{ .B = 1 },
};
- expect(x.x == 3);
+ try expect(x.x == 3);
}
diff --git a/test/stage1/behavior/bugs/421.zig b/test/stage1/behavior/bugs/421.zig
index 748cb3a62d..2da4728067 100644
--- a/test/stage1/behavior/bugs/421.zig
+++ b/test/stage1/behavior/bugs/421.zig
@@ -1,12 +1,12 @@
const expect = @import("std").testing.expect;
test "bitCast to array" {
- comptime testBitCastArray();
- testBitCastArray();
+ comptime try testBitCastArray();
+ try testBitCastArray();
}
-fn testBitCastArray() void {
- expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef);
+fn testBitCastArray() !void {
+ try expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef);
}
fn extractOne64(a: u128) u64 {
diff --git a/test/stage1/behavior/bugs/4328.zig b/test/stage1/behavior/bugs/4328.zig
index 98ab7bd155..76c3e788fd 100644
--- a/test/stage1/behavior/bugs/4328.zig
+++ b/test/stage1/behavior/bugs/4328.zig
@@ -25,14 +25,14 @@ test "Extern function calls in @TypeOf" {
return 1;
}
- fn doTheTest() void {
- expectEqual(c_int, @TypeOf(test_fn_1(0, 42)));
- expectEqual(c_short, @TypeOf(test_fn_2(0)));
+ fn doTheTest() !void {
+ try expectEqual(c_int, @TypeOf(test_fn_1(0, 42)));
+ try expectEqual(c_short, @TypeOf(test_fn_2(0)));
}
};
- Test.doTheTest();
- comptime Test.doTheTest();
+ try Test.doTheTest();
+ comptime try Test.doTheTest();
}
test "Peer resolution of extern function calls in @TypeOf" {
@@ -41,13 +41,13 @@ test "Peer resolution of extern function calls in @TypeOf" {
return 0;
}
- fn doTheTest() void {
- expectEqual(c_long, @TypeOf(test_fn()));
+ fn doTheTest() !void {
+ try expectEqual(c_long, @TypeOf(test_fn()));
}
};
- Test.doTheTest();
- comptime Test.doTheTest();
+ try Test.doTheTest();
+ comptime try Test.doTheTest();
}
test "Extern function calls, dereferences and field access in @TypeOf" {
@@ -60,12 +60,12 @@ test "Extern function calls, dereferences and field access in @TypeOf" {
return 255;
}
- fn doTheTest() void {
- expectEqual(FILE, @TypeOf(test_fn_1(0)));
- expectEqual(u8, @TypeOf(test_fn_2(0)));
+ fn doTheTest() !void {
+ try expectEqual(FILE, @TypeOf(test_fn_1(0)));
+ try expectEqual(u8, @TypeOf(test_fn_2(0)));
}
};
- Test.doTheTest();
- comptime Test.doTheTest();
+ try Test.doTheTest();
+ comptime try Test.doTheTest();
}
diff --git a/test/stage1/behavior/bugs/4560.zig b/test/stage1/behavior/bugs/4560.zig
index 6821527894..682d3f2125 100644
--- a/test/stage1/behavior/bugs/4560.zig
+++ b/test/stage1/behavior/bugs/4560.zig
@@ -8,9 +8,9 @@ test "fixed" {
.max_distance_from_start_index = 456,
},
};
- std.testing.expect(s.a == 1);
- std.testing.expect(s.b.size == 123);
- std.testing.expect(s.b.max_distance_from_start_index == 456);
+ try std.testing.expect(s.a == 1);
+ try std.testing.expect(s.b.size == 123);
+ try std.testing.expect(s.b.max_distance_from_start_index == 456);
}
const S = struct {
diff --git a/test/stage1/behavior/bugs/4769_a.zig b/test/stage1/behavior/bugs/4769_a.zig
index ab0c01417a..8337712ea5 100644
--- a/test/stage1/behavior/bugs/4769_a.zig
+++ b/test/stage1/behavior/bugs/4769_a.zig
@@ -1 +1 @@
-//
\ No newline at end of file
+//
diff --git a/test/stage1/behavior/bugs/4769_b.zig b/test/stage1/behavior/bugs/4769_b.zig
index 23b2513f17..9d0f028e57 100644
--- a/test/stage1/behavior/bugs/4769_b.zig
+++ b/test/stage1/behavior/bugs/4769_b.zig
@@ -1 +1 @@
-//!
\ No newline at end of file
+//!
diff --git a/test/stage1/behavior/bugs/5398.zig b/test/stage1/behavior/bugs/5398.zig
index fdfd0b3698..4921c05703 100644
--- a/test/stage1/behavior/bugs/5398.zig
+++ b/test/stage1/behavior/bugs/5398.zig
@@ -25,7 +25,7 @@ test "assignment of field with padding" {
.emits_shadows = false,
},
};
- testing.expectEqual(false, renderable.material.transparent);
- testing.expectEqual(false, renderable.material.emits_shadows);
- testing.expectEqual(true, renderable.material.render_color);
+ try testing.expectEqual(false, renderable.material.transparent);
+ try testing.expectEqual(false, renderable.material.emits_shadows);
+ try testing.expectEqual(true, renderable.material.render_color);
}
diff --git a/test/stage1/behavior/bugs/5413.zig b/test/stage1/behavior/bugs/5413.zig
index 5ef533a761..fab8e043aa 100644
--- a/test/stage1/behavior/bugs/5413.zig
+++ b/test/stage1/behavior/bugs/5413.zig
@@ -1,6 +1,6 @@
const expect = @import("std").testing.expect;
test "Peer type resolution with string literals and unknown length u8 pointers" {
- expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8);
- expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8);
+ try expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8);
+ try expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8);
}
diff --git a/test/stage1/behavior/bugs/5474.zig b/test/stage1/behavior/bugs/5474.zig
index 88ce96095e..8a0180a799 100644
--- a/test/stage1/behavior/bugs/5474.zig
+++ b/test/stage1/behavior/bugs/5474.zig
@@ -25,33 +25,33 @@ const Box2 = struct {
};
};
-fn doTest() void {
+fn doTest() !void {
// var
{
var box0: Box0 = .{ .items = undefined };
- std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == false);
+ try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == false);
var box1: Box1 = .{ .items = undefined };
- std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == false);
+ try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == false);
var box2: Box2 = .{ .items = undefined };
- std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == false);
+ try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == false);
}
// const
{
const box0: Box0 = .{ .items = undefined };
- std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == true);
+ try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == true);
const box1: Box1 = .{ .items = undefined };
- std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == true);
+ try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == true);
const box2: Box2 = .{ .items = undefined };
- std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == true);
+ try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == true);
}
}
test "pointer-to-array constness for zero-size elements" {
- doTest();
- comptime doTest();
+ try doTest();
+ comptime try doTest();
}
diff --git a/test/stage1/behavior/bugs/624.zig b/test/stage1/behavior/bugs/624.zig
index 1eee889a0d..4d52aad693 100644
--- a/test/stage1/behavior/bugs/624.zig
+++ b/test/stage1/behavior/bugs/624.zig
@@ -19,5 +19,5 @@ fn MemoryPool(comptime T: type) type {
test "foo" {
var allocator = ContextAllocator{ .n = 10 };
- expect(allocator.n == 10);
+ try expect(allocator.n == 10);
}
diff --git a/test/stage1/behavior/bugs/6456.zig b/test/stage1/behavior/bugs/6456.zig
index 001e25ec49..8b01b80be8 100644
--- a/test/stage1/behavior/bugs/6456.zig
+++ b/test/stage1/behavior/bugs/6456.zig
@@ -35,9 +35,9 @@ test "issue 6456" {
});
const gen_fields = @typeInfo(T).Struct.fields;
- testing.expectEqual(3, gen_fields.len);
- testing.expectEqualStrings("f1", gen_fields[0].name);
- testing.expectEqualStrings("f2", gen_fields[1].name);
- testing.expectEqualStrings("f3", gen_fields[2].name);
+ try testing.expectEqual(3, gen_fields.len);
+ try testing.expectEqualStrings("f1", gen_fields[0].name);
+ try testing.expectEqualStrings("f2", gen_fields[1].name);
+ try testing.expectEqualStrings("f3", gen_fields[2].name);
}
}
diff --git a/test/stage1/behavior/bugs/655.zig b/test/stage1/behavior/bugs/655.zig
index 3d1bccb183..9ec9f01e69 100644
--- a/test/stage1/behavior/bugs/655.zig
+++ b/test/stage1/behavior/bugs/655.zig
@@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig");
test "function with *const parameter with type dereferenced by namespace" {
const x: other_file.Integer = 1234;
- comptime std.testing.expect(@TypeOf(&x) == *const other_file.Integer);
- foo(&x);
+ comptime try std.testing.expect(@TypeOf(&x) == *const other_file.Integer);
+ try foo(&x);
}
-fn foo(x: *const other_file.Integer) void {
- std.testing.expect(x.* == 1234);
+fn foo(x: *const other_file.Integer) !void {
+ try std.testing.expect(x.* == 1234);
}
diff --git a/test/stage1/behavior/bugs/656.zig b/test/stage1/behavior/bugs/656.zig
index 159ec52d43..178d655f93 100644
--- a/test/stage1/behavior/bugs/656.zig
+++ b/test/stage1/behavior/bugs/656.zig
@@ -10,10 +10,10 @@ const Value = struct {
};
test "optional if after an if in a switch prong of a switch with 2 prongs in an else" {
- foo(false, true);
+ try foo(false, true);
}
-fn foo(a: bool, b: bool) void {
+fn foo(a: bool, b: bool) !void {
var prefix_op = PrefixOp{
.AddrOf = Value{ .align_expr = 1234 },
};
@@ -22,7 +22,7 @@ fn foo(a: bool, b: bool) void {
PrefixOp.AddrOf => |addr_of_info| {
if (b) {}
if (addr_of_info.align_expr) |align_expr| {
- expect(align_expr == 1234);
+ try expect(align_expr == 1234);
}
},
PrefixOp.Return => {},
diff --git a/test/stage1/behavior/bugs/679.zig b/test/stage1/behavior/bugs/679.zig
index 20b2b7b02a..9b402defca 100644
--- a/test/stage1/behavior/bugs/679.zig
+++ b/test/stage1/behavior/bugs/679.zig
@@ -13,5 +13,5 @@ const Element = struct {
test "false dependency loop in struct definition" {
const listType = ElementList;
var x: listType = 42;
- expect(x == 42);
+ try expect(x == 42);
}
diff --git a/test/stage1/behavior/bugs/6850.zig b/test/stage1/behavior/bugs/6850.zig
index 6759ba79ca..1eb1cd0a24 100644
--- a/test/stage1/behavior/bugs/6850.zig
+++ b/test/stage1/behavior/bugs/6850.zig
@@ -4,7 +4,7 @@ test "lazy sizeof comparison with zero" {
const Empty = struct {};
const T = *Empty;
- std.testing.expect(hasNoBits(T));
+ try std.testing.expect(hasNoBits(T));
}
fn hasNoBits(comptime T: type) bool {
diff --git a/test/stage1/behavior/bugs/7047.zig b/test/stage1/behavior/bugs/7047.zig
index 0704e97b48..a60a7d2bbb 100644
--- a/test/stage1/behavior/bugs/7047.zig
+++ b/test/stage1/behavior/bugs/7047.zig
@@ -15,8 +15,8 @@ fn S(comptime query: U) type {
test "compiler doesn't consider equal unions with different 'type' payload" {
const s1 = S(U{ .T = u32 }).tag();
- std.testing.expectEqual(u32, s1);
+ try std.testing.expectEqual(u32, s1);
const s2 = S(U{ .T = u64 }).tag();
- std.testing.expectEqual(u64, s2);
+ try std.testing.expectEqual(u64, s2);
}
diff --git a/test/stage1/behavior/bugs/718.zig b/test/stage1/behavior/bugs/718.zig
index b5a57b8944..078c3604ee 100644
--- a/test/stage1/behavior/bugs/718.zig
+++ b/test/stage1/behavior/bugs/718.zig
@@ -10,8 +10,8 @@ const Keys = struct {
var keys: Keys = undefined;
test "zero keys with @memset" {
@memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@TypeOf(keys)));
- expect(!keys.up);
- expect(!keys.down);
- expect(!keys.left);
- expect(!keys.right);
+ try expect(!keys.up);
+ try expect(!keys.down);
+ try expect(!keys.left);
+ try expect(!keys.right);
}
diff --git a/test/stage1/behavior/bugs/726.zig b/test/stage1/behavior/bugs/726.zig
index 632d3b1511..364d209e3b 100644
--- a/test/stage1/behavior/bugs/726.zig
+++ b/test/stage1/behavior/bugs/726.zig
@@ -3,7 +3,7 @@ const expect = @import("std").testing.expect;
test "@ptrCast from const to nullable" {
const c: u8 = 4;
var x: ?*const u8 = @ptrCast(?*const u8, &c);
- expect(x.?.* == 4);
+ try expect(x.?.* == 4);
}
test "@ptrCast from var in empty struct to nullable" {
@@ -11,5 +11,5 @@ test "@ptrCast from var in empty struct to nullable" {
var c: u8 = 4;
};
var x: ?*const u8 = @ptrCast(?*const u8, &container.c);
- expect(x.?.* == 4);
+ try expect(x.?.* == 4);
}
diff --git a/test/stage1/behavior/bugs/920.zig b/test/stage1/behavior/bugs/920.zig
index 72854956a1..b148fce578 100644
--- a/test/stage1/behavior/bugs/920.zig
+++ b/test/stage1/behavior/bugs/920.zig
@@ -60,6 +60,6 @@ test "bug 920 fixed" {
};
for (NormalDist1.f) |_, i| {
- std.testing.expectEqual(NormalDist1.f[i], NormalDist.f[i]);
+ try std.testing.expectEqual(NormalDist1.f[i], NormalDist.f[i]);
}
}
diff --git a/test/stage1/behavior/byteswap.zig b/test/stage1/behavior/byteswap.zig
index c6d658a8a2..5afb9be0ec 100644
--- a/test/stage1/behavior/byteswap.zig
+++ b/test/stage1/behavior/byteswap.zig
@@ -3,39 +3,39 @@ const expect = std.testing.expect;
test "@byteSwap integers" {
const ByteSwapIntTest = struct {
- fn run() void {
- t(u0, 0, 0);
- t(u8, 0x12, 0x12);
- t(u16, 0x1234, 0x3412);
- t(u24, 0x123456, 0x563412);
- t(u32, 0x12345678, 0x78563412);
- t(u40, 0x123456789a, 0x9a78563412);
- t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));
- t(u56, 0x123456789abcde, 0xdebc9a78563412);
- t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);
- t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);
+ fn run() !void {
+ try t(u0, 0, 0);
+ try t(u8, 0x12, 0x12);
+ try t(u16, 0x1234, 0x3412);
+ try t(u24, 0x123456, 0x563412);
+ try t(u32, 0x12345678, 0x78563412);
+ try t(u40, 0x123456789a, 0x9a78563412);
+ try t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));
+ try t(u56, 0x123456789abcde, 0xdebc9a78563412);
+ try t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);
+ try t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);
- t(u0, @as(u0, 0), 0);
- t(i8, @as(i8, -50), -50);
- t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));
- t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412)));
- t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));
- t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412));
- t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));
- t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412)));
- t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));
- t(
+ try t(u0, @as(u0, 0), 0);
+ try t(i8, @as(i8, -50), -50);
+ try t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));
+ try t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412)));
+ try t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));
+ try t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412));
+ try t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));
+ try t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412)));
+ try t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));
+ try t(
i128,
@bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)),
@bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)),
);
}
- fn t(comptime I: type, input: I, expected_output: I) void {
- std.testing.expectEqual(expected_output, @byteSwap(I, input));
+ fn t(comptime I: type, input: I, expected_output: I) !void {
+ try std.testing.expectEqual(expected_output, @byteSwap(I, input));
}
};
- comptime ByteSwapIntTest.run();
- ByteSwapIntTest.run();
+ comptime try ByteSwapIntTest.run();
+ try ByteSwapIntTest.run();
}
test "@byteSwap vectors" {
@@ -46,10 +46,10 @@ test "@byteSwap vectors" {
if (std.Target.current.cpu.arch == .mipsel or std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
const ByteSwapVectorTest = struct {
- fn run() void {
- t(u8, 2, [_]u8{ 0x12, 0x13 }, [_]u8{ 0x12, 0x13 });
- t(u16, 2, [_]u16{ 0x1234, 0x2345 }, [_]u16{ 0x3412, 0x4523 });
- t(u24, 2, [_]u24{ 0x123456, 0x234567 }, [_]u24{ 0x563412, 0x674523 });
+ fn run() !void {
+ try t(u8, 2, [_]u8{ 0x12, 0x13 }, [_]u8{ 0x12, 0x13 });
+ try t(u16, 2, [_]u16{ 0x1234, 0x2345 }, [_]u16{ 0x3412, 0x4523 });
+ try t(u24, 2, [_]u24{ 0x123456, 0x234567 }, [_]u24{ 0x563412, 0x674523 });
}
fn t(
@@ -57,12 +57,12 @@ test "@byteSwap vectors" {
comptime n: comptime_int,
input: std.meta.Vector(n, I),
expected_vector: std.meta.Vector(n, I),
- ) void {
+ ) !void {
const actual_output: [n]I = @byteSwap(I, input);
const expected_output: [n]I = expected_vector;
- std.testing.expectEqual(expected_output, actual_output);
+ try std.testing.expectEqual(expected_output, actual_output);
}
};
- comptime ByteSwapVectorTest.run();
- ByteSwapVectorTest.run();
+ comptime try ByteSwapVectorTest.run();
+ try ByteSwapVectorTest.run();
}
diff --git a/test/stage1/behavior/byval_arg_var.zig b/test/stage1/behavior/byval_arg_var.zig
index ec3d18a532..a46a9ed0b2 100644
--- a/test/stage1/behavior/byval_arg_var.zig
+++ b/test/stage1/behavior/byval_arg_var.zig
@@ -6,7 +6,7 @@ test "pass string literal byvalue to a generic var param" {
start();
blowUpStack(10);
- std.testing.expect(std.mem.eql(u8, result, "string literal"));
+ try std.testing.expect(std.mem.eql(u8, result, "string literal"));
}
fn start() void {
diff --git a/test/stage1/behavior/call.zig b/test/stage1/behavior/call.zig
index 4d05a83a39..f036c3c7c3 100644
--- a/test/stage1/behavior/call.zig
+++ b/test/stage1/behavior/call.zig
@@ -8,25 +8,25 @@ test "basic invocations" {
return 1234;
}
}.foo;
- expect(@call(.{}, foo, .{}) == 1234);
+ try expect(@call(.{}, foo, .{}) == 1234);
comptime {
// modifiers that allow comptime calls
- expect(@call(.{}, foo, .{}) == 1234);
- expect(@call(.{ .modifier = .no_async }, foo, .{}) == 1234);
- expect(@call(.{ .modifier = .always_tail }, foo, .{}) == 1234);
- expect(@call(.{ .modifier = .always_inline }, foo, .{}) == 1234);
+ try expect(@call(.{}, foo, .{}) == 1234);
+ try expect(@call(.{ .modifier = .no_async }, foo, .{}) == 1234);
+ try expect(@call(.{ .modifier = .always_tail }, foo, .{}) == 1234);
+ try expect(@call(.{ .modifier = .always_inline }, foo, .{}) == 1234);
}
{
// comptime call without comptime keyword
const result = @call(.{ .modifier = .compile_time }, foo, .{}) == 1234;
- comptime expect(result);
+ comptime try expect(result);
}
{
// call of non comptime-known function
var alias_foo = foo;
- expect(@call(.{ .modifier = .no_async }, alias_foo, .{}) == 1234);
- expect(@call(.{ .modifier = .never_tail }, alias_foo, .{}) == 1234);
- expect(@call(.{ .modifier = .never_inline }, alias_foo, .{}) == 1234);
+ try expect(@call(.{ .modifier = .no_async }, alias_foo, .{}) == 1234);
+ try expect(@call(.{ .modifier = .never_tail }, alias_foo, .{}) == 1234);
+ try expect(@call(.{ .modifier = .never_inline }, alias_foo, .{}) == 1234);
}
}
@@ -38,20 +38,20 @@ test "tuple parameters" {
}.add;
var a: i32 = 12;
var b: i32 = 34;
- expect(@call(.{}, add, .{ a, 34 }) == 46);
- expect(@call(.{}, add, .{ 12, b }) == 46);
- expect(@call(.{}, add, .{ a, b }) == 46);
- expect(@call(.{}, add, .{ 12, 34 }) == 46);
- comptime expect(@call(.{}, add, .{ 12, 34 }) == 46);
+ try expect(@call(.{}, add, .{ a, 34 }) == 46);
+ try expect(@call(.{}, add, .{ 12, b }) == 46);
+ try expect(@call(.{}, add, .{ a, b }) == 46);
+ try expect(@call(.{}, add, .{ 12, 34 }) == 46);
+ comptime try expect(@call(.{}, add, .{ 12, 34 }) == 46);
{
const separate_args0 = .{ a, b };
const separate_args1 = .{ a, 34 };
const separate_args2 = .{ 12, 34 };
const separate_args3 = .{ 12, b };
- expect(@call(.{ .modifier = .always_inline }, add, separate_args0) == 46);
- expect(@call(.{ .modifier = .always_inline }, add, separate_args1) == 46);
- expect(@call(.{ .modifier = .always_inline }, add, separate_args2) == 46);
- expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46);
+ try expect(@call(.{ .modifier = .always_inline }, add, separate_args0) == 46);
+ try expect(@call(.{ .modifier = .always_inline }, add, separate_args1) == 46);
+ try expect(@call(.{ .modifier = .always_inline }, add, separate_args2) == 46);
+ try expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46);
}
}
@@ -70,5 +70,5 @@ test "comptime call with bound function as parameter" {
};
var inst: S = undefined;
- expectEqual(?i32, S.ReturnType(inst.call_me_maybe));
+ try expectEqual(?i32, S.ReturnType(inst.call_me_maybe));
}
diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig
index 94ba2636b7..ead02e1de2 100644
--- a/test/stage1/behavior/cast.zig
+++ b/test/stage1/behavior/cast.zig
@@ -8,12 +8,12 @@ test "int to ptr cast" {
const x = @as(usize, 13);
const y = @intToPtr(*u8, x);
const z = @ptrToInt(y);
- expect(z == 13);
+ try expect(z == 13);
}
test "integer literal to pointer cast" {
const vga_mem = @intToPtr(*u16, 0xB8000);
- expect(@ptrToInt(vga_mem) == 0xB8000);
+ try expect(@ptrToInt(vga_mem) == 0xB8000);
}
test "pointer reinterpret const float to int" {
@@ -23,9 +23,9 @@ test "pointer reinterpret const float to int" {
const int_ptr = @ptrCast(*const i32, float_ptr);
const int_val = int_ptr.*;
if (std.builtin.endian == .Little)
- expect(int_val == 0x33333303)
+ try expect(int_val == 0x33333303)
else
- expect(int_val == 0x3fe33333);
+ try expect(int_val == 0x3fe33333);
}
test "implicitly cast indirect pointer to maybe-indirect pointer" {
@@ -49,62 +49,62 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
const p = &s;
const q = &p;
const r = &q;
- expect(42 == S.constConst(q));
- expect(42 == S.maybeConstConst(q));
- expect(42 == S.constConstConst(r));
- expect(42 == S.maybeConstConstConst(r));
+ try expect(42 == S.constConst(q));
+ try expect(42 == S.maybeConstConst(q));
+ try expect(42 == S.constConstConst(r));
+ try expect(42 == S.maybeConstConstConst(r));
}
test "explicit cast from integer to error type" {
- testCastIntToErr(error.ItBroke);
- comptime testCastIntToErr(error.ItBroke);
+ try testCastIntToErr(error.ItBroke);
+ comptime try testCastIntToErr(error.ItBroke);
}
-fn testCastIntToErr(err: anyerror) void {
+fn testCastIntToErr(err: anyerror) !void {
const x = @errorToInt(err);
const y = @intToError(x);
- expect(error.ItBroke == y);
+ try expect(error.ItBroke == y);
}
test "peer resolve arrays of different size to const slice" {
- expect(mem.eql(u8, boolToStr(true), "true"));
- expect(mem.eql(u8, boolToStr(false), "false"));
- comptime expect(mem.eql(u8, boolToStr(true), "true"));
- comptime expect(mem.eql(u8, boolToStr(false), "false"));
+ try expect(mem.eql(u8, boolToStr(true), "true"));
+ try expect(mem.eql(u8, boolToStr(false), "false"));
+ comptime try expect(mem.eql(u8, boolToStr(true), "true"));
+ comptime try expect(mem.eql(u8, boolToStr(false), "false"));
}
fn boolToStr(b: bool) []const u8 {
return if (b) "true" else "false";
}
test "peer resolve array and const slice" {
- testPeerResolveArrayConstSlice(true);
- comptime testPeerResolveArrayConstSlice(true);
+ try testPeerResolveArrayConstSlice(true);
+ comptime try testPeerResolveArrayConstSlice(true);
}
-fn testPeerResolveArrayConstSlice(b: bool) void {
+fn testPeerResolveArrayConstSlice(b: bool) !void {
const value1 = if (b) "aoeu" else @as([]const u8, "zz");
const value2 = if (b) @as([]const u8, "zz") else "aoeu";
- expect(mem.eql(u8, value1, "aoeu"));
- expect(mem.eql(u8, value2, "zz"));
+ try expect(mem.eql(u8, value1, "aoeu"));
+ try expect(mem.eql(u8, value2, "zz"));
}
test "implicitly cast from T to anyerror!?T" {
- castToOptionalTypeError(1);
- comptime castToOptionalTypeError(1);
+ try castToOptionalTypeError(1);
+ comptime try castToOptionalTypeError(1);
}
const A = struct {
a: i32,
};
-fn castToOptionalTypeError(z: i32) void {
+fn castToOptionalTypeError(z: i32) !void {
const x = @as(i32, 1);
const y: anyerror!?i32 = x;
- expect((try y).? == 1);
+ try expect((try y).? == 1);
const f = z;
const g: anyerror!?i32 = f;
const a = A{ .a = z };
const b: anyerror!?A = a;
- expect((b catch unreachable).?.a == 1);
+ try expect((b catch unreachable).?.a == 1);
}
test "implicitly cast from int to anyerror!?T" {
@@ -119,7 +119,7 @@ fn implicitIntLitToOptional() void {
test "return null from fn() anyerror!?&T" {
const a = returnNullFromOptionalTypeErrorRef();
const b = returnNullLitFromOptionalTypeErrorRef();
- expect((try a) == null and (try b) == null);
+ try expect((try a) == null and (try b) == null);
}
fn returnNullFromOptionalTypeErrorRef() anyerror!?*A {
const a: ?*A = null;
@@ -130,11 +130,11 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A {
}
test "peer type resolution: ?T and T" {
- expect(peerTypeTAndOptionalT(true, false).? == 0);
- expect(peerTypeTAndOptionalT(false, false).? == 3);
+ try expect(peerTypeTAndOptionalT(true, false).? == 0);
+ try expect(peerTypeTAndOptionalT(false, false).? == 3);
comptime {
- expect(peerTypeTAndOptionalT(true, false).? == 0);
- expect(peerTypeTAndOptionalT(false, false).? == 3);
+ try expect(peerTypeTAndOptionalT(true, false).? == 0);
+ try expect(peerTypeTAndOptionalT(false, false).? == 3);
}
}
fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
@@ -146,11 +146,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
}
test "peer type resolution: [0]u8 and []const u8" {
- expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
- expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
+ try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
+ try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
comptime {
- expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
- expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
+ try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
+ try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
}
}
fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
@@ -162,8 +162,8 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
}
test "implicitly cast from [N]T to ?[]const T" {
- expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
- comptime expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
+ try expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
+ comptime try expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
}
fn castToOptionalSlice() ?[]const u8 {
@@ -171,12 +171,12 @@ fn castToOptionalSlice() ?[]const u8 {
}
test "implicitly cast from [0]T to anyerror![]T" {
- testCastZeroArrayToErrSliceMut();
- comptime testCastZeroArrayToErrSliceMut();
+ try testCastZeroArrayToErrSliceMut();
+ comptime try testCastZeroArrayToErrSliceMut();
}
-fn testCastZeroArrayToErrSliceMut() void {
- expect((gimmeErrOrSlice() catch unreachable).len == 0);
+fn testCastZeroArrayToErrSliceMut() !void {
+ try expect((gimmeErrOrSlice() catch unreachable).len == 0);
}
fn gimmeErrOrSlice() anyerror![]u8 {
@@ -189,19 +189,19 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
{
var data = "hi".*;
const slice = data[0..];
- expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
- expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
+ try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
+ try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
}
{
var data: [2]u8 = "hi".*;
const slice = data[0..];
- expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
- expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
+ try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
+ try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
}
}
};
try S.doTheTest();
- try comptime S.doTheTest();
+ comptime try S.doTheTest();
}
fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
if (a) {
@@ -212,43 +212,43 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
}
test "resolve undefined with integer" {
- testResolveUndefWithInt(true, 1234);
- comptime testResolveUndefWithInt(true, 1234);
+ try testResolveUndefWithInt(true, 1234);
+ comptime try testResolveUndefWithInt(true, 1234);
}
-fn testResolveUndefWithInt(b: bool, x: i32) void {
+fn testResolveUndefWithInt(b: bool, x: i32) !void {
const value = if (b) x else undefined;
if (b) {
- expect(value == x);
+ try expect(value == x);
}
}
test "implicit cast from &const [N]T to []const T" {
- testCastConstArrayRefToConstSlice();
- comptime testCastConstArrayRefToConstSlice();
+ try testCastConstArrayRefToConstSlice();
+ comptime try testCastConstArrayRefToConstSlice();
}
-fn testCastConstArrayRefToConstSlice() void {
+fn testCastConstArrayRefToConstSlice() !void {
{
const blah = "aoeu".*;
const const_array_ref = &blah;
- expect(@TypeOf(const_array_ref) == *const [4:0]u8);
+ try expect(@TypeOf(const_array_ref) == *const [4:0]u8);
const slice: []const u8 = const_array_ref;
- expect(mem.eql(u8, slice, "aoeu"));
+ try expect(mem.eql(u8, slice, "aoeu"));
}
{
const blah: [4]u8 = "aoeu".*;
const const_array_ref = &blah;
- expect(@TypeOf(const_array_ref) == *const [4]u8);
+ try expect(@TypeOf(const_array_ref) == *const [4]u8);
const slice: []const u8 = const_array_ref;
- expect(mem.eql(u8, slice, "aoeu"));
+ try expect(mem.eql(u8, slice, "aoeu"));
}
}
test "peer type resolution: error and [N]T" {
- expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
- comptime expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
- expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
- comptime expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
+ try expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
+ comptime try expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
+ try expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
+ comptime try expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
}
fn testPeerErrorAndArray(x: u8) anyerror![]const u8 {
@@ -266,35 +266,35 @@ fn testPeerErrorAndArray2(x: u8) anyerror![]const u8 {
}
test "@floatToInt" {
- testFloatToInts();
- comptime testFloatToInts();
+ try testFloatToInts();
+ comptime try testFloatToInts();
}
-fn testFloatToInts() void {
+fn testFloatToInts() !void {
const x = @as(i32, 1e4);
- expect(x == 10000);
+ try expect(x == 10000);
const y = @floatToInt(i32, @as(f32, 1e4));
- expect(y == 10000);
- expectFloatToInt(f16, 255.1, u8, 255);
- expectFloatToInt(f16, 127.2, i8, 127);
- expectFloatToInt(f16, -128.2, i8, -128);
- expectFloatToInt(f32, 255.1, u8, 255);
- expectFloatToInt(f32, 127.2, i8, 127);
- expectFloatToInt(f32, -128.2, i8, -128);
- expectFloatToInt(comptime_int, 1234, i16, 1234);
+ try expect(y == 10000);
+ try expectFloatToInt(f16, 255.1, u8, 255);
+ try expectFloatToInt(f16, 127.2, i8, 127);
+ try expectFloatToInt(f16, -128.2, i8, -128);
+ try expectFloatToInt(f32, 255.1, u8, 255);
+ try expectFloatToInt(f32, 127.2, i8, 127);
+ try expectFloatToInt(f32, -128.2, i8, -128);
+ try expectFloatToInt(comptime_int, 1234, i16, 1234);
}
-fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) void {
- expect(@floatToInt(I, f) == i);
+fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) !void {
+ try expect(@floatToInt(I, f) == i);
}
test "cast u128 to f128 and back" {
- comptime testCast128();
- testCast128();
+ comptime try testCast128();
+ try testCast128();
}
-fn testCast128() void {
- expect(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000);
+fn testCast128() !void {
+ try expect(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000);
}
fn cast128Int(x: f128) u128 {
@@ -306,69 +306,69 @@ fn cast128Float(x: u128) f128 {
}
test "single-item pointer of array to slice and to unknown length pointer" {
- testCastPtrOfArrayToSliceAndPtr();
- comptime testCastPtrOfArrayToSliceAndPtr();
+ try testCastPtrOfArrayToSliceAndPtr();
+ comptime try testCastPtrOfArrayToSliceAndPtr();
}
-fn testCastPtrOfArrayToSliceAndPtr() void {
+fn testCastPtrOfArrayToSliceAndPtr() !void {
{
var array = "aoeu".*;
const x: [*]u8 = &array;
x[0] += 1;
- expect(mem.eql(u8, array[0..], "boeu"));
+ try expect(mem.eql(u8, array[0..], "boeu"));
const y: []u8 = &array;
y[0] += 1;
- expect(mem.eql(u8, array[0..], "coeu"));
+ try expect(mem.eql(u8, array[0..], "coeu"));
}
{
var array: [4]u8 = "aoeu".*;
const x: [*]u8 = &array;
x[0] += 1;
- expect(mem.eql(u8, array[0..], "boeu"));
+ try expect(mem.eql(u8, array[0..], "boeu"));
const y: []u8 = &array;
y[0] += 1;
- expect(mem.eql(u8, array[0..], "coeu"));
+ try expect(mem.eql(u8, array[0..], "coeu"));
}
}
test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
const window_name = [1][*]const u8{"window name"};
const x: [*]const ?[*]const u8 = &window_name;
- expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
+ try expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
}
test "@intCast comptime_int" {
const result = @intCast(i32, 1234);
- expect(@TypeOf(result) == i32);
- expect(result == 1234);
+ try expect(@TypeOf(result) == i32);
+ try expect(result == 1234);
}
test "@floatCast comptime_int and comptime_float" {
{
const result = @floatCast(f16, 1234);
- expect(@TypeOf(result) == f16);
- expect(result == 1234.0);
+ try expect(@TypeOf(result) == f16);
+ try expect(result == 1234.0);
}
{
const result = @floatCast(f16, 1234.0);
- expect(@TypeOf(result) == f16);
- expect(result == 1234.0);
+ try expect(@TypeOf(result) == f16);
+ try expect(result == 1234.0);
}
{
const result = @floatCast(f32, 1234);
- expect(@TypeOf(result) == f32);
- expect(result == 1234.0);
+ try expect(@TypeOf(result) == f32);
+ try expect(result == 1234.0);
}
{
const result = @floatCast(f32, 1234.0);
- expect(@TypeOf(result) == f32);
- expect(result == 1234.0);
+ try expect(@TypeOf(result) == f32);
+ try expect(result == 1234.0);
}
}
test "vector casts" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
// Upcast (implicit, equivalent to @intCast)
var up0: Vector(2, u8) = [_]u8{ 0x55, 0xaa };
var up1 = @as(Vector(2, u16), up0);
@@ -380,55 +380,55 @@ test "vector casts" {
var down2 = @intCast(Vector(2, u16), down0);
var down3 = @intCast(Vector(2, u8), down0);
- expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));
- expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa }));
- expect(mem.eql(u64, &@as([2]u64, up3), &[2]u64{ 0x55, 0xaa }));
+ try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));
+ try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa }));
+ try expect(mem.eql(u64, &@as([2]u64, up3), &[2]u64{ 0x55, 0xaa }));
- expect(mem.eql(u32, &@as([2]u32, down1), &[2]u32{ 0x55, 0xaa }));
- expect(mem.eql(u16, &@as([2]u16, down2), &[2]u16{ 0x55, 0xaa }));
- expect(mem.eql(u8, &@as([2]u8, down3), &[2]u8{ 0x55, 0xaa }));
+ try expect(mem.eql(u32, &@as([2]u32, down1), &[2]u32{ 0x55, 0xaa }));
+ try expect(mem.eql(u16, &@as([2]u16, down2), &[2]u16{ 0x55, 0xaa }));
+ try expect(mem.eql(u8, &@as([2]u8, down3), &[2]u8{ 0x55, 0xaa }));
}
- fn doTheTestFloat() void {
+ fn doTheTestFloat() !void {
var vec = @splat(2, @as(f32, 1234.0));
var wider: Vector(2, f64) = vec;
- expect(wider[0] == 1234.0);
- expect(wider[1] == 1234.0);
+ try expect(wider[0] == 1234.0);
+ try expect(wider[1] == 1234.0);
}
};
- S.doTheTest();
- comptime S.doTheTest();
- S.doTheTestFloat();
- comptime S.doTheTestFloat();
+ try S.doTheTest();
+ comptime try S.doTheTest();
+ try S.doTheTestFloat();
+ comptime try S.doTheTestFloat();
}
test "comptime_int @intToFloat" {
{
const result = @intToFloat(f16, 1234);
- expect(@TypeOf(result) == f16);
- expect(result == 1234.0);
+ try expect(@TypeOf(result) == f16);
+ try expect(result == 1234.0);
}
{
const result = @intToFloat(f32, 1234);
- expect(@TypeOf(result) == f32);
- expect(result == 1234.0);
+ try expect(@TypeOf(result) == f32);
+ try expect(result == 1234.0);
}
{
const result = @intToFloat(f64, 1234);
- expect(@TypeOf(result) == f64);
- expect(result == 1234.0);
+ try expect(@TypeOf(result) == f64);
+ try expect(result == 1234.0);
}
{
const result = @intToFloat(f128, 1234);
- expect(@TypeOf(result) == f128);
- expect(result == 1234.0);
+ try expect(@TypeOf(result) == f128);
+ try expect(result == 1234.0);
}
// big comptime_int (> 64 bits) to f128 conversion
{
const result = @intToFloat(f128, 0x1_0000_0000_0000_0000);
- expect(@TypeOf(result) == f128);
- expect(result == 0x1_0000_0000_0000_0000.0);
+ try expect(@TypeOf(result) == f128);
+ try expect(result == 0x1_0000_0000_0000_0000.0);
}
}
@@ -436,25 +436,25 @@ test "@intCast i32 to u7" {
var x: u128 = maxInt(u128);
var y: i32 = 120;
var z = x >> @intCast(u7, y);
- expect(z == 0xff);
+ try expect(z == 0xff);
}
test "@floatCast cast down" {
{
var double: f64 = 0.001534;
var single = @floatCast(f32, double);
- expect(single == 0.001534);
+ try expect(single == 0.001534);
}
{
const double: f64 = 0.001534;
const single = @floatCast(f32, double);
- expect(single == 0.001534);
+ try expect(single == 0.001534);
}
}
test "implicit cast undefined to optional" {
- expect(MakeType(void).getNull() == null);
- expect(MakeType(void).getNonNull() != null);
+ try expect(MakeType(void).getNull() == null);
+ try expect(MakeType(void).getNonNull() != null);
}
fn MakeType(comptime T: type) type {
@@ -474,26 +474,26 @@ test "implicit cast from *[N]T to ?[*]T" {
var y: [4]u16 = [4]u16{ 0, 1, 2, 3 };
x = &y;
- expect(std.mem.eql(u16, x.?[0..4], y[0..4]));
+ try expect(std.mem.eql(u16, x.?[0..4], y[0..4]));
x.?[0] = 8;
y[3] = 6;
- expect(std.mem.eql(u16, x.?[0..4], y[0..4]));
+ try expect(std.mem.eql(u16, x.?[0..4], y[0..4]));
}
test "implicit cast from *[N]T to [*c]T" {
var x: [4]u16 = [4]u16{ 0, 1, 2, 3 };
var y: [*c]u16 = &x;
- expect(std.mem.eql(u16, x[0..4], y[0..4]));
+ try expect(std.mem.eql(u16, x[0..4], y[0..4]));
x[0] = 8;
y[3] = 6;
- expect(std.mem.eql(u16, x[0..4], y[0..4]));
+ try expect(std.mem.eql(u16, x[0..4], y[0..4]));
}
test "implicit cast from *T to ?*c_void" {
var a: u8 = 1;
incrementVoidPtrValue(&a);
- std.testing.expect(a == 2);
+ try std.testing.expect(a == 2);
}
fn incrementVoidPtrValue(value: ?*c_void) void {
@@ -504,7 +504,7 @@ test "implicit cast from [*]T to ?*c_void" {
var a = [_]u8{ 3, 2, 1 };
var runtime_zero: usize = 0;
incrementVoidPtrArray(a[runtime_zero..].ptr, 3);
- expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 }));
+ try expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 }));
}
fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
@@ -521,34 +521,34 @@ test "*usize to *void" {
}
test "compile time int to ptr of function" {
- foobar(FUNCTION_CONSTANT);
+ try foobar(FUNCTION_CONSTANT);
}
pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize));
pub const PFN_void = fn (*c_void) callconv(.C) void;
-fn foobar(func: PFN_void) void {
- std.testing.expect(@ptrToInt(func) == maxInt(usize));
+fn foobar(func: PFN_void) !void {
+ try std.testing.expect(@ptrToInt(func) == maxInt(usize));
}
test "implicit ptr to *c_void" {
var a: u32 = 1;
var ptr: *align(@alignOf(u32)) c_void = &a;
var b: *u32 = @ptrCast(*u32, ptr);
- expect(b.* == 1);
+ try expect(b.* == 1);
var ptr2: ?*align(@alignOf(u32)) c_void = &a;
var c: *u32 = @ptrCast(*u32, ptr2.?);
- expect(c.* == 1);
+ try expect(c.* == 1);
}
test "@intCast to comptime_int" {
- expect(@intCast(comptime_int, 0) == 0);
+ try expect(@intCast(comptime_int, 0) == 0);
}
test "implicit cast comptime numbers to any type when the value fits" {
const a: u64 = 255;
var b: u8 = a;
- expect(b == 255);
+ try expect(b == 255);
}
test "@intToEnum passed a comptime_int to an enum with one item" {
@@ -556,7 +556,7 @@ test "@intToEnum passed a comptime_int to an enum with one item" {
A,
};
const x = @intToEnum(E, 0);
- expect(x == E.A);
+ try expect(x == E.A);
}
test "@intToEnum runtime to an extern enum with duplicate values" {
@@ -566,33 +566,33 @@ test "@intToEnum runtime to an extern enum with duplicate values" {
};
var a: u8 = 1;
var x = @intToEnum(E, a);
- expect(x == E.A);
- expect(x == E.B);
+ try expect(x == E.A);
+ try expect(x == E.B);
}
test "@intCast to u0 and use the result" {
const S = struct {
- fn doTheTest(zero: u1, one: u1, bigzero: i32) void {
- expect((one << @intCast(u0, bigzero)) == 1);
- expect((zero << @intCast(u0, bigzero)) == 0);
+ fn doTheTest(zero: u1, one: u1, bigzero: i32) !void {
+ try expect((one << @intCast(u0, bigzero)) == 1);
+ try expect((zero << @intCast(u0, bigzero)) == 0);
}
};
- S.doTheTest(0, 1, 0);
- comptime S.doTheTest(0, 1, 0);
+ try S.doTheTest(0, 1, 0);
+ comptime try S.doTheTest(0, 1, 0);
}
test "peer type resolution: unreachable, null, slice" {
const S = struct {
- fn doTheTest(num: usize, word: []const u8) void {
+ fn doTheTest(num: usize, word: []const u8) !void {
const result = switch (num) {
0 => null,
1 => word,
else => unreachable,
};
- expect(mem.eql(u8, result.?, "hi"));
+ try expect(mem.eql(u8, result.?, "hi"));
}
};
- S.doTheTest(1, "hi");
+ try S.doTheTest(1, "hi");
}
test "peer type resolution: unreachable, error set, unreachable" {
@@ -615,17 +615,17 @@ test "peer type resolution: unreachable, error set, unreachable" {
error.FileDescriptorIncompatibleWithEpoll => unreachable,
error.Unexpected => unreachable,
};
- expect(transformed_err == error.SystemResources);
+ try expect(transformed_err == error.SystemResources);
}
test "implicit cast comptime_int to comptime_float" {
- comptime expect(@as(comptime_float, 10) == @as(f32, 10));
- expect(2 == 2.0);
+ comptime try expect(@as(comptime_float, 10) == @as(f32, 10));
+ try expect(2 == 2.0);
}
test "implicit cast *[0]T to E![]const u8" {
var x = @as(anyerror![]const u8, &[0]u8{});
- expect((x catch unreachable).len == 0);
+ try expect((x catch unreachable).len == 0);
}
test "peer cast *[0]T to E![]const T" {
@@ -633,7 +633,7 @@ test "peer cast *[0]T to E![]const T" {
var buf: anyerror![]const u8 = buffer[0..];
var b = false;
var y = if (b) &[0]u8{} else buf;
- expect(mem.eql(u8, "abcde", y catch unreachable));
+ try expect(mem.eql(u8, "abcde", y catch unreachable));
}
test "peer cast *[0]T to []const T" {
@@ -641,25 +641,25 @@ test "peer cast *[0]T to []const T" {
var buf: []const u8 = buffer[0..];
var b = false;
var y = if (b) &[0]u8{} else buf;
- expect(mem.eql(u8, "abcde", y));
+ try expect(mem.eql(u8, "abcde", y));
}
var global_array: [4]u8 = undefined;
test "cast from array reference to fn" {
const f = @ptrCast(fn () callconv(.C) void, &global_array);
- expect(@ptrToInt(f) == @ptrToInt(&global_array));
+ try expect(@ptrToInt(f) == @ptrToInt(&global_array));
}
test "*const [N]null u8 to ?[]const u8" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var a = "Hello";
var b: ?[]const u8 = a;
- expect(mem.eql(u8, b.?, "Hello"));
+ try expect(mem.eql(u8, b.?, "Hello"));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "peer resolution of string literals" {
@@ -671,54 +671,54 @@ test "peer resolution of string literals" {
d,
};
- fn doTheTest(e: E) void {
+ fn doTheTest(e: E) !void {
const cmd = switch (e) {
.a => "one",
.b => "two",
.c => "three",
.d => "four",
};
- expect(mem.eql(u8, cmd, "two"));
+ try expect(mem.eql(u8, cmd, "two"));
}
};
- S.doTheTest(.b);
- comptime S.doTheTest(.b);
+ try S.doTheTest(.b);
+ comptime try S.doTheTest(.b);
}
test "type coercion related to sentinel-termination" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
// [:x]T to []T
{
var array = [4:0]i32{ 1, 2, 3, 4 };
var slice: [:0]i32 = &array;
var dest: []i32 = slice;
- expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
+ try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
}
// [*:x]T to [*]T
{
var array = [4:99]i32{ 1, 2, 3, 4 };
var dest: [*]i32 = &array;
- expect(dest[0] == 1);
- expect(dest[1] == 2);
- expect(dest[2] == 3);
- expect(dest[3] == 4);
- expect(dest[4] == 99);
+ try expect(dest[0] == 1);
+ try expect(dest[1] == 2);
+ try expect(dest[2] == 3);
+ try expect(dest[3] == 4);
+ try expect(dest[4] == 99);
}
// [N:x]T to [N]T
{
var array = [4:0]i32{ 1, 2, 3, 4 };
var dest: [4]i32 = array;
- expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 }));
+ try expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 }));
}
// *[N:x]T to *[N]T
{
var array = [4:0]i32{ 1, 2, 3, 4 };
var dest: *[4]i32 = &array;
- expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
+ try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
}
// [:x]T to [*:x]T
@@ -726,24 +726,24 @@ test "type coercion related to sentinel-termination" {
var array = [4:0]i32{ 1, 2, 3, 4 };
var slice: [:0]i32 = &array;
var dest: [*:0]i32 = slice;
- expect(dest[0] == 1);
- expect(dest[1] == 2);
- expect(dest[2] == 3);
- expect(dest[3] == 4);
- expect(dest[4] == 0);
+ try expect(dest[0] == 1);
+ try expect(dest[1] == 2);
+ try expect(dest[2] == 3);
+ try expect(dest[3] == 4);
+ try expect(dest[4] == 0);
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "cast i8 fn call peers to i32 result" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var cond = true;
const value: i32 = if (cond) smallBoi() else bigBoi();
- expect(value == 123);
+ try expect(value == 123);
}
fn smallBoi() i8 {
return 123;
@@ -752,21 +752,21 @@ test "cast i8 fn call peers to i32 result" {
return 1234;
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "return u8 coercing into ?u32 return type" {
const S = struct {
- fn doTheTest() void {
- expect(foo(123).? == 123);
+ fn doTheTest() !void {
+ try expect(foo(123).? == 123);
}
fn foo(arg: u8) ?u32 {
return arg;
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "peer result null and comptime_int" {
@@ -782,17 +782,17 @@ test "peer result null and comptime_int" {
}
};
- expect(S.blah(0) == null);
- comptime expect(S.blah(0) == null);
- expect(S.blah(10).? == 1);
- comptime expect(S.blah(10).? == 1);
- expect(S.blah(-10).? == -1);
- comptime expect(S.blah(-10).? == -1);
+ try expect(S.blah(0) == null);
+ comptime try expect(S.blah(0) == null);
+ try expect(S.blah(10).? == 1);
+ comptime try expect(S.blah(10).? == 1);
+ try expect(S.blah(-10).? == -1);
+ comptime try expect(S.blah(-10).? == -1);
}
test "peer type resolution implicit cast to return type" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
for ("hello") |c| _ = f(c);
}
fn f(c: u8) []const u8 {
@@ -803,13 +803,13 @@ test "peer type resolution implicit cast to return type" {
};
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "peer type resolution implicit cast to variable type" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var x: []const u8 = undefined;
for ("hello") |c| x = switch (c) {
'h', 'e' => &[_]u8{c}, // should cast to slice
@@ -818,14 +818,14 @@ test "peer type resolution implicit cast to variable type" {
};
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "variable initialization uses result locations properly with regards to the type" {
var b = true;
const x: i32 = if (b) 1 else 2;
- expect(x == 1);
+ try expect(x == 1);
}
test "cast between [*c]T and ?[*:0]T on fn parameter" {
@@ -847,27 +847,27 @@ test "cast between C pointer with different but compatible types" {
fn foo(arg: [*]c_ushort) u16 {
return arg[0];
}
- fn doTheTest() void {
+ fn doTheTest() !void {
var x = [_]u16{ 4, 2, 1, 3 };
- expect(foo(@ptrCast([*]u16, &x)) == 4);
+ try expect(foo(@ptrCast([*]u16, &x)) == 4);
}
};
- S.doTheTest();
+ try S.doTheTest();
}
var global_struct: struct { f0: usize } = undefined;
test "assignment to optional pointer result loc" {
var foo: struct { ptr: ?*c_void } = .{ .ptr = &global_struct };
- expect(foo.ptr.? == @ptrCast(*c_void, &global_struct));
+ try expect(foo.ptr.? == @ptrCast(*c_void, &global_struct));
}
test "peer type resolve string lit with sentinel-terminated mutable slice" {
var array: [4:0]u8 = undefined;
array[4] = 0; // TODO remove this when #4372 is solved
var slice: [:0]u8 = array[0..4 :0];
- comptime expect(@TypeOf(slice, "hi") == [:0]const u8);
- comptime expect(@TypeOf("hi", slice) == [:0]const u8);
+ comptime try expect(@TypeOf(slice, "hi") == [:0]const u8);
+ comptime try expect(@TypeOf("hi", slice) == [:0]const u8);
}
test "peer type unsigned int to signed" {
@@ -875,15 +875,15 @@ test "peer type unsigned int to signed" {
var x: u8 = 7;
var y: i32 = -5;
var a = w + y + x;
- comptime expect(@TypeOf(a) == i32);
- expect(a == 7);
+ comptime try expect(@TypeOf(a) == i32);
+ try expect(a == 7);
}
test "peer type resolve array pointers, one of them const" {
var array1: [4]u8 = undefined;
const array2: [5]u8 = undefined;
- comptime expect(@TypeOf(&array1, &array2) == []const u8);
- comptime expect(@TypeOf(&array2, &array1) == []const u8);
+ comptime try expect(@TypeOf(&array1, &array2) == []const u8);
+ comptime try expect(@TypeOf(&array2, &array1) == []const u8);
}
test "peer type resolve array pointer and unknown pointer" {
@@ -892,35 +892,35 @@ test "peer type resolve array pointer and unknown pointer" {
var const_ptr: [*]const u8 = undefined;
var ptr: [*]u8 = undefined;
- comptime expect(@TypeOf(&array, ptr) == [*]u8);
- comptime expect(@TypeOf(ptr, &array) == [*]u8);
+ comptime try expect(@TypeOf(&array, ptr) == [*]u8);
+ comptime try expect(@TypeOf(ptr, &array) == [*]u8);
- comptime expect(@TypeOf(&const_array, ptr) == [*]const u8);
- comptime expect(@TypeOf(ptr, &const_array) == [*]const u8);
+ comptime try expect(@TypeOf(&const_array, ptr) == [*]const u8);
+ comptime try expect(@TypeOf(ptr, &const_array) == [*]const u8);
- comptime expect(@TypeOf(&array, const_ptr) == [*]const u8);
- comptime expect(@TypeOf(const_ptr, &array) == [*]const u8);
+ comptime try expect(@TypeOf(&array, const_ptr) == [*]const u8);
+ comptime try expect(@TypeOf(const_ptr, &array) == [*]const u8);
- comptime expect(@TypeOf(&const_array, const_ptr) == [*]const u8);
- comptime expect(@TypeOf(const_ptr, &const_array) == [*]const u8);
+ comptime try expect(@TypeOf(&const_array, const_ptr) == [*]const u8);
+ comptime try expect(@TypeOf(const_ptr, &const_array) == [*]const u8);
}
test "comptime float casts" {
const a = @intToFloat(comptime_float, 1);
- expect(a == 1);
- expect(@TypeOf(a) == comptime_float);
+ try expect(a == 1);
+ try expect(@TypeOf(a) == comptime_float);
const b = @floatToInt(comptime_int, 2);
- expect(b == 2);
- expect(@TypeOf(b) == comptime_int);
+ try expect(b == 2);
+ try expect(@TypeOf(b) == comptime_int);
}
test "cast from ?[*]T to ??[*]T" {
const a: ??[*]u8 = @as(?[*]u8, null);
- expect(a != null and a.? == null);
+ try expect(a != null and a.? == null);
}
test "cast between *[N]void and []void" {
var a: [4]void = undefined;
var b: []void = &a;
- expect(b.len == 4);
+ try expect(b.len == 4);
}
diff --git a/test/stage1/behavior/const_slice_child.zig b/test/stage1/behavior/const_slice_child.zig
index 92e5121026..0fa9d71ee6 100644
--- a/test/stage1/behavior/const_slice_child.zig
+++ b/test/stage1/behavior/const_slice_child.zig
@@ -12,24 +12,24 @@ test "const slice child" {
"three",
};
argv = &strs;
- bar(strs.len);
+ try bar(strs.len);
}
-fn foo(args: [][]const u8) void {
- expect(args.len == 3);
- expect(streql(args[0], "one"));
- expect(streql(args[1], "two"));
- expect(streql(args[2], "three"));
+fn foo(args: [][]const u8) !void {
+ try expect(args.len == 3);
+ try expect(streql(args[0], "one"));
+ try expect(streql(args[1], "two"));
+ try expect(streql(args[2], "three"));
}
-fn bar(argc: usize) void {
+fn bar(argc: usize) !void {
const args = testing.allocator.alloc([]const u8, argc) catch unreachable;
defer testing.allocator.free(args);
for (args) |_, i| {
const ptr = argv[i];
args[i] = ptr[0..strlen(ptr)];
}
- foo(args);
+ try foo(args);
}
fn strlen(ptr: [*]const u8) usize {
diff --git a/test/stage1/behavior/defer.zig b/test/stage1/behavior/defer.zig
index 6bfeb485cc..53ce188928 100644
--- a/test/stage1/behavior/defer.zig
+++ b/test/stage1/behavior/defer.zig
@@ -24,18 +24,18 @@ fn runSomeErrorDefers(x: bool) !bool {
}
test "mixing normal and error defers" {
- expect(runSomeErrorDefers(true) catch unreachable);
- expect(result[0] == 'c');
- expect(result[1] == 'a');
+ try expect(runSomeErrorDefers(true) catch unreachable);
+ try expect(result[0] == 'c');
+ try expect(result[1] == 'a');
const ok = runSomeErrorDefers(false) catch |err| x: {
- expect(err == error.FalseNotAllowed);
+ try expect(err == error.FalseNotAllowed);
break :x true;
};
- expect(ok);
- expect(result[0] == 'c');
- expect(result[1] == 'b');
- expect(result[2] == 'a');
+ try expect(ok);
+ try expect(result[0] == 'c');
+ try expect(result[1] == 'b');
+ try expect(result[2] == 'a');
}
test "break and continue inside loop inside defer expression" {
@@ -50,7 +50,7 @@ fn testBreakContInDefer(x: usize) void {
if (i < 5) continue;
if (i == 5) break;
}
- expect(i == 5);
+ expect(i == 5) catch @panic("test failure");
}
}
@@ -62,11 +62,11 @@ test "defer and labeled break" {
break :blk;
}
- expect(i == 1);
+ try expect(i == 1);
}
test "errdefer does not apply to fn inside fn" {
- if (testNestedFnErrDefer()) |_| @panic("expected error") else |e| expect(e == error.Bad);
+ if (testNestedFnErrDefer()) |_| @panic("expected error") else |e| try expect(e == error.Bad);
}
fn testNestedFnErrDefer() anyerror!void {
@@ -82,8 +82,8 @@ fn testNestedFnErrDefer() anyerror!void {
test "return variable while defer expression in scope to modify it" {
const S = struct {
- fn doTheTest() void {
- expect(notNull().? == 1);
+ fn doTheTest() !void {
+ try expect(notNull().? == 1);
}
fn notNull() ?u8 {
@@ -93,22 +93,22 @@ test "return variable while defer expression in scope to modify it" {
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "errdefer with payload" {
const S = struct {
fn foo() !i32 {
errdefer |a| {
- expectEqual(error.One, a);
+ expectEqual(error.One, a) catch @panic("test failure");
}
return error.One;
}
- fn doTheTest() void {
- expectError(error.One, foo());
+ fn doTheTest() !void {
+ try expectError(error.One, foo());
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
diff --git a/test/stage1/behavior/enum.zig b/test/stage1/behavior/enum.zig
index ecb95be8f5..0ab4e50b24 100644
--- a/test/stage1/behavior/enum.zig
+++ b/test/stage1/behavior/enum.zig
@@ -29,41 +29,41 @@ test "non-exhaustive enum" {
b,
_,
};
- fn doTheTest(y: u8) void {
+ fn doTheTest(y: u8) !void {
var e: E = .b;
- expect(switch (e) {
+ try expect(switch (e) {
.a => false,
.b => true,
_ => false,
});
e = @intToEnum(E, 12);
- expect(switch (e) {
+ try expect(switch (e) {
.a => false,
.b => false,
_ => true,
});
- expect(switch (e) {
+ try expect(switch (e) {
.a => false,
.b => false,
else => true,
});
e = .b;
- expect(switch (e) {
+ try expect(switch (e) {
.a => false,
else => true,
});
- expect(@typeInfo(E).Enum.fields.len == 2);
+ try expect(@typeInfo(E).Enum.fields.len == 2);
e = @intToEnum(E, 12);
- expect(@enumToInt(e) == 12);
+ try expect(@enumToInt(e) == 12);
e = @intToEnum(E, y);
- expect(@enumToInt(e) == 52);
- expect(@typeInfo(E).Enum.is_exhaustive == false);
+ try expect(@enumToInt(e) == 52);
+ try expect(@typeInfo(E).Enum.is_exhaustive == false);
}
};
- S.doTheTest(52);
- comptime S.doTheTest(52);
+ try S.doTheTest(52);
+ comptime try S.doTheTest(52);
}
test "empty non-exhaustive enum" {
@@ -71,19 +71,19 @@ test "empty non-exhaustive enum" {
const E = enum(u8) {
_,
};
- fn doTheTest(y: u8) void {
+ fn doTheTest(y: u8) !void {
var e = @intToEnum(E, y);
- expect(switch (e) {
+ try expect(switch (e) {
_ => true,
});
- expect(@enumToInt(e) == y);
+ try expect(@enumToInt(e) == y);
- expect(@typeInfo(E).Enum.fields.len == 0);
- expect(@typeInfo(E).Enum.is_exhaustive == false);
+ try expect(@typeInfo(E).Enum.fields.len == 0);
+ try expect(@typeInfo(E).Enum.is_exhaustive == false);
}
};
- S.doTheTest(42);
- comptime S.doTheTest(42);
+ try S.doTheTest(42);
+ comptime try S.doTheTest(42);
}
test "single field non-exhaustive enum" {
@@ -92,35 +92,35 @@ test "single field non-exhaustive enum" {
a,
_,
};
- fn doTheTest(y: u8) void {
+ fn doTheTest(y: u8) !void {
var e: E = .a;
- expect(switch (e) {
+ try expect(switch (e) {
.a => true,
_ => false,
});
e = @intToEnum(E, 12);
- expect(switch (e) {
+ try expect(switch (e) {
.a => false,
_ => true,
});
- expect(switch (e) {
+ try expect(switch (e) {
.a => false,
else => true,
});
e = .a;
- expect(switch (e) {
+ try expect(switch (e) {
.a => true,
else => false,
});
- expect(@enumToInt(@intToEnum(E, y)) == y);
- expect(@typeInfo(E).Enum.fields.len == 1);
- expect(@typeInfo(E).Enum.is_exhaustive == false);
+ try expect(@enumToInt(@intToEnum(E, y)) == y);
+ try expect(@typeInfo(E).Enum.fields.len == 1);
+ try expect(@typeInfo(E).Enum.is_exhaustive == false);
}
};
- S.doTheTest(23);
- comptime S.doTheTest(23);
+ try S.doTheTest(23);
+ comptime try S.doTheTest(23);
}
test "enum type" {
@@ -133,16 +133,16 @@ test "enum type" {
};
const bar = Bar.B;
- expect(bar == Bar.B);
- expect(@typeInfo(Foo).Union.fields.len == 3);
- expect(@typeInfo(Bar).Enum.fields.len == 4);
- expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));
- expect(@sizeOf(Bar) == 1);
+ try expect(bar == Bar.B);
+ try expect(@typeInfo(Foo).Union.fields.len == 3);
+ try expect(@typeInfo(Bar).Enum.fields.len == 4);
+ try expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));
+ try expect(@sizeOf(Bar) == 1);
}
test "enum as return value" {
switch (returnAnInt(13)) {
- Foo.One => |value| expect(value == 13),
+ Foo.One => |value| try expect(value == 13),
else => unreachable,
}
}
@@ -206,22 +206,22 @@ const Number = enum {
};
test "enum to int" {
- shouldEqual(Number.Zero, 0);
- shouldEqual(Number.One, 1);
- shouldEqual(Number.Two, 2);
- shouldEqual(Number.Three, 3);
- shouldEqual(Number.Four, 4);
+ try shouldEqual(Number.Zero, 0);
+ try shouldEqual(Number.One, 1);
+ try shouldEqual(Number.Two, 2);
+ try shouldEqual(Number.Three, 3);
+ try shouldEqual(Number.Four, 4);
}
-fn shouldEqual(n: Number, expected: u3) void {
- expect(@enumToInt(n) == expected);
+fn shouldEqual(n: Number, expected: u3) !void {
+ try expect(@enumToInt(n) == expected);
}
test "int to enum" {
- testIntToEnumEval(3);
+ try testIntToEnumEval(3);
}
-fn testIntToEnumEval(x: i32) void {
- expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);
+fn testIntToEnumEval(x: i32) !void {
+ try expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);
}
const IntToEnumNumber = enum {
Zero,
@@ -232,18 +232,18 @@ const IntToEnumNumber = enum {
};
test "@tagName" {
- expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
- comptime expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
+ try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
+ comptime try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
}
test "@tagName extern enum with duplicates" {
- expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));
- comptime expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));
+ try expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));
+ comptime try expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));
}
test "@tagName non-exhaustive enum" {
- expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
- comptime expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
+ try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
+ comptime try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
}
fn testEnumTagNameBare(n: anytype) []const u8 {
@@ -269,8 +269,8 @@ const NonExhaustive = enum(u8) {
test "enum alignment" {
comptime {
- expect(@alignOf(AlignTestEnum) >= @alignOf([9]u8));
- expect(@alignOf(AlignTestEnum) >= @alignOf(u64));
+ try expect(@alignOf(AlignTestEnum) >= @alignOf([9]u8));
+ try expect(@alignOf(AlignTestEnum) >= @alignOf(u64));
}
}
@@ -806,10 +806,10 @@ const ValueCount257 = enum {
test "enum sizes" {
comptime {
- expect(@sizeOf(ValueCount1) == 0);
- expect(@sizeOf(ValueCount2) == 1);
- expect(@sizeOf(ValueCount256) == 1);
- expect(@sizeOf(ValueCount257) == 2);
+ try expect(@sizeOf(ValueCount1) == 0);
+ try expect(@sizeOf(ValueCount2) == 1);
+ try expect(@sizeOf(ValueCount256) == 1);
+ try expect(@sizeOf(ValueCount257) == 2);
}
}
@@ -828,12 +828,12 @@ test "set enum tag type" {
{
var x = Small.One;
x = Small.Two;
- comptime expect(Tag(Small) == u2);
+ comptime try expect(Tag(Small) == u2);
}
{
var x = Small2.One;
x = Small2.Two;
- comptime expect(Tag(Small2) == u2);
+ comptime try expect(Tag(Small2) == u2);
}
}
@@ -880,17 +880,17 @@ const bit_field_1 = BitFieldOfEnums{
test "bit field access with enum fields" {
var data = bit_field_1;
- expect(getA(&data) == A.Two);
- expect(getB(&data) == B.Three3);
- expect(getC(&data) == C.Four4);
- comptime expect(@sizeOf(BitFieldOfEnums) == 1);
+ try expect(getA(&data) == A.Two);
+ try expect(getB(&data) == B.Three3);
+ try expect(getC(&data) == C.Four4);
+ comptime try expect(@sizeOf(BitFieldOfEnums) == 1);
data.b = B.Four3;
- expect(data.b == B.Four3);
+ try expect(data.b == B.Four3);
data.a = A.Three;
- expect(data.a == A.Three);
- expect(data.b == B.Four3);
+ try expect(data.a == A.Three);
+ try expect(data.b == B.Four3);
}
fn getA(data: *const BitFieldOfEnums) A {
@@ -906,12 +906,12 @@ fn getC(data: *const BitFieldOfEnums) C {
}
test "casting enum to its tag type" {
- testCastEnumTag(Small2.Two);
- comptime testCastEnumTag(Small2.Two);
+ try testCastEnumTag(Small2.Two);
+ comptime try testCastEnumTag(Small2.Two);
}
-fn testCastEnumTag(value: Small2) void {
- expect(@enumToInt(value) == 1);
+fn testCastEnumTag(value: Small2) !void {
+ try expect(@enumToInt(value) == 1);
}
const MultipleChoice = enum(u32) {
@@ -922,13 +922,13 @@ const MultipleChoice = enum(u32) {
};
test "enum with specified tag values" {
- testEnumWithSpecifiedTagValues(MultipleChoice.C);
- comptime testEnumWithSpecifiedTagValues(MultipleChoice.C);
+ try testEnumWithSpecifiedTagValues(MultipleChoice.C);
+ comptime try testEnumWithSpecifiedTagValues(MultipleChoice.C);
}
-fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {
- expect(@enumToInt(x) == 60);
- expect(1234 == switch (x) {
+fn testEnumWithSpecifiedTagValues(x: MultipleChoice) !void {
+ try expect(@enumToInt(x) == 60);
+ try expect(1234 == switch (x) {
MultipleChoice.A => 1,
MultipleChoice.B => 2,
MultipleChoice.C => @as(u32, 1234),
@@ -949,13 +949,13 @@ const MultipleChoice2 = enum(u32) {
};
test "enum with specified and unspecified tag values" {
- testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
- comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
+ try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
+ comptime try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
}
-fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
- expect(@enumToInt(x) == 1000);
- expect(1234 == switch (x) {
+fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) !void {
+ try expect(@enumToInt(x) == 1000);
+ try expect(1234 == switch (x) {
MultipleChoice2.A => 1,
MultipleChoice2.B => 2,
MultipleChoice2.C => 3,
@@ -969,8 +969,8 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
}
test "cast integer literal to enum" {
- expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);
- expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);
+ try expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);
+ try expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);
}
const EnumWithOneMember = enum {
@@ -1008,14 +1008,14 @@ const EnumWithTagValues = enum(u4) {
D = 1 << 3,
};
test "enum with tag values don't require parens" {
- expect(@enumToInt(EnumWithTagValues.C) == 0b0100);
+ try expect(@enumToInt(EnumWithTagValues.C) == 0b0100);
}
test "enum with 1 field but explicit tag type should still have the tag type" {
const Enum = enum(u8) {
B = 2,
};
- comptime @import("std").testing.expect(@sizeOf(Enum) == @sizeOf(u8));
+ comptime try expect(@sizeOf(Enum) == @sizeOf(u8));
}
test "empty extern enum with members" {
@@ -1024,7 +1024,7 @@ test "empty extern enum with members" {
B,
C,
};
- expect(@sizeOf(E) == @sizeOf(c_int));
+ try expect(@sizeOf(E) == @sizeOf(c_int));
}
test "tag name with assigned enum values" {
@@ -1033,7 +1033,7 @@ test "tag name with assigned enum values" {
B = 0,
};
var b = LocalFoo.B;
- expect(mem.eql(u8, @tagName(b), "B"));
+ try expect(mem.eql(u8, @tagName(b), "B"));
}
test "enum literal equality" {
@@ -1041,8 +1041,8 @@ test "enum literal equality" {
const y = .ok;
const z = .hi;
- expect(x != y);
- expect(x == z);
+ try expect(x != y);
+ try expect(x == z);
}
test "enum literal cast to enum" {
@@ -1054,7 +1054,7 @@ test "enum literal cast to enum" {
var color1: Color = .Auto;
var color2 = Color.Auto;
- expect(color1 == color2);
+ try expect(color1 == color2);
}
test "peer type resolution with enum literal" {
@@ -1063,8 +1063,8 @@ test "peer type resolution with enum literal" {
two,
};
- expect(Items.two == .two);
- expect(.two == Items.two);
+ try expect(Items.two == .two);
+ try expect(.two == Items.two);
}
test "enum literal in array literal" {
@@ -1078,8 +1078,8 @@ test "enum literal in array literal" {
.two,
};
- expect(array[0] == .one);
- expect(array[1] == .two);
+ try expect(array[0] == .one);
+ try expect(array[1] == .two);
}
test "signed integer as enum tag" {
@@ -1089,9 +1089,9 @@ test "signed integer as enum tag" {
A2 = 1,
};
- expect(@enumToInt(SignedEnum.A0) == -1);
- expect(@enumToInt(SignedEnum.A1) == 0);
- expect(@enumToInt(SignedEnum.A2) == 1);
+ try expect(@enumToInt(SignedEnum.A0) == -1);
+ try expect(@enumToInt(SignedEnum.A1) == 0);
+ try expect(@enumToInt(SignedEnum.A2) == 1);
}
test "enum value allocation" {
@@ -1101,9 +1101,9 @@ test "enum value allocation" {
A2,
};
- expect(@enumToInt(LargeEnum.A0) == 0x80000000);
- expect(@enumToInt(LargeEnum.A1) == 0x80000001);
- expect(@enumToInt(LargeEnum.A2) == 0x80000002);
+ try expect(@enumToInt(LargeEnum.A0) == 0x80000000);
+ try expect(@enumToInt(LargeEnum.A1) == 0x80000001);
+ try expect(@enumToInt(LargeEnum.A2) == 0x80000002);
}
test "enum literal casting to tagged union" {
@@ -1130,32 +1130,32 @@ test "enum with one member and custom tag type" {
const E = enum(u2) {
One,
};
- expect(@enumToInt(E.One) == 0);
+ try expect(@enumToInt(E.One) == 0);
const E2 = enum(u2) {
One = 2,
};
- expect(@enumToInt(E2.One) == 2);
+ try expect(@enumToInt(E2.One) == 2);
}
test "enum literal casting to optional" {
var bar: ?Bar = undefined;
bar = .B;
- expect(bar.? == Bar.B);
+ try expect(bar.? == Bar.B);
}
test "enum literal casting to error union with payload enum" {
var bar: error{B}!Bar = undefined;
bar = .B; // should never cast to the error set
- expect((try bar) == Bar.B);
+ try expect((try bar) == Bar.B);
}
test "enum with one member and u1 tag type @enumToInt" {
const Enum = enum(u1) {
Test,
};
- expect(@enumToInt(Enum.Test) == 0);
+ try expect(@enumToInt(Enum.Test) == 0);
}
test "enum with comptime_int tag type" {
@@ -1164,19 +1164,19 @@ test "enum with comptime_int tag type" {
Two = 2,
Three = 1,
};
- comptime expect(Tag(Enum) == comptime_int);
+ comptime try expect(Tag(Enum) == comptime_int);
}
test "enum with one member default to u0 tag type" {
const E0 = enum {
X,
};
- comptime expect(Tag(E0) == u0);
+ comptime try expect(Tag(E0) == u0);
}
test "tagName on enum literals" {
- expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
- comptime expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
+ try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
+ comptime try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
}
test "method call on an enum" {
@@ -1193,12 +1193,12 @@ test "method call on an enum" {
return self.* == .two and foo == bool;
}
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var e = E.two;
- expect(e.method());
- expect(e.generic_method(bool));
+ try expect(e.method());
+ try expect(e.generic_method(bool));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
diff --git a/test/stage1/behavior/enum_with_members.zig b/test/stage1/behavior/enum_with_members.zig
index 08b195494b..cfbf85812d 100644
--- a/test/stage1/behavior/enum_with_members.zig
+++ b/test/stage1/behavior/enum_with_members.zig
@@ -19,9 +19,9 @@ test "enum with members" {
const b = ET{ .UINT = 42 };
var buf: [20]u8 = undefined;
- expect((a.print(buf[0..]) catch unreachable) == 3);
- expect(mem.eql(u8, buf[0..3], "-42"));
+ try expect((a.print(buf[0..]) catch unreachable) == 3);
+ try expect(mem.eql(u8, buf[0..3], "-42"));
- expect((b.print(buf[0..]) catch unreachable) == 2);
- expect(mem.eql(u8, buf[0..2], "42"));
+ try expect((b.print(buf[0..]) catch unreachable) == 2);
+ try expect(mem.eql(u8, buf[0..2], "42"));
}
diff --git a/test/stage1/behavior/error.zig b/test/stage1/behavior/error.zig
index 529b89d1e2..e5129f180d 100644
--- a/test/stage1/behavior/error.zig
+++ b/test/stage1/behavior/error.zig
@@ -19,7 +19,7 @@ pub fn baz() anyerror!i32 {
}
test "error wrapping" {
- expect((baz() catch unreachable) == 15);
+ try expect((baz() catch unreachable) == 15);
}
fn gimmeItBroke() []const u8 {
@@ -27,14 +27,14 @@ fn gimmeItBroke() []const u8 {
}
test "@errorName" {
- expect(mem.eql(u8, @errorName(error.AnError), "AnError"));
- expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
+ try expect(mem.eql(u8, @errorName(error.AnError), "AnError"));
+ try expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
}
test "error values" {
const a = @errorToInt(error.err1);
const b = @errorToInt(error.err2);
- expect(a != b);
+ try expect(a != b);
}
test "redefinition of error values allowed" {
@@ -47,8 +47,8 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void {
test "error binary operator" {
const a = errBinaryOperatorG(true) catch 3;
const b = errBinaryOperatorG(false) catch 3;
- expect(a == 3);
- expect(b == 10);
+ try expect(a == 3);
+ try expect(b == 10);
}
fn errBinaryOperatorG(x: bool) anyerror!isize {
return if (x) error.ItBroke else @as(isize, 10);
@@ -56,7 +56,7 @@ fn errBinaryOperatorG(x: bool) anyerror!isize {
test "unwrap simple value from error" {
const i = unwrapSimpleValueFromErrorDo() catch unreachable;
- expect(i == 13);
+ try expect(i == 13);
}
fn unwrapSimpleValueFromErrorDo() anyerror!isize {
return 13;
@@ -76,21 +76,21 @@ fn makeANonErr() anyerror!i32 {
}
test "error union type " {
- testErrorUnionType();
- comptime testErrorUnionType();
+ try testErrorUnionType();
+ comptime try testErrorUnionType();
}
-fn testErrorUnionType() void {
+fn testErrorUnionType() !void {
const x: anyerror!i32 = 1234;
- if (x) |value| expect(value == 1234) else |_| unreachable;
- expect(@typeInfo(@TypeOf(x)) == .ErrorUnion);
- expect(@typeInfo(@typeInfo(@TypeOf(x)).ErrorUnion.error_set) == .ErrorSet);
- expect(@typeInfo(@TypeOf(x)).ErrorUnion.error_set == anyerror);
+ if (x) |value| try expect(value == 1234) else |_| unreachable;
+ try expect(@typeInfo(@TypeOf(x)) == .ErrorUnion);
+ try expect(@typeInfo(@typeInfo(@TypeOf(x)).ErrorUnion.error_set) == .ErrorSet);
+ try expect(@typeInfo(@TypeOf(x)).ErrorUnion.error_set == anyerror);
}
test "error set type" {
- testErrorSetType();
- comptime testErrorSetType();
+ try testErrorSetType();
+ comptime try testErrorSetType();
}
const MyErrSet = error{
@@ -98,21 +98,21 @@ const MyErrSet = error{
FileNotFound,
};
-fn testErrorSetType() void {
- expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2);
+fn testErrorSetType() !void {
+ try expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2);
const a: MyErrSet!i32 = 5678;
const b: MyErrSet!i32 = MyErrSet.OutOfMemory;
- if (a) |value| expect(value == 5678) else |err| switch (err) {
+ if (a) |value| try expect(value == 5678) else |err| switch (err) {
error.OutOfMemory => unreachable,
error.FileNotFound => unreachable,
}
}
test "explicit error set cast" {
- testExplicitErrorSetCast(Set1.A);
- comptime testExplicitErrorSetCast(Set1.A);
+ try testExplicitErrorSetCast(Set1.A);
+ comptime try testExplicitErrorSetCast(Set1.A);
}
const Set1 = error{
@@ -124,26 +124,26 @@ const Set2 = error{
C,
};
-fn testExplicitErrorSetCast(set1: Set1) void {
+fn testExplicitErrorSetCast(set1: Set1) !void {
var x = @errSetCast(Set2, set1);
var y = @errSetCast(Set1, x);
- expect(y == error.A);
+ try expect(y == error.A);
}
test "comptime test error for empty error set" {
- testComptimeTestErrorEmptySet(1234);
- comptime testComptimeTestErrorEmptySet(1234);
+ try testComptimeTestErrorEmptySet(1234);
+ comptime try testComptimeTestErrorEmptySet(1234);
}
const EmptyErrorSet = error{};
-fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {
- if (x) |v| expect(v == 1234) else |err| @compileError("bad");
+fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) !void {
+ if (x) |v| try expect(v == 1234) else |err| @compileError("bad");
}
test "syntax: optional operator in front of error union operator" {
comptime {
- expect(?(anyerror!i32) == ?(anyerror!i32));
+ try expect(?(anyerror!i32) == ?(anyerror!i32));
}
}
@@ -165,10 +165,10 @@ test "empty error union" {
}
test "error union peer type resolution" {
- testErrorUnionPeerTypeResolution(1);
+ try testErrorUnionPeerTypeResolution(1);
}
-fn testErrorUnionPeerTypeResolution(x: i32) void {
+fn testErrorUnionPeerTypeResolution(x: i32) !void {
const y = switch (x) {
1 => bar_1(),
2 => baz_1(),
@@ -177,7 +177,7 @@ fn testErrorUnionPeerTypeResolution(x: i32) void {
if (y) |_| {
@panic("expected error");
} else |e| {
- expect(e == error.A);
+ try expect(e == error.A);
}
}
@@ -286,13 +286,13 @@ test "nested error union function call in optional unwrap" {
return null;
}
};
- expect((try S.errorable()) == 1234);
- expectError(error.Failure, S.errorable2());
- expectError(error.Other, S.errorable3());
+ try expect((try S.errorable()) == 1234);
+ try expectError(error.Failure, S.errorable2());
+ try expectError(error.Other, S.errorable3());
comptime {
- expect((try S.errorable()) == 1234);
- expectError(error.Failure, S.errorable2());
- expectError(error.Other, S.errorable3());
+ try expect((try S.errorable()) == 1234);
+ try expectError(error.Failure, S.errorable2());
+ try expectError(error.Other, S.errorable3());
}
}
@@ -307,7 +307,7 @@ test "widen cast integer payload of error union function call" {
return 1234;
}
};
- expect((try S.errorable()) == 1234);
+ try expect((try S.errorable()) == 1234);
}
test "return function call to error set from error union function" {
@@ -320,19 +320,19 @@ test "return function call to error set from error union function" {
return error.Failure;
}
};
- expectError(error.Failure, S.errorable());
- comptime expectError(error.Failure, S.errorable());
+ try expectError(error.Failure, S.errorable());
+ comptime try expectError(error.Failure, S.errorable());
}
test "optional error set is the same size as error set" {
- comptime expect(@sizeOf(?anyerror) == @sizeOf(anyerror));
+ comptime try expect(@sizeOf(?anyerror) == @sizeOf(anyerror));
const S = struct {
fn returnsOptErrSet() ?anyerror {
return null;
}
};
- expect(S.returnsOptErrSet() == null);
- comptime expect(S.returnsOptErrSet() == null);
+ try expect(S.returnsOptErrSet() == null);
+ comptime try expect(S.returnsOptErrSet() == null);
}
test "debug info for optional error set" {
@@ -342,8 +342,8 @@ test "debug info for optional error set" {
test "nested catch" {
const S = struct {
- fn entry() void {
- expectError(error.Bad, func());
+ fn entry() !void {
+ try expectError(error.Bad, func());
}
fn fail() anyerror!Foo {
return error.Wrong;
@@ -358,16 +358,16 @@ test "nested catch" {
field: i32,
};
};
- S.entry();
- comptime S.entry();
+ try S.entry();
+ comptime try S.entry();
}
test "implicit cast to optional to error union to return result loc" {
const S = struct {
- fn entry() void {
+ fn entry() !void {
var x: Foo = undefined;
if (func(&x)) |opt| {
- expect(opt != null);
+ try expect(opt != null);
} else |_| @panic("expected non error");
}
fn func(f: *Foo) anyerror!?*Foo {
@@ -377,7 +377,7 @@ test "implicit cast to optional to error union to return result loc" {
field: i32,
};
};
- S.entry();
+ try S.entry();
//comptime S.entry(); TODO
}
@@ -393,23 +393,23 @@ test "function pointer with return type that is error union with payload which i
return Err.UnspecifiedErr;
}
- fn doTheTest() void {
+ fn doTheTest() !void {
var x = Foo{ .fun = bar };
- expectError(error.UnspecifiedErr, x.fun(1));
+ try expectError(error.UnspecifiedErr, x.fun(1));
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "return result loc as peer result loc in inferred error set function" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
if (foo(2)) |x| {
- expect(x.Two);
+ try expect(x.Two);
} else |e| switch (e) {
error.Whatever => @panic("fail"),
}
- expectError(error.Whatever, foo(99));
+ try expectError(error.Whatever, foo(99));
}
const FormValue = union(enum) {
One: void,
@@ -424,8 +424,8 @@ test "return result loc as peer result loc in inferred error set function" {
};
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "error payload type is correctly resolved" {
@@ -439,7 +439,7 @@ test "error payload type is correctly resolved" {
}
};
- expectEqual(MyIntWrapper{ .x = 42 }, try MyIntWrapper.create());
+ try expectEqual(MyIntWrapper{ .x = 42 }, try MyIntWrapper.create());
}
test "error union comptime caching" {
@@ -449,4 +449,4 @@ test "error union comptime caching" {
S.foo(@as(anyerror!void, {}));
S.foo(@as(anyerror!void, {}));
-}
\ No newline at end of file
+}
diff --git a/test/stage1/behavior/eval.zig b/test/stage1/behavior/eval.zig
index 38dd12c59d..580ad3509c 100644
--- a/test/stage1/behavior/eval.zig
+++ b/test/stage1/behavior/eval.zig
@@ -4,7 +4,7 @@ const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");
test "compile time recursion" {
- expect(some_data.len == 21);
+ try expect(some_data.len == 21);
}
var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined;
fn fibonacci(x: i32) i32 {
@@ -17,7 +17,7 @@ fn unwrapAndAddOne(blah: ?i32) i32 {
}
const should_be_1235 = unwrapAndAddOne(1234);
test "static add one" {
- expect(should_be_1235 == 1235);
+ try expect(should_be_1235 == 1235);
}
test "inlined loop" {
@@ -25,7 +25,7 @@ test "inlined loop" {
comptime var sum = 0;
inline while (i <= 5) : (i += 1)
sum += i;
- expect(sum == 15);
+ try expect(sum == 15);
}
fn gimme1or2(comptime a: bool) i32 {
@@ -35,12 +35,12 @@ fn gimme1or2(comptime a: bool) i32 {
return z;
}
test "inline variable gets result of const if" {
- expect(gimme1or2(true) == 1);
- expect(gimme1or2(false) == 2);
+ try expect(gimme1or2(true) == 1);
+ try expect(gimme1or2(false) == 2);
}
test "static function evaluation" {
- expect(statically_added_number == 3);
+ try expect(statically_added_number == 3);
}
const statically_added_number = staticAdd(1, 2);
fn staticAdd(a: i32, b: i32) i32 {
@@ -48,8 +48,8 @@ fn staticAdd(a: i32, b: i32) i32 {
}
test "const expr eval on single expr blocks" {
- expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
- comptime expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
+ try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
+ comptime try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
}
fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
@@ -65,10 +65,10 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
}
test "statically initialized list" {
- expect(static_point_list[0].x == 1);
- expect(static_point_list[0].y == 2);
- expect(static_point_list[1].x == 3);
- expect(static_point_list[1].y == 4);
+ try expect(static_point_list[0].x == 1);
+ try expect(static_point_list[0].y == 2);
+ try expect(static_point_list[1].x == 3);
+ try expect(static_point_list[1].y == 4);
}
const Point = struct {
x: i32,
@@ -86,8 +86,8 @@ fn makePoint(x: i32, y: i32) Point {
}
test "static eval list init" {
- expect(static_vec3.data[2] == 1.0);
- expect(vec3(0.0, 0.0, 3.0).data[2] == 3.0);
+ try expect(static_vec3.data[2] == 1.0);
+ try expect(vec3(0.0, 0.0, 3.0).data[2] == 3.0);
}
const static_vec3 = vec3(0.0, 0.0, 1.0);
pub const Vec3 = struct {
@@ -105,12 +105,12 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 {
test "constant expressions" {
var array: [array_size]u8 = undefined;
- expect(@sizeOf(@TypeOf(array)) == 20);
+ try expect(@sizeOf(@TypeOf(array)) == 20);
}
const array_size: u8 = 20;
test "constant struct with negation" {
- expect(vertices[0].x == -0.6);
+ try expect(vertices[0].x == -0.6);
}
const Vertex = struct {
x: f32,
@@ -145,7 +145,7 @@ const vertices = [_]Vertex{
test "statically initialized struct" {
st_init_str_foo.x += 1;
- expect(st_init_str_foo.x == 14);
+ try expect(st_init_str_foo.x == 14);
}
const StInitStrFoo = struct {
x: i32,
@@ -158,7 +158,7 @@ var st_init_str_foo = StInitStrFoo{
test "statically initalized array literal" {
const y: [4]u8 = st_init_arr_lit_x;
- expect(y[3] == 4);
+ try expect(y[3] == 4);
}
const st_init_arr_lit_x = [_]u8{
1,
@@ -170,15 +170,15 @@ const st_init_arr_lit_x = [_]u8{
test "const slice" {
comptime {
const a = "1234567890";
- expect(a.len == 10);
+ try expect(a.len == 10);
const b = a[1..2];
- expect(b.len == 1);
- expect(b[0] == '2');
+ try expect(b.len == 1);
+ try expect(b[0] == '2');
}
}
test "try to trick eval with runtime if" {
- expect(testTryToTrickEvalWithRuntimeIf(true) == 10);
+ try expect(testTryToTrickEvalWithRuntimeIf(true) == 10);
}
fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {
@@ -198,7 +198,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio
const result = if (i == 0) [1]i32{2} else runtime;
}
comptime {
- expect(i == 2);
+ try expect(i == 2);
}
}
@@ -215,16 +215,16 @@ fn letsTryToCompareBools(a: bool, b: bool) bool {
return max(bool, a, b);
}
test "inlined block and runtime block phi" {
- expect(letsTryToCompareBools(true, true));
- expect(letsTryToCompareBools(true, false));
- expect(letsTryToCompareBools(false, true));
- expect(!letsTryToCompareBools(false, false));
+ try expect(letsTryToCompareBools(true, true));
+ try expect(letsTryToCompareBools(true, false));
+ try expect(letsTryToCompareBools(false, true));
+ try expect(!letsTryToCompareBools(false, false));
comptime {
- expect(letsTryToCompareBools(true, true));
- expect(letsTryToCompareBools(true, false));
- expect(letsTryToCompareBools(false, true));
- expect(!letsTryToCompareBools(false, false));
+ try expect(letsTryToCompareBools(true, true));
+ try expect(letsTryToCompareBools(true, false));
+ try expect(letsTryToCompareBools(false, true));
+ try expect(!letsTryToCompareBools(false, false));
}
}
@@ -269,14 +269,14 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
}
test "comptime iterate over fn ptr list" {
- expect(performFn('t', 1) == 6);
- expect(performFn('o', 0) == 1);
- expect(performFn('w', 99) == 99);
+ try expect(performFn('t', 1) == 6);
+ try expect(performFn('o', 0) == 1);
+ try expect(performFn('w', 99) == 99);
}
test "eval @setRuntimeSafety at compile-time" {
const result = comptime fnWithSetRuntimeSafety();
- expect(result == 1234);
+ try expect(result == 1234);
}
fn fnWithSetRuntimeSafety() i32 {
@@ -286,7 +286,7 @@ fn fnWithSetRuntimeSafety() i32 {
test "eval @setFloatMode at compile-time" {
const result = comptime fnWithFloatMode();
- expect(result == 1234.0);
+ try expect(result == 1234.0);
}
fn fnWithFloatMode() f32 {
@@ -307,15 +307,15 @@ var simple_struct = SimpleStruct{ .field = 1234 };
const bound_fn = simple_struct.method;
test "call method on bound fn referring to var instance" {
- expect(bound_fn() == 1237);
+ try expect(bound_fn() == 1237);
}
test "ptr to local array argument at comptime" {
comptime {
var bytes: [10]u8 = undefined;
modifySomeBytes(bytes[0..]);
- expect(bytes[0] == 'a');
- expect(bytes[9] == 'b');
+ try expect(bytes[0] == 'a');
+ try expect(bytes[9] == 'b');
}
}
@@ -343,9 +343,9 @@ fn testCompTimeUIntComparisons(x: u32) void {
}
test "const ptr to variable data changes at runtime" {
- expect(foo_ref.name[0] == 'a');
+ try expect(foo_ref.name[0] == 'a');
foo_ref.name = "b";
- expect(foo_ref.name[0] == 'b');
+ try expect(foo_ref.name[0] == 'b');
}
const Foo = struct {
@@ -356,8 +356,8 @@ var foo_contents = Foo{ .name = "a" };
const foo_ref = &foo_contents;
test "create global array with for loop" {
- expect(global_array[5] == 5 * 5);
- expect(global_array[9] == 9 * 9);
+ try expect(global_array[5] == 5 * 5);
+ try expect(global_array[9] == 9 * 9);
}
const global_array = x: {
@@ -372,18 +372,18 @@ test "compile-time downcast when the bits fit" {
comptime {
const spartan_count: u16 = 255;
const byte = @intCast(u8, spartan_count);
- expect(byte == 255);
+ try expect(byte == 255);
}
}
const hi1 = "hi";
const hi2 = hi1;
test "const global shares pointer with other same one" {
- assertEqualPtrs(&hi1[0], &hi2[0]);
- comptime expect(&hi1[0] == &hi2[0]);
+ try assertEqualPtrs(&hi1[0], &hi2[0]);
+ comptime try expect(&hi1[0] == &hi2[0]);
}
-fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) void {
- expect(ptr1 == ptr2);
+fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void {
+ try expect(ptr1 == ptr2);
}
test "@setEvalBranchQuota" {
@@ -395,29 +395,29 @@ test "@setEvalBranchQuota" {
while (i < 1001) : (i += 1) {
sum += i;
}
- expect(sum == 500500);
+ try expect(sum == 500500);
}
}
test "float literal at compile time not lossy" {
- expect(16777216.0 + 1.0 == 16777217.0);
- expect(9007199254740992.0 + 1.0 == 9007199254740993.0);
+ try expect(16777216.0 + 1.0 == 16777217.0);
+ try expect(9007199254740992.0 + 1.0 == 9007199254740993.0);
}
test "f32 at compile time is lossy" {
- expect(@as(f32, 1 << 24) + 1 == 1 << 24);
+ try expect(@as(f32, 1 << 24) + 1 == 1 << 24);
}
test "f64 at compile time is lossy" {
- expect(@as(f64, 1 << 53) + 1 == 1 << 53);
+ try expect(@as(f64, 1 << 53) + 1 == 1 << 53);
}
test "f128 at compile time is lossy" {
- expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
+ try expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
}
comptime {
- expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192);
+ try expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192);
}
pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
@@ -429,15 +429,15 @@ pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
test "string literal used as comptime slice is memoized" {
const a = "link";
const b = "link";
- comptime expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);
- comptime expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);
+ comptime try expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);
+ comptime try expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);
}
test "comptime slice of undefined pointer of length 0" {
const slice1 = @as([*]i32, undefined)[0..0];
- expect(slice1.len == 0);
+ try expect(slice1.len == 0);
const slice2 = @as([*]i32, undefined)[100..100];
- expect(slice2.len == 0);
+ try expect(slice2.len == 0);
}
fn copyWithPartialInline(s: []u32, b: []u8) void {
@@ -459,16 +459,16 @@ test "binary math operator in partially inlined function" {
r.* = @intCast(u8, i + 1);
copyWithPartialInline(s[0..], b[0..]);
- expect(s[0] == 0x1020304);
- expect(s[1] == 0x5060708);
- expect(s[2] == 0x90a0b0c);
- expect(s[3] == 0xd0e0f10);
+ try expect(s[0] == 0x1020304);
+ try expect(s[1] == 0x5060708);
+ try expect(s[2] == 0x90a0b0c);
+ try expect(s[3] == 0xd0e0f10);
}
test "comptime function with the same args is memoized" {
comptime {
- expect(MakeType(i32) == MakeType(i32));
- expect(MakeType(i32) != MakeType(f64));
+ try expect(MakeType(i32) == MakeType(i32));
+ try expect(MakeType(i32) != MakeType(f64));
}
}
@@ -484,7 +484,7 @@ test "comptime function with mutable pointer is not memoized" {
const ptr = &x;
increment(ptr);
increment(ptr);
- expect(x == 3);
+ try expect(x == 3);
}
}
@@ -510,14 +510,14 @@ fn doesAlotT(comptime T: type, value: usize) T {
}
test "@setEvalBranchQuota at same scope as generic function call" {
- expect(doesAlotT(u32, 2) == 2);
+ try expect(doesAlotT(u32, 2) == 2);
}
test "comptime slice of slice preserves comptime var" {
comptime {
var buff: [10]u8 = undefined;
buff[0..][0..][0] = 1;
- expect(buff[0..][0..][0] == 1);
+ try expect(buff[0..][0..][0] == 1);
}
}
@@ -526,7 +526,7 @@ test "comptime slice of pointer preserves comptime var" {
var buff: [10]u8 = undefined;
var a = @ptrCast([*]u8, &buff);
a[0..1][0] = 1;
- expect(buff[0..][0..][0] == 1);
+ try expect(buff[0..][0..][0] == 1);
}
}
@@ -540,9 +540,9 @@ const SingleFieldStruct = struct {
test "const ptr to comptime mutable data is not memoized" {
comptime {
var foo = SingleFieldStruct{ .x = 1 };
- expect(foo.read_x() == 1);
+ try expect(foo.read_x() == 1);
foo.x = 2;
- expect(foo.read_x() == 2);
+ try expect(foo.read_x() == 2);
}
}
@@ -551,7 +551,7 @@ test "array concat of slices gives slice" {
var a: []const u8 = "aoeu";
var b: []const u8 = "asdf";
const c = a ++ b;
- expect(std.mem.eql(u8, c, "aoeuasdf"));
+ try expect(std.mem.eql(u8, c, "aoeuasdf"));
}
}
@@ -568,14 +568,14 @@ test "comptime shlWithOverflow" {
break :amt amt;
};
- expect(ct_shifted == rt_shifted);
+ try expect(ct_shifted == rt_shifted);
}
test "runtime 128 bit integer division" {
var a: u128 = 152313999999999991610955792383;
var b: u128 = 10000000000000000000;
var c = a / b;
- expect(c == 15231399999);
+ try expect(c == 15231399999);
}
pub const Info = struct {
@@ -588,20 +588,20 @@ test "comptime modification of const struct field" {
comptime {
var res = diamond_info;
res.version = 1;
- expect(diamond_info.version == 0);
- expect(res.version == 1);
+ try expect(diamond_info.version == 0);
+ try expect(res.version == 1);
}
}
test "pointer to type" {
comptime {
var T: type = i32;
- expect(T == i32);
+ try expect(T == i32);
var ptr = &T;
- expect(@TypeOf(ptr) == *type);
+ try expect(@TypeOf(ptr) == *type);
ptr.* = f32;
- expect(T == f32);
- expect(*T == *f32);
+ try expect(T == f32);
+ try expect(*T == *f32);
}
}
@@ -610,17 +610,17 @@ test "slice of type" {
var types_array = [_]type{ i32, f64, type };
for (types_array) |T, i| {
switch (i) {
- 0 => expect(T == i32),
- 1 => expect(T == f64),
- 2 => expect(T == type),
+ 0 => try expect(T == i32),
+ 1 => try expect(T == f64),
+ 2 => try expect(T == type),
else => unreachable,
}
}
for (types_array[0..]) |T, i| {
switch (i) {
- 0 => expect(T == i32),
- 1 => expect(T == f64),
- 2 => expect(T == type),
+ 0 => try expect(T == i32),
+ 1 => try expect(T == f64),
+ 2 => try expect(T == type),
else => unreachable,
}
}
@@ -637,7 +637,7 @@ fn wrap(comptime T: type) Wrapper {
test "function which returns struct with type field causes implicit comptime" {
const ty = wrap(i32).T;
- expect(ty == i32);
+ try expect(ty == i32);
}
test "call method with comptime pass-by-non-copying-value self parameter" {
@@ -651,12 +651,12 @@ test "call method with comptime pass-by-non-copying-value self parameter" {
const s = S{ .a = 2 };
var b = s.b();
- expect(b == 2);
+ try expect(b == 2);
}
test "@tagName of @typeInfo" {
const str = @tagName(@typeInfo(u8));
- expect(std.mem.eql(u8, str, "Int"));
+ try expect(std.mem.eql(u8, str, "Int"));
}
test "setting backward branch quota just before a generic fn call" {
@@ -670,15 +670,15 @@ fn loopNTimes(comptime n: usize) void {
}
test "variable inside inline loop that has different types on different iterations" {
- testVarInsideInlineLoop(.{ true, @as(u32, 42) });
+ try testVarInsideInlineLoop(.{ true, @as(u32, 42) });
}
-fn testVarInsideInlineLoop(args: anytype) void {
+fn testVarInsideInlineLoop(args: anytype) !void {
comptime var i = 0;
inline while (i < args.len) : (i += 1) {
const x = args[i];
- if (i == 0) expect(x);
- if (i == 1) expect(x == 42);
+ if (i == 0) try expect(x);
+ if (i == 1) try expect(x == 42);
}
}
@@ -688,7 +688,7 @@ test "inline for with same type but different values" {
var a: T = undefined;
res += a.len;
}
- expect(res == 5);
+ try expect(res == 5);
}
test "refer to the type of a generic function" {
@@ -702,13 +702,13 @@ fn doNothingWithType(comptime T: type) void {}
test "zero extend from u0 to u1" {
var zero_u0: u0 = 0;
var zero_u1: u1 = zero_u0;
- expect(zero_u1 == 0);
+ try expect(zero_u1 == 0);
}
test "bit shift a u1" {
var x: u1 = 1;
var y = x << 0;
- expect(y == 1);
+ try expect(y == 1);
}
test "comptime pointer cast array and then slice" {
@@ -720,8 +720,8 @@ test "comptime pointer cast array and then slice" {
const ptrB: [*]const u8 = &array;
const sliceB: []const u8 = ptrB[0..2];
- expect(sliceA[1] == 2);
- expect(sliceB[1] == 2);
+ try expect(sliceA[1] == 2);
+ try expect(sliceB[1] == 2);
}
test "slice bounds in comptime concatenation" {
@@ -730,46 +730,46 @@ test "slice bounds in comptime concatenation" {
break :blk b[8..9];
};
const str = "" ++ bs;
- expect(str.len == 1);
- expect(std.mem.eql(u8, str, "1"));
+ try expect(str.len == 1);
+ try expect(std.mem.eql(u8, str, "1"));
const str2 = bs ++ "";
- expect(str2.len == 1);
- expect(std.mem.eql(u8, str2, "1"));
+ try expect(str2.len == 1);
+ try expect(std.mem.eql(u8, str2, "1"));
}
test "comptime bitwise operators" {
comptime {
- expect(3 & 1 == 1);
- expect(3 & -1 == 3);
- expect(-3 & -1 == -3);
- expect(3 | -1 == -1);
- expect(-3 | -1 == -1);
- expect(3 ^ -1 == -4);
- expect(-3 ^ -1 == 2);
- expect(~@as(i8, -1) == 0);
- expect(~@as(i128, -1) == 0);
- expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);
- expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);
- expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff);
+ try expect(3 & 1 == 1);
+ try expect(3 & -1 == 3);
+ try expect(-3 & -1 == -3);
+ try expect(3 | -1 == -1);
+ try expect(-3 | -1 == -1);
+ try expect(3 ^ -1 == -4);
+ try expect(-3 ^ -1 == 2);
+ try expect(~@as(i8, -1) == 0);
+ try expect(~@as(i128, -1) == 0);
+ try expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);
+ try expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);
+ try expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff);
}
}
test "*align(1) u16 is the same as *align(1:0:2) u16" {
comptime {
- expect(*align(1:0:2) u16 == *align(1) u16);
- expect(*align(2:0:2) u16 == *u16);
+ try expect(*align(1:0:2) u16 == *align(1) u16);
+ try expect(*align(2:0:2) u16 == *u16);
}
}
test "array concatenation forces comptime" {
var a = oneItem(3) ++ oneItem(4);
- expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 }));
+ try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 }));
}
test "array multiplication forces comptime" {
var a = oneItem(3) ** scalar(2);
- expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 }));
+ try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 }));
}
fn oneItem(x: i32) [1]i32 {
@@ -791,7 +791,7 @@ test "comptime assign int to optional int" {
var x: ?i32 = null;
x = 2;
x.? *= 10;
- expectEqual(20, x.?);
+ try expectEqual(20, x.?);
}
}
diff --git a/test/stage1/behavior/field_parent_ptr.zig b/test/stage1/behavior/field_parent_ptr.zig
index 6026a49d12..addb7942ad 100644
--- a/test/stage1/behavior/field_parent_ptr.zig
+++ b/test/stage1/behavior/field_parent_ptr.zig
@@ -1,13 +1,13 @@
const expect = @import("std").testing.expect;
test "@fieldParentPtr non-first field" {
- testParentFieldPtr(&foo.c);
- comptime testParentFieldPtr(&foo.c);
+ try testParentFieldPtr(&foo.c);
+ comptime try testParentFieldPtr(&foo.c);
}
test "@fieldParentPtr first field" {
- testParentFieldPtrFirst(&foo.a);
- comptime testParentFieldPtrFirst(&foo.a);
+ try testParentFieldPtrFirst(&foo.a);
+ comptime try testParentFieldPtrFirst(&foo.a);
}
const Foo = struct {
@@ -24,18 +24,18 @@ const foo = Foo{
.d = -10,
};
-fn testParentFieldPtr(c: *const i32) void {
- expect(c == &foo.c);
+fn testParentFieldPtr(c: *const i32) !void {
+ try expect(c == &foo.c);
const base = @fieldParentPtr(Foo, "c", c);
- expect(base == &foo);
- expect(&base.c == c);
+ try expect(base == &foo);
+ try expect(&base.c == c);
}
-fn testParentFieldPtrFirst(a: *const bool) void {
- expect(a == &foo.a);
+fn testParentFieldPtrFirst(a: *const bool) !void {
+ try expect(a == &foo.a);
const base = @fieldParentPtr(Foo, "a", a);
- expect(base == &foo);
- expect(&base.a == a);
+ try expect(base == &foo);
+ try expect(&base.a == a);
}
diff --git a/test/stage1/behavior/floatop.zig b/test/stage1/behavior/floatop.zig
index 9f2e45ed26..ec8641340f 100644
--- a/test/stage1/behavior/floatop.zig
+++ b/test/stage1/behavior/floatop.zig
@@ -8,441 +8,441 @@ const Vector = std.meta.Vector;
const epsilon = 0.000001;
test "@sqrt" {
- comptime testSqrt();
- testSqrt();
+ comptime try testSqrt();
+ try testSqrt();
}
-fn testSqrt() void {
+fn testSqrt() !void {
{
var a: f16 = 4;
- expect(@sqrt(a) == 2);
+ try expect(@sqrt(a) == 2);
}
{
var a: f32 = 9;
- expect(@sqrt(a) == 3);
+ try expect(@sqrt(a) == 3);
var b: f32 = 1.1;
- expect(math.approxEqAbs(f32, @sqrt(b), 1.0488088481701516, epsilon));
+ try expect(math.approxEqAbs(f32, @sqrt(b), 1.0488088481701516, epsilon));
}
{
var a: f64 = 25;
- expect(@sqrt(a) == 5);
+ try expect(@sqrt(a) == 5);
}
{
const a: comptime_float = 25.0;
- expect(@sqrt(a) == 5.0);
+ try expect(@sqrt(a) == 5.0);
}
// TODO https://github.com/ziglang/zig/issues/4026
//{
// var a: f128 = 49;
- // expect(@sqrt(a) == 7);
+ //try expect(@sqrt(a) == 7);
//}
{
var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
var result = @sqrt(v);
- expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @sqrt(@as(f32, 4.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 4.4)), result[3], epsilon));
}
}
test "more @sqrt f16 tests" {
// TODO these are not all passing at comptime
- expect(@sqrt(@as(f16, 0.0)) == 0.0);
- expect(math.approxEqAbs(f16, @sqrt(@as(f16, 2.0)), 1.414214, epsilon));
- expect(math.approxEqAbs(f16, @sqrt(@as(f16, 3.6)), 1.897367, epsilon));
- expect(@sqrt(@as(f16, 4.0)) == 2.0);
- expect(math.approxEqAbs(f16, @sqrt(@as(f16, 7.539840)), 2.745877, epsilon));
- expect(math.approxEqAbs(f16, @sqrt(@as(f16, 19.230934)), 4.385309, epsilon));
- expect(@sqrt(@as(f16, 64.0)) == 8.0);
- expect(math.approxEqAbs(f16, @sqrt(@as(f16, 64.1)), 8.006248, epsilon));
- expect(math.approxEqAbs(f16, @sqrt(@as(f16, 8942.230469)), 94.563370, epsilon));
+ try expect(@sqrt(@as(f16, 0.0)) == 0.0);
+ try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 2.0)), 1.414214, epsilon));
+ try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 3.6)), 1.897367, epsilon));
+ try expect(@sqrt(@as(f16, 4.0)) == 2.0);
+ try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 7.539840)), 2.745877, epsilon));
+ try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 19.230934)), 4.385309, epsilon));
+ try expect(@sqrt(@as(f16, 64.0)) == 8.0);
+ try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 64.1)), 8.006248, epsilon));
+ try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 8942.230469)), 94.563370, epsilon));
// special cases
- expect(math.isPositiveInf(@sqrt(@as(f16, math.inf(f16)))));
- expect(@sqrt(@as(f16, 0.0)) == 0.0);
- expect(@sqrt(@as(f16, -0.0)) == -0.0);
- expect(math.isNan(@sqrt(@as(f16, -1.0))));
- expect(math.isNan(@sqrt(@as(f16, math.nan(f16)))));
+ try expect(math.isPositiveInf(@sqrt(@as(f16, math.inf(f16)))));
+ try expect(@sqrt(@as(f16, 0.0)) == 0.0);
+ try expect(@sqrt(@as(f16, -0.0)) == -0.0);
+ try expect(math.isNan(@sqrt(@as(f16, -1.0))));
+ try expect(math.isNan(@sqrt(@as(f16, math.nan(f16)))));
}
test "@sin" {
- comptime testSin();
- testSin();
+ comptime try testSin();
+ try testSin();
}
-fn testSin() void {
+fn testSin() !void {
// TODO test f128, and c_longdouble
// https://github.com/ziglang/zig/issues/4026
{
var a: f16 = 0;
- expect(@sin(a) == 0);
+ try expect(@sin(a) == 0);
}
{
var a: f32 = 0;
- expect(@sin(a) == 0);
+ try expect(@sin(a) == 0);
}
{
var a: f64 = 0;
- expect(@sin(a) == 0);
+ try expect(@sin(a) == 0);
}
{
var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
var result = @sin(v);
- expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @sin(@as(f32, 4.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @sin(@as(f32, 4.4)), result[3], epsilon));
}
}
test "@cos" {
- comptime testCos();
- testCos();
+ comptime try testCos();
+ try testCos();
}
-fn testCos() void {
+fn testCos() !void {
// TODO test f128, and c_longdouble
// https://github.com/ziglang/zig/issues/4026
{
var a: f16 = 0;
- expect(@cos(a) == 1);
+ try expect(@cos(a) == 1);
}
{
var a: f32 = 0;
- expect(@cos(a) == 1);
+ try expect(@cos(a) == 1);
}
{
var a: f64 = 0;
- expect(@cos(a) == 1);
+ try expect(@cos(a) == 1);
}
{
var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
var result = @cos(v);
- expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @cos(@as(f32, 4.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @cos(@as(f32, 4.4)), result[3], epsilon));
}
}
test "@exp" {
- comptime testExp();
- testExp();
+ comptime try testExp();
+ try testExp();
}
-fn testExp() void {
+fn testExp() !void {
// TODO test f128, and c_longdouble
// https://github.com/ziglang/zig/issues/4026
{
var a: f16 = 0;
- expect(@exp(a) == 1);
+ try expect(@exp(a) == 1);
}
{
var a: f32 = 0;
- expect(@exp(a) == 1);
+ try expect(@exp(a) == 1);
}
{
var a: f64 = 0;
- expect(@exp(a) == 1);
+ try expect(@exp(a) == 1);
}
{
var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
var result = @exp(v);
- expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @exp(@as(f32, 0.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.4)), result[3], epsilon));
}
}
test "@exp2" {
- comptime testExp2();
- testExp2();
+ comptime try testExp2();
+ try testExp2();
}
-fn testExp2() void {
+fn testExp2() !void {
// TODO test f128, and c_longdouble
// https://github.com/ziglang/zig/issues/4026
{
var a: f16 = 2;
- expect(@exp2(a) == 4);
+ try expect(@exp2(a) == 4);
}
{
var a: f32 = 2;
- expect(@exp2(a) == 4);
+ try expect(@exp2(a) == 4);
}
{
var a: f64 = 2;
- expect(@exp2(a) == 4);
+ try expect(@exp2(a) == 4);
}
{
var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
var result = @exp2(v);
- expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.4)), result[3], epsilon));
}
}
test "@log" {
// Old musl (and glibc?), and our current math.ln implementation do not return 1
// so also accept those values.
- comptime testLog();
- testLog();
+ comptime try testLog();
+ try testLog();
}
-fn testLog() void {
+fn testLog() !void {
// TODO test f128, and c_longdouble
// https://github.com/ziglang/zig/issues/4026
{
var a: f16 = e;
- expect(math.approxEqAbs(f16, @log(a), 1, epsilon));
+ try expect(math.approxEqAbs(f16, @log(a), 1, epsilon));
}
{
var a: f32 = e;
- expect(@log(a) == 1 or @log(a) == @bitCast(f32, @as(u32, 0x3f7fffff)));
+ try expect(@log(a) == 1 or @log(a) == @bitCast(f32, @as(u32, 0x3f7fffff)));
}
{
var a: f64 = e;
- expect(@log(a) == 1 or @log(a) == @bitCast(f64, @as(u64, 0x3ff0000000000000)));
+ try expect(@log(a) == 1 or @log(a) == @bitCast(f64, @as(u64, 0x3ff0000000000000)));
}
{
var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
var result = @log(v);
- expect(math.approxEqAbs(f32, @log(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @log(@as(f32, 2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @log(@as(f32, 0.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @log(@as(f32, 0.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @log(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @log(@as(f32, 2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @log(@as(f32, 0.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @log(@as(f32, 0.4)), result[3], epsilon));
}
}
test "@log2" {
- comptime testLog2();
- testLog2();
+ comptime try testLog2();
+ try testLog2();
}
-fn testLog2() void {
+fn testLog2() !void {
// TODO test f128, and c_longdouble
// https://github.com/ziglang/zig/issues/4026
{
var a: f16 = 4;
- expect(@log2(a) == 2);
+ try expect(@log2(a) == 2);
}
{
var a: f32 = 4;
- expect(@log2(a) == 2);
+ try expect(@log2(a) == 2);
}
{
var a: f64 = 4;
- expect(@log2(a) == 2);
+ try expect(@log2(a) == 2);
}
{
var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
var result = @log2(v);
- expect(math.approxEqAbs(f32, @log2(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @log2(@as(f32, 2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @log2(@as(f32, 0.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @log2(@as(f32, 0.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @log2(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @log2(@as(f32, 2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @log2(@as(f32, 0.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @log2(@as(f32, 0.4)), result[3], epsilon));
}
}
test "@log10" {
- comptime testLog10();
- testLog10();
+ comptime try testLog10();
+ try testLog10();
}
-fn testLog10() void {
+fn testLog10() !void {
// TODO test f128, and c_longdouble
// https://github.com/ziglang/zig/issues/4026
{
var a: f16 = 100;
- expect(@log10(a) == 2);
+ try expect(@log10(a) == 2);
}
{
var a: f32 = 100;
- expect(@log10(a) == 2);
+ try expect(@log10(a) == 2);
}
{
var a: f64 = 1000;
- expect(@log10(a) == 3);
+ try expect(@log10(a) == 3);
}
{
var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
var result = @log10(v);
- expect(math.approxEqAbs(f32, @log10(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @log10(@as(f32, 2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @log10(@as(f32, 0.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @log10(@as(f32, 0.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @log10(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @log10(@as(f32, 2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @log10(@as(f32, 0.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @log10(@as(f32, 0.4)), result[3], epsilon));
}
}
test "@fabs" {
- comptime testFabs();
- testFabs();
+ comptime try testFabs();
+ try testFabs();
}
-fn testFabs() void {
+fn testFabs() !void {
// TODO test f128, and c_longdouble
// https://github.com/ziglang/zig/issues/4026
{
var a: f16 = -2.5;
var b: f16 = 2.5;
- expect(@fabs(a) == 2.5);
- expect(@fabs(b) == 2.5);
+ try expect(@fabs(a) == 2.5);
+ try expect(@fabs(b) == 2.5);
}
{
var a: f32 = -2.5;
var b: f32 = 2.5;
- expect(@fabs(a) == 2.5);
- expect(@fabs(b) == 2.5);
+ try expect(@fabs(a) == 2.5);
+ try expect(@fabs(b) == 2.5);
}
{
var a: f64 = -2.5;
var b: f64 = 2.5;
- expect(@fabs(a) == 2.5);
- expect(@fabs(b) == 2.5);
+ try expect(@fabs(a) == 2.5);
+ try expect(@fabs(b) == 2.5);
}
{
var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
var result = @fabs(v);
- expect(math.approxEqAbs(f32, @fabs(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @fabs(@as(f32, -2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @fabs(@as(f32, 0.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @fabs(@as(f32, -0.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @fabs(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @fabs(@as(f32, -2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @fabs(@as(f32, 0.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @fabs(@as(f32, -0.4)), result[3], epsilon));
}
}
test "@floor" {
- comptime testFloor();
- testFloor();
+ comptime try testFloor();
+ try testFloor();
}
-fn testFloor() void {
+fn testFloor() !void {
// TODO test f128, and c_longdouble
// https://github.com/ziglang/zig/issues/4026
{
var a: f16 = 2.1;
- expect(@floor(a) == 2);
+ try expect(@floor(a) == 2);
}
{
var a: f32 = 2.1;
- expect(@floor(a) == 2);
+ try expect(@floor(a) == 2);
}
{
var a: f64 = 3.5;
- expect(@floor(a) == 3);
+ try expect(@floor(a) == 3);
}
{
var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
var result = @floor(v);
- expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @floor(@as(f32, -0.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @floor(@as(f32, -0.4)), result[3], epsilon));
}
}
test "@ceil" {
- comptime testCeil();
- testCeil();
+ comptime try testCeil();
+ try testCeil();
}
-fn testCeil() void {
+fn testCeil() !void {
// TODO test f128, and c_longdouble
// https://github.com/ziglang/zig/issues/4026
{
var a: f16 = 2.1;
- expect(@ceil(a) == 3);
+ try expect(@ceil(a) == 3);
}
{
var a: f32 = 2.1;
- expect(@ceil(a) == 3);
+ try expect(@ceil(a) == 3);
}
{
var a: f64 = 3.5;
- expect(@ceil(a) == 4);
+ try expect(@ceil(a) == 4);
}
{
var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
var result = @ceil(v);
- expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @ceil(@as(f32, -0.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @ceil(@as(f32, -0.4)), result[3], epsilon));
}
}
test "@trunc" {
- comptime testTrunc();
- testTrunc();
+ comptime try testTrunc();
+ try testTrunc();
}
-fn testTrunc() void {
+fn testTrunc() !void {
// TODO test f128, and c_longdouble
// https://github.com/ziglang/zig/issues/4026
{
var a: f16 = 2.1;
- expect(@trunc(a) == 2);
+ try expect(@trunc(a) == 2);
}
{
var a: f32 = 2.1;
- expect(@trunc(a) == 2);
+ try expect(@trunc(a) == 2);
}
{
var a: f64 = -3.5;
- expect(@trunc(a) == -3);
+ try expect(@trunc(a) == -3);
}
{
var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
var result = @trunc(v);
- expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon));
- expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon));
- expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon));
- expect(math.approxEqAbs(f32, @trunc(@as(f32, -0.4)), result[3], epsilon));
+ try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon));
+ try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon));
+ try expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon));
+ try expect(math.approxEqAbs(f32, @trunc(@as(f32, -0.4)), result[3], epsilon));
}
}
test "floating point comparisons" {
- testFloatComparisons();
- comptime testFloatComparisons();
+ try testFloatComparisons();
+ comptime try testFloatComparisons();
}
-fn testFloatComparisons() void {
+fn testFloatComparisons() !void {
inline for ([_]type{ f16, f32, f64, f128 }) |ty| {
// No decimal part
{
const x: ty = 1.0;
- expect(x == 1);
- expect(x != 0);
- expect(x > 0);
- expect(x < 2);
- expect(x >= 1);
- expect(x <= 1);
+ try expect(x == 1);
+ try expect(x != 0);
+ try expect(x > 0);
+ try expect(x < 2);
+ try expect(x >= 1);
+ try expect(x <= 1);
}
// Non-zero decimal part
{
const x: ty = 1.5;
- expect(x != 1);
- expect(x != 2);
- expect(x > 1);
- expect(x < 2);
- expect(x >= 1);
- expect(x <= 2);
+ try expect(x != 1);
+ try expect(x != 2);
+ try expect(x > 1);
+ try expect(x < 2);
+ try expect(x >= 1);
+ try expect(x <= 2);
}
}
}
test "different sized float comparisons" {
- testDifferentSizedFloatComparisons();
- comptime testDifferentSizedFloatComparisons();
+ try testDifferentSizedFloatComparisons();
+ comptime try testDifferentSizedFloatComparisons();
}
-fn testDifferentSizedFloatComparisons() void {
+fn testDifferentSizedFloatComparisons() !void {
var a: f16 = 1;
var b: f64 = 2;
- expect(a < b);
+ try expect(a < b);
}
// TODO This is waiting on library support for the Windows build (not sure why the other's don't need it)
@@ -456,10 +456,10 @@ fn testDifferentSizedFloatComparisons() void {
// // https://github.com/ziglang/zig/issues/4026
// {
// var a: f32 = 2.1;
-// expect(@nearbyint(a) == 2);
+// try expect(@nearbyint(a) == 2);
// }
// {
// var a: f64 = -3.75;
-// expect(@nearbyint(a) == -4);
+// try expect(@nearbyint(a) == -4);
// }
//}
diff --git a/test/stage1/behavior/fn.zig b/test/stage1/behavior/fn.zig
index a1e726c565..f6d9bce3fe 100644
--- a/test/stage1/behavior/fn.zig
+++ b/test/stage1/behavior/fn.zig
@@ -4,7 +4,7 @@ const expect = testing.expect;
const expectEqual = testing.expectEqual;
test "params" {
- expect(testParamsAdd(22, 11) == 33);
+ try expect(testParamsAdd(22, 11) == 33);
}
fn testParamsAdd(a: i32, b: i32) i32 {
return a + b;
@@ -19,37 +19,37 @@ fn testLocVars(b: i32) void {
}
test "void parameters" {
- voidFun(1, void{}, 2, {});
+ try voidFun(1, void{}, 2, {});
}
-fn voidFun(a: i32, b: void, c: i32, d: void) void {
+fn voidFun(a: i32, b: void, c: i32, d: void) !void {
const v = b;
const vv: void = if (a == 1) v else {};
- expect(a + c == 3);
+ try expect(a + c == 3);
return vv;
}
test "mutable local variables" {
var zero: i32 = 0;
- expect(zero == 0);
+ try expect(zero == 0);
var i = @as(i32, 0);
while (i != 3) {
i += 1;
}
- expect(i == 3);
+ try expect(i == 3);
}
test "separate block scopes" {
{
const no_conflict: i32 = 5;
- expect(no_conflict == 5);
+ try expect(no_conflict == 5);
}
const c = x: {
const no_conflict = @as(i32, 10);
break :x no_conflict;
};
- expect(c == 10);
+ try expect(c == 10);
}
test "call function with empty string" {
@@ -62,7 +62,7 @@ fn @"weird function name"() i32 {
return 1234;
}
test "weird function name" {
- expect(@"weird function name"() == 1234);
+ try expect(@"weird function name"() == 1234);
}
test "implicit cast function unreachable return" {
@@ -83,7 +83,7 @@ test "function pointers" {
fn4,
};
for (fns) |f, i| {
- expect(f() == @intCast(u32, i) + 5);
+ try expect(f() == @intCast(u32, i) + 5);
}
}
fn fn1() u32 {
@@ -100,12 +100,12 @@ fn fn4() u32 {
}
test "number literal as an argument" {
- numberLiteralArg(3);
- comptime numberLiteralArg(3);
+ try numberLiteralArg(3);
+ comptime try numberLiteralArg(3);
}
-fn numberLiteralArg(a: anytype) void {
- expect(a == 3);
+fn numberLiteralArg(a: anytype) !void {
+ try expect(a == 3);
}
test "assign inline fn to const variable" {
@@ -116,7 +116,7 @@ test "assign inline fn to const variable" {
fn inlineFn() callconv(.Inline) void {}
test "pass by non-copying value" {
- expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);
+ try expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);
}
const Point = struct {
@@ -129,17 +129,17 @@ fn addPointCoords(pt: Point) i32 {
}
test "pass by non-copying value through var arg" {
- expect(addPointCoordsVar(Point{ .x = 1, .y = 2 }) == 3);
+ try expect((try addPointCoordsVar(Point{ .x = 1, .y = 2 })) == 3);
}
-fn addPointCoordsVar(pt: anytype) i32 {
- comptime expect(@TypeOf(pt) == Point);
+fn addPointCoordsVar(pt: anytype) !i32 {
+ comptime try expect(@TypeOf(pt) == Point);
return pt.x + pt.y;
}
test "pass by non-copying value as method" {
var pt = Point2{ .x = 1, .y = 2 };
- expect(pt.addPointCoords() == 3);
+ try expect(pt.addPointCoords() == 3);
}
const Point2 = struct {
@@ -153,7 +153,7 @@ const Point2 = struct {
test "pass by non-copying value as method, which is generic" {
var pt = Point3{ .x = 1, .y = 2 };
- expect(pt.addPointCoords(i32) == 3);
+ try expect(pt.addPointCoords(i32) == 3);
}
const Point3 = struct {
@@ -168,7 +168,7 @@ const Point3 = struct {
test "pass by non-copying value as method, at comptime" {
comptime {
var pt = Point2{ .x = 1, .y = 2 };
- expect(pt.addPointCoords() == 3);
+ try expect(pt.addPointCoords() == 3);
}
}
@@ -184,7 +184,7 @@ fn outer(y: u32) fn (u32) u32 {
test "return inner function which references comptime variable of outer function" {
var func = outer(10);
- expect(func(3) == 7);
+ try expect(func(3) == 7);
}
test "extern struct with stdcallcc fn pointer" {
@@ -198,16 +198,16 @@ test "extern struct with stdcallcc fn pointer" {
var s: S = undefined;
s.ptr = S.foo;
- expect(s.ptr() == 1234);
+ try expect(s.ptr() == 1234);
}
test "implicit cast fn call result to optional in field result" {
const S = struct {
- fn entry() void {
+ fn entry() !void {
var x = Foo{
.field = optionalPtr(),
};
- expect(x.field.?.* == 999);
+ try expect(x.field.?.* == 999);
}
const glob: i32 = 999;
@@ -220,8 +220,8 @@ test "implicit cast fn call result to optional in field result" {
field: ?*const i32,
};
};
- S.entry();
- comptime S.entry();
+ try S.entry();
+ comptime try S.entry();
}
test "discard the result of a function that returns a struct" {
@@ -245,26 +245,26 @@ test "discard the result of a function that returns a struct" {
test "function call with anon list literal" {
const S = struct {
- fn doTheTest() void {
- consumeVec(.{ 9, 8, 7 });
+ fn doTheTest() !void {
+ try consumeVec(.{ 9, 8, 7 });
}
- fn consumeVec(vec: [3]f32) void {
- expect(vec[0] == 9);
- expect(vec[1] == 8);
- expect(vec[2] == 7);
+ fn consumeVec(vec: [3]f32) !void {
+ try expect(vec[0] == 9);
+ try expect(vec[1] == 8);
+ try expect(vec[2] == 7);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "ability to give comptime types and non comptime types to same parameter" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var x: i32 = 1;
- expect(foo(x) == 10);
- expect(foo(i32) == 20);
+ try expect(foo(x) == 10);
+ try expect(foo(i32) == 20);
}
fn foo(arg: anytype) i32 {
@@ -272,8 +272,8 @@ test "ability to give comptime types and non comptime types to same parameter" {
return 9 + arg;
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "function with inferred error set but returning no error" {
@@ -282,5 +282,5 @@ test "function with inferred error set but returning no error" {
};
const return_ty = @typeInfo(@TypeOf(S.foo)).Fn.return_type.?;
- expectEqual(0, @typeInfo(@typeInfo(return_ty).ErrorUnion.error_set).ErrorSet.?.len);
+ try expectEqual(0, @typeInfo(@typeInfo(return_ty).ErrorUnion.error_set).ErrorSet.?.len);
}
diff --git a/test/stage1/behavior/fn_delegation.zig b/test/stage1/behavior/fn_delegation.zig
index 57006805c8..72a72c0bdd 100644
--- a/test/stage1/behavior/fn_delegation.zig
+++ b/test/stage1/behavior/fn_delegation.zig
@@ -32,8 +32,8 @@ fn custom(comptime T: type, comptime num: u64) fn (T) u64 {
test "fn delegation" {
const foo = Foo{};
- expect(foo.one() == 11);
- expect(foo.two() == 12);
- expect(foo.three() == 13);
- expect(foo.four() == 14);
+ try expect(foo.one() == 11);
+ try expect(foo.two() == 12);
+ try expect(foo.three() == 13);
+ try expect(foo.four() == 14);
}
diff --git a/test/stage1/behavior/fn_in_struct_in_comptime.zig b/test/stage1/behavior/fn_in_struct_in_comptime.zig
index 030693ac59..ee8e98ad1c 100644
--- a/test/stage1/behavior/fn_in_struct_in_comptime.zig
+++ b/test/stage1/behavior/fn_in_struct_in_comptime.zig
@@ -13,5 +13,5 @@ fn get_foo() fn (*u8) usize {
test "define a function in an anonymous struct in comptime" {
const foo = get_foo();
- expect(foo(@intToPtr(*u8, 12345)) == 12345);
+ try expect(foo(@intToPtr(*u8, 12345)) == 12345);
}
diff --git a/test/stage1/behavior/for.zig b/test/stage1/behavior/for.zig
index c49c73802d..9f08d41246 100644
--- a/test/stage1/behavior/for.zig
+++ b/test/stage1/behavior/for.zig
@@ -27,12 +27,12 @@ test "for loop with pointer elem var" {
var target: [source.len]u8 = undefined;
mem.copy(u8, target[0..], source);
mangleString(target[0..]);
- expect(mem.eql(u8, &target, "bcdefgh"));
+ try expect(mem.eql(u8, &target, "bcdefgh"));
for (source) |*c, i|
- expect(@TypeOf(c) == *const u8);
+ try expect(@TypeOf(c) == *const u8);
for (target) |*c, i|
- expect(@TypeOf(c) == *u8);
+ try expect(@TypeOf(c) == *u8);
}
fn mangleString(s: []u8) void {
@@ -75,15 +75,15 @@ test "basic for loop" {
buf_index += 1;
}
- expect(mem.eql(u8, buffer[0..buf_index], &expected_result));
+ try expect(mem.eql(u8, buffer[0..buf_index], &expected_result));
}
test "break from outer for loop" {
- testBreakOuter();
- comptime testBreakOuter();
+ try testBreakOuter();
+ comptime try testBreakOuter();
}
-fn testBreakOuter() void {
+fn testBreakOuter() !void {
var array = "aoeu";
var count: usize = 0;
outer: for (array) |_| {
@@ -92,15 +92,15 @@ fn testBreakOuter() void {
break :outer;
}
}
- expect(count == 1);
+ try expect(count == 1);
}
test "continue outer for loop" {
- testContinueOuter();
- comptime testContinueOuter();
+ try testContinueOuter();
+ comptime try testContinueOuter();
}
-fn testContinueOuter() void {
+fn testContinueOuter() !void {
var array = "aoeu";
var counter: usize = 0;
outer: for (array) |_| {
@@ -109,28 +109,28 @@ fn testContinueOuter() void {
continue :outer;
}
}
- expect(counter == array.len);
+ try expect(counter == array.len);
}
test "2 break statements and an else" {
const S = struct {
- fn entry(t: bool, f: bool) void {
+ fn entry(t: bool, f: bool) !void {
var buf: [10]u8 = undefined;
var ok = false;
ok = for (buf) |item| {
if (f) break false;
if (t) break true;
} else false;
- expect(ok);
+ try expect(ok);
}
};
- S.entry(true, false);
- comptime S.entry(true, false);
+ try S.entry(true, false);
+ comptime try S.entry(true, false);
}
test "for with null and T peer types and inferred result location type" {
const S = struct {
- fn doTheTest(slice: []const u8) void {
+ fn doTheTest(slice: []const u8) !void {
if (for (slice) |item| {
if (item == 10) {
break item;
@@ -140,33 +140,33 @@ test "for with null and T peer types and inferred result location type" {
}
}
};
- S.doTheTest(&[_]u8{ 1, 2 });
- comptime S.doTheTest(&[_]u8{ 1, 2 });
+ try S.doTheTest(&[_]u8{ 1, 2 });
+ comptime try S.doTheTest(&[_]u8{ 1, 2 });
}
test "for copies its payload" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var x = [_]usize{ 1, 2, 3 };
for (x) |value, i| {
// Modify the original array
x[i] += 99;
- expectEqual(value, i + 1);
+ try expectEqual(value, i + 1);
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "for on slice with allowzero ptr" {
const S = struct {
- fn doTheTest(slice: []const u8) void {
+ fn doTheTest(slice: []const u8) !void {
var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len];
- for (ptr) |x, i| expect(x == i + 1);
- for (ptr) |*x, i| expect(x.* == i + 1);
+ for (ptr) |x, i| try expect(x == i + 1);
+ for (ptr) |*x, i| try expect(x.* == i + 1);
}
};
- S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
- comptime S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
+ try S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
+ comptime try S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
}
diff --git a/test/stage1/behavior/generics.zig b/test/stage1/behavior/generics.zig
index ee6496bcaa..2a4fabde45 100644
--- a/test/stage1/behavior/generics.zig
+++ b/test/stage1/behavior/generics.zig
@@ -4,9 +4,9 @@ const expect = testing.expect;
const expectEqual = testing.expectEqual;
test "simple generic fn" {
- expect(max(i32, 3, -1) == 3);
- expect(max(f32, 0.123, 0.456) == 0.456);
- expect(add(2, 3) == 5);
+ try expect(max(i32, 3, -1) == 3);
+ try expect(max(f32, 0.123, 0.456) == 0.456);
+ try expect(add(2, 3) == 5);
}
fn max(comptime T: type, a: T, b: T) T {
@@ -19,7 +19,7 @@ fn add(comptime a: i32, b: i32) i32 {
const the_max = max(u32, 1234, 5678);
test "compile time generic eval" {
- expect(the_max == 5678);
+ try expect(the_max == 5678);
}
fn gimmeTheBigOne(a: u32, b: u32) u32 {
@@ -35,19 +35,19 @@ fn sameButWithFloats(a: f64, b: f64) f64 {
}
test "fn with comptime args" {
- expect(gimmeTheBigOne(1234, 5678) == 5678);
- expect(shouldCallSameInstance(34, 12) == 34);
- expect(sameButWithFloats(0.43, 0.49) == 0.49);
+ try expect(gimmeTheBigOne(1234, 5678) == 5678);
+ try expect(shouldCallSameInstance(34, 12) == 34);
+ try expect(sameButWithFloats(0.43, 0.49) == 0.49);
}
test "var params" {
- expect(max_i32(12, 34) == 34);
- expect(max_f64(1.2, 3.4) == 3.4);
+ try expect(max_i32(12, 34) == 34);
+ try expect(max_f64(1.2, 3.4) == 3.4);
}
comptime {
- expect(max_i32(12, 34) == 34);
- expect(max_f64(1.2, 3.4) == 3.4);
+ try expect(max_i32(12, 34) == 34);
+ try expect(max_f64(1.2, 3.4) == 3.4);
}
fn max_var(a: anytype, b: anytype) @TypeOf(a + b) {
@@ -79,8 +79,8 @@ test "function with return type type" {
var list2: List(i32) = undefined;
list.length = 10;
list2.length = 10;
- expect(list.prealloc_items.len == 8);
- expect(list2.prealloc_items.len == 8);
+ try expect(list.prealloc_items.len == 8);
+ try expect(list2.prealloc_items.len == 8);
}
test "generic struct" {
@@ -92,9 +92,9 @@ test "generic struct" {
.value = true,
.next = null,
};
- expect(a1.value == 13);
- expect(a1.value == a1.getVal());
- expect(b1.getVal());
+ try expect(a1.value == 13);
+ try expect(a1.value == a1.getVal());
+ try expect(b1.getVal());
}
fn GenNode(comptime T: type) type {
return struct {
@@ -107,7 +107,7 @@ fn GenNode(comptime T: type) type {
}
test "const decls in struct" {
- expect(GenericDataThing(3).count_plus_one == 4);
+ try expect(GenericDataThing(3).count_plus_one == 4);
}
fn GenericDataThing(comptime count: isize) type {
return struct {
@@ -116,15 +116,15 @@ fn GenericDataThing(comptime count: isize) type {
}
test "use generic param in generic param" {
- expect(aGenericFn(i32, 3, 4) == 7);
+ try expect(aGenericFn(i32, 3, 4) == 7);
}
fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
return a + b;
}
test "generic fn with implicit cast" {
- expect(getFirstByte(u8, &[_]u8{13}) == 13);
- expect(getFirstByte(u16, &[_]u16{
+ try expect(getFirstByte(u8, &[_]u8{13}) == 13);
+ try expect(getFirstByte(u16, &[_]u16{
0,
13,
}) == 0);
@@ -149,21 +149,21 @@ fn foo2(arg: anytype) bool {
}
test "array of generic fns" {
- expect(foos[0](true));
- expect(!foos[1](true));
+ try expect(foos[0](true));
+ try expect(!foos[1](true));
}
test "generic fn keeps non-generic parameter types" {
const A = 128;
const S = struct {
- fn f(comptime T: type, s: []T) void {
- expect(A != @typeInfo(@TypeOf(s)).Pointer.alignment);
+ fn f(comptime T: type, s: []T) !void {
+ try expect(A != @typeInfo(@TypeOf(s)).Pointer.alignment);
}
};
// The compiler monomorphizes `S.f` for `T=u8` on its first use, check that
// `x` type not affect `s` parameter type.
var x: [16]u8 align(A) = undefined;
- S.f(u8, &x);
+ try S.f(u8, &x);
}
diff --git a/test/stage1/behavior/hasdecl.zig b/test/stage1/behavior/hasdecl.zig
index f3bb9887fe..381e79760c 100644
--- a/test/stage1/behavior/hasdecl.zig
+++ b/test/stage1/behavior/hasdecl.zig
@@ -11,11 +11,11 @@ const Bar = struct {
};
test "@hasDecl" {
- expect(@hasDecl(Foo, "public_thing"));
- expect(!@hasDecl(Foo, "private_thing"));
- expect(!@hasDecl(Foo, "no_thing"));
+ try expect(@hasDecl(Foo, "public_thing"));
+ try expect(!@hasDecl(Foo, "private_thing"));
+ try expect(!@hasDecl(Foo, "no_thing"));
- expect(@hasDecl(Bar, "hi"));
- expect(@hasDecl(Bar, "blah"));
- expect(!@hasDecl(Bar, "nope"));
+ try expect(@hasDecl(Bar, "hi"));
+ try expect(@hasDecl(Bar, "blah"));
+ try expect(!@hasDecl(Bar, "nope"));
}
diff --git a/test/stage1/behavior/hasfield.zig b/test/stage1/behavior/hasfield.zig
index c179fedd56..81026273c0 100644
--- a/test/stage1/behavior/hasfield.zig
+++ b/test/stage1/behavior/hasfield.zig
@@ -8,10 +8,10 @@ test "@hasField" {
pub const nope = 1;
};
- expect(@hasField(struc, "a") == true);
- expect(@hasField(struc, "b") == true);
- expect(@hasField(struc, "non-existant") == false);
- expect(@hasField(struc, "nope") == false);
+ try expect(@hasField(struc, "a") == true);
+ try expect(@hasField(struc, "b") == true);
+ try expect(@hasField(struc, "non-existant") == false);
+ try expect(@hasField(struc, "nope") == false);
const unin = union {
a: u64,
@@ -19,10 +19,10 @@ test "@hasField" {
pub const nope = 1;
};
- expect(@hasField(unin, "a") == true);
- expect(@hasField(unin, "b") == true);
- expect(@hasField(unin, "non-existant") == false);
- expect(@hasField(unin, "nope") == false);
+ try expect(@hasField(unin, "a") == true);
+ try expect(@hasField(unin, "b") == true);
+ try expect(@hasField(unin, "non-existant") == false);
+ try expect(@hasField(unin, "nope") == false);
const enm = enum {
a,
@@ -30,8 +30,8 @@ test "@hasField" {
pub const nope = 1;
};
- expect(@hasField(enm, "a") == true);
- expect(@hasField(enm, "b") == true);
- expect(@hasField(enm, "non-existant") == false);
- expect(@hasField(enm, "nope") == false);
+ try expect(@hasField(enm, "a") == true);
+ try expect(@hasField(enm, "b") == true);
+ try expect(@hasField(enm, "non-existant") == false);
+ try expect(@hasField(enm, "nope") == false);
}
diff --git a/test/stage1/behavior/if.zig b/test/stage1/behavior/if.zig
index de8a29c76d..1951a9262a 100644
--- a/test/stage1/behavior/if.zig
+++ b/test/stage1/behavior/if.zig
@@ -26,7 +26,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) void {
}
test "else if expression" {
- expect(elseIfExpressionF(1) == 1);
+ try expect(elseIfExpressionF(1) == 1);
}
fn elseIfExpressionF(c: u8) u8 {
if (c == 0) {
@@ -44,14 +44,14 @@ var global_with_err: anyerror!u32 = error.SomeError;
test "unwrap mutable global var" {
if (global_with_val) |v| {
- expect(v == 0);
+ try expect(v == 0);
} else |e| {
unreachable;
}
if (global_with_err) |_| {
unreachable;
} else |e| {
- expect(e == error.SomeError);
+ try expect(e == error.SomeError);
}
}
@@ -63,7 +63,7 @@ test "labeled break inside comptime if inside runtime if" {
break :blk @as(i32, 42);
};
}
- expect(answer == 42);
+ try expect(answer == 42);
}
test "const result loc, runtime if cond, else unreachable" {
@@ -74,36 +74,36 @@ test "const result loc, runtime if cond, else unreachable" {
var t = true;
const x = if (t) Num.Two else unreachable;
- expect(x == .Two);
+ try expect(x == .Two);
}
test "if prongs cast to expected type instead of peer type resolution" {
const S = struct {
- fn doTheTest(f: bool) void {
+ fn doTheTest(f: bool) !void {
var x: i32 = 0;
x = if (f) 1 else 2;
- expect(x == 2);
+ try expect(x == 2);
var b = true;
const y: i32 = if (b) 1 else 2;
- expect(y == 1);
+ try expect(y == 1);
}
};
- S.doTheTest(false);
- comptime S.doTheTest(false);
+ try S.doTheTest(false);
+ comptime try S.doTheTest(false);
}
test "while copies its payload" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var tmp: ?i32 = 10;
if (tmp) |value| {
// Modify the original variable
tmp = null;
- expectEqual(@as(i32, 10), value);
+ try expectEqual(@as(i32, 10), value);
} else unreachable;
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
diff --git a/test/stage1/behavior/import.zig b/test/stage1/behavior/import.zig
index 30655554bf..2b037637da 100644
--- a/test/stage1/behavior/import.zig
+++ b/test/stage1/behavior/import.zig
@@ -3,18 +3,18 @@ const expectEqual = @import("std").testing.expectEqual;
const a_namespace = @import("import/a_namespace.zig");
test "call fn via namespace lookup" {
- expectEqual(@as(i32, 1234), a_namespace.foo());
+ try expectEqual(@as(i32, 1234), a_namespace.foo());
}
test "importing the same thing gives the same import" {
- expect(@import("std") == @import("std"));
+ try expect(@import("std") == @import("std"));
}
test "import in non-toplevel scope" {
const S = struct {
usingnamespace @import("import/a_namespace.zig");
};
- expectEqual(@as(i32, 1234), S.foo());
+ try expectEqual(@as(i32, 1234), S.foo());
}
test "import empty file" {
diff --git a/test/stage1/behavior/incomplete_struct_param_tld.zig b/test/stage1/behavior/incomplete_struct_param_tld.zig
index 77a3dfd221..a1e0672c7b 100644
--- a/test/stage1/behavior/incomplete_struct_param_tld.zig
+++ b/test/stage1/behavior/incomplete_struct_param_tld.zig
@@ -26,5 +26,5 @@ test "incomplete struct param top level declaration" {
.c = C{ .x = 13 },
},
};
- expect(foo(a) == 13);
+ try expect(foo(a) == 13);
}
diff --git a/test/stage1/behavior/inttoptr.zig b/test/stage1/behavior/inttoptr.zig
index b1780f93d6..de6e8e3a1e 100644
--- a/test/stage1/behavior/inttoptr.zig
+++ b/test/stage1/behavior/inttoptr.zig
@@ -1,7 +1,3 @@
-const builtin = @import("builtin");
-const std = @import("std");
-const expect = std.testing.expect;
-
test "casting random address to function pointer" {
randomAddressToFunction();
comptime randomAddressToFunction();
diff --git a/test/stage1/behavior/ir_block_deps.zig b/test/stage1/behavior/ir_block_deps.zig
index 821079df79..aacb7b7658 100644
--- a/test/stage1/behavior/ir_block_deps.zig
+++ b/test/stage1/behavior/ir_block_deps.zig
@@ -16,6 +16,6 @@ fn getErrInt() anyerror!i32 {
}
test "ir block deps" {
- expect((foo(1) catch unreachable) == 0);
- expect((foo(2) catch unreachable) == 0);
+ try expect((foo(1) catch unreachable) == 0);
+ try expect((foo(2) catch unreachable) == 0);
}
diff --git a/test/stage1/behavior/math.zig b/test/stage1/behavior/math.zig
index 32f4842702..e615c36551 100644
--- a/test/stage1/behavior/math.zig
+++ b/test/stage1/behavior/math.zig
@@ -7,71 +7,71 @@ const minInt = std.math.minInt;
const mem = std.mem;
test "division" {
- testDivision();
- comptime testDivision();
+ try testDivision();
+ comptime try testDivision();
}
-fn testDivision() void {
- expect(div(u32, 13, 3) == 4);
- expect(div(f16, 1.0, 2.0) == 0.5);
- expect(div(f32, 1.0, 2.0) == 0.5);
+fn testDivision() !void {
+ try expect(div(u32, 13, 3) == 4);
+ try expect(div(f16, 1.0, 2.0) == 0.5);
+ try expect(div(f32, 1.0, 2.0) == 0.5);
- expect(divExact(u32, 55, 11) == 5);
- expect(divExact(i32, -55, 11) == -5);
- expect(divExact(f16, 55.0, 11.0) == 5.0);
- expect(divExact(f16, -55.0, 11.0) == -5.0);
- expect(divExact(f32, 55.0, 11.0) == 5.0);
- expect(divExact(f32, -55.0, 11.0) == -5.0);
+ try expect(divExact(u32, 55, 11) == 5);
+ try expect(divExact(i32, -55, 11) == -5);
+ try expect(divExact(f16, 55.0, 11.0) == 5.0);
+ try expect(divExact(f16, -55.0, 11.0) == -5.0);
+ try expect(divExact(f32, 55.0, 11.0) == 5.0);
+ try expect(divExact(f32, -55.0, 11.0) == -5.0);
- expect(divFloor(i32, 5, 3) == 1);
- expect(divFloor(i32, -5, 3) == -2);
- expect(divFloor(f16, 5.0, 3.0) == 1.0);
- expect(divFloor(f16, -5.0, 3.0) == -2.0);
- expect(divFloor(f32, 5.0, 3.0) == 1.0);
- expect(divFloor(f32, -5.0, 3.0) == -2.0);
- expect(divFloor(i32, -0x80000000, -2) == 0x40000000);
- expect(divFloor(i32, 0, -0x80000000) == 0);
- expect(divFloor(i32, -0x40000001, 0x40000000) == -2);
- expect(divFloor(i32, -0x80000000, 1) == -0x80000000);
- expect(divFloor(i32, 10, 12) == 0);
- expect(divFloor(i32, -14, 12) == -2);
- expect(divFloor(i32, -2, 12) == -1);
+ try expect(divFloor(i32, 5, 3) == 1);
+ try expect(divFloor(i32, -5, 3) == -2);
+ try expect(divFloor(f16, 5.0, 3.0) == 1.0);
+ try expect(divFloor(f16, -5.0, 3.0) == -2.0);
+ try expect(divFloor(f32, 5.0, 3.0) == 1.0);
+ try expect(divFloor(f32, -5.0, 3.0) == -2.0);
+ try expect(divFloor(i32, -0x80000000, -2) == 0x40000000);
+ try expect(divFloor(i32, 0, -0x80000000) == 0);
+ try expect(divFloor(i32, -0x40000001, 0x40000000) == -2);
+ try expect(divFloor(i32, -0x80000000, 1) == -0x80000000);
+ try expect(divFloor(i32, 10, 12) == 0);
+ try expect(divFloor(i32, -14, 12) == -2);
+ try expect(divFloor(i32, -2, 12) == -1);
- expect(divTrunc(i32, 5, 3) == 1);
- expect(divTrunc(i32, -5, 3) == -1);
- expect(divTrunc(f16, 5.0, 3.0) == 1.0);
- expect(divTrunc(f16, -5.0, 3.0) == -1.0);
- expect(divTrunc(f32, 5.0, 3.0) == 1.0);
- expect(divTrunc(f32, -5.0, 3.0) == -1.0);
- expect(divTrunc(f64, 5.0, 3.0) == 1.0);
- expect(divTrunc(f64, -5.0, 3.0) == -1.0);
- expect(divTrunc(i32, 10, 12) == 0);
- expect(divTrunc(i32, -14, 12) == -1);
- expect(divTrunc(i32, -2, 12) == 0);
+ try expect(divTrunc(i32, 5, 3) == 1);
+ try expect(divTrunc(i32, -5, 3) == -1);
+ try expect(divTrunc(f16, 5.0, 3.0) == 1.0);
+ try expect(divTrunc(f16, -5.0, 3.0) == -1.0);
+ try expect(divTrunc(f32, 5.0, 3.0) == 1.0);
+ try expect(divTrunc(f32, -5.0, 3.0) == -1.0);
+ try expect(divTrunc(f64, 5.0, 3.0) == 1.0);
+ try expect(divTrunc(f64, -5.0, 3.0) == -1.0);
+ try expect(divTrunc(i32, 10, 12) == 0);
+ try expect(divTrunc(i32, -14, 12) == -1);
+ try expect(divTrunc(i32, -2, 12) == 0);
- expect(mod(i32, 10, 12) == 10);
- expect(mod(i32, -14, 12) == 10);
- expect(mod(i32, -2, 12) == 10);
+ try expect(mod(i32, 10, 12) == 10);
+ try expect(mod(i32, -14, 12) == 10);
+ try expect(mod(i32, -2, 12) == 10);
comptime {
- expect(
+ try expect(
1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600,
);
- expect(
+ try expect(
@rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600,
);
- expect(
+ try expect(
1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2,
);
- expect(
+ try expect(
@divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2,
);
- expect(
+ try expect(
@divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2,
);
- expect(
+ try expect(
@divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2,
);
- expect(
+ try expect(
4126227191251978491697987544882340798050766755606969681711 % 10 == 1,
);
}
@@ -94,9 +94,9 @@ fn mod(comptime T: type, a: T, b: T) T {
test "@addWithOverflow" {
var result: u8 = undefined;
- expect(@addWithOverflow(u8, 250, 100, &result));
- expect(!@addWithOverflow(u8, 100, 150, &result));
- expect(result == 250);
+ try expect(@addWithOverflow(u8, 250, 100, &result));
+ try expect(!@addWithOverflow(u8, 100, 150, &result));
+ try expect(result == 250);
}
// TODO test mulWithOverflow
@@ -104,31 +104,31 @@ test "@addWithOverflow" {
test "@shlWithOverflow" {
var result: u16 = undefined;
- expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));
- expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));
- expect(result == 0b1011111111111100);
+ try expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));
+ try expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));
+ try expect(result == 0b1011111111111100);
}
test "@*WithOverflow with u0 values" {
var result: u0 = undefined;
- expect(!@addWithOverflow(u0, 0, 0, &result));
- expect(!@subWithOverflow(u0, 0, 0, &result));
- expect(!@mulWithOverflow(u0, 0, 0, &result));
- expect(!@shlWithOverflow(u0, 0, 0, &result));
+ try expect(!@addWithOverflow(u0, 0, 0, &result));
+ try expect(!@subWithOverflow(u0, 0, 0, &result));
+ try expect(!@mulWithOverflow(u0, 0, 0, &result));
+ try expect(!@shlWithOverflow(u0, 0, 0, &result));
}
test "@clz" {
- testClz();
- comptime testClz();
+ try testClz();
+ comptime try testClz();
}
-fn testClz() void {
- expect(clz(u8, 0b10001010) == 0);
- expect(clz(u8, 0b00001010) == 4);
- expect(clz(u8, 0b00011010) == 3);
- expect(clz(u8, 0b00000000) == 8);
- expect(clz(u128, 0xffffffffffffffff) == 64);
- expect(clz(u128, 0x10000000000000000) == 63);
+fn testClz() !void {
+ try expect(clz(u8, 0b10001010) == 0);
+ try expect(clz(u8, 0b00001010) == 4);
+ try expect(clz(u8, 0b00011010) == 3);
+ try expect(clz(u8, 0b00000000) == 8);
+ try expect(clz(u128, 0xffffffffffffffff) == 64);
+ try expect(clz(u128, 0x10000000000000000) == 63);
}
fn clz(comptime T: type, x: T) usize {
@@ -136,15 +136,15 @@ fn clz(comptime T: type, x: T) usize {
}
test "@ctz" {
- testCtz();
- comptime testCtz();
+ try testCtz();
+ comptime try testCtz();
}
-fn testCtz() void {
- expect(ctz(u8, 0b10100000) == 5);
- expect(ctz(u8, 0b10001010) == 1);
- expect(ctz(u8, 0b00000000) == 8);
- expect(ctz(u16, 0b00000000) == 16);
+fn testCtz() !void {
+ try expect(ctz(u8, 0b10100000) == 5);
+ try expect(ctz(u8, 0b10001010) == 1);
+ try expect(ctz(u8, 0b00000000) == 8);
+ try expect(ctz(u16, 0b00000000) == 16);
}
fn ctz(comptime T: type, x: T) usize {
@@ -154,109 +154,109 @@ fn ctz(comptime T: type, x: T) usize {
test "assignment operators" {
var i: u32 = 0;
i += 5;
- expect(i == 5);
+ try expect(i == 5);
i -= 2;
- expect(i == 3);
+ try expect(i == 3);
i *= 20;
- expect(i == 60);
+ try expect(i == 60);
i /= 3;
- expect(i == 20);
+ try expect(i == 20);
i %= 11;
- expect(i == 9);
+ try expect(i == 9);
i <<= 1;
- expect(i == 18);
+ try expect(i == 18);
i >>= 2;
- expect(i == 4);
+ try expect(i == 4);
i = 6;
i &= 5;
- expect(i == 4);
+ try expect(i == 4);
i ^= 6;
- expect(i == 2);
+ try expect(i == 2);
i = 6;
i |= 3;
- expect(i == 7);
+ try expect(i == 7);
}
test "three expr in a row" {
- testThreeExprInARow(false, true);
- comptime testThreeExprInARow(false, true);
+ try testThreeExprInARow(false, true);
+ comptime try testThreeExprInARow(false, true);
}
-fn testThreeExprInARow(f: bool, t: bool) void {
- assertFalse(f or f or f);
- assertFalse(t and t and f);
- assertFalse(1 | 2 | 4 != 7);
- assertFalse(3 ^ 6 ^ 8 != 13);
- assertFalse(7 & 14 & 28 != 4);
- assertFalse(9 << 1 << 2 != 9 << 3);
- assertFalse(90 >> 1 >> 2 != 90 >> 3);
- assertFalse(100 - 1 + 1000 != 1099);
- assertFalse(5 * 4 / 2 % 3 != 1);
- assertFalse(@as(i32, @as(i32, 5)) != 5);
- assertFalse(!!false);
- assertFalse(@as(i32, 7) != --(@as(i32, 7)));
+fn testThreeExprInARow(f: bool, t: bool) !void {
+ try assertFalse(f or f or f);
+ try assertFalse(t and t and f);
+ try assertFalse(1 | 2 | 4 != 7);
+ try assertFalse(3 ^ 6 ^ 8 != 13);
+ try assertFalse(7 & 14 & 28 != 4);
+ try assertFalse(9 << 1 << 2 != 9 << 3);
+ try assertFalse(90 >> 1 >> 2 != 90 >> 3);
+ try assertFalse(100 - 1 + 1000 != 1099);
+ try assertFalse(5 * 4 / 2 % 3 != 1);
+ try assertFalse(@as(i32, @as(i32, 5)) != 5);
+ try assertFalse(!!false);
+ try assertFalse(@as(i32, 7) != --(@as(i32, 7)));
}
-fn assertFalse(b: bool) void {
- expect(!b);
+fn assertFalse(b: bool) !void {
+ try expect(!b);
}
test "const number literal" {
const one = 1;
const eleven = ten + one;
- expect(eleven == 11);
+ try expect(eleven == 11);
}
const ten = 10;
test "unsigned wrapping" {
- testUnsignedWrappingEval(maxInt(u32));
- comptime testUnsignedWrappingEval(maxInt(u32));
+ try testUnsignedWrappingEval(maxInt(u32));
+ comptime try testUnsignedWrappingEval(maxInt(u32));
}
-fn testUnsignedWrappingEval(x: u32) void {
+fn testUnsignedWrappingEval(x: u32) !void {
const zero = x +% 1;
- expect(zero == 0);
+ try expect(zero == 0);
const orig = zero -% 1;
- expect(orig == maxInt(u32));
+ try expect(orig == maxInt(u32));
}
test "signed wrapping" {
- testSignedWrappingEval(maxInt(i32));
- comptime testSignedWrappingEval(maxInt(i32));
+ try testSignedWrappingEval(maxInt(i32));
+ comptime try testSignedWrappingEval(maxInt(i32));
}
-fn testSignedWrappingEval(x: i32) void {
+fn testSignedWrappingEval(x: i32) !void {
const min_val = x +% 1;
- expect(min_val == minInt(i32));
+ try expect(min_val == minInt(i32));
const max_val = min_val -% 1;
- expect(max_val == maxInt(i32));
+ try expect(max_val == maxInt(i32));
}
test "signed negation wrapping" {
- testSignedNegationWrappingEval(minInt(i16));
- comptime testSignedNegationWrappingEval(minInt(i16));
+ try testSignedNegationWrappingEval(minInt(i16));
+ comptime try testSignedNegationWrappingEval(minInt(i16));
}
-fn testSignedNegationWrappingEval(x: i16) void {
- expect(x == -32768);
+fn testSignedNegationWrappingEval(x: i16) !void {
+ try expect(x == -32768);
const neg = -%x;
- expect(neg == -32768);
+ try expect(neg == -32768);
}
test "unsigned negation wrapping" {
- testUnsignedNegationWrappingEval(1);
- comptime testUnsignedNegationWrappingEval(1);
+ try testUnsignedNegationWrappingEval(1);
+ comptime try testUnsignedNegationWrappingEval(1);
}
-fn testUnsignedNegationWrappingEval(x: u16) void {
- expect(x == 1);
+fn testUnsignedNegationWrappingEval(x: u16) !void {
+ try expect(x == 1);
const neg = -%x;
- expect(neg == maxInt(u16));
+ try expect(neg == maxInt(u16));
}
test "unsigned 64-bit division" {
- test_u64_div();
- comptime test_u64_div();
+ try test_u64_div();
+ comptime try test_u64_div();
}
-fn test_u64_div() void {
+fn test_u64_div() !void {
const result = divWithResult(1152921504606846976, 34359738365);
- expect(result.quotient == 33554432);
- expect(result.remainder == 100663296);
+ try expect(result.quotient == 33554432);
+ try expect(result.remainder == 100663296);
}
fn divWithResult(a: u64, b: u64) DivResult {
return DivResult{
@@ -270,62 +270,62 @@ const DivResult = struct {
};
test "binary not" {
- expect(comptime x: {
+ try expect(comptime x: {
break :x ~@as(u16, 0b1010101010101010) == 0b0101010101010101;
});
- expect(comptime x: {
+ try expect(comptime x: {
break :x ~@as(u64, 2147483647) == 18446744071562067968;
});
- testBinaryNot(0b1010101010101010);
+ try testBinaryNot(0b1010101010101010);
}
-fn testBinaryNot(x: u16) void {
- expect(~x == 0b0101010101010101);
+fn testBinaryNot(x: u16) !void {
+ try expect(~x == 0b0101010101010101);
}
test "small int addition" {
var x: u2 = 0;
- expect(x == 0);
+ try expect(x == 0);
x += 1;
- expect(x == 1);
+ try expect(x == 1);
x += 1;
- expect(x == 2);
+ try expect(x == 2);
x += 1;
- expect(x == 3);
+ try expect(x == 3);
var result: @TypeOf(x) = 3;
- expect(@addWithOverflow(@TypeOf(x), x, 1, &result));
+ try expect(@addWithOverflow(@TypeOf(x), x, 1, &result));
- expect(result == 0);
+ try expect(result == 0);
}
test "float equality" {
const x: f64 = 0.012;
const y: f64 = x + 1.0;
- testFloatEqualityImpl(x, y);
- comptime testFloatEqualityImpl(x, y);
+ try testFloatEqualityImpl(x, y);
+ comptime try testFloatEqualityImpl(x, y);
}
-fn testFloatEqualityImpl(x: f64, y: f64) void {
+fn testFloatEqualityImpl(x: f64, y: f64) !void {
const y2 = x + 1.0;
- expect(y == y2);
+ try expect(y == y2);
}
test "allow signed integer division/remainder when values are comptime known and positive or exact" {
- expect(5 / 3 == 1);
- expect(-5 / -3 == 1);
- expect(-6 / 3 == -2);
+ try expect(5 / 3 == 1);
+ try expect(-5 / -3 == 1);
+ try expect(-6 / 3 == -2);
- expect(5 % 3 == 2);
- expect(-6 % 3 == 0);
+ try expect(5 % 3 == 2);
+ try expect(-6 % 3 == 0);
}
test "hex float literal parsing" {
- comptime expect(0x1.0 == 1.0);
+ comptime try expect(0x1.0 == 1.0);
}
test "quad hex float literal parsing in range" {
@@ -340,29 +340,29 @@ test "quad hex float literal parsing accurate" {
// implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing.
const expected: u128 = 0x3fff1111222233334444555566667777;
- expect(@bitCast(u128, a) == expected);
+ try expect(@bitCast(u128, a) == expected);
// non-normalized
const b: f128 = 0x11.111222233334444555566667777p-4;
- expect(@bitCast(u128, b) == expected);
+ try expect(@bitCast(u128, b) == expected);
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
{
var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;
- expect(@bitCast(u128, f) == 0x40042eab345678439abcdefea5678234);
+ try expect(@bitCast(u128, f) == 0x40042eab345678439abcdefea5678234);
}
{
var f: f128 = 0x1.edcb34a235253948765432134674fp-1;
- expect(@bitCast(u128, f) == 0x3ffeedcb34a235253948765432134674);
+ try expect(@bitCast(u128, f) == 0x3ffeedcb34a235253948765432134674);
}
{
var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50;
- expect(@bitCast(u128, f) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
+ try expect(@bitCast(u128, f) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
}
{
var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;
- expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568);
+ try expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568);
}
const exp2ft = [_]f64{
0x1.6a09e667f3bcdp-1,
@@ -417,40 +417,40 @@ test "quad hex float literal parsing accurate" {
};
for (exp2ft) |x, i| {
- expect(@bitCast(u64, x) == answers[i]);
+ try expect(@bitCast(u64, x) == answers[i]);
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "underscore separator parsing" {
- expect(0_0_0_0 == 0);
- expect(1_234_567 == 1234567);
- expect(001_234_567 == 1234567);
- expect(0_0_1_2_3_4_5_6_7 == 1234567);
+ try expect(0_0_0_0 == 0);
+ try expect(1_234_567 == 1234567);
+ try expect(001_234_567 == 1234567);
+ try expect(0_0_1_2_3_4_5_6_7 == 1234567);
- expect(0b0_0_0_0 == 0);
- expect(0b1010_1010 == 0b10101010);
- expect(0b0000_1010_1010 == 0b10101010);
- expect(0b1_0_1_0_1_0_1_0 == 0b10101010);
+ try expect(0b0_0_0_0 == 0);
+ try expect(0b1010_1010 == 0b10101010);
+ try expect(0b0000_1010_1010 == 0b10101010);
+ try expect(0b1_0_1_0_1_0_1_0 == 0b10101010);
- expect(0o0_0_0_0 == 0);
- expect(0o1010_1010 == 0o10101010);
- expect(0o0000_1010_1010 == 0o10101010);
- expect(0o1_0_1_0_1_0_1_0 == 0o10101010);
+ try expect(0o0_0_0_0 == 0);
+ try expect(0o1010_1010 == 0o10101010);
+ try expect(0o0000_1010_1010 == 0o10101010);
+ try expect(0o1_0_1_0_1_0_1_0 == 0o10101010);
- expect(0x0_0_0_0 == 0);
- expect(0x1010_1010 == 0x10101010);
- expect(0x0000_1010_1010 == 0x10101010);
- expect(0x1_0_1_0_1_0_1_0 == 0x10101010);
+ try expect(0x0_0_0_0 == 0);
+ try expect(0x1010_1010 == 0x10101010);
+ try expect(0x0000_1010_1010 == 0x10101010);
+ try expect(0x1_0_1_0_1_0_1_0 == 0x10101010);
- expect(123_456.789_000e1_0 == 123456.789000e10);
- expect(0_1_2_3_4_5_6.7_8_9_0_0_0e0_0_1_0 == 123456.789000e10);
+ try expect(123_456.789_000e1_0 == 123456.789000e10);
+ try expect(0_1_2_3_4_5_6.7_8_9_0_0_0e0_0_1_0 == 123456.789000e10);
- expect(0x1234_5678.9ABC_DEF0p-1_0 == 0x12345678.9ABCDEF0p-10);
- expect(0x1_2_3_4_5_6_7_8.9_A_B_C_D_E_F_0p-0_0_0_1_0 == 0x12345678.9ABCDEF0p-10);
+ try expect(0x1234_5678.9ABC_DEF0p-1_0 == 0x12345678.9ABCDEF0p-10);
+ try expect(0x1_2_3_4_5_6_7_8.9_A_B_C_D_E_F_0p-0_0_0_1_0 == 0x12345678.9ABCDEF0p-10);
}
test "hex float literal within range" {
@@ -460,73 +460,73 @@ test "hex float literal within range" {
}
test "truncating shift left" {
- testShlTrunc(maxInt(u16));
- comptime testShlTrunc(maxInt(u16));
+ try testShlTrunc(maxInt(u16));
+ comptime try testShlTrunc(maxInt(u16));
}
-fn testShlTrunc(x: u16) void {
+fn testShlTrunc(x: u16) !void {
const shifted = x << 1;
- expect(shifted == 65534);
+ try expect(shifted == 65534);
}
test "truncating shift right" {
- testShrTrunc(maxInt(u16));
- comptime testShrTrunc(maxInt(u16));
+ try testShrTrunc(maxInt(u16));
+ comptime try testShrTrunc(maxInt(u16));
}
-fn testShrTrunc(x: u16) void {
+fn testShrTrunc(x: u16) !void {
const shifted = x >> 1;
- expect(shifted == 32767);
+ try expect(shifted == 32767);
}
test "exact shift left" {
- testShlExact(0b00110101);
- comptime testShlExact(0b00110101);
+ try testShlExact(0b00110101);
+ comptime try testShlExact(0b00110101);
}
-fn testShlExact(x: u8) void {
+fn testShlExact(x: u8) !void {
const shifted = @shlExact(x, 2);
- expect(shifted == 0b11010100);
+ try expect(shifted == 0b11010100);
}
test "exact shift right" {
- testShrExact(0b10110100);
- comptime testShrExact(0b10110100);
+ try testShrExact(0b10110100);
+ comptime try testShrExact(0b10110100);
}
-fn testShrExact(x: u8) void {
+fn testShrExact(x: u8) !void {
const shifted = @shrExact(x, 2);
- expect(shifted == 0b00101101);
+ try expect(shifted == 0b00101101);
}
test "shift left/right on u0 operand" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var x: u0 = 0;
var y: u0 = 0;
- expectEqual(@as(u0, 0), x << 0);
- expectEqual(@as(u0, 0), x >> 0);
- expectEqual(@as(u0, 0), x << y);
- expectEqual(@as(u0, 0), x >> y);
- expectEqual(@as(u0, 0), @shlExact(x, 0));
- expectEqual(@as(u0, 0), @shrExact(x, 0));
- expectEqual(@as(u0, 0), @shlExact(x, y));
- expectEqual(@as(u0, 0), @shrExact(x, y));
+ try expectEqual(@as(u0, 0), x << 0);
+ try expectEqual(@as(u0, 0), x >> 0);
+ try expectEqual(@as(u0, 0), x << y);
+ try expectEqual(@as(u0, 0), x >> y);
+ try expectEqual(@as(u0, 0), @shlExact(x, 0));
+ try expectEqual(@as(u0, 0), @shrExact(x, 0));
+ try expectEqual(@as(u0, 0), @shlExact(x, y));
+ try expectEqual(@as(u0, 0), @shrExact(x, y));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "comptime_int addition" {
comptime {
- expect(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950);
- expect(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380);
+ try expect(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950);
+ try expect(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380);
}
}
test "comptime_int multiplication" {
comptime {
- expect(
+ try expect(
45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567,
);
- expect(
+ try expect(
594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016,
);
}
@@ -534,7 +534,7 @@ test "comptime_int multiplication" {
test "comptime_int shifting" {
comptime {
- expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000);
+ try expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000);
}
}
@@ -542,16 +542,16 @@ test "comptime_int multi-limb shift and mask" {
comptime {
var a = 0xefffffffa0000001eeeeeeefaaaaaaab;
- expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab);
+ try expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab);
a >>= 32;
- expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef);
+ try expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef);
a >>= 32;
- expect(@as(u32, a & 0xffffffff) == 0xa0000001);
+ try expect(@as(u32, a & 0xffffffff) == 0xa0000001);
a >>= 32;
- expect(@as(u32, a & 0xffffffff) == 0xefffffff);
+ try expect(@as(u32, a & 0xffffffff) == 0xefffffff);
a >>= 32;
- expect(a == 0);
+ try expect(a == 0);
}
}
@@ -559,227 +559,227 @@ test "comptime_int multi-limb partial shift right" {
comptime {
var a = 0x1ffffffffeeeeeeee;
a >>= 16;
- expect(a == 0x1ffffffffeeee);
+ try expect(a == 0x1ffffffffeeee);
}
}
test "xor" {
- test_xor();
- comptime test_xor();
+ try test_xor();
+ comptime try test_xor();
}
-fn test_xor() void {
- expect(0xFF ^ 0x00 == 0xFF);
- expect(0xF0 ^ 0x0F == 0xFF);
- expect(0xFF ^ 0xF0 == 0x0F);
- expect(0xFF ^ 0x0F == 0xF0);
- expect(0xFF ^ 0xFF == 0x00);
+fn test_xor() !void {
+ try expect(0xFF ^ 0x00 == 0xFF);
+ try expect(0xF0 ^ 0x0F == 0xFF);
+ try expect(0xFF ^ 0xF0 == 0x0F);
+ try expect(0xFF ^ 0x0F == 0xF0);
+ try expect(0xFF ^ 0xFF == 0x00);
}
test "comptime_int xor" {
comptime {
- expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF);
- expect(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000);
- expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000);
- expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
- expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF);
- expect(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000);
+ try expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF);
+ try expect(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000);
+ try expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000);
+ try expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF);
+ try expect(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000);
}
}
test "f128" {
- test_f128();
- comptime test_f128();
+ try test_f128();
+ comptime try test_f128();
}
fn make_f128(x: f128) f128 {
return x;
}
-fn test_f128() void {
- expect(@sizeOf(f128) == 16);
- expect(make_f128(1.0) == 1.0);
- expect(make_f128(1.0) != 1.1);
- expect(make_f128(1.0) > 0.9);
- expect(make_f128(1.0) >= 0.9);
- expect(make_f128(1.0) >= 1.0);
- should_not_be_zero(1.0);
+fn test_f128() !void {
+ try expect(@sizeOf(f128) == 16);
+ try expect(make_f128(1.0) == 1.0);
+ try expect(make_f128(1.0) != 1.1);
+ try expect(make_f128(1.0) > 0.9);
+ try expect(make_f128(1.0) >= 0.9);
+ try expect(make_f128(1.0) >= 1.0);
+ try should_not_be_zero(1.0);
}
-fn should_not_be_zero(x: f128) void {
- expect(x != 0.0);
+fn should_not_be_zero(x: f128) !void {
+ try expect(x != 0.0);
}
test "comptime float rem int" {
comptime {
var x = @as(f32, 1) % 2;
- expect(x == 1.0);
+ try expect(x == 1.0);
}
}
test "remainder division" {
- comptime remdiv(f16);
- comptime remdiv(f32);
- comptime remdiv(f64);
- comptime remdiv(f128);
- remdiv(f16);
- remdiv(f64);
- remdiv(f128);
+ comptime try remdiv(f16);
+ comptime try remdiv(f32);
+ comptime try remdiv(f64);
+ comptime try remdiv(f128);
+ try remdiv(f16);
+ try remdiv(f64);
+ try remdiv(f128);
}
-fn remdiv(comptime T: type) void {
- expect(@as(T, 1) == @as(T, 1) % @as(T, 2));
- expect(@as(T, 1) == @as(T, 7) % @as(T, 3));
+fn remdiv(comptime T: type) !void {
+ try expect(@as(T, 1) == @as(T, 1) % @as(T, 2));
+ try expect(@as(T, 1) == @as(T, 7) % @as(T, 3));
}
test "@sqrt" {
- testSqrt(f64, 12.0);
- comptime testSqrt(f64, 12.0);
- testSqrt(f32, 13.0);
- comptime testSqrt(f32, 13.0);
- testSqrt(f16, 13.0);
- comptime testSqrt(f16, 13.0);
+ try testSqrt(f64, 12.0);
+ comptime try testSqrt(f64, 12.0);
+ try testSqrt(f32, 13.0);
+ comptime try testSqrt(f32, 13.0);
+ try testSqrt(f16, 13.0);
+ comptime try testSqrt(f16, 13.0);
const x = 14.0;
const y = x * x;
const z = @sqrt(y);
- comptime expect(z == x);
+ comptime try expect(z == x);
}
-fn testSqrt(comptime T: type, x: T) void {
- expect(@sqrt(x * x) == x);
+fn testSqrt(comptime T: type, x: T) !void {
+ try expect(@sqrt(x * x) == x);
}
test "@fabs" {
- testFabs(f128, 12.0);
- comptime testFabs(f128, 12.0);
- testFabs(f64, 12.0);
- comptime testFabs(f64, 12.0);
- testFabs(f32, 12.0);
- comptime testFabs(f32, 12.0);
- testFabs(f16, 12.0);
- comptime testFabs(f16, 12.0);
+ try testFabs(f128, 12.0);
+ comptime try testFabs(f128, 12.0);
+ try testFabs(f64, 12.0);
+ comptime try testFabs(f64, 12.0);
+ try testFabs(f32, 12.0);
+ comptime try testFabs(f32, 12.0);
+ try testFabs(f16, 12.0);
+ comptime try testFabs(f16, 12.0);
const x = 14.0;
const y = -x;
const z = @fabs(y);
- comptime expectEqual(x, z);
+ comptime try expectEqual(x, z);
}
-fn testFabs(comptime T: type, x: T) void {
+fn testFabs(comptime T: type, x: T) !void {
const y = -x;
const z = @fabs(y);
- expectEqual(x, z);
+ try expectEqual(x, z);
}
test "@floor" {
// FIXME: Generates a floorl function call
// testFloor(f128, 12.0);
- comptime testFloor(f128, 12.0);
- testFloor(f64, 12.0);
- comptime testFloor(f64, 12.0);
- testFloor(f32, 12.0);
- comptime testFloor(f32, 12.0);
- testFloor(f16, 12.0);
- comptime testFloor(f16, 12.0);
+ comptime try testFloor(f128, 12.0);
+ try testFloor(f64, 12.0);
+ comptime try testFloor(f64, 12.0);
+ try testFloor(f32, 12.0);
+ comptime try testFloor(f32, 12.0);
+ try testFloor(f16, 12.0);
+ comptime try testFloor(f16, 12.0);
const x = 14.0;
const y = x + 0.7;
const z = @floor(y);
- comptime expectEqual(x, z);
+ comptime try expectEqual(x, z);
}
-fn testFloor(comptime T: type, x: T) void {
+fn testFloor(comptime T: type, x: T) !void {
const y = x + 0.6;
const z = @floor(y);
- expectEqual(x, z);
+ try expectEqual(x, z);
}
test "@ceil" {
// FIXME: Generates a ceill function call
//testCeil(f128, 12.0);
- comptime testCeil(f128, 12.0);
- testCeil(f64, 12.0);
- comptime testCeil(f64, 12.0);
- testCeil(f32, 12.0);
- comptime testCeil(f32, 12.0);
- testCeil(f16, 12.0);
- comptime testCeil(f16, 12.0);
+ comptime try testCeil(f128, 12.0);
+ try testCeil(f64, 12.0);
+ comptime try testCeil(f64, 12.0);
+ try testCeil(f32, 12.0);
+ comptime try testCeil(f32, 12.0);
+ try testCeil(f16, 12.0);
+ comptime try testCeil(f16, 12.0);
const x = 14.0;
const y = x - 0.7;
const z = @ceil(y);
- comptime expectEqual(x, z);
+ comptime try expectEqual(x, z);
}
-fn testCeil(comptime T: type, x: T) void {
+fn testCeil(comptime T: type, x: T) !void {
const y = x - 0.8;
const z = @ceil(y);
- expectEqual(x, z);
+ try expectEqual(x, z);
}
test "@trunc" {
// FIXME: Generates a truncl function call
//testTrunc(f128, 12.0);
- comptime testTrunc(f128, 12.0);
- testTrunc(f64, 12.0);
- comptime testTrunc(f64, 12.0);
- testTrunc(f32, 12.0);
- comptime testTrunc(f32, 12.0);
- testTrunc(f16, 12.0);
- comptime testTrunc(f16, 12.0);
+ comptime try testTrunc(f128, 12.0);
+ try testTrunc(f64, 12.0);
+ comptime try testTrunc(f64, 12.0);
+ try testTrunc(f32, 12.0);
+ comptime try testTrunc(f32, 12.0);
+ try testTrunc(f16, 12.0);
+ comptime try testTrunc(f16, 12.0);
const x = 14.0;
const y = x + 0.7;
const z = @trunc(y);
- comptime expectEqual(x, z);
+ comptime try expectEqual(x, z);
}
-fn testTrunc(comptime T: type, x: T) void {
+fn testTrunc(comptime T: type, x: T) !void {
{
const y = x + 0.8;
const z = @trunc(y);
- expectEqual(x, z);
+ try expectEqual(x, z);
}
{
const y = -x - 0.8;
const z = @trunc(y);
- expectEqual(-x, z);
+ try expectEqual(-x, z);
}
}
test "@round" {
// FIXME: Generates a roundl function call
//testRound(f128, 12.0);
- comptime testRound(f128, 12.0);
- testRound(f64, 12.0);
- comptime testRound(f64, 12.0);
- testRound(f32, 12.0);
- comptime testRound(f32, 12.0);
- testRound(f16, 12.0);
- comptime testRound(f16, 12.0);
+ comptime try testRound(f128, 12.0);
+ try testRound(f64, 12.0);
+ comptime try testRound(f64, 12.0);
+ try testRound(f32, 12.0);
+ comptime try testRound(f32, 12.0);
+ try testRound(f16, 12.0);
+ comptime try testRound(f16, 12.0);
const x = 14.0;
const y = x + 0.4;
const z = @round(y);
- comptime expectEqual(x, z);
+ comptime try expectEqual(x, z);
}
-fn testRound(comptime T: type, x: T) void {
+fn testRound(comptime T: type, x: T) !void {
const y = x - 0.5;
const z = @round(y);
- expectEqual(x, z);
+ try expectEqual(x, z);
}
test "comptime_int param and return" {
const a = comptimeAdd(35361831660712422535336160538497375248, 101752735581729509668353361206450473702);
- expect(a == 137114567242441932203689521744947848950);
+ try expect(a == 137114567242441932203689521744947848950);
const b = comptimeAdd(594491908217841670578297176641415611445982232488944558774612, 390603545391089362063884922208143568023166603618446395589768);
- expect(b == 985095453608931032642182098849559179469148836107390954364380);
+ try expect(b == 985095453608931032642182098849559179469148836107390954364380);
}
fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int {
@@ -788,85 +788,85 @@ fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int
test "vector integer addition" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var a: std.meta.Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
var b: std.meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
var result = a + b;
var result_array: [4]i32 = result;
const expected = [_]i32{ 6, 8, 10, 12 };
- expectEqualSlices(i32, &expected, &result_array);
+ try expectEqualSlices(i32, &expected, &result_array);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "NaN comparison" {
- testNanEqNan(f16);
- testNanEqNan(f32);
- testNanEqNan(f64);
- testNanEqNan(f128);
- comptime testNanEqNan(f16);
- comptime testNanEqNan(f32);
- comptime testNanEqNan(f64);
- comptime testNanEqNan(f128);
+ try testNanEqNan(f16);
+ try testNanEqNan(f32);
+ try testNanEqNan(f64);
+ try testNanEqNan(f128);
+ comptime try testNanEqNan(f16);
+ comptime try testNanEqNan(f32);
+ comptime try testNanEqNan(f64);
+ comptime try testNanEqNan(f128);
}
-fn testNanEqNan(comptime F: type) void {
+fn testNanEqNan(comptime F: type) !void {
var nan1 = std.math.nan(F);
var nan2 = std.math.nan(F);
- expect(nan1 != nan2);
- expect(!(nan1 == nan2));
- expect(!(nan1 > nan2));
- expect(!(nan1 >= nan2));
- expect(!(nan1 < nan2));
- expect(!(nan1 <= nan2));
+ try expect(nan1 != nan2);
+ try expect(!(nan1 == nan2));
+ try expect(!(nan1 > nan2));
+ try expect(!(nan1 >= nan2));
+ try expect(!(nan1 < nan2));
+ try expect(!(nan1 <= nan2));
}
test "128-bit multiplication" {
var a: i128 = 3;
var b: i128 = 2;
var c = a * b;
- expect(c == 6);
+ try expect(c == 6);
}
test "vector comparison" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var a: std.meta.Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };
var b: std.meta.Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 };
- expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false }));
- expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false }));
- expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false }));
- expect(mem.eql(bool, &@as([6]bool, a != b), &[_]bool{ true, false, true, true, true, true }));
- expect(mem.eql(bool, &@as([6]bool, a > b), &[_]bool{ true, false, false, false, false, true }));
- expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{ true, true, false, false, false, true }));
+ try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false }));
+ try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false }));
+ try expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false }));
+ try expect(mem.eql(bool, &@as([6]bool, a != b), &[_]bool{ true, false, true, true, true, true }));
+ try expect(mem.eql(bool, &@as([6]bool, a > b), &[_]bool{ true, false, false, false, false, true }));
+ try expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{ true, true, false, false, false, true }));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "compare undefined literal with comptime_int" {
var x = undefined == 1;
// x is now undefined with type bool
x = true;
- expect(x);
+ try expect(x);
}
test "signed zeros are represented properly" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
inline for ([_]type{ f16, f32, f64, f128 }) |T| {
const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
var as_fp_val = -@as(T, 0.0);
var as_uint_val = @bitCast(ST, as_fp_val);
// Ensure the sign bit is set.
- expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
+ try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig
index 850622c5ba..0300afcdea 100644
--- a/test/stage1/behavior/misc.zig
+++ b/test/stage1/behavior/misc.zig
@@ -25,18 +25,18 @@ test "call disabled extern fn" {
}
test "short circuit" {
- testShortCircuit(false, true);
- comptime testShortCircuit(false, true);
+ try testShortCircuit(false, true);
+ comptime try testShortCircuit(false, true);
}
-fn testShortCircuit(f: bool, t: bool) void {
+fn testShortCircuit(f: bool, t: bool) !void {
var hit_1 = f;
var hit_2 = f;
var hit_3 = f;
var hit_4 = f;
if (t or x: {
- expect(f);
+ try expect(f);
break :x f;
}) {
hit_1 = t;
@@ -45,31 +45,31 @@ fn testShortCircuit(f: bool, t: bool) void {
hit_2 = t;
break :x f;
}) {
- expect(f);
+ try expect(f);
}
if (t and x: {
hit_3 = t;
break :x f;
}) {
- expect(f);
+ try expect(f);
}
if (f and x: {
- expect(f);
+ try expect(f);
break :x f;
}) {
- expect(f);
+ try expect(f);
} else {
hit_4 = t;
}
- expect(hit_1);
- expect(hit_2);
- expect(hit_3);
- expect(hit_4);
+ try expect(hit_1);
+ try expect(hit_2);
+ try expect(hit_3);
+ try expect(hit_4);
}
test "truncate" {
- expect(testTruncate(0x10fd) == 0xfd);
+ try expect(testTruncate(0x10fd) == 0xfd);
}
fn testTruncate(x: u32) u8 {
return @truncate(u8, x);
@@ -80,16 +80,16 @@ fn first4KeysOfHomeRow() []const u8 {
}
test "return string from function" {
- expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
+ try expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
}
const g1: i32 = 1233 + 1;
var g2: i32 = 0;
test "global variables" {
- expect(g2 == 0);
+ try expect(g2 == 0);
g2 = g1;
- expect(g2 == 1234);
+ try expect(g2 == 1234);
}
test "memcpy and memset intrinsics" {
@@ -106,7 +106,7 @@ test "builtin static eval" {
const x: i32 = comptime x: {
break :x 1 + 2 + 3;
};
- expect(x == comptime 6);
+ try expect(x == comptime 6);
}
test "slicing" {
@@ -127,7 +127,7 @@ test "slicing" {
test "constant equal function pointers" {
const alias = emptyFn;
- expect(comptime x: {
+ try expect(comptime x: {
break :x emptyFn == alias;
});
}
@@ -135,25 +135,25 @@ test "constant equal function pointers" {
fn emptyFn() void {}
test "hex escape" {
- expect(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello"));
+ try expect(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello"));
}
test "string concatenation" {
- expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED"));
+ try expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED"));
}
test "array mult operator" {
- expect(mem.eql(u8, "ab" ** 5, "ababababab"));
+ try expect(mem.eql(u8, "ab" ** 5, "ababababab"));
}
test "string escapes" {
- expect(mem.eql(u8, "\"", "\x22"));
- expect(mem.eql(u8, "\'", "\x27"));
- expect(mem.eql(u8, "\n", "\x0a"));
- expect(mem.eql(u8, "\r", "\x0d"));
- expect(mem.eql(u8, "\t", "\x09"));
- expect(mem.eql(u8, "\\", "\x5c"));
- expect(mem.eql(u8, "\u{1234}\u{069}\u{1}", "\xe1\x88\xb4\x69\x01"));
+ try expect(mem.eql(u8, "\"", "\x22"));
+ try expect(mem.eql(u8, "\'", "\x27"));
+ try expect(mem.eql(u8, "\n", "\x0a"));
+ try expect(mem.eql(u8, "\r", "\x0d"));
+ try expect(mem.eql(u8, "\t", "\x09"));
+ try expect(mem.eql(u8, "\\", "\x5c"));
+ try expect(mem.eql(u8, "\u{1234}\u{069}\u{1}", "\xe1\x88\xb4\x69\x01"));
}
test "multiline string" {
@@ -163,7 +163,7 @@ test "multiline string" {
\\three
;
const s2 = "one\ntwo)\nthree";
- expect(mem.eql(u8, s1, s2));
+ try expect(mem.eql(u8, s1, s2));
}
test "multiline string comments at start" {
@@ -173,7 +173,7 @@ test "multiline string comments at start" {
\\three
;
const s2 = "two)\nthree";
- expect(mem.eql(u8, s1, s2));
+ try expect(mem.eql(u8, s1, s2));
}
test "multiline string comments at end" {
@@ -183,7 +183,7 @@ test "multiline string comments at end" {
//\\three
;
const s2 = "one\ntwo)";
- expect(mem.eql(u8, s1, s2));
+ try expect(mem.eql(u8, s1, s2));
}
test "multiline string comments in middle" {
@@ -193,7 +193,7 @@ test "multiline string comments in middle" {
\\three
;
const s2 = "one\nthree";
- expect(mem.eql(u8, s1, s2));
+ try expect(mem.eql(u8, s1, s2));
}
test "multiline string comments at multiple places" {
@@ -205,7 +205,7 @@ test "multiline string comments at multiple places" {
\\five
;
const s2 = "one\nthree\nfive";
- expect(mem.eql(u8, s1, s2));
+ try expect(mem.eql(u8, s1, s2));
}
test "multiline C string" {
@@ -215,11 +215,11 @@ test "multiline C string" {
\\three
;
const s2 = "one\ntwo)\nthree";
- expect(std.cstr.cmp(s1, s2) == 0);
+ try expect(std.cstr.cmp(s1, s2) == 0);
}
test "type equality" {
- expect(*const u8 != *u8);
+ try expect(*const u8 != *u8);
}
const global_a: i32 = 1234;
@@ -227,7 +227,7 @@ const global_b: *const i32 = &global_a;
const global_c: *const f32 = @ptrCast(*const f32, global_b);
test "compile time global reinterpret" {
const d = @ptrCast(*const i32, global_c);
- expect(d.* == 1234);
+ try expect(d.* == 1234);
}
test "explicit cast maybe pointers" {
@@ -253,8 +253,8 @@ test "cast undefined" {
fn testCastUndefined(x: []const u8) void {}
test "cast small unsigned to larger signed" {
- expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
- expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999));
+ try expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
+ try expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999));
}
fn castSmallUnsignedToLargerSigned1(x: u8) i16 {
return x;
@@ -264,7 +264,7 @@ fn castSmallUnsignedToLargerSigned2(x: u16) i64 {
}
test "implicit cast after unreachable" {
- expect(outer() == 1234);
+ try expect(outer() == 1234);
}
fn inner() i32 {
return 1234;
@@ -279,13 +279,13 @@ test "pointer dereferencing" {
y.* += 1;
- expect(x == 4);
- expect(y.* == 4);
+ try expect(x == 4);
+ try expect(y.* == 4);
}
test "call result of if else expression" {
- expect(mem.eql(u8, f2(true), "a"));
- expect(mem.eql(u8, f2(false), "b"));
+ try expect(mem.eql(u8, f2(true), "a"));
+ try expect(mem.eql(u8, f2(false), "b"));
}
fn f2(x: bool) []const u8 {
return (if (x) fA else fB)();
@@ -305,8 +305,8 @@ test "const expression eval handling of variables" {
}
test "constant enum initialization with differing sizes" {
- test3_1(test3_foo);
- test3_2(test3_bar);
+ try test3_1(test3_foo);
+ try test3_2(test3_bar);
}
const Test3Foo = union(enum) {
One: void,
@@ -324,41 +324,41 @@ const test3_foo = Test3Foo{
},
};
const test3_bar = Test3Foo{ .Two = 13 };
-fn test3_1(f: Test3Foo) void {
+fn test3_1(f: Test3Foo) !void {
switch (f) {
Test3Foo.Three => |pt| {
- expect(pt.x == 3);
- expect(pt.y == 4);
+ try expect(pt.x == 3);
+ try expect(pt.y == 4);
},
else => unreachable,
}
}
-fn test3_2(f: Test3Foo) void {
+fn test3_2(f: Test3Foo) !void {
switch (f) {
Test3Foo.Two => |x| {
- expect(x == 13);
+ try expect(x == 13);
},
else => unreachable,
}
}
test "character literals" {
- expect('\'' == single_quote);
+ try expect('\'' == single_quote);
}
const single_quote = '\'';
test "take address of parameter" {
- testTakeAddressOfParameter(12.34);
+ try testTakeAddressOfParameter(12.34);
}
-fn testTakeAddressOfParameter(f: f32) void {
+fn testTakeAddressOfParameter(f: f32) !void {
const f_ptr = &f;
- expect(f_ptr.* == 12.34);
+ try expect(f_ptr.* == 12.34);
}
test "pointer comparison" {
const a = @as([]const u8, "a");
const b = &a;
- expect(ptrEql(b, b));
+ try expect(ptrEql(b, b));
}
fn ptrEql(a: *const []const u8, b: *const []const u8) bool {
return a == b;
@@ -368,19 +368,19 @@ test "string concatenation" {
const a = "OK" ++ " IT " ++ "WORKED";
const b = "OK IT WORKED";
- comptime expect(@TypeOf(a) == *const [12:0]u8);
- comptime expect(@TypeOf(b) == *const [12:0]u8);
+ comptime try expect(@TypeOf(a) == *const [12:0]u8);
+ comptime try expect(@TypeOf(b) == *const [12:0]u8);
const len = mem.len(b);
const len_with_null = len + 1;
{
var i: u32 = 0;
while (i < len_with_null) : (i += 1) {
- expect(a[i] == b[i]);
+ try expect(a[i] == b[i]);
}
}
- expect(a[len] == 0);
- expect(b[len] == 0);
+ try expect(a[len] == 0);
+ try expect(b[len] == 0);
}
test "pointer to void return type" {
@@ -397,7 +397,7 @@ fn testPointerToVoidReturnType2() *const void {
test "non const ptr to aliased type" {
const int = i32;
- expect(?*int == ?*i32);
+ try expect(?*int == ?*i32);
}
test "array 2D const double ptr" {
@@ -405,13 +405,13 @@ test "array 2D const double ptr" {
[_]f32{1.0},
[_]f32{2.0},
};
- testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);
+ try testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);
}
-fn testArray2DConstDoublePtr(ptr: *const f32) void {
+fn testArray2DConstDoublePtr(ptr: *const f32) !void {
const ptr2 = @ptrCast([*]const f32, ptr);
- expect(ptr2[0] == 1.0);
- expect(ptr2[1] == 2.0);
+ try expect(ptr2[0] == 1.0);
+ try expect(ptr2[1] == 2.0);
}
const AStruct = struct {
@@ -439,13 +439,13 @@ test "@typeName" {
Unused,
};
comptime {
- expect(mem.eql(u8, @typeName(i64), "i64"));
- expect(mem.eql(u8, @typeName(*usize), "*usize"));
+ try expect(mem.eql(u8, @typeName(i64), "i64"));
+ try expect(mem.eql(u8, @typeName(*usize), "*usize"));
// https://github.com/ziglang/zig/issues/675
- expect(mem.eql(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8))));
- expect(mem.eql(u8, @typeName(Struct), "Struct"));
- expect(mem.eql(u8, @typeName(Union), "Union"));
- expect(mem.eql(u8, @typeName(Enum), "Enum"));
+ try expect(mem.eql(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8))));
+ try expect(mem.eql(u8, @typeName(Struct), "Struct"));
+ try expect(mem.eql(u8, @typeName(Union), "Union"));
+ try expect(mem.eql(u8, @typeName(Enum), "Enum"));
}
}
@@ -455,14 +455,14 @@ fn TypeFromFn(comptime T: type) type {
test "double implicit cast in same expression" {
var x = @as(i32, @as(u16, nine()));
- expect(x == 9);
+ try expect(x == 9);
}
fn nine() u8 {
return 9;
}
test "global variable initialized to global variable array element" {
- expect(global_ptr == &gdt[0]);
+ try expect(global_ptr == &gdt[0]);
}
const GDTEntry = struct {
field: i32,
@@ -483,9 +483,9 @@ export fn writeToVRam() void {
const OpaqueA = opaque {};
const OpaqueB = opaque {};
test "opaque types" {
- expect(*OpaqueA != *OpaqueB);
- expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
- expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
+ try expect(*OpaqueA != *OpaqueB);
+ try expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
+ try expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
}
test "variable is allowed to be a pointer to an opaque type" {
@@ -525,7 +525,7 @@ fn fnThatClosesOverLocalConst() type {
test "function closes over local const" {
const x = fnThatClosesOverLocalConst().g();
- expect(x == 1);
+ try expect(x == 1);
}
test "cold function" {
@@ -562,21 +562,21 @@ export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: Pack
test "slicing zero length array" {
const s1 = ""[0..];
const s2 = ([_]u32{})[0..];
- expect(s1.len == 0);
- expect(s2.len == 0);
- expect(mem.eql(u8, s1, ""));
- expect(mem.eql(u32, s2, &[_]u32{}));
+ try expect(s1.len == 0);
+ try expect(s2.len == 0);
+ try expect(mem.eql(u8, s1, ""));
+ try expect(mem.eql(u32, s2, &[_]u32{}));
}
const addr1 = @ptrCast(*const u8, emptyFn);
test "comptime cast fn to ptr" {
const addr2 = @ptrCast(*const u8, emptyFn);
- comptime expect(addr1 == addr2);
+ comptime try expect(addr1 == addr2);
}
test "equality compare fn ptrs" {
var a = emptyFn;
- expect(a == a);
+ try expect(a == a);
}
test "self reference through fn ptr field" {
@@ -591,34 +591,34 @@ test "self reference through fn ptr field" {
};
var a: S.A = undefined;
a.f = S.foo;
- expect(a.f(a) == 12);
+ try expect(a.f(a) == 12);
}
test "volatile load and store" {
var number: i32 = 1234;
const ptr = @as(*volatile i32, &number);
ptr.* += 1;
- expect(ptr.* == 1235);
+ try expect(ptr.* == 1235);
}
test "slice string literal has correct type" {
comptime {
- expect(@TypeOf("aoeu"[0..]) == *const [4:0]u8);
+ try expect(@TypeOf("aoeu"[0..]) == *const [4:0]u8);
const array = [_]i32{ 1, 2, 3, 4 };
- expect(@TypeOf(array[0..]) == *const [4]i32);
+ try expect(@TypeOf(array[0..]) == *const [4]i32);
}
var runtime_zero: usize = 0;
- comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8);
+ comptime try expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8);
const array = [_]i32{ 1, 2, 3, 4 };
- comptime expect(@TypeOf(array[runtime_zero..]) == []const i32);
+ comptime try expect(@TypeOf(array[runtime_zero..]) == []const i32);
}
test "struct inside function" {
- testStructInFn();
- comptime testStructInFn();
+ try testStructInFn();
+ comptime try testStructInFn();
}
-fn testStructInFn() void {
+fn testStructInFn() !void {
const BlockKind = u32;
const Block = struct {
@@ -629,11 +629,11 @@ fn testStructInFn() void {
block.kind += 1;
- expect(block.kind == 1235);
+ try expect(block.kind == 1235);
}
test "fn call returning scalar optional in equality expression" {
- expect(getNull() == null);
+ try expect(getNull() == null);
}
fn getNull() ?*i32 {
@@ -645,16 +645,16 @@ test "thread local variable" {
threadlocal var t: i32 = 1234;
};
S.t += 1;
- expect(S.t == 1235);
+ try expect(S.t == 1235);
}
test "unicode escape in character literal" {
var a: u24 = '\u{01f4a9}';
- expect(a == 128169);
+ try expect(a == 128169);
}
test "unicode character in character literal" {
- expect('π©' == 128169);
+ try expect('π©' == 128169);
}
test "result location zero sized array inside struct field implicit cast to slice" {
@@ -662,7 +662,7 @@ test "result location zero sized array inside struct field implicit cast to slic
entries: []u32,
};
var foo = E{ .entries = &[_]u32{} };
- expect(foo.entries.len == 0);
+ try expect(foo.entries.len == 0);
}
var global_foo: *i32 = undefined;
@@ -677,7 +677,7 @@ test "global variable assignment with optional unwrapping with var initialized t
global_foo = S.foo() orelse {
@panic("bad");
};
- expect(global_foo.* == 1234);
+ try expect(global_foo.* == 1234);
}
test "peer result location with typed parent, runtime condition, comptime prongs" {
@@ -696,8 +696,8 @@ test "peer result location with typed parent, runtime condition, comptime prongs
bleh: i32,
};
};
- expect(S.doTheTest(0) == 1234);
- expect(S.doTheTest(1) == 1234);
+ try expect(S.doTheTest(0) == 1234);
+ try expect(S.doTheTest(1) == 1234);
}
test "nested optional field in struct" {
@@ -710,7 +710,7 @@ test "nested optional field in struct" {
var s = S1{
.x = S2{ .y = 127 },
};
- expect(s.x.?.y == 127);
+ try expect(s.x.?.y == 127);
}
fn maybe(x: bool) anyerror!?u32 {
@@ -722,7 +722,7 @@ fn maybe(x: bool) anyerror!?u32 {
test "result location is optional inside error union" {
const x = maybe(true) catch unreachable;
- expect(x.? == 42);
+ try expect(x.? == 42);
}
threadlocal var buffer: [11]u8 = undefined;
@@ -730,7 +730,7 @@ threadlocal var buffer: [11]u8 = undefined;
test "pointer to thread local array" {
const s = "Hello world";
std.mem.copy(u8, buffer[0..], s);
- std.testing.expectEqualSlices(u8, buffer[0..], s);
+ try std.testing.expectEqualSlices(u8, buffer[0..], s);
}
test "auto created variables have correct alignment" {
@@ -742,15 +742,15 @@ test "auto created variables have correct alignment" {
return 0;
}
};
- expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
- comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
+ try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
+ comptime try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
}
extern var opaque_extern_var: opaque {};
var var_to_export: u32 = 42;
test "extern variable with non-pointer opaque type" {
@export(var_to_export, .{ .name = "opaque_extern_var" });
- expect(@ptrCast(*align(1) u32, &opaque_extern_var).* == 42);
+ try expect(@ptrCast(*align(1) u32, &opaque_extern_var).* == 42);
}
test "lazy typeInfo value as generic parameter" {
diff --git a/test/stage1/behavior/muladd.zig b/test/stage1/behavior/muladd.zig
index d507f503f5..87fbf57fd3 100644
--- a/test/stage1/behavior/muladd.zig
+++ b/test/stage1/behavior/muladd.zig
@@ -1,34 +1,34 @@
const expect = @import("std").testing.expect;
test "@mulAdd" {
- comptime testMulAdd();
- testMulAdd();
+ comptime try testMulAdd();
+ try testMulAdd();
}
-fn testMulAdd() void {
+fn testMulAdd() !void {
{
var a: f16 = 5.5;
var b: f16 = 2.5;
var c: f16 = 6.25;
- expect(@mulAdd(f16, a, b, c) == 20);
+ try expect(@mulAdd(f16, a, b, c) == 20);
}
{
var a: f32 = 5.5;
var b: f32 = 2.5;
var c: f32 = 6.25;
- expect(@mulAdd(f32, a, b, c) == 20);
+ try expect(@mulAdd(f32, a, b, c) == 20);
}
{
var a: f64 = 5.5;
var b: f64 = 2.5;
var c: f64 = 6.25;
- expect(@mulAdd(f64, a, b, c) == 20);
+ try expect(@mulAdd(f64, a, b, c) == 20);
}
// Awaits implementation in libm.zig
//{
// var a: f16 = 5.5;
// var b: f128 = 2.5;
// var c: f128 = 6.25;
- // expect(@mulAdd(f128, a, b, c) == 20);
+ //try expect(@mulAdd(f128, a, b, c) == 20);
//}
}
diff --git a/test/stage1/behavior/namespace_depends_on_compile_var.zig b/test/stage1/behavior/namespace_depends_on_compile_var.zig
index 8c5c19d733..3e8cab3528 100644
--- a/test/stage1/behavior/namespace_depends_on_compile_var.zig
+++ b/test/stage1/behavior/namespace_depends_on_compile_var.zig
@@ -3,9 +3,9 @@ const expect = std.testing.expect;
test "namespace depends on compile var" {
if (some_namespace.a_bool) {
- expect(some_namespace.a_bool);
+ try expect(some_namespace.a_bool);
} else {
- expect(!some_namespace.a_bool);
+ try expect(!some_namespace.a_bool);
}
}
const some_namespace = switch (std.builtin.os.tag) {
diff --git a/test/stage1/behavior/null.zig b/test/stage1/behavior/null.zig
index 8c9b86b260..45401f621a 100644
--- a/test/stage1/behavior/null.zig
+++ b/test/stage1/behavior/null.zig
@@ -17,13 +17,13 @@ test "optional type" {
const z = next_x orelse 1234;
- expect(z == 1234);
+ try expect(z == 1234);
const final_x: ?i32 = 13;
const num = final_x orelse unreachable;
- expect(num == 13);
+ try expect(num == 13);
}
test "test maybe object and get a pointer to the inner value" {
@@ -33,7 +33,7 @@ test "test maybe object and get a pointer to the inner value" {
b.* = false;
}
- expect(maybe_bool.? == false);
+ try expect(maybe_bool.? == false);
}
test "rhs maybe unwrap return" {
@@ -42,14 +42,14 @@ test "rhs maybe unwrap return" {
}
test "maybe return" {
- maybeReturnImpl();
- comptime maybeReturnImpl();
+ try maybeReturnImpl();
+ comptime try maybeReturnImpl();
}
-fn maybeReturnImpl() void {
- expect(foo(1235).?);
+fn maybeReturnImpl() !void {
+ try expect(foo(1235).?);
if (foo(null) != null) unreachable;
- expect(!foo(1234).?);
+ try expect(!foo(1234).?);
}
fn foo(x: ?i32) ?bool {
@@ -58,7 +58,7 @@ fn foo(x: ?i32) ?bool {
}
test "if var maybe pointer" {
- expect(shouldBeAPlus1(Particle{
+ try expect(shouldBeAPlus1(Particle{
.a = 14,
.b = 1,
.c = 1,
@@ -84,10 +84,10 @@ const Particle = struct {
test "null literal outside function" {
const is_null = here_is_a_null_literal.context == null;
- expect(is_null);
+ try expect(is_null);
const is_non_null = here_is_a_null_literal.context != null;
- expect(!is_non_null);
+ try expect(!is_non_null);
}
const SillyStruct = struct {
context: ?i32,
@@ -95,21 +95,21 @@ const SillyStruct = struct {
const here_is_a_null_literal = SillyStruct{ .context = null };
test "test null runtime" {
- testTestNullRuntime(null);
+ try testTestNullRuntime(null);
}
-fn testTestNullRuntime(x: ?i32) void {
- expect(x == null);
- expect(!(x != null));
+fn testTestNullRuntime(x: ?i32) !void {
+ try expect(x == null);
+ try expect(!(x != null));
}
test "optional void" {
- optionalVoidImpl();
- comptime optionalVoidImpl();
+ try optionalVoidImpl();
+ comptime try optionalVoidImpl();
}
-fn optionalVoidImpl() void {
- expect(bar(null) == null);
- expect(bar({}) != null);
+fn optionalVoidImpl() !void {
+ try expect(bar(null) == null);
+ try expect(bar({}) != null);
}
fn bar(x: ?void) ?void {
@@ -133,7 +133,7 @@ test "unwrap optional which is field of global var" {
}
struct_with_optional.field = 1234;
if (struct_with_optional.field) |payload| {
- expect(payload == 1234);
+ try expect(payload == 1234);
} else {
unreachable;
}
@@ -141,13 +141,13 @@ test "unwrap optional which is field of global var" {
test "null with default unwrap" {
const x: i32 = null orelse 1;
- expect(x == 1);
+ try expect(x == 1);
}
test "optional types" {
comptime {
const opt_type_struct = StructWithOptionalType{ .t = u8 };
- expect(opt_type_struct.t != null and opt_type_struct.t.? == u8);
+ try expect(opt_type_struct.t != null and opt_type_struct.t.? == u8);
}
}
@@ -158,5 +158,5 @@ const StructWithOptionalType = struct {
test "optional pointer to 0 bit type null value at runtime" {
const EmptyStruct = struct {};
var x: ?*EmptyStruct = null;
- expect(x == null);
+ try expect(x == null);
}
diff --git a/test/stage1/behavior/optional.zig b/test/stage1/behavior/optional.zig
index 1dc33eb8ea..75b4311159 100644
--- a/test/stage1/behavior/optional.zig
+++ b/test/stage1/behavior/optional.zig
@@ -8,28 +8,28 @@ pub const EmptyStruct = struct {};
test "optional pointer to size zero struct" {
var e = EmptyStruct{};
var o: ?*EmptyStruct = &e;
- expect(o != null);
+ try expect(o != null);
}
test "equality compare nullable pointers" {
- testNullPtrsEql();
- comptime testNullPtrsEql();
+ try testNullPtrsEql();
+ comptime try testNullPtrsEql();
}
-fn testNullPtrsEql() void {
+fn testNullPtrsEql() !void {
var number: i32 = 1234;
var x: ?*i32 = null;
var y: ?*i32 = null;
- expect(x == y);
+ try expect(x == y);
y = &number;
- expect(x != y);
- expect(x != &number);
- expect(&number != x);
+ try expect(x != y);
+ try expect(x != &number);
+ try expect(&number != x);
x = &number;
- expect(x == y);
- expect(x == &number);
- expect(&number == x);
+ try expect(x == y);
+ try expect(x == &number);
+ try expect(&number == x);
}
test "address of unwrap optional" {
@@ -46,23 +46,23 @@ test "address of unwrap optional" {
};
S.global = S.Foo{ .a = 1234 };
const foo = S.getFoo() catch unreachable;
- expect(foo.a == 1234);
+ try expect(foo.a == 1234);
}
test "equality compare optional with non-optional" {
- test_cmp_optional_non_optional();
- comptime test_cmp_optional_non_optional();
+ try test_cmp_optional_non_optional();
+ comptime try test_cmp_optional_non_optional();
}
-fn test_cmp_optional_non_optional() void {
+fn test_cmp_optional_non_optional() !void {
var ten: i32 = 10;
var opt_ten: ?i32 = 10;
var five: i32 = 5;
var int_n: ?i32 = null;
- expect(int_n != ten);
- expect(opt_ten == ten);
- expect(opt_ten != five);
+ try expect(int_n != ten);
+ try expect(opt_ten == ten);
+ try expect(opt_ten != five);
// test evaluation is always lexical
// ensure that the optional isn't always computed before the non-optional
@@ -71,14 +71,14 @@ fn test_cmp_optional_non_optional() void {
mutable_state += 1;
break :blk1 @as(?f64, 10.0);
} != blk2: {
- expect(mutable_state == 1);
+ try expect(mutable_state == 1);
break :blk2 @as(f64, 5.0);
};
_ = blk1: {
mutable_state += 1;
break :blk1 @as(f64, 10.0);
} != blk2: {
- expect(mutable_state == 2);
+ try expect(mutable_state == 2);
break :blk2 @as(?f64, 5.0);
};
}
@@ -94,15 +94,15 @@ test "passing an optional integer as a parameter" {
return x.? == 1234;
}
};
- expect(S.entry());
- comptime expect(S.entry());
+ try expect(S.entry());
+ comptime try expect(S.entry());
}
test "unwrap function call with optional pointer return value" {
const S = struct {
- fn entry() void {
- expect(foo().?.* == 1234);
- expect(bar() == null);
+ fn entry() !void {
+ try expect(foo().?.* == 1234);
+ try expect(bar() == null);
}
const global: i32 = 1234;
fn foo() ?*const i32 {
@@ -112,14 +112,14 @@ test "unwrap function call with optional pointer return value" {
return null;
}
};
- S.entry();
- comptime S.entry();
+ try S.entry();
+ comptime try S.entry();
}
test "nested orelse" {
const S = struct {
- fn entry() void {
- expect(func() == null);
+ fn entry() !void {
+ try expect(func() == null);
}
fn maybe() ?Foo {
return null;
@@ -134,8 +134,8 @@ test "nested orelse" {
field: i32,
};
};
- S.entry();
- comptime S.entry();
+ try S.entry();
+ comptime try S.entry();
}
test "self-referential struct through a slice of optional" {
@@ -154,7 +154,7 @@ test "self-referential struct through a slice of optional" {
};
var n = S.Node.new();
- expect(n.data == null);
+ try expect(n.data == null);
}
test "assigning to an unwrapped optional field in an inline loop" {
@@ -173,14 +173,14 @@ test "coerce an anon struct literal to optional struct" {
const Struct = struct {
field: u32,
};
- export fn doTheTest() void {
+ fn doTheTest() !void {
var maybe_dims: ?Struct = null;
maybe_dims = .{ .field = 1 };
- expect(maybe_dims.?.field == 1);
+ try expect(maybe_dims.?.field == 1);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "optional with void type" {
@@ -188,15 +188,15 @@ test "optional with void type" {
x: ?void,
};
var x = Foo{ .x = null };
- expect(x.x == null);
+ try expect(x.x == null);
}
test "0-bit child type coerced to optional return ptr result location" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var y = Foo{};
var z = y.thing();
- expect(z != null);
+ try expect(z != null);
}
const Foo = struct {
@@ -209,17 +209,17 @@ test "0-bit child type coerced to optional return ptr result location" {
}
};
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "0-bit child type coerced to optional" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var it: Foo = .{
.list = undefined,
};
- expect(it.foo() != null);
+ try expect(it.foo() != null);
}
const Empty = struct {};
@@ -232,8 +232,8 @@ test "0-bit child type coerced to optional" {
}
};
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "array of optional unaligned types" {
@@ -255,15 +255,15 @@ test "array of optional unaligned types" {
// The index must be a runtime value
var i: usize = 0;
- expectEqual(Enum.one, values[i].?.Num);
+ try expectEqual(Enum.one, values[i].?.Num);
i += 1;
- expectEqual(Enum.two, values[i].?.Num);
+ try expectEqual(Enum.two, values[i].?.Num);
i += 1;
- expectEqual(Enum.three, values[i].?.Num);
+ try expectEqual(Enum.three, values[i].?.Num);
i += 1;
- expectEqual(Enum.one, values[i].?.Num);
+ try expectEqual(Enum.one, values[i].?.Num);
i += 1;
- expectEqual(Enum.two, values[i].?.Num);
+ try expectEqual(Enum.two, values[i].?.Num);
i += 1;
- expectEqual(Enum.three, values[i].?.Num);
+ try expectEqual(Enum.three, values[i].?.Num);
}
diff --git a/test/stage1/behavior/pointers.zig b/test/stage1/behavior/pointers.zig
index a4f619b538..a078e58ab5 100644
--- a/test/stage1/behavior/pointers.zig
+++ b/test/stage1/behavior/pointers.zig
@@ -4,15 +4,15 @@ const expect = testing.expect;
const expectError = testing.expectError;
test "dereference pointer" {
- comptime testDerefPtr();
- testDerefPtr();
+ comptime try testDerefPtr();
+ try testDerefPtr();
}
-fn testDerefPtr() void {
+fn testDerefPtr() !void {
var x: i32 = 1234;
var y = &x;
y.* += 1;
- expect(x == 1235);
+ try expect(x == 1235);
}
const Foo1 = struct {
@@ -20,41 +20,41 @@ const Foo1 = struct {
};
test "dereference pointer again" {
- testDerefPtrOneVal();
- comptime testDerefPtrOneVal();
+ try testDerefPtrOneVal();
+ comptime try testDerefPtrOneVal();
}
-fn testDerefPtrOneVal() void {
+fn testDerefPtrOneVal() !void {
// Foo1 satisfies the OnePossibleValueYes criteria
const x = &Foo1{ .x = {} };
const y = x.*;
- expect(@TypeOf(y.x) == void);
+ try expect(@TypeOf(y.x) == void);
}
test "pointer arithmetic" {
var ptr: [*]const u8 = "abcd";
- expect(ptr[0] == 'a');
+ try expect(ptr[0] == 'a');
ptr += 1;
- expect(ptr[0] == 'b');
+ try expect(ptr[0] == 'b');
ptr += 1;
- expect(ptr[0] == 'c');
+ try expect(ptr[0] == 'c');
ptr += 1;
- expect(ptr[0] == 'd');
+ try expect(ptr[0] == 'd');
ptr += 1;
- expect(ptr[0] == 0);
+ try expect(ptr[0] == 0);
ptr -= 1;
- expect(ptr[0] == 'd');
+ try expect(ptr[0] == 'd');
ptr -= 1;
- expect(ptr[0] == 'c');
+ try expect(ptr[0] == 'c');
ptr -= 1;
- expect(ptr[0] == 'b');
+ try expect(ptr[0] == 'b');
ptr -= 1;
- expect(ptr[0] == 'a');
+ try expect(ptr[0] == 'a');
}
test "double pointer parsing" {
- comptime expect(PtrOf(PtrOf(i32)) == **i32);
+ comptime try expect(PtrOf(PtrOf(i32)) == **i32);
}
fn PtrOf(comptime T: type) type {
@@ -72,33 +72,33 @@ test "implicit cast single item pointer to C pointer and back" {
var x: [*c]u8 = &y;
var z: *u8 = x;
z.* += 1;
- expect(y == 12);
+ try expect(y == 12);
}
test "C pointer comparison and arithmetic" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var one: usize = 1;
var ptr1: [*c]u32 = 0;
var ptr2 = ptr1 + 10;
- expect(ptr1 == 0);
- expect(ptr1 >= 0);
- expect(ptr1 <= 0);
+ try expect(ptr1 == 0);
+ try expect(ptr1 >= 0);
+ try expect(ptr1 <= 0);
// expect(ptr1 < 1);
// expect(ptr1 < one);
// expect(1 > ptr1);
// expect(one > ptr1);
- expect(ptr1 < ptr2);
- expect(ptr2 > ptr1);
- expect(ptr2 >= 40);
- expect(ptr2 == 40);
- expect(ptr2 <= 40);
+ try expect(ptr1 < ptr2);
+ try expect(ptr2 > ptr1);
+ try expect(ptr2 >= 40);
+ try expect(ptr2 == 40);
+ try expect(ptr2 <= 40);
ptr2 -= 10;
- expect(ptr1 == ptr2);
+ try expect(ptr1 == ptr2);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "peer type resolution with C pointers" {
@@ -110,10 +110,10 @@ test "peer type resolution with C pointers" {
var x2 = if (t) ptr_many else ptr_c;
var x3 = if (t) ptr_c else ptr_one;
var x4 = if (t) ptr_c else ptr_many;
- expect(@TypeOf(x1) == [*c]u8);
- expect(@TypeOf(x2) == [*c]u8);
- expect(@TypeOf(x3) == [*c]u8);
- expect(@TypeOf(x4) == [*c]u8);
+ try expect(@TypeOf(x1) == [*c]u8);
+ try expect(@TypeOf(x2) == [*c]u8);
+ try expect(@TypeOf(x3) == [*c]u8);
+ try expect(@TypeOf(x4) == [*c]u8);
}
test "implicit casting between C pointer and optional non-C pointer" {
@@ -121,15 +121,15 @@ test "implicit casting between C pointer and optional non-C pointer" {
const opt_many_ptr: ?[*]const u8 = slice.ptr;
var ptr_opt_many_ptr = &opt_many_ptr;
var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
- expect(c_ptr.*.* == 'a');
+ try expect(c_ptr.*.* == 'a');
ptr_opt_many_ptr = c_ptr;
- expect(ptr_opt_many_ptr.*.?[1] == 'o');
+ try expect(ptr_opt_many_ptr.*.?[1] == 'o');
}
test "implicit cast error unions with non-optional to optional pointer" {
const S = struct {
- fn doTheTest() void {
- expectError(error.Fail, foo());
+ fn doTheTest() !void {
+ try expectError(error.Fail, foo());
}
fn foo() anyerror!?*u8 {
return bar() orelse error.Fail;
@@ -138,111 +138,111 @@ test "implicit cast error unions with non-optional to optional pointer" {
return null;
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "initialize const optional C pointer to null" {
const a: ?[*c]i32 = null;
- expect(a == null);
- comptime expect(a == null);
+ try expect(a == null);
+ comptime try expect(a == null);
}
test "compare equality of optional and non-optional pointer" {
const a = @intToPtr(*const usize, 0x12345678);
const b = @intToPtr(?*usize, 0x12345678);
- expect(a == b);
- expect(b == a);
+ try expect(a == b);
+ try expect(b == a);
}
test "allowzero pointer and slice" {
var ptr = @intToPtr([*]allowzero i32, 0);
var opt_ptr: ?[*]allowzero i32 = ptr;
- expect(opt_ptr != null);
- expect(@ptrToInt(ptr) == 0);
+ try expect(opt_ptr != null);
+ try expect(@ptrToInt(ptr) == 0);
var runtime_zero: usize = 0;
var slice = ptr[runtime_zero..10];
- comptime expect(@TypeOf(slice) == []allowzero i32);
- expect(@ptrToInt(&slice[5]) == 20);
+ comptime try expect(@TypeOf(slice) == []allowzero i32);
+ try expect(@ptrToInt(&slice[5]) == 20);
- comptime expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero);
- comptime expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero);
+ comptime try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero);
+ comptime try expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero);
}
test "assign null directly to C pointer and test null equality" {
var x: [*c]i32 = null;
- expect(x == null);
- expect(null == x);
- expect(!(x != null));
- expect(!(null != x));
+ try expect(x == null);
+ try expect(null == x);
+ try expect(!(x != null));
+ try expect(!(null != x));
if (x) |same_x| {
@panic("fail");
}
var otherx: i32 = undefined;
- expect((x orelse &otherx) == &otherx);
+ try expect((x orelse &otherx) == &otherx);
const y: [*c]i32 = null;
- comptime expect(y == null);
- comptime expect(null == y);
- comptime expect(!(y != null));
- comptime expect(!(null != y));
+ comptime try expect(y == null);
+ comptime try expect(null == y);
+ comptime try expect(!(y != null));
+ comptime try expect(!(null != y));
if (y) |same_y| @panic("fail");
const othery: i32 = undefined;
- comptime expect((y orelse &othery) == &othery);
+ comptime try expect((y orelse &othery) == &othery);
var n: i32 = 1234;
var x1: [*c]i32 = &n;
- expect(!(x1 == null));
- expect(!(null == x1));
- expect(x1 != null);
- expect(null != x1);
- expect(x1.?.* == 1234);
+ try expect(!(x1 == null));
+ try expect(!(null == x1));
+ try expect(x1 != null);
+ try expect(null != x1);
+ try expect(x1.?.* == 1234);
if (x1) |same_x1| {
- expect(same_x1.* == 1234);
+ try expect(same_x1.* == 1234);
} else {
@panic("fail");
}
- expect((x1 orelse &otherx) == x1);
+ try expect((x1 orelse &otherx) == x1);
const nc: i32 = 1234;
const y1: [*c]const i32 = &nc;
- comptime expect(!(y1 == null));
- comptime expect(!(null == y1));
- comptime expect(y1 != null);
- comptime expect(null != y1);
- comptime expect(y1.?.* == 1234);
+ comptime try expect(!(y1 == null));
+ comptime try expect(!(null == y1));
+ comptime try expect(y1 != null);
+ comptime try expect(null != y1);
+ comptime try expect(y1.?.* == 1234);
if (y1) |same_y1| {
- expect(same_y1.* == 1234);
+ try expect(same_y1.* == 1234);
} else {
@compileError("fail");
}
- comptime expect((y1 orelse &othery) == y1);
+ comptime try expect((y1 orelse &othery) == y1);
}
test "null terminated pointer" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' };
var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);
var no_zero_ptr: [*]const u8 = zero_ptr;
var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);
- expect(std.mem.eql(u8, std.mem.spanZ(zero_ptr_again), "hello"));
+ try expect(std.mem.eql(u8, std.mem.spanZ(zero_ptr_again), "hello"));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "allow any sentinel" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 };
var ptr: [*:std.math.minInt(i32)]i32 = &array;
- expect(ptr[4] == std.math.minInt(i32));
+ try expect(ptr[4] == std.math.minInt(i32));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "pointer sentinel with enums" {
@@ -253,42 +253,42 @@ test "pointer sentinel with enums" {
sentinel,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one };
- expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731
+ try expect(ptr[4] == .sentinel); // TODO this should be comptime try expect, see #3731
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "pointer sentinel with optional element" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 };
- expect(ptr[4] == null); // TODO this should be comptime expect, see #3731
+ try expect(ptr[4] == null); // TODO this should be comptime try expect, see #3731
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "pointer sentinel with +inf" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
const inf = std.math.inf_f32;
var ptr: [*:inf]const f32 = &[_:inf]f32{ 1.1, 2.2, 3.3, 4.4 };
- expect(ptr[4] == inf); // TODO this should be comptime expect, see #3731
+ try expect(ptr[4] == inf); // TODO this should be comptime try expect, see #3731
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "pointer to array at fixed address" {
const array = @intToPtr(*volatile [1]u32, 0x10);
// Silly check just to reference `array`
- expect(@ptrToInt(&array[0]) == 0x10);
+ try expect(@ptrToInt(&array[0]) == 0x10);
}
test "pointer arithmetic affects the alignment" {
@@ -296,28 +296,28 @@ test "pointer arithmetic affects the alignment" {
var ptr: [*]align(8) u32 = undefined;
var x: usize = 1;
- expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8);
+ try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8);
const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4
- expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 4);
+ try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 4);
const ptr2 = ptr + 4; // 4 * 4 = 16 -> lcd(16,8) = 8
- expect(@typeInfo(@TypeOf(ptr2)).Pointer.alignment == 8);
+ try expect(@typeInfo(@TypeOf(ptr2)).Pointer.alignment == 8);
const ptr3 = ptr + 0; // no-op
- expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8);
+ try expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8);
const ptr4 = ptr + x; // runtime-known addend
- expect(@typeInfo(@TypeOf(ptr4)).Pointer.alignment == 4);
+ try expect(@typeInfo(@TypeOf(ptr4)).Pointer.alignment == 4);
}
{
var ptr: [*]align(8) [3]u8 = undefined;
var x: usize = 1;
const ptr1 = ptr + 17; // 3 * 17 = 51
- expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1);
+ try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1);
const ptr2 = ptr + x; // runtime-known addend
- expect(@typeInfo(@TypeOf(ptr2)).Pointer.alignment == 1);
+ try expect(@typeInfo(@TypeOf(ptr2)).Pointer.alignment == 1);
const ptr3 = ptr + 8; // 3 * 8 = 24 -> lcd(8,24) = 8
- expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8);
+ try expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8);
const ptr4 = ptr + 4; // 3 * 4 = 12 -> lcd(8,12) = 4
- expect(@typeInfo(@TypeOf(ptr4)).Pointer.alignment == 4);
+ try expect(@typeInfo(@TypeOf(ptr4)).Pointer.alignment == 4);
}
}
@@ -325,15 +325,15 @@ test "@ptrToInt on null optional at comptime" {
{
const pointer = @intToPtr(?*u8, 0x000);
const x = @ptrToInt(pointer);
- comptime expect(0 == @ptrToInt(pointer));
+ comptime try expect(0 == @ptrToInt(pointer));
}
{
const pointer = @intToPtr(?*u8, 0xf00);
- comptime expect(0xf00 == @ptrToInt(pointer));
+ comptime try expect(0xf00 == @ptrToInt(pointer));
}
}
test "indexing array with sentinel returns correct type" {
var s: [:0]const u8 = "abc";
- testing.expectEqualSlices(u8, "*const u8", @typeName(@TypeOf(&s[0])));
+ try testing.expectEqualSlices(u8, "*const u8", @typeName(@TypeOf(&s[0])));
}
diff --git a/test/stage1/behavior/popcount.zig b/test/stage1/behavior/popcount.zig
index 884a7bdb6d..99a1849d80 100644
--- a/test/stage1/behavior/popcount.zig
+++ b/test/stage1/behavior/popcount.zig
@@ -1,43 +1,43 @@
const expect = @import("std").testing.expect;
test "@popCount" {
- comptime testPopCount();
- testPopCount();
+ comptime try testPopCount();
+ try testPopCount();
}
-fn testPopCount() void {
+fn testPopCount() !void {
{
var x: u32 = 0xffffffff;
- expect(@popCount(u32, x) == 32);
+ try expect(@popCount(u32, x) == 32);
}
{
var x: u5 = 0x1f;
- expect(@popCount(u5, x) == 5);
+ try expect(@popCount(u5, x) == 5);
}
{
var x: u32 = 0xaa;
- expect(@popCount(u32, x) == 4);
+ try expect(@popCount(u32, x) == 4);
}
{
var x: u32 = 0xaaaaaaaa;
- expect(@popCount(u32, x) == 16);
+ try expect(@popCount(u32, x) == 16);
}
{
var x: u32 = 0xaaaaaaaa;
- expect(@popCount(u32, x) == 16);
+ try expect(@popCount(u32, x) == 16);
}
{
var x: i16 = -1;
- expect(@popCount(i16, x) == 16);
+ try expect(@popCount(i16, x) == 16);
}
{
var x: i8 = -120;
- expect(@popCount(i8, x) == 2);
+ try expect(@popCount(i8, x) == 2);
}
comptime {
- expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2);
+ try expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2);
}
comptime {
- expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24);
+ try expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24);
}
}
diff --git a/test/stage1/behavior/ptrcast.zig b/test/stage1/behavior/ptrcast.zig
index 26e9545248..6c67dd504b 100644
--- a/test/stage1/behavior/ptrcast.zig
+++ b/test/stage1/behavior/ptrcast.zig
@@ -3,25 +3,25 @@ const builtin = std.builtin;
const expect = std.testing.expect;
test "reinterpret bytes as integer with nonzero offset" {
- testReinterpretBytesAsInteger();
- comptime testReinterpretBytesAsInteger();
+ try testReinterpretBytesAsInteger();
+ comptime try testReinterpretBytesAsInteger();
}
-fn testReinterpretBytesAsInteger() void {
+fn testReinterpretBytesAsInteger() !void {
const bytes = "\x12\x34\x56\x78\xab";
const expected = switch (builtin.endian) {
builtin.Endian.Little => 0xab785634,
builtin.Endian.Big => 0x345678ab,
};
- expect(@ptrCast(*align(1) const u32, bytes[1..5]).* == expected);
+ try expect(@ptrCast(*align(1) const u32, bytes[1..5]).* == expected);
}
test "reinterpret bytes of an array into an extern struct" {
- testReinterpretBytesAsExternStruct();
- comptime testReinterpretBytesAsExternStruct();
+ try testReinterpretBytesAsExternStruct();
+ comptime try testReinterpretBytesAsExternStruct();
}
-fn testReinterpretBytesAsExternStruct() void {
+fn testReinterpretBytesAsExternStruct() !void {
var bytes align(2) = [_]u8{ 1, 2, 3, 4, 5, 6 };
const S = extern struct {
@@ -32,15 +32,15 @@ fn testReinterpretBytesAsExternStruct() void {
var ptr = @ptrCast(*const S, &bytes);
var val = ptr.c;
- expect(val == 5);
+ try expect(val == 5);
}
test "reinterpret struct field at comptime" {
const numNative = comptime Bytes.init(0x12345678);
if (builtin.endian != .Little) {
- expect(std.mem.eql(u8, &[_]u8{ 0x12, 0x34, 0x56, 0x78 }, &numNative.bytes));
+ try expect(std.mem.eql(u8, &[_]u8{ 0x12, 0x34, 0x56, 0x78 }, &numNative.bytes));
} else {
- expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numNative.bytes));
+ try expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numNative.bytes));
}
}
@@ -59,7 +59,7 @@ test "comptime ptrcast keeps larger alignment" {
comptime {
const a: u32 = 1234;
const p = @ptrCast([*]const u8, &a);
- std.debug.assert(@TypeOf(p) == [*]align(@alignOf(u32)) const u8);
+ try expect(@TypeOf(p) == [*]align(@alignOf(u32)) const u8);
}
}
@@ -68,5 +68,5 @@ test "implicit optional pointer to optional c_void pointer" {
var x: ?[*]u8 = &buf;
var y: ?*c_void = x;
var z = @ptrCast(*[4]u8, y);
- expect(std.mem.eql(u8, z, "aoeu"));
+ try expect(std.mem.eql(u8, z, "aoeu"));
}
diff --git a/test/stage1/behavior/pub_enum.zig b/test/stage1/behavior/pub_enum.zig
index 0613df94d9..d2e887b12e 100644
--- a/test/stage1/behavior/pub_enum.zig
+++ b/test/stage1/behavior/pub_enum.zig
@@ -2,12 +2,12 @@ const other = @import("pub_enum/other.zig");
const expect = @import("std").testing.expect;
test "pub enum" {
- pubEnumTest(other.APubEnum.Two);
+ try pubEnumTest(other.APubEnum.Two);
}
-fn pubEnumTest(foo: other.APubEnum) void {
- expect(foo == other.APubEnum.Two);
+fn pubEnumTest(foo: other.APubEnum) !void {
+ try expect(foo == other.APubEnum.Two);
}
test "cast with imported symbol" {
- expect(@as(other.size_t, 42) == 42);
+ try expect(@as(other.size_t, 42) == 42);
}
diff --git a/test/stage1/behavior/ref_var_in_if_after_if_2nd_switch_prong.zig b/test/stage1/behavior/ref_var_in_if_after_if_2nd_switch_prong.zig
index 2c1cf06268..488bc1a232 100644
--- a/test/stage1/behavior/ref_var_in_if_after_if_2nd_switch_prong.zig
+++ b/test/stage1/behavior/ref_var_in_if_after_if_2nd_switch_prong.zig
@@ -3,12 +3,12 @@ const mem = @import("std").mem;
var ok: bool = false;
test "reference a variable in an if after an if in the 2nd switch prong" {
- foo(true, Num.Two, false, "aoeu");
- expect(!ok);
- foo(false, Num.One, false, "aoeu");
- expect(!ok);
- foo(true, Num.One, false, "aoeu");
- expect(ok);
+ try foo(true, Num.Two, false, "aoeu");
+ try expect(!ok);
+ try foo(false, Num.One, false, "aoeu");
+ try expect(!ok);
+ try foo(true, Num.One, false, "aoeu");
+ try expect(ok);
}
const Num = enum {
@@ -16,7 +16,7 @@ const Num = enum {
Two,
};
-fn foo(c: bool, k: Num, c2: bool, b: []const u8) void {
+fn foo(c: bool, k: Num, c2: bool, b: []const u8) !void {
switch (k) {
Num.Two => {},
Num.One => {
@@ -25,13 +25,13 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) void {
if (c2) {}
- a(output_path);
+ try a(output_path);
}
},
}
}
-fn a(x: []const u8) void {
- expect(mem.eql(u8, x, "aoeu"));
+fn a(x: []const u8) !void {
+ try expect(mem.eql(u8, x, "aoeu"));
ok = true;
}
diff --git a/test/stage1/behavior/reflection.zig b/test/stage1/behavior/reflection.zig
index 6d1c341713..3e5e4087c4 100644
--- a/test/stage1/behavior/reflection.zig
+++ b/test/stage1/behavior/reflection.zig
@@ -5,12 +5,12 @@ const reflection = @This();
test "reflection: function return type, var args, and param types" {
comptime {
const info = @typeInfo(@TypeOf(dummy)).Fn;
- expect(info.return_type.? == i32);
- expect(!info.is_var_args);
- expect(info.args.len == 3);
- expect(info.args[0].arg_type.? == bool);
- expect(info.args[1].arg_type.? == i32);
- expect(info.args[2].arg_type.? == f32);
+ try expect(info.return_type.? == i32);
+ try expect(!info.is_var_args);
+ try expect(info.args.len == 3);
+ try expect(info.args[0].arg_type.? == bool);
+ try expect(info.args[1].arg_type.? == i32);
+ try expect(info.args[2].arg_type.? == f32);
}
}
@@ -25,18 +25,18 @@ test "reflection: @field" {
.three = void{},
};
- expect(f.one == f.one);
- expect(@field(f, "o" ++ "ne") == f.one);
- expect(@field(f, "t" ++ "wo") == f.two);
- expect(@field(f, "th" ++ "ree") == f.three);
- expect(@field(Foo, "const" ++ "ant") == Foo.constant);
- expect(@field(Bar, "O" ++ "ne") == Bar.One);
- expect(@field(Bar, "T" ++ "wo") == Bar.Two);
- expect(@field(Bar, "Th" ++ "ree") == Bar.Three);
- expect(@field(Bar, "F" ++ "our") == Bar.Four);
- expect(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2));
+ try expect(f.one == f.one);
+ try expect(@field(f, "o" ++ "ne") == f.one);
+ try expect(@field(f, "t" ++ "wo") == f.two);
+ try expect(@field(f, "th" ++ "ree") == f.three);
+ try expect(@field(Foo, "const" ++ "ant") == Foo.constant);
+ try expect(@field(Bar, "O" ++ "ne") == Bar.One);
+ try expect(@field(Bar, "T" ++ "wo") == Bar.Two);
+ try expect(@field(Bar, "Th" ++ "ree") == Bar.Three);
+ try expect(@field(Bar, "F" ++ "our") == Bar.Four);
+ try expect(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2));
@field(f, "o" ++ "ne") = 4;
- expect(f.one == 4);
+ try expect(f.one == 4);
}
const Foo = struct {
diff --git a/test/stage1/behavior/shuffle.zig b/test/stage1/behavior/shuffle.zig
index 3b6412b386..e839b7eddc 100644
--- a/test/stage1/behavior/shuffle.zig
+++ b/test/stage1/behavior/shuffle.zig
@@ -9,33 +9,33 @@ test "@shuffle" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
var x: Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
const mask: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
var res = @shuffle(i32, v, x, mask);
- expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
+ try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
// Implicit cast from array (of mask)
res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });
- expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
+ try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
// Undefined
const mask2: Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };
res = @shuffle(i32, v, undefined, mask2);
- expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 40, -2, 30, 2147483647 }));
+ try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 40, -2, 30, 2147483647 }));
// Upcasting of b
var v2: Vector(2, i32) = [2]i32{ 2147483647, undefined };
const mask3: Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
res = @shuffle(i32, x, v2, mask3);
- expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 }));
+ try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 }));
// Upcasting of a
var v3: Vector(2, i32) = [2]i32{ 2147483647, -2 };
const mask4: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
res = @shuffle(i32, v3, x, mask4);
- expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 }));
+ try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 }));
// bool
// Disabled because of #3317
@@ -44,7 +44,7 @@ test "@shuffle" {
var v4: Vector(2, bool) = [2]bool{ true, false };
const mask5: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
var res2 = @shuffle(bool, x2, v4, mask5);
- expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
+ try expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
}
// TODO re-enable when LLVM codegen is fixed
@@ -54,10 +54,10 @@ test "@shuffle" {
var v4: Vector(2, bool) = [2]bool{ true, false };
const mask5: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
var res2 = @shuffle(bool, x2, v4, mask5);
- expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
+ try expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
diff --git a/test/stage1/behavior/sizeof_and_typeof.zig b/test/stage1/behavior/sizeof_and_typeof.zig
index 54efe9cb35..ae5e760f59 100644
--- a/test/stage1/behavior/sizeof_and_typeof.zig
+++ b/test/stage1/behavior/sizeof_and_typeof.zig
@@ -5,7 +5,7 @@ const expectEqual = std.testing.expectEqual;
test "@sizeOf and @TypeOf" {
const y: @TypeOf(x) = 120;
- expect(@sizeOf(@TypeOf(y)) == 2);
+ try expect(@sizeOf(@TypeOf(y)) == 2);
}
const x: u16 = 13;
const z: @TypeOf(x) = 19;
@@ -36,27 +36,27 @@ const P = packed struct {
test "@byteOffsetOf" {
// Packed structs have fixed memory layout
- expect(@byteOffsetOf(P, "a") == 0);
- expect(@byteOffsetOf(P, "b") == 1);
- expect(@byteOffsetOf(P, "c") == 5);
- expect(@byteOffsetOf(P, "d") == 6);
- expect(@byteOffsetOf(P, "e") == 6);
- expect(@byteOffsetOf(P, "f") == 7);
- expect(@byteOffsetOf(P, "g") == 9);
- expect(@byteOffsetOf(P, "h") == 11);
- expect(@byteOffsetOf(P, "i") == 12);
+ try expect(@byteOffsetOf(P, "a") == 0);
+ try expect(@byteOffsetOf(P, "b") == 1);
+ try expect(@byteOffsetOf(P, "c") == 5);
+ try expect(@byteOffsetOf(P, "d") == 6);
+ try expect(@byteOffsetOf(P, "e") == 6);
+ try expect(@byteOffsetOf(P, "f") == 7);
+ try expect(@byteOffsetOf(P, "g") == 9);
+ try expect(@byteOffsetOf(P, "h") == 11);
+ try expect(@byteOffsetOf(P, "i") == 12);
// Normal struct fields can be moved/padded
var a: A = undefined;
- expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a"));
- expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b"));
- expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c"));
- expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d"));
- expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));
- expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));
- expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));
- expect(@ptrToInt(&a.h) - @ptrToInt(&a) == @byteOffsetOf(A, "h"));
- expect(@ptrToInt(&a.i) - @ptrToInt(&a) == @byteOffsetOf(A, "i"));
+ try expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a"));
+ try expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b"));
+ try expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c"));
+ try expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d"));
+ try expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));
+ try expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));
+ try expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));
+ try expect(@ptrToInt(&a.h) - @ptrToInt(&a) == @byteOffsetOf(A, "h"));
+ try expect(@ptrToInt(&a.i) - @ptrToInt(&a) == @byteOffsetOf(A, "i"));
}
test "@byteOffsetOf packed struct, array length not power of 2 or multiple of native pointer width in bytes" {
@@ -65,68 +65,68 @@ test "@byteOffsetOf packed struct, array length not power of 2 or multiple of na
a: [p3a_len]u8,
b: usize,
};
- std.testing.expectEqual(0, @byteOffsetOf(P3, "a"));
- std.testing.expectEqual(p3a_len, @byteOffsetOf(P3, "b"));
+ try std.testing.expectEqual(0, @byteOffsetOf(P3, "a"));
+ try std.testing.expectEqual(p3a_len, @byteOffsetOf(P3, "b"));
const p5a_len = 5;
const P5 = packed struct {
a: [p5a_len]u8,
b: usize,
};
- std.testing.expectEqual(0, @byteOffsetOf(P5, "a"));
- std.testing.expectEqual(p5a_len, @byteOffsetOf(P5, "b"));
+ try std.testing.expectEqual(0, @byteOffsetOf(P5, "a"));
+ try std.testing.expectEqual(p5a_len, @byteOffsetOf(P5, "b"));
const p6a_len = 6;
const P6 = packed struct {
a: [p6a_len]u8,
b: usize,
};
- std.testing.expectEqual(0, @byteOffsetOf(P6, "a"));
- std.testing.expectEqual(p6a_len, @byteOffsetOf(P6, "b"));
+ try std.testing.expectEqual(0, @byteOffsetOf(P6, "a"));
+ try std.testing.expectEqual(p6a_len, @byteOffsetOf(P6, "b"));
const p7a_len = 7;
const P7 = packed struct {
a: [p7a_len]u8,
b: usize,
};
- std.testing.expectEqual(0, @byteOffsetOf(P7, "a"));
- std.testing.expectEqual(p7a_len, @byteOffsetOf(P7, "b"));
+ try std.testing.expectEqual(0, @byteOffsetOf(P7, "a"));
+ try std.testing.expectEqual(p7a_len, @byteOffsetOf(P7, "b"));
const p9a_len = 9;
const P9 = packed struct {
a: [p9a_len]u8,
b: usize,
};
- std.testing.expectEqual(0, @byteOffsetOf(P9, "a"));
- std.testing.expectEqual(p9a_len, @byteOffsetOf(P9, "b"));
+ try std.testing.expectEqual(0, @byteOffsetOf(P9, "a"));
+ try std.testing.expectEqual(p9a_len, @byteOffsetOf(P9, "b"));
// 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25 etc. are further cases
}
test "@bitOffsetOf" {
// Packed structs have fixed memory layout
- expect(@bitOffsetOf(P, "a") == 0);
- expect(@bitOffsetOf(P, "b") == 8);
- expect(@bitOffsetOf(P, "c") == 40);
- expect(@bitOffsetOf(P, "d") == 48);
- expect(@bitOffsetOf(P, "e") == 51);
- expect(@bitOffsetOf(P, "f") == 56);
- expect(@bitOffsetOf(P, "g") == 72);
+ try expect(@bitOffsetOf(P, "a") == 0);
+ try expect(@bitOffsetOf(P, "b") == 8);
+ try expect(@bitOffsetOf(P, "c") == 40);
+ try expect(@bitOffsetOf(P, "d") == 48);
+ try expect(@bitOffsetOf(P, "e") == 51);
+ try expect(@bitOffsetOf(P, "f") == 56);
+ try expect(@bitOffsetOf(P, "g") == 72);
- expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));
- expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));
- expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));
- expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));
- expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));
- expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));
- expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));
+ try expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));
+ try expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));
+ try expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));
+ try expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));
+ try expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));
+ try expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));
+ try expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));
}
test "@sizeOf on compile-time types" {
- expect(@sizeOf(comptime_int) == 0);
- expect(@sizeOf(comptime_float) == 0);
- expect(@sizeOf(@TypeOf(.hi)) == 0);
- expect(@sizeOf(@TypeOf(type)) == 0);
+ try expect(@sizeOf(comptime_int) == 0);
+ try expect(@sizeOf(comptime_float) == 0);
+ try expect(@sizeOf(@TypeOf(.hi)) == 0);
+ try expect(@sizeOf(@TypeOf(type)) == 0);
}
test "@sizeOf(T) == 0 doesn't force resolving struct size" {
@@ -140,8 +140,8 @@ test "@sizeOf(T) == 0 doesn't force resolving struct size" {
};
};
- expect(@sizeOf(S.Foo) == 4);
- expect(@sizeOf(S.Bar) == 8);
+ try expect(@sizeOf(S.Foo) == 4);
+ try expect(@sizeOf(S.Bar) == 8);
}
test "@TypeOf() has no runtime side effects" {
@@ -153,8 +153,8 @@ test "@TypeOf() has no runtime side effects" {
};
var data: i32 = 0;
const T = @TypeOf(S.foo(i32, &data));
- comptime expect(T == i32);
- expect(data == 0);
+ comptime try expect(T == i32);
+ try expect(data == 0);
}
test "@TypeOf() with multiple arguments" {
@@ -162,21 +162,21 @@ test "@TypeOf() with multiple arguments" {
var var_1: u32 = undefined;
var var_2: u8 = undefined;
var var_3: u64 = undefined;
- comptime expect(@TypeOf(var_1, var_2, var_3) == u64);
+ comptime try expect(@TypeOf(var_1, var_2, var_3) == u64);
}
{
var var_1: f16 = undefined;
var var_2: f32 = undefined;
var var_3: f64 = undefined;
- comptime expect(@TypeOf(var_1, var_2, var_3) == f64);
+ comptime try expect(@TypeOf(var_1, var_2, var_3) == f64);
}
{
var var_1: u16 = undefined;
- comptime expect(@TypeOf(var_1, 0xffff) == u16);
+ comptime try expect(@TypeOf(var_1, 0xffff) == u16);
}
{
var var_1: f32 = undefined;
- comptime expect(@TypeOf(var_1, 3.1415) == f32);
+ comptime try expect(@TypeOf(var_1, 3.1415) == f32);
}
}
@@ -189,8 +189,8 @@ test "branching logic inside @TypeOf" {
}
};
const T = @TypeOf(S.foo() catch undefined);
- comptime expect(T == i32);
- expect(S.data == 0);
+ comptime try expect(T == i32);
+ try expect(S.data == 0);
}
fn fn1(alpha: bool) void {
@@ -203,12 +203,12 @@ test "lazy @sizeOf result is checked for definedness" {
}
test "@bitSizeOf" {
- expect(@bitSizeOf(u2) == 2);
- expect(@bitSizeOf(u8) == @sizeOf(u8) * 8);
- expect(@bitSizeOf(struct {
+ try expect(@bitSizeOf(u2) == 2);
+ try expect(@bitSizeOf(u8) == @sizeOf(u8) * 8);
+ try expect(@bitSizeOf(struct {
a: u2,
}) == 8);
- expect(@bitSizeOf(packed struct {
+ try expect(@bitSizeOf(packed struct {
a: u2,
}) == 2);
}
@@ -241,24 +241,24 @@ test "@sizeOf comparison against zero" {
f2: H(***@This()),
};
const S = struct {
- fn doTheTest(comptime T: type, comptime result: bool) void {
- expectEqual(result, @sizeOf(T) > 0);
+ fn doTheTest(comptime T: type, comptime result: bool) !void {
+ try expectEqual(result, @sizeOf(T) > 0);
}
};
// Zero-sized type
- S.doTheTest(u0, false);
- S.doTheTest(*u0, false);
+ try S.doTheTest(u0, false);
+ try S.doTheTest(*u0, false);
// Non byte-sized type
- S.doTheTest(u1, true);
- S.doTheTest(*u1, true);
+ try S.doTheTest(u1, true);
+ try S.doTheTest(*u1, true);
// Regular type
- S.doTheTest(u8, true);
- S.doTheTest(*u8, true);
- S.doTheTest(f32, true);
- S.doTheTest(*f32, true);
+ try S.doTheTest(u8, true);
+ try S.doTheTest(*u8, true);
+ try S.doTheTest(f32, true);
+ try S.doTheTest(*f32, true);
// Container with ptr pointing to themselves
- S.doTheTest(S0, true);
- S.doTheTest(U0, true);
- S.doTheTest(S1, true);
- S.doTheTest(U1, true);
+ try S.doTheTest(S0, true);
+ try S.doTheTest(U0, true);
+ try S.doTheTest(S1, true);
+ try S.doTheTest(U1, true);
}
diff --git a/test/stage1/behavior/slice.zig b/test/stage1/behavior/slice.zig
index 330e218f93..d324c34477 100644
--- a/test/stage1/behavior/slice.zig
+++ b/test/stage1/behavior/slice.zig
@@ -7,11 +7,11 @@ const mem = std.mem;
const x = @intToPtr([*]i32, 0x1000)[0..0x500];
const y = x[0x100..];
test "compile time slice of pointer to hard coded address" {
- expect(@ptrToInt(x) == 0x1000);
- expect(x.len == 0x500);
+ try expect(@ptrToInt(x) == 0x1000);
+ try expect(x.len == 0x500);
- expect(@ptrToInt(y) == 0x1100);
- expect(y.len == 0x400);
+ try expect(@ptrToInt(y) == 0x1100);
+ try expect(y.len == 0x400);
}
test "runtime safety lets us slice from len..len" {
@@ -20,7 +20,7 @@ test "runtime safety lets us slice from len..len" {
2,
3,
};
- expect(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
+ try expect(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
}
fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
@@ -29,18 +29,18 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
test "implicitly cast array of size 0 to slice" {
var msg = [_]u8{};
- assertLenIsZero(&msg);
+ try assertLenIsZero(&msg);
}
-fn assertLenIsZero(msg: []const u8) void {
- expect(msg.len == 0);
+fn assertLenIsZero(msg: []const u8) !void {
+ try expect(msg.len == 0);
}
test "C pointer" {
var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf";
var len: u32 = 10;
var slice = buf[0..len];
- expectEqualSlices(u8, "kjdhfkjdhf", slice);
+ try expectEqualSlices(u8, "kjdhfkjdhf", slice);
}
test "C pointer slice access" {
@@ -48,11 +48,11 @@ test "C pointer slice access" {
const c_ptr = @ptrCast([*c]const u32, &buf);
var runtime_zero: usize = 0;
- comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));
- comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1]));
+ comptime try expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));
+ comptime try expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1]));
for (c_ptr[0..5]) |*cl| {
- expectEqual(@as(u32, 42), cl.*);
+ try expectEqual(@as(u32, 42), cl.*);
}
}
@@ -65,8 +65,8 @@ fn sliceSum(comptime q: []const u8) i32 {
}
test "comptime slices are disambiguated" {
- expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
- expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
+ try expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
+ try expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
}
test "slice type with custom alignment" {
@@ -77,20 +77,20 @@ test "slice type with custom alignment" {
var array: [10]LazilyResolvedType align(32) = undefined;
slice = &array;
slice[1].anything = 42;
- expect(array[1].anything == 42);
+ try expect(array[1].anything == 42);
}
test "access len index of sentinel-terminated slice" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var slice: [:0]const u8 = "hello";
- expect(slice.len == 5);
- expect(slice[5] == 0);
+ try expect(slice.len == 5);
+ try expect(slice[5] == 0);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "obtaining a null terminated slice" {
@@ -108,230 +108,230 @@ test "obtaining a null terminated slice" {
var runtime_len: usize = 3;
const ptr2 = buf[0..runtime_len :0];
// ptr2 is a null-terminated slice
- comptime expect(@TypeOf(ptr2) == [:0]u8);
- comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8);
+ comptime try expect(@TypeOf(ptr2) == [:0]u8);
+ comptime try expect(@TypeOf(ptr2[0..2]) == *[2]u8);
var runtime_zero: usize = 0;
- comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8);
+ comptime try expect(@TypeOf(ptr2[runtime_zero..2]) == []u8);
}
test "empty array to slice" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
const empty: []align(16) u8 = &[_]u8{};
const align_1: []align(1) u8 = empty;
const align_4: []align(4) u8 = empty;
const align_16: []align(16) u8 = empty;
- expectEqual(1, @typeInfo(@TypeOf(align_1)).Pointer.alignment);
- expectEqual(4, @typeInfo(@TypeOf(align_4)).Pointer.alignment);
- expectEqual(16, @typeInfo(@TypeOf(align_16)).Pointer.alignment);
+ try expectEqual(1, @typeInfo(@TypeOf(align_1)).Pointer.alignment);
+ try expectEqual(4, @typeInfo(@TypeOf(align_4)).Pointer.alignment);
+ try expectEqual(16, @typeInfo(@TypeOf(align_16)).Pointer.alignment);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "@ptrCast slice to pointer" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff };
var slice: []u8 = &array;
var ptr = @ptrCast(*u16, slice);
- expect(ptr.* == 65535);
+ try expect(ptr.* == 65535);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "slice syntax resulting in pointer-to-array" {
const S = struct {
- fn doTheTest() void {
- testArray();
- testArrayZ();
- testArray0();
- testArrayAlign();
- testPointer();
- testPointerZ();
- testPointer0();
- testPointerAlign();
- testSlice();
- testSliceZ();
- testSlice0();
- testSliceOpt();
- testSliceAlign();
+ fn doTheTest() !void {
+ try testArray();
+ try testArrayZ();
+ try testArray0();
+ try testArrayAlign();
+ try testPointer();
+ try testPointerZ();
+ try testPointer0();
+ try testPointerAlign();
+ try testSlice();
+ try testSliceZ();
+ try testSlice0();
+ try testSliceOpt();
+ try testSliceAlign();
}
- fn testArray() void {
+ fn testArray() !void {
var array = [5]u8{ 1, 2, 3, 4, 5 };
var slice = array[1..3];
- comptime expect(@TypeOf(slice) == *[2]u8);
- expect(slice[0] == 2);
- expect(slice[1] == 3);
+ comptime try expect(@TypeOf(slice) == *[2]u8);
+ try expect(slice[0] == 2);
+ try expect(slice[1] == 3);
}
- fn testArrayZ() void {
+ fn testArrayZ() !void {
var array = [5:0]u8{ 1, 2, 3, 4, 5 };
- comptime expect(@TypeOf(array[1..3]) == *[2]u8);
- comptime expect(@TypeOf(array[1..5]) == *[4:0]u8);
- comptime expect(@TypeOf(array[1..]) == *[4:0]u8);
- comptime expect(@TypeOf(array[1..3 :4]) == *[2:4]u8);
+ comptime try expect(@TypeOf(array[1..3]) == *[2]u8);
+ comptime try expect(@TypeOf(array[1..5]) == *[4:0]u8);
+ comptime try expect(@TypeOf(array[1..]) == *[4:0]u8);
+ comptime try expect(@TypeOf(array[1..3 :4]) == *[2:4]u8);
}
- fn testArray0() void {
+ fn testArray0() !void {
{
var array = [0]u8{};
var slice = array[0..0];
- comptime expect(@TypeOf(slice) == *[0]u8);
+ comptime try expect(@TypeOf(slice) == *[0]u8);
}
{
var array = [0:0]u8{};
var slice = array[0..0];
- comptime expect(@TypeOf(slice) == *[0:0]u8);
- expect(slice[0] == 0);
+ comptime try expect(@TypeOf(slice) == *[0:0]u8);
+ try expect(slice[0] == 0);
}
}
- fn testArrayAlign() void {
+ fn testArrayAlign() !void {
var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
var slice = array[4..5];
- comptime expect(@TypeOf(slice) == *align(4) [1]u8);
- expect(slice[0] == 5);
- comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8);
+ comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
+ try expect(slice[0] == 5);
+ comptime try expect(@TypeOf(array[0..2]) == *align(4) [2]u8);
}
- fn testPointer() void {
+ fn testPointer() !void {
var array = [5]u8{ 1, 2, 3, 4, 5 };
var pointer: [*]u8 = &array;
var slice = pointer[1..3];
- comptime expect(@TypeOf(slice) == *[2]u8);
- expect(slice[0] == 2);
- expect(slice[1] == 3);
+ comptime try expect(@TypeOf(slice) == *[2]u8);
+ try expect(slice[0] == 2);
+ try expect(slice[1] == 3);
}
- fn testPointerZ() void {
+ fn testPointerZ() !void {
var array = [5:0]u8{ 1, 2, 3, 4, 5 };
var pointer: [*:0]u8 = &array;
- comptime expect(@TypeOf(pointer[1..3]) == *[2]u8);
- comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
+ comptime try expect(@TypeOf(pointer[1..3]) == *[2]u8);
+ comptime try expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
}
- fn testPointer0() void {
+ fn testPointer0() !void {
var pointer: [*]const u0 = &[1]u0{0};
var slice = pointer[0..1];
- comptime expect(@TypeOf(slice) == *const [1]u0);
- expect(slice[0] == 0);
+ comptime try expect(@TypeOf(slice) == *const [1]u0);
+ try expect(slice[0] == 0);
}
- fn testPointerAlign() void {
+ fn testPointerAlign() !void {
var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
var pointer: [*]align(4) u8 = &array;
var slice = pointer[4..5];
- comptime expect(@TypeOf(slice) == *align(4) [1]u8);
- expect(slice[0] == 5);
- comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8);
+ comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
+ try expect(slice[0] == 5);
+ comptime try expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8);
}
- fn testSlice() void {
+ fn testSlice() !void {
var array = [5]u8{ 1, 2, 3, 4, 5 };
var src_slice: []u8 = &array;
var slice = src_slice[1..3];
- comptime expect(@TypeOf(slice) == *[2]u8);
- expect(slice[0] == 2);
- expect(slice[1] == 3);
+ comptime try expect(@TypeOf(slice) == *[2]u8);
+ try expect(slice[0] == 2);
+ try expect(slice[1] == 3);
}
- fn testSliceZ() void {
+ fn testSliceZ() !void {
var array = [5:0]u8{ 1, 2, 3, 4, 5 };
var slice: [:0]u8 = &array;
- comptime expect(@TypeOf(slice[1..3]) == *[2]u8);
- comptime expect(@TypeOf(slice[1..]) == [:0]u8);
- comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
+ comptime try expect(@TypeOf(slice[1..3]) == *[2]u8);
+ comptime try expect(@TypeOf(slice[1..]) == [:0]u8);
+ comptime try expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
}
- fn testSliceOpt() void {
+ fn testSliceOpt() !void {
var array: [2]u8 = [2]u8{ 1, 2 };
var slice: ?[]u8 = &array;
- comptime expect(@TypeOf(&array, slice) == ?[]u8);
- comptime expect(@TypeOf(slice.?[0..2]) == *[2]u8);
+ comptime try expect(@TypeOf(&array, slice) == ?[]u8);
+ comptime try expect(@TypeOf(slice.?[0..2]) == *[2]u8);
}
- fn testSlice0() void {
+ fn testSlice0() !void {
{
var array = [0]u8{};
var src_slice: []u8 = &array;
var slice = src_slice[0..0];
- comptime expect(@TypeOf(slice) == *[0]u8);
+ comptime try expect(@TypeOf(slice) == *[0]u8);
}
{
var array = [0:0]u8{};
var src_slice: [:0]u8 = &array;
var slice = src_slice[0..0];
- comptime expect(@TypeOf(slice) == *[0]u8);
+ comptime try expect(@TypeOf(slice) == *[0]u8);
}
}
- fn testSliceAlign() void {
+ fn testSliceAlign() !void {
var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
var src_slice: []align(4) u8 = &array;
var slice = src_slice[4..5];
- comptime expect(@TypeOf(slice) == *align(4) [1]u8);
- expect(slice[0] == 5);
- comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8);
+ comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
+ try expect(slice[0] == 5);
+ comptime try expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8);
}
- fn testConcatStrLiterals() void {
- expectEqualSlices("a"[0..] ++ "b"[0..], "ab");
- expectEqualSlices("a"[0..:0] ++ "b"[0..:0], "ab");
+ fn testConcatStrLiterals() !void {
+ try expectEqualSlices("a"[0..] ++ "b"[0..], "ab");
+ try expectEqualSlices("a"[0.. :0] ++ "b"[0.. :0], "ab");
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "slice of hardcoded address to pointer" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
const pointer = @intToPtr([*]u8, 0x04)[0..2];
- comptime expect(@TypeOf(pointer) == *[2]u8);
+ comptime try expect(@TypeOf(pointer) == *[2]u8);
const slice: []const u8 = pointer;
- expect(@ptrToInt(slice.ptr) == 4);
- expect(slice.len == 2);
+ try expect(@ptrToInt(slice.ptr) == 4);
+ try expect(slice.len == 2);
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "type coercion of pointer to anon struct literal to pointer to slice" {
const S = struct {
- const U = union{
+ const U = union {
a: u32,
b: bool,
c: []const u8,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var x1: u8 = 42;
const t1 = &.{ x1, 56, 54 };
var slice1: []const u8 = t1;
- expect(slice1.len == 3);
- expect(slice1[0] == 42);
- expect(slice1[1] == 56);
- expect(slice1[2] == 54);
-
+ try expect(slice1.len == 3);
+ try expect(slice1[0] == 42);
+ try expect(slice1[1] == 56);
+ try expect(slice1[2] == 54);
+
var x2: []const u8 = "hello";
const t2 = &.{ x2, ", ", "world!" };
// @compileLog(@TypeOf(t2));
var slice2: []const []const u8 = t2;
- expect(slice2.len == 3);
- expect(mem.eql(u8, slice2[0], "hello"));
- expect(mem.eql(u8, slice2[1], ", "));
- expect(mem.eql(u8, slice2[2], "world!"));
+ try expect(slice2.len == 3);
+ try expect(mem.eql(u8, slice2[0], "hello"));
+ try expect(mem.eql(u8, slice2[1], ", "));
+ try expect(mem.eql(u8, slice2[2], "world!"));
}
};
- // S.doTheTest();
- comptime S.doTheTest();
+ // try S.doTheTest();
+ comptime try S.doTheTest();
}
diff --git a/test/stage1/behavior/src.zig b/test/stage1/behavior/src.zig
index 27fa144e54..9dd1badaae 100644
--- a/test/stage1/behavior/src.zig
+++ b/test/stage1/behavior/src.zig
@@ -2,16 +2,16 @@ const std = @import("std");
const expect = std.testing.expect;
test "@src" {
- doTheTest();
+ try doTheTest();
}
-fn doTheTest() void {
+fn doTheTest() !void {
const src = @src();
- expect(src.line == 9);
- expect(src.column == 17);
- expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
- expect(std.mem.endsWith(u8, src.file, "src.zig"));
- expect(src.fn_name[src.fn_name.len] == 0);
- expect(src.file[src.file.len] == 0);
+ try expect(src.line == 9);
+ try expect(src.column == 17);
+ try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
+ try expect(std.mem.endsWith(u8, src.file, "src.zig"));
+ try expect(src.fn_name[src.fn_name.len] == 0);
+ try expect(src.file[src.file.len] == 0);
}
diff --git a/test/stage1/behavior/struct.zig b/test/stage1/behavior/struct.zig
index f893e5b4ca..85bc3b04bc 100644
--- a/test/stage1/behavior/struct.zig
+++ b/test/stage1/behavior/struct.zig
@@ -18,12 +18,12 @@ test "top level fields" {
.top_level_field = 1234,
};
instance.top_level_field += 1;
- expectEqual(@as(i32, 1235), instance.top_level_field);
+ try expectEqual(@as(i32, 1235), instance.top_level_field);
}
test "call struct static method" {
const result = StructWithNoFields.add(3, 4);
- expect(result == 7);
+ try expect(result == 7);
}
test "return empty struct instance" {
@@ -36,7 +36,7 @@ fn returnEmptyStructInstance() StructWithNoFields {
const should_be_11 = StructWithNoFields.add(5, 6);
test "invoke static method in global scope" {
- expect(should_be_11 == 11);
+ try expect(should_be_11 == 11);
}
test "void struct fields" {
@@ -45,8 +45,8 @@ test "void struct fields" {
.b = 1,
.c = void{},
};
- expect(foo.b == 1);
- expect(@sizeOf(VoidStructFieldsFoo) == 4);
+ try expect(foo.b == 1);
+ try expect(@sizeOf(VoidStructFieldsFoo) == 4);
}
const VoidStructFieldsFoo = struct {
a: void,
@@ -59,17 +59,17 @@ test "structs" {
@memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
foo.a += 1;
foo.b = foo.a == 1;
- testFoo(foo);
+ try testFoo(foo);
testMutation(&foo);
- expect(foo.c == 100);
+ try expect(foo.c == 100);
}
const StructFoo = struct {
a: i32,
b: bool,
c: f32,
};
-fn testFoo(foo: StructFoo) void {
- expect(foo.b);
+fn testFoo(foo: StructFoo) !void {
+ try expect(foo.b);
}
fn testMutation(foo: *StructFoo) void {
foo.c = 100;
@@ -94,7 +94,7 @@ test "struct point to self" {
root.next = &node;
- expect(node.next.next.next.val.x == 1);
+ try expect(node.next.next.next.val.x == 1);
}
test "struct byval assign" {
@@ -103,14 +103,14 @@ test "struct byval assign" {
foo1.a = 1234;
foo2.a = 0;
- expect(foo2.a == 0);
+ try expect(foo2.a == 0);
foo2 = foo1;
- expect(foo2.a == 1234);
+ try expect(foo2.a == 1234);
}
fn structInitializer() void {
const val = Val{ .x = 42 };
- expect(val.x == 42);
+ try expect(val.x == 42);
}
test "fn call of struct field" {
@@ -127,14 +127,14 @@ test "fn call of struct field" {
}
};
- expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13);
+ try expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13);
}
test "store member function in variable" {
const instance = MemberFnTestFoo{ .x = 1234 };
const memberFn = MemberFnTestFoo.member;
const result = memberFn(instance);
- expect(result == 1234);
+ try expect(result == 1234);
}
const MemberFnTestFoo = struct {
x: i32,
@@ -146,12 +146,12 @@ const MemberFnTestFoo = struct {
test "call member function directly" {
const instance = MemberFnTestFoo{ .x = 1234 };
const result = MemberFnTestFoo.member(instance);
- expect(result == 1234);
+ try expect(result == 1234);
}
test "member functions" {
const r = MemberFnRand{ .seed = 1234 };
- expect(r.getSeed() == 1234);
+ try expect(r.getSeed() == 1234);
}
const MemberFnRand = struct {
seed: u32,
@@ -162,7 +162,7 @@ const MemberFnRand = struct {
test "return struct byval from function" {
const bar = makeBar(1234, 5678);
- expect(bar.y == 5678);
+ try expect(bar.y == 5678);
}
const Bar = struct {
x: i32,
@@ -177,7 +177,7 @@ fn makeBar(x: i32, y: i32) Bar {
test "empty struct method call" {
const es = EmptyStruct{};
- expect(es.method() == 1234);
+ try expect(es.method() == 1234);
}
const EmptyStruct = struct {
fn method(es: *const EmptyStruct) i32 {
@@ -194,7 +194,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
}
test "pass slice of empty struct to fn" {
- expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
+ try expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
}
fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
return slice.len;
@@ -212,7 +212,7 @@ test "packed struct" {
};
foo.y += 1;
const four = foo.x + foo.y;
- expect(four == 4);
+ try expect(four == 4);
}
const BitField1 = packed struct {
@@ -229,17 +229,17 @@ const bit_field_1 = BitField1{
test "bit field access" {
var data = bit_field_1;
- expect(getA(&data) == 1);
- expect(getB(&data) == 2);
- expect(getC(&data) == 3);
- comptime expect(@sizeOf(BitField1) == 1);
+ try expect(getA(&data) == 1);
+ try expect(getB(&data) == 2);
+ try expect(getC(&data) == 3);
+ comptime try expect(@sizeOf(BitField1) == 1);
data.b += 1;
- expect(data.b == 3);
+ try expect(data.b == 3);
data.a += 1;
- expect(data.a == 2);
- expect(data.b == 3);
+ try expect(data.a == 2);
+ try expect(data.b == 3);
}
fn getA(data: *const BitField1) u3 {
@@ -266,11 +266,11 @@ const Foo96Bits = packed struct {
test "packed struct 24bits" {
comptime {
- expect(@sizeOf(Foo24Bits) == 4);
+ try expect(@sizeOf(Foo24Bits) == 4);
if (@sizeOf(usize) == 4) {
- expect(@sizeOf(Foo96Bits) == 12);
+ try expect(@sizeOf(Foo96Bits) == 12);
} else {
- expect(@sizeOf(Foo96Bits) == 16);
+ try expect(@sizeOf(Foo96Bits) == 16);
}
}
@@ -281,28 +281,28 @@ test "packed struct 24bits" {
.d = 0,
};
value.a += 1;
- expect(value.a == 1);
- expect(value.b == 0);
- expect(value.c == 0);
- expect(value.d == 0);
+ try expect(value.a == 1);
+ try expect(value.b == 0);
+ try expect(value.c == 0);
+ try expect(value.d == 0);
value.b += 1;
- expect(value.a == 1);
- expect(value.b == 1);
- expect(value.c == 0);
- expect(value.d == 0);
+ try expect(value.a == 1);
+ try expect(value.b == 1);
+ try expect(value.c == 0);
+ try expect(value.d == 0);
value.c += 1;
- expect(value.a == 1);
- expect(value.b == 1);
- expect(value.c == 1);
- expect(value.d == 0);
+ try expect(value.a == 1);
+ try expect(value.b == 1);
+ try expect(value.c == 1);
+ try expect(value.d == 0);
value.d += 1;
- expect(value.a == 1);
- expect(value.b == 1);
- expect(value.c == 1);
- expect(value.d == 1);
+ try expect(value.a == 1);
+ try expect(value.b == 1);
+ try expect(value.c == 1);
+ try expect(value.d == 1);
}
const Foo32Bits = packed struct {
@@ -319,43 +319,43 @@ const FooArray24Bits = packed struct {
// TODO revisit this test when doing https://github.com/ziglang/zig/issues/1512
test "packed array 24bits" {
comptime {
- expect(@sizeOf([9]Foo32Bits) == 9 * 4);
- expect(@sizeOf(FooArray24Bits) == 2 + 2 * 4 + 2);
+ try expect(@sizeOf([9]Foo32Bits) == 9 * 4);
+ try expect(@sizeOf(FooArray24Bits) == 2 + 2 * 4 + 2);
}
var bytes = [_]u8{0} ** (@sizeOf(FooArray24Bits) + 1);
bytes[bytes.len - 1] = 0xaa;
const ptr = &std.mem.bytesAsSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0];
- expect(ptr.a == 0);
- expect(ptr.b[0].field == 0);
- expect(ptr.b[1].field == 0);
- expect(ptr.c == 0);
+ try expect(ptr.a == 0);
+ try expect(ptr.b[0].field == 0);
+ try expect(ptr.b[1].field == 0);
+ try expect(ptr.c == 0);
ptr.a = maxInt(u16);
- expect(ptr.a == maxInt(u16));
- expect(ptr.b[0].field == 0);
- expect(ptr.b[1].field == 0);
- expect(ptr.c == 0);
+ try expect(ptr.a == maxInt(u16));
+ try expect(ptr.b[0].field == 0);
+ try expect(ptr.b[1].field == 0);
+ try expect(ptr.c == 0);
ptr.b[0].field = maxInt(u24);
- expect(ptr.a == maxInt(u16));
- expect(ptr.b[0].field == maxInt(u24));
- expect(ptr.b[1].field == 0);
- expect(ptr.c == 0);
+ try expect(ptr.a == maxInt(u16));
+ try expect(ptr.b[0].field == maxInt(u24));
+ try expect(ptr.b[1].field == 0);
+ try expect(ptr.c == 0);
ptr.b[1].field = maxInt(u24);
- expect(ptr.a == maxInt(u16));
- expect(ptr.b[0].field == maxInt(u24));
- expect(ptr.b[1].field == maxInt(u24));
- expect(ptr.c == 0);
+ try expect(ptr.a == maxInt(u16));
+ try expect(ptr.b[0].field == maxInt(u24));
+ try expect(ptr.b[1].field == maxInt(u24));
+ try expect(ptr.c == 0);
ptr.c = maxInt(u16);
- expect(ptr.a == maxInt(u16));
- expect(ptr.b[0].field == maxInt(u24));
- expect(ptr.b[1].field == maxInt(u24));
- expect(ptr.c == maxInt(u16));
+ try expect(ptr.a == maxInt(u16));
+ try expect(ptr.b[0].field == maxInt(u24));
+ try expect(ptr.b[1].field == maxInt(u24));
+ try expect(ptr.c == maxInt(u16));
- expect(bytes[bytes.len - 1] == 0xaa);
+ try expect(bytes[bytes.len - 1] == 0xaa);
}
const FooStructAligned = packed struct {
@@ -369,17 +369,17 @@ const FooArrayOfAligned = packed struct {
test "aligned array of packed struct" {
comptime {
- expect(@sizeOf(FooStructAligned) == 2);
- expect(@sizeOf(FooArrayOfAligned) == 2 * 2);
+ try expect(@sizeOf(FooStructAligned) == 2);
+ try expect(@sizeOf(FooArrayOfAligned) == 2 * 2);
}
var bytes = [_]u8{0xbb} ** @sizeOf(FooArrayOfAligned);
const ptr = &std.mem.bytesAsSlice(FooArrayOfAligned, bytes[0..])[0];
- expect(ptr.a[0].a == 0xbb);
- expect(ptr.a[0].b == 0xbb);
- expect(ptr.a[1].a == 0xbb);
- expect(ptr.a[1].b == 0xbb);
+ try expect(ptr.a[0].a == 0xbb);
+ try expect(ptr.a[0].b == 0xbb);
+ try expect(ptr.a[1].a == 0xbb);
+ try expect(ptr.a[1].b == 0xbb);
}
test "runtime struct initialization of bitfield" {
@@ -392,10 +392,10 @@ test "runtime struct initialization of bitfield" {
.y = @intCast(u4, x2),
};
- expect(s1.x == x1);
- expect(s1.y == x1);
- expect(s2.x == @intCast(u4, x2));
- expect(s2.y == @intCast(u4, x2));
+ try expect(s1.x == x1);
+ try expect(s1.y == x1);
+ try expect(s2.x == @intCast(u4, x2));
+ try expect(s2.y == @intCast(u4, x2));
}
var x1 = @as(u4, 1);
@@ -425,18 +425,18 @@ test "native bit field understands endianness" {
@memcpy(&bytes, @ptrCast([*]u8, &all), 8);
var bitfields = @ptrCast(*Bitfields, &bytes).*;
- expect(bitfields.f1 == 0x1111);
- expect(bitfields.f2 == 0x2222);
- expect(bitfields.f3 == 0x33);
- expect(bitfields.f4 == 0x44);
- expect(bitfields.f5 == 0x5);
- expect(bitfields.f6 == 0x6);
- expect(bitfields.f7 == 0x77);
+ try expect(bitfields.f1 == 0x1111);
+ try expect(bitfields.f2 == 0x2222);
+ try expect(bitfields.f3 == 0x33);
+ try expect(bitfields.f4 == 0x44);
+ try expect(bitfields.f5 == 0x5);
+ try expect(bitfields.f6 == 0x6);
+ try expect(bitfields.f7 == 0x77);
}
test "align 1 field before self referential align 8 field as slice return type" {
const result = alloc(Expr);
- expect(result.len == 0);
+ try expect(result.len == 0);
}
const Expr = union(enum) {
@@ -459,10 +459,10 @@ test "call method with mutable reference to struct with no fields" {
};
var s = S{};
- expect(S.doC(&s));
- expect(s.doC());
- expect(S.do(&s));
- expect(s.do());
+ try expect(S.doC(&s));
+ try expect(s.doC());
+ try expect(S.do(&s));
+ try expect(s.do());
}
test "implicit cast packed struct field to const ptr" {
@@ -478,7 +478,7 @@ test "implicit cast packed struct field to const ptr" {
var lup: LevelUpMove = undefined;
lup.level = 12;
const res = LevelUpMove.toInt(lup.level);
- expect(res == 12);
+ try expect(res == 12);
}
test "pointer to packed struct member in a stack variable" {
@@ -489,9 +489,9 @@ test "pointer to packed struct member in a stack variable" {
var s = S{ .a = 2, .b = 0 };
var b_ptr = &s.b;
- expect(s.b == 0);
+ try expect(s.b == 0);
b_ptr.* = 2;
- expect(s.b == 2);
+ try expect(s.b == 2);
}
test "non-byte-aligned array inside packed struct" {
@@ -500,20 +500,20 @@ test "non-byte-aligned array inside packed struct" {
b: [0x16]u8,
};
const S = struct {
- fn bar(slice: []const u8) void {
- expectEqualSlices(u8, slice, "abcdefghijklmnopqurstu");
+ fn bar(slice: []const u8) !void {
+ try expectEqualSlices(u8, slice, "abcdefghijklmnopqurstu");
}
- fn doTheTest() void {
+ fn doTheTest() !void {
var foo = Foo{
.a = true,
.b = "abcdefghijklmnopqurstu".*,
};
const value = foo.b;
- bar(&value);
+ try bar(&value);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "packed struct with u0 field access" {
@@ -521,7 +521,7 @@ test "packed struct with u0 field access" {
f0: u0,
};
var s = S{ .f0 = 0 };
- comptime expect(s.f0 == 0);
+ comptime try expect(s.f0 == 0);
}
const S0 = struct {
@@ -540,7 +540,7 @@ var g_foo: S0 = S0.init();
test "access to global struct fields" {
g_foo.bar.value = 42;
- expect(g_foo.bar.value == 42);
+ try expect(g_foo.bar.value == 42);
}
test "packed struct with fp fields" {
@@ -559,9 +559,9 @@ test "packed struct with fp fields" {
s.data[1] = 2.0;
s.data[2] = 3.0;
s.frob();
- expectEqual(@as(f32, 6.0), s.data[0]);
- expectEqual(@as(f32, 11.0), s.data[1]);
- expectEqual(@as(f32, 20.0), s.data[2]);
+ try expectEqual(@as(f32, 6.0), s.data[0]);
+ try expectEqual(@as(f32, 11.0), s.data[1]);
+ try expectEqual(@as(f32, 20.0), s.data[2]);
}
test "use within struct scope" {
@@ -572,7 +572,7 @@ test "use within struct scope" {
}
};
};
- expectEqual(@as(i32, 42), S.inner());
+ try expectEqual(@as(i32, 42), S.inner());
}
test "default struct initialization fields" {
@@ -590,14 +590,14 @@ test "default struct initialization fields" {
const y = S{
.b = five,
};
- expectEqual(1239, x.a + x.b);
+ try expectEqual(1239, x.a + x.b);
}
test "fn with C calling convention returns struct by value" {
const S = struct {
- fn entry() void {
+ fn entry() !void {
var x = makeBar(10);
- expectEqual(@as(i32, 10), x.handle);
+ try expectEqual(@as(i32, 10), x.handle);
}
const ExternBar = extern struct {
@@ -610,8 +610,8 @@ test "fn with C calling convention returns struct by value" {
};
}
};
- S.entry();
- comptime S.entry();
+ try S.entry();
+ comptime try S.entry();
}
test "for loop over pointers to struct, getting field from struct pointer" {
@@ -632,7 +632,7 @@ test "for loop over pointers to struct, getting field from struct pointer" {
}
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var objects: ArrayList = undefined;
for (objects.toSlice()) |obj| {
@@ -641,10 +641,10 @@ test "for loop over pointers to struct, getting field from struct pointer" {
}
}
- expect(ok);
+ try expect(ok);
}
};
- S.doTheTest();
+ try S.doTheTest();
}
test "zero-bit field in packed struct" {
@@ -657,20 +657,20 @@ test "zero-bit field in packed struct" {
test "struct field init with catch" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var x: anyerror!isize = 1;
var req = Foo{
.field = x catch undefined,
};
- expect(req.field == 1);
+ try expect(req.field == 1);
}
pub const Foo = extern struct {
field: isize,
};
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "packed struct with non-ABI-aligned field" {
@@ -681,8 +681,8 @@ test "packed struct with non-ABI-aligned field" {
var s: S = undefined;
s.x = 1;
s.y = 42;
- expect(s.x == 1);
- expect(s.y == 42);
+ try expect(s.x == 1);
+ try expect(s.y == 42);
}
test "non-packed struct with u128 entry in union" {
@@ -698,10 +698,10 @@ test "non-packed struct with u128 entry in union" {
var sx: S = undefined;
var s = &sx;
- std.testing.expect(@ptrToInt(&s.f2) - @ptrToInt(&s.f1) == @byteOffsetOf(S, "f2"));
+ try std.testing.expect(@ptrToInt(&s.f2) - @ptrToInt(&s.f1) == @byteOffsetOf(S, "f2"));
var v2 = U{ .Num = 123 };
s.f2 = v2;
- std.testing.expect(s.f2.Num == 123);
+ try std.testing.expect(s.f2.Num == 123);
}
test "packed struct field passed to generic function" {
@@ -721,7 +721,7 @@ test "packed struct field passed to generic function" {
var p: S.P = undefined;
p.b = 29;
var loaded = S.genericReadPackedField(&p.b);
- expect(loaded == 29);
+ try expect(loaded == 29);
}
test "anonymous struct literal syntax" {
@@ -731,63 +731,63 @@ test "anonymous struct literal syntax" {
y: i32,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var p: Point = .{
.x = 1,
.y = 2,
};
- expect(p.x == 1);
- expect(p.y == 2);
+ try expect(p.x == 1);
+ try expect(p.y == 2);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "fully anonymous struct" {
const S = struct {
- fn doTheTest() void {
- dump(.{
+ fn doTheTest() !void {
+ try dump(.{
.int = @as(u32, 1234),
.float = @as(f64, 12.34),
.b = true,
.s = "hi",
});
}
- fn dump(args: anytype) void {
- expect(args.int == 1234);
- expect(args.float == 12.34);
- expect(args.b);
- expect(args.s[0] == 'h');
- expect(args.s[1] == 'i');
+ fn dump(args: anytype) !void {
+ try expect(args.int == 1234);
+ try expect(args.float == 12.34);
+ try expect(args.b);
+ try expect(args.s[0] == 'h');
+ try expect(args.s[1] == 'i');
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "fully anonymous list literal" {
const S = struct {
- fn doTheTest() void {
- dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" });
+ fn doTheTest() !void {
+ try dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" });
}
- fn dump(args: anytype) void {
- expect(args.@"0" == 1234);
- expect(args.@"1" == 12.34);
- expect(args.@"2");
- expect(args.@"3"[0] == 'h');
- expect(args.@"3"[1] == 'i');
+ fn dump(args: anytype) !void {
+ try expect(args.@"0" == 1234);
+ try expect(args.@"1" == 12.34);
+ try expect(args.@"2");
+ try expect(args.@"3"[0] == 'h');
+ try expect(args.@"3"[1] == 'i');
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "anonymous struct literal assigned to variable" {
var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) };
- expect(vec.@"0" == 22);
- expect(vec.@"1" == 55);
- expect(vec.@"2" == 99);
+ try expect(vec.@"0" == 22);
+ try expect(vec.@"1" == 55);
+ try expect(vec.@"2" == 99);
}
test "struct with var field" {
@@ -799,8 +799,8 @@ test "struct with var field" {
.x = 1,
.y = 2,
};
- expect(pt.x == 1);
- expect(pt.y == 2);
+ try expect(pt.x == 1);
+ try expect(pt.y == 2);
}
test "comptime struct field" {
@@ -810,21 +810,21 @@ test "comptime struct field" {
};
var foo: T = undefined;
- comptime expect(foo.b == 1234);
+ comptime try expect(foo.b == 1234);
}
test "anon struct literal field value initialized with fn call" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var x = .{foo()};
- expectEqualSlices(u8, x[0], "hi");
+ try expectEqualSlices(u8, x[0], "hi");
}
fn foo() []const u8 {
return "hi";
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "self-referencing struct via array member" {
@@ -833,7 +833,7 @@ test "self-referencing struct via array member" {
};
var x: T = undefined;
x = T{ .children = .{&x} };
- expect(x.children[0] == &x);
+ try expect(x.children[0] == &x);
}
test "struct with union field" {
@@ -848,8 +848,8 @@ test "struct with union field" {
var True = Value{
.kind = .{ .Bool = true },
};
- expectEqual(@as(u32, 2), True.ref);
- expectEqual(true, True.kind.Bool);
+ try expectEqual(@as(u32, 2), True.ref);
+ try expectEqual(true, True.kind.Bool);
}
test "type coercion of anon struct literal to struct" {
@@ -865,24 +865,24 @@ test "type coercion of anon struct literal to struct" {
field: i32 = 1234,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var y: u32 = 42;
const t0 = .{ .A = 123, .B = "foo", .C = {} };
const t1 = .{ .A = y, .B = "foo", .C = {} };
const y0: S2 = t0;
var y1: S2 = t1;
- expect(y0.A == 123);
- expect(std.mem.eql(u8, y0.B, "foo"));
- expect(y0.C == {});
- expect(y0.D.field == 1234);
- expect(y1.A == y);
- expect(std.mem.eql(u8, y1.B, "foo"));
- expect(y1.C == {});
- expect(y1.D.field == 1234);
+ try expect(y0.A == 123);
+ try expect(std.mem.eql(u8, y0.B, "foo"));
+ try expect(y0.C == {});
+ try expect(y0.D.field == 1234);
+ try expect(y1.A == y);
+ try expect(std.mem.eql(u8, y1.B, "foo"));
+ try expect(y1.C == {});
+ try expect(y1.D.field == 1234);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "type coercion of pointer to anon struct literal to pointer to struct" {
@@ -898,24 +898,24 @@ test "type coercion of pointer to anon struct literal to pointer to struct" {
field: i32 = 1234,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var y: u32 = 42;
const t0 = &.{ .A = 123, .B = "foo", .C = {} };
const t1 = &.{ .A = y, .B = "foo", .C = {} };
const y0: *const S2 = t0;
var y1: *const S2 = t1;
- expect(y0.A == 123);
- expect(std.mem.eql(u8, y0.B, "foo"));
- expect(y0.C == {});
- expect(y0.D.field == 1234);
- expect(y1.A == y);
- expect(std.mem.eql(u8, y1.B, "foo"));
- expect(y1.C == {});
- expect(y1.D.field == 1234);
+ try expect(y0.A == 123);
+ try expect(std.mem.eql(u8, y0.B, "foo"));
+ try expect(y0.C == {});
+ try expect(y0.D.field == 1234);
+ try expect(y1.A == y);
+ try expect(std.mem.eql(u8, y1.B, "foo"));
+ try expect(y1.C == {});
+ try expect(y1.D.field == 1234);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "packed struct with undefined initializers" {
@@ -929,16 +929,17 @@ test "packed struct with undefined initializers" {
_c: u3 = undefined,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var p: P = undefined;
p = P{ .a = 2, .b = 4, .c = 6 };
// Make sure the compiler doesn't touch the unprefixed fields.
- expectEqual(@as(u3, 2), p.a);
- expectEqual(@as(u3, 4), p.b);
- expectEqual(@as(u3, 6), p.c);
+ // Use expect since i386-linux doesn't like expectEqual
+ try expect(p.a == 2);
+ try expect(p.b == 4);
+ try expect(p.c == 6);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
diff --git a/test/stage1/behavior/struct_contains_null_ptr_itself.zig b/test/stage1/behavior/struct_contains_null_ptr_itself.zig
index 991d742cec..28aa1d57aa 100644
--- a/test/stage1/behavior/struct_contains_null_ptr_itself.zig
+++ b/test/stage1/behavior/struct_contains_null_ptr_itself.zig
@@ -3,7 +3,7 @@ const expect = std.testing.expect;
test "struct contains null pointer which contains original struct" {
var x: ?*NodeLineComment = null;
- expect(x == null);
+ try expect(x == null);
}
pub const Node = struct {
diff --git a/test/stage1/behavior/struct_contains_slice_of_itself.zig b/test/stage1/behavior/struct_contains_slice_of_itself.zig
index 14bf0320a2..11b838a758 100644
--- a/test/stage1/behavior/struct_contains_slice_of_itself.zig
+++ b/test/stage1/behavior/struct_contains_slice_of_itself.zig
@@ -39,12 +39,12 @@ test "struct contains slice of itself" {
.payload = 1234,
.children = nodes[0..],
};
- expect(root.payload == 1234);
- expect(root.children[0].payload == 1);
- expect(root.children[1].payload == 2);
- expect(root.children[2].payload == 3);
- expect(root.children[2].children[0].payload == 31);
- expect(root.children[2].children[1].payload == 32);
+ try expect(root.payload == 1234);
+ try expect(root.children[0].payload == 1);
+ try expect(root.children[1].payload == 2);
+ try expect(root.children[2].payload == 3);
+ try expect(root.children[2].children[0].payload == 31);
+ try expect(root.children[2].children[1].payload == 32);
}
test "struct contains aligned slice of itself" {
@@ -76,10 +76,10 @@ test "struct contains aligned slice of itself" {
.payload = 1234,
.children = nodes[0..],
};
- expect(root.payload == 1234);
- expect(root.children[0].payload == 1);
- expect(root.children[1].payload == 2);
- expect(root.children[2].payload == 3);
- expect(root.children[2].children[0].payload == 31);
- expect(root.children[2].children[1].payload == 32);
+ try expect(root.payload == 1234);
+ try expect(root.children[0].payload == 1);
+ try expect(root.children[1].payload == 2);
+ try expect(root.children[2].payload == 3);
+ try expect(root.children[2].children[0].payload == 31);
+ try expect(root.children[2].children[1].payload == 32);
}
diff --git a/test/stage1/behavior/switch.zig b/test/stage1/behavior/switch.zig
index 20ca0d3146..9d05e3edea 100644
--- a/test/stage1/behavior/switch.zig
+++ b/test/stage1/behavior/switch.zig
@@ -4,23 +4,23 @@ const expectError = std.testing.expectError;
const expectEqual = std.testing.expectEqual;
test "switch with numbers" {
- testSwitchWithNumbers(13);
+ try testSwitchWithNumbers(13);
}
-fn testSwitchWithNumbers(x: u32) void {
+fn testSwitchWithNumbers(x: u32) !void {
const result = switch (x) {
1, 2, 3, 4...8 => false,
13 => true,
else => false,
};
- expect(result);
+ try expect(result);
}
test "switch with all ranges" {
- expect(testSwitchWithAllRanges(50, 3) == 1);
- expect(testSwitchWithAllRanges(101, 0) == 2);
- expect(testSwitchWithAllRanges(300, 5) == 3);
- expect(testSwitchWithAllRanges(301, 6) == 6);
+ try expect(testSwitchWithAllRanges(50, 3) == 1);
+ try expect(testSwitchWithAllRanges(101, 0) == 2);
+ try expect(testSwitchWithAllRanges(300, 5) == 3);
+ try expect(testSwitchWithAllRanges(301, 6) == 6);
}
fn testSwitchWithAllRanges(x: u32, y: u32) u32 {
@@ -43,7 +43,7 @@ test "implicit comptime switch" {
};
comptime {
- expect(result + 1 == 14);
+ try expect(result + 1 == 14);
}
}
@@ -65,16 +65,16 @@ fn nonConstSwitchOnEnum(fruit: Fruit) void {
}
test "switch statement" {
- nonConstSwitch(SwitchStatmentFoo.C);
+ try nonConstSwitch(SwitchStatmentFoo.C);
}
-fn nonConstSwitch(foo: SwitchStatmentFoo) void {
+fn nonConstSwitch(foo: SwitchStatmentFoo) !void {
const val = switch (foo) {
SwitchStatmentFoo.A => @as(i32, 1),
SwitchStatmentFoo.B => 2,
SwitchStatmentFoo.C => 3,
SwitchStatmentFoo.D => 4,
};
- expect(val == 3);
+ try expect(val == 3);
}
const SwitchStatmentFoo = enum {
A,
@@ -84,22 +84,22 @@ const SwitchStatmentFoo = enum {
};
test "switch prong with variable" {
- switchProngWithVarFn(SwitchProngWithVarEnum{ .One = 13 });
- switchProngWithVarFn(SwitchProngWithVarEnum{ .Two = 13.0 });
- switchProngWithVarFn(SwitchProngWithVarEnum{ .Meh = {} });
+ try switchProngWithVarFn(SwitchProngWithVarEnum{ .One = 13 });
+ try switchProngWithVarFn(SwitchProngWithVarEnum{ .Two = 13.0 });
+ try switchProngWithVarFn(SwitchProngWithVarEnum{ .Meh = {} });
}
const SwitchProngWithVarEnum = union(enum) {
One: i32,
Two: f32,
Meh: void,
};
-fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {
+fn switchProngWithVarFn(a: SwitchProngWithVarEnum) !void {
switch (a) {
SwitchProngWithVarEnum.One => |x| {
- expect(x == 13);
+ try expect(x == 13);
},
SwitchProngWithVarEnum.Two => |x| {
- expect(x == 13.0);
+ try expect(x == 13.0);
},
SwitchProngWithVarEnum.Meh => |x| {
const v: void = x;
@@ -108,18 +108,18 @@ fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {
}
test "switch on enum using pointer capture" {
- testSwitchEnumPtrCapture();
- comptime testSwitchEnumPtrCapture();
+ try testSwitchEnumPtrCapture();
+ comptime try testSwitchEnumPtrCapture();
}
-fn testSwitchEnumPtrCapture() void {
+fn testSwitchEnumPtrCapture() !void {
var value = SwitchProngWithVarEnum{ .One = 1234 };
switch (value) {
SwitchProngWithVarEnum.One => |*x| x.* += 1,
else => unreachable,
}
switch (value) {
- SwitchProngWithVarEnum.One => |x| expect(x == 1235),
+ SwitchProngWithVarEnum.One => |x| try expect(x == 1235),
else => unreachable,
}
}
@@ -130,7 +130,7 @@ test "switch with multiple expressions" {
4, 5, 6 => 2,
else => @as(i32, 3),
};
- expect(x == 2);
+ try expect(x == 2);
}
fn returnsFive() i32 {
return 5;
@@ -152,12 +152,12 @@ fn returnsFalse() bool {
}
}
test "switch on const enum with var" {
- expect(!returnsFalse());
+ try expect(!returnsFalse());
}
test "switch on type" {
- expect(trueIfBoolFalseOtherwise(bool));
- expect(!trueIfBoolFalseOtherwise(i32));
+ try expect(trueIfBoolFalseOtherwise(bool));
+ try expect(!trueIfBoolFalseOtherwise(i32));
}
fn trueIfBoolFalseOtherwise(comptime T: type) bool {
@@ -168,21 +168,21 @@ fn trueIfBoolFalseOtherwise(comptime T: type) bool {
}
test "switch handles all cases of number" {
- testSwitchHandleAllCases();
- comptime testSwitchHandleAllCases();
+ try testSwitchHandleAllCases();
+ comptime try testSwitchHandleAllCases();
}
-fn testSwitchHandleAllCases() void {
- expect(testSwitchHandleAllCasesExhaustive(0) == 3);
- expect(testSwitchHandleAllCasesExhaustive(1) == 2);
- expect(testSwitchHandleAllCasesExhaustive(2) == 1);
- expect(testSwitchHandleAllCasesExhaustive(3) == 0);
+fn testSwitchHandleAllCases() !void {
+ try expect(testSwitchHandleAllCasesExhaustive(0) == 3);
+ try expect(testSwitchHandleAllCasesExhaustive(1) == 2);
+ try expect(testSwitchHandleAllCasesExhaustive(2) == 1);
+ try expect(testSwitchHandleAllCasesExhaustive(3) == 0);
- expect(testSwitchHandleAllCasesRange(100) == 0);
- expect(testSwitchHandleAllCasesRange(200) == 1);
- expect(testSwitchHandleAllCasesRange(201) == 2);
- expect(testSwitchHandleAllCasesRange(202) == 4);
- expect(testSwitchHandleAllCasesRange(230) == 3);
+ try expect(testSwitchHandleAllCasesRange(100) == 0);
+ try expect(testSwitchHandleAllCasesRange(200) == 1);
+ try expect(testSwitchHandleAllCasesRange(201) == 2);
+ try expect(testSwitchHandleAllCasesRange(202) == 4);
+ try expect(testSwitchHandleAllCasesRange(230) == 3);
}
fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
@@ -205,13 +205,13 @@ fn testSwitchHandleAllCasesRange(x: u8) u8 {
}
test "switch all prongs unreachable" {
- testAllProngsUnreachable();
- comptime testAllProngsUnreachable();
+ try testAllProngsUnreachable();
+ comptime try testAllProngsUnreachable();
}
-fn testAllProngsUnreachable() void {
- expect(switchWithUnreachable(1) == 2);
- expect(switchWithUnreachable(2) == 10);
+fn testAllProngsUnreachable() !void {
+ try expect(switchWithUnreachable(1) == 2);
+ try expect(switchWithUnreachable(2) == 10);
}
fn switchWithUnreachable(x: i32) i32 {
@@ -233,23 +233,23 @@ test "capture value of switch with all unreachable prongs" {
const x = return_a_number() catch |err| switch (err) {
else => unreachable,
};
- expect(x == 1);
+ try expect(x == 1);
}
test "switching on booleans" {
- testSwitchOnBools();
- comptime testSwitchOnBools();
+ try testSwitchOnBools();
+ comptime try testSwitchOnBools();
}
-fn testSwitchOnBools() void {
- expect(testSwitchOnBoolsTrueAndFalse(true) == false);
- expect(testSwitchOnBoolsTrueAndFalse(false) == true);
+fn testSwitchOnBools() !void {
+ try expect(testSwitchOnBoolsTrueAndFalse(true) == false);
+ try expect(testSwitchOnBoolsTrueAndFalse(false) == true);
- expect(testSwitchOnBoolsTrueWithElse(true) == false);
- expect(testSwitchOnBoolsTrueWithElse(false) == true);
+ try expect(testSwitchOnBoolsTrueWithElse(true) == false);
+ try expect(testSwitchOnBoolsTrueWithElse(false) == true);
- expect(testSwitchOnBoolsFalseWithElse(true) == false);
- expect(testSwitchOnBoolsFalseWithElse(false) == true);
+ try expect(testSwitchOnBoolsFalseWithElse(true) == false);
+ try expect(testSwitchOnBoolsFalseWithElse(false) == true);
}
fn testSwitchOnBoolsTrueAndFalse(x: bool) bool {
@@ -276,14 +276,14 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool {
test "u0" {
var val: u0 = 0;
switch (val) {
- 0 => expect(val == 0),
+ 0 => try expect(val == 0),
}
}
test "undefined.u0" {
var val: u0 = undefined;
switch (val) {
- 0 => expect(val == 0),
+ 0 => try expect(val == 0),
}
}
@@ -295,15 +295,15 @@ test "anon enum literal used in switch on union enum" {
var foo = Foo{ .a = 1234 };
switch (foo) {
.a => |x| {
- expect(x == 1234);
+ try expect(x == 1234);
},
}
}
test "else prong of switch on error set excludes other cases" {
const S = struct {
- fn doTheTest() void {
- expectError(error.C, bar());
+ fn doTheTest() !void {
+ try expectError(error.C, bar());
}
const E = error{
A,
@@ -326,14 +326,14 @@ test "else prong of switch on error set excludes other cases" {
};
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "switch prongs with error set cases make a new error set type for capture value" {
const S = struct {
- fn doTheTest() void {
- expectError(error.B, bar());
+ fn doTheTest() !void {
+ try expectError(error.B, bar());
}
const E = E1 || E2;
@@ -358,14 +358,14 @@ test "switch prongs with error set cases make a new error set type for capture v
};
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "return result loc and then switch with range implicit casted to error union" {
const S = struct {
- fn doTheTest() void {
- expect((func(0xb) catch unreachable) == 0xb);
+ fn doTheTest() !void {
+ try expect((func(0xb) catch unreachable) == 0xb);
}
fn func(d: u8) anyerror!u8 {
return switch (d) {
@@ -374,13 +374,13 @@ test "return result loc and then switch with range implicit casted to error unio
};
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "switch with null and T peer types and inferred result location type" {
const S = struct {
- fn doTheTest(c: u8) void {
+ fn doTheTest(c: u8) !void {
if (switch (c) {
0 => true,
else => null,
@@ -389,8 +389,8 @@ test "switch with null and T peer types and inferred result location type" {
}
}
};
- S.doTheTest(1);
- comptime S.doTheTest(1);
+ try S.doTheTest(1);
+ comptime try S.doTheTest(1);
}
test "switch prongs with cases with identical payload types" {
@@ -400,31 +400,31 @@ test "switch prongs with cases with identical payload types" {
C: usize,
};
const S = struct {
- fn doTheTest() void {
- doTheSwitch1(Union{ .A = 8 });
- doTheSwitch2(Union{ .B = -8 });
+ fn doTheTest() !void {
+ try doTheSwitch1(Union{ .A = 8 });
+ try doTheSwitch2(Union{ .B = -8 });
}
- fn doTheSwitch1(u: Union) void {
+ fn doTheSwitch1(u: Union) !void {
switch (u) {
.A, .C => |e| {
- expect(@TypeOf(e) == usize);
- expect(e == 8);
+ try expect(@TypeOf(e) == usize);
+ try expect(e == 8);
},
.B => |e| @panic("fail"),
}
}
- fn doTheSwitch2(u: Union) void {
+ fn doTheSwitch2(u: Union) !void {
switch (u) {
.A, .C => |e| @panic("fail"),
.B => |e| {
- expect(@TypeOf(e) == isize);
- expect(e == -8);
+ try expect(@TypeOf(e) == isize);
+ try expect(e == -8);
},
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "switch with disjoint range" {
@@ -438,19 +438,19 @@ test "switch with disjoint range" {
test "switch variable for range and multiple prongs" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var u: u8 = 16;
- doTheSwitch(u);
- comptime doTheSwitch(u);
+ try doTheSwitch(u);
+ comptime try doTheSwitch(u);
var v: u8 = 42;
- doTheSwitch(v);
- comptime doTheSwitch(v);
+ try doTheSwitch(v);
+ comptime try doTheSwitch(v);
}
- fn doTheSwitch(q: u8) void {
+ fn doTheSwitch(q: u8) !void {
switch (q) {
- 0...40 => |x| expect(x == 16),
- 41, 42, 43 => |x| expect(x == 42),
- else => expect(false),
+ 0...40 => |x| try expect(x == 16),
+ 41, 42, 43 => |x| try expect(x == 42),
+ else => try expect(false),
}
}
};
@@ -493,31 +493,31 @@ test "switch on pointer type" {
}
};
- expect(1 == S.doTheTest(S.P1));
- expect(2 == S.doTheTest(S.P2));
- expect(3 == S.doTheTest(S.P3));
- comptime expect(1 == S.doTheTest(S.P1));
- comptime expect(2 == S.doTheTest(S.P2));
- comptime expect(3 == S.doTheTest(S.P3));
+ try expect(1 == S.doTheTest(S.P1));
+ try expect(2 == S.doTheTest(S.P2));
+ try expect(3 == S.doTheTest(S.P3));
+ comptime try expect(1 == S.doTheTest(S.P1));
+ comptime try expect(2 == S.doTheTest(S.P2));
+ comptime try expect(3 == S.doTheTest(S.P3));
}
test "switch on error set with single else" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var some: error{Foo} = error.Foo;
- expect(switch (some) {
+ try expect(switch (some) {
else => |a| true,
});
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "while copies its payload" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var tmp: union(enum) {
A: u8,
B: u32,
@@ -526,12 +526,12 @@ test "while copies its payload" {
.A => |value| {
// Modify the original union
tmp = .{ .B = 0x10101010 };
- expectEqual(@as(u8, 42), value);
+ try expectEqual(@as(u8, 42), value);
},
else => unreachable,
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
diff --git a/test/stage1/behavior/switch_prong_err_enum.zig b/test/stage1/behavior/switch_prong_err_enum.zig
index 3593eabb5a..b68f21df6f 100644
--- a/test/stage1/behavior/switch_prong_err_enum.zig
+++ b/test/stage1/behavior/switch_prong_err_enum.zig
@@ -22,9 +22,9 @@ fn doThing(form_id: u64) anyerror!FormValue {
test "switch prong returns error enum" {
switch (doThing(17) catch unreachable) {
FormValue.Address => |payload| {
- expect(payload == 1);
+ try expect(payload == 1);
},
else => unreachable,
}
- expect(read_count == 1);
+ try expect(read_count == 1);
}
diff --git a/test/stage1/behavior/switch_prong_implicit_cast.zig b/test/stage1/behavior/switch_prong_implicit_cast.zig
index da965915ca..bc08fea93f 100644
--- a/test/stage1/behavior/switch_prong_implicit_cast.zig
+++ b/test/stage1/behavior/switch_prong_implicit_cast.zig
@@ -18,5 +18,5 @@ test "switch prong implicit cast" {
FormValue.One => false,
FormValue.Two => |x| x,
};
- expect(result);
+ try expect(result);
}
diff --git a/test/stage1/behavior/this.zig b/test/stage1/behavior/this.zig
index 927c0808ea..086fe2814a 100644
--- a/test/stage1/behavior/this.zig
+++ b/test/stage1/behavior/this.zig
@@ -20,7 +20,7 @@ fn add(x: i32, y: i32) i32 {
}
test "this refer to module call private fn" {
- expect(module.add(1, 2) == 3);
+ try expect(module.add(1, 2) == 3);
}
test "this refer to container" {
@@ -29,6 +29,6 @@ test "this refer to container" {
.y = 34,
};
pt.addOne();
- expect(pt.x == 13);
- expect(pt.y == 35);
+ try expect(pt.x == 13);
+ try expect(pt.y == 35);
}
diff --git a/test/stage1/behavior/translate_c_macros.zig b/test/stage1/behavior/translate_c_macros.zig
index 640f1c8c86..21b289af25 100644
--- a/test/stage1/behavior/translate_c_macros.zig
+++ b/test/stage1/behavior/translate_c_macros.zig
@@ -4,7 +4,7 @@ const expectEqual = @import("std").testing.expectEqual;
const h = @cImport(@cInclude("stage1/behavior/translate_c_macros.h"));
test "initializer list expression" {
- expectEqual(h.Color{
+ try expectEqual(h.Color{
.r = 200,
.g = 200,
.b = 200,
@@ -13,10 +13,10 @@ test "initializer list expression" {
}
test "sizeof in macros" {
- expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF(u32));
- expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF2(u32));
+ try expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF(u32));
+ try expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF2(u32));
}
test "reference to a struct type" {
- expectEqual(@sizeOf(h.struct_Foo), h.SIZE_OF_FOO);
+ try expectEqual(@sizeOf(h.struct_Foo), h.SIZE_OF_FOO);
}
diff --git a/test/stage1/behavior/truncate.zig b/test/stage1/behavior/truncate.zig
index 099b6c3359..0d67c5d6dd 100644
--- a/test/stage1/behavior/truncate.zig
+++ b/test/stage1/behavior/truncate.zig
@@ -4,33 +4,33 @@ const expect = std.testing.expect;
test "truncate u0 to larger integer allowed and has comptime known result" {
var x: u0 = 0;
const y = @truncate(u8, x);
- comptime expect(y == 0);
+ comptime try expect(y == 0);
}
test "truncate.u0.literal" {
var z = @truncate(u0, 0);
- expect(z == 0);
+ try expect(z == 0);
}
test "truncate.u0.const" {
const c0: usize = 0;
var z = @truncate(u0, c0);
- expect(z == 0);
+ try expect(z == 0);
}
test "truncate.u0.var" {
var d: u8 = 2;
var z = @truncate(u0, d);
- expect(z == 0);
+ try expect(z == 0);
}
test "truncate sign mismatch but comptime known so it works anyway" {
const x: u32 = 10;
var result = @truncate(i8, x);
- expect(result == 10);
+ try expect(result == 10);
}
test "truncate on comptime integer" {
var x = @truncate(u16, 9999);
- expect(x == 9999);
+ try expect(x == 9999);
}
diff --git a/test/stage1/behavior/try.zig b/test/stage1/behavior/try.zig
index 9e93183c3b..029d946588 100644
--- a/test/stage1/behavior/try.zig
+++ b/test/stage1/behavior/try.zig
@@ -1,17 +1,17 @@
const expect = @import("std").testing.expect;
test "try on error union" {
- tryOnErrorUnionImpl();
- comptime tryOnErrorUnionImpl();
+ try tryOnErrorUnionImpl();
+ comptime try tryOnErrorUnionImpl();
}
-fn tryOnErrorUnionImpl() void {
+fn tryOnErrorUnionImpl() !void {
const x = if (returnsTen()) |val| val + 1 else |err| switch (err) {
error.ItBroke, error.NoMem => 1,
error.CrappedOut => @as(i32, 2),
else => unreachable,
};
- expect(x == 11);
+ try expect(x == 11);
}
fn returnsTen() anyerror!i32 {
@@ -20,10 +20,10 @@ fn returnsTen() anyerror!i32 {
test "try without vars" {
const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2);
- expect(result1 == 2);
+ try expect(result1 == 2);
const result2 = if (failIfTrue(false)) 1 else |_| @as(i32, 2);
- expect(result2 == 1);
+ try expect(result2 == 1);
}
fn failIfTrue(ok: bool) anyerror!void {
@@ -38,6 +38,6 @@ test "try then not executed with assignment" {
if (failIfTrue(true)) {
unreachable;
} else |err| {
- expect(err == error.ItBroke);
+ try expect(err == error.ItBroke);
}
}
diff --git a/test/stage1/behavior/tuple.zig b/test/stage1/behavior/tuple.zig
index 4eb5b73abb..0a32c664dd 100644
--- a/test/stage1/behavior/tuple.zig
+++ b/test/stage1/behavior/tuple.zig
@@ -5,93 +5,93 @@ const expectEqual = testing.expectEqual;
test "tuple concatenation" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var a: i32 = 1;
var b: i32 = 2;
var x = .{a};
var y = .{b};
var c = x ++ y;
- expectEqual(@as(i32, 1), c[0]);
- expectEqual(@as(i32, 2), c[1]);
+ try expectEqual(@as(i32, 1), c[0]);
+ try expectEqual(@as(i32, 2), c[1]);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "tuple multiplication" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
{
const t = .{} ** 4;
- expectEqual(0, @typeInfo(@TypeOf(t)).Struct.fields.len);
+ try expectEqual(0, @typeInfo(@TypeOf(t)).Struct.fields.len);
}
{
const t = .{'a'} ** 4;
- expectEqual(4, @typeInfo(@TypeOf(t)).Struct.fields.len);
- inline for (t) |x| expectEqual('a', x);
+ try expectEqual(4, @typeInfo(@TypeOf(t)).Struct.fields.len);
+ inline for (t) |x| try expectEqual('a', x);
}
{
const t = .{ 1, 2, 3 } ** 4;
- expectEqual(12, @typeInfo(@TypeOf(t)).Struct.fields.len);
- inline for (t) |x, i| expectEqual(1 + i % 3, x);
+ try expectEqual(12, @typeInfo(@TypeOf(t)).Struct.fields.len);
+ inline for (t) |x, i| try expectEqual(1 + i % 3, x);
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
const T = struct {
- fn consume_tuple(tuple: anytype, len: usize) void {
- expect(tuple.len == len);
+ fn consume_tuple(tuple: anytype, len: usize) !void {
+ try expect(tuple.len == len);
}
- fn doTheTest() void {
+ fn doTheTest() !void {
const t1 = .{};
var rt_var: u8 = 42;
const t2 = .{rt_var} ++ .{};
- expect(t2.len == 1);
- expect(t2.@"0" == rt_var);
- expect(t2.@"0" == 42);
- expect(&t2.@"0" != &rt_var);
+ try expect(t2.len == 1);
+ try expect(t2.@"0" == rt_var);
+ try expect(t2.@"0" == 42);
+ try expect(&t2.@"0" != &rt_var);
- consume_tuple(t1 ++ t1, 0);
- consume_tuple(.{} ++ .{}, 0);
- consume_tuple(.{0} ++ .{}, 1);
- consume_tuple(.{0} ++ .{1}, 2);
- consume_tuple(.{ 0, 1, 2 } ++ .{ u8, 1, noreturn }, 6);
- consume_tuple(t2 ++ t1, 1);
- consume_tuple(t1 ++ t2, 1);
- consume_tuple(t2 ++ t2, 2);
- consume_tuple(.{rt_var} ++ .{}, 1);
- consume_tuple(.{rt_var} ++ t1, 1);
- consume_tuple(.{} ++ .{rt_var}, 1);
- consume_tuple(t2 ++ .{void}, 2);
- consume_tuple(t2 ++ .{0}, 2);
- consume_tuple(.{0} ++ t2, 2);
- consume_tuple(.{void} ++ t2, 2);
- consume_tuple(.{u8} ++ .{rt_var} ++ .{true}, 3);
+ try consume_tuple(t1 ++ t1, 0);
+ try consume_tuple(.{} ++ .{}, 0);
+ try consume_tuple(.{0} ++ .{}, 1);
+ try consume_tuple(.{0} ++ .{1}, 2);
+ try consume_tuple(.{ 0, 1, 2 } ++ .{ u8, 1, noreturn }, 6);
+ try consume_tuple(t2 ++ t1, 1);
+ try consume_tuple(t1 ++ t2, 1);
+ try consume_tuple(t2 ++ t2, 2);
+ try consume_tuple(.{rt_var} ++ .{}, 1);
+ try consume_tuple(.{rt_var} ++ t1, 1);
+ try consume_tuple(.{} ++ .{rt_var}, 1);
+ try consume_tuple(t2 ++ .{void}, 2);
+ try consume_tuple(t2 ++ .{0}, 2);
+ try consume_tuple(.{0} ++ t2, 2);
+ try consume_tuple(.{void} ++ t2, 2);
+ try consume_tuple(.{u8} ++ .{rt_var} ++ .{true}, 3);
}
};
- T.doTheTest();
- comptime T.doTheTest();
+ try T.doTheTest();
+ comptime try T.doTheTest();
}
test "pass tuple to comptime var parameter" {
const S = struct {
- fn Foo(comptime args: anytype) void {
- expect(args[0] == 1);
+ fn Foo(comptime args: anytype) !void {
+ try expect(args[0] == 1);
}
- fn doTheTest() void {
- Foo(.{1});
+ fn doTheTest() !void {
+ try Foo(.{1});
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "tuple initializer for var" {
diff --git a/test/stage1/behavior/type.zig b/test/stage1/behavior/type.zig
index 7b0f3a9e6c..7a01283bfb 100644
--- a/test/stage1/behavior/type.zig
+++ b/test/stage1/behavior/type.zig
@@ -4,52 +4,52 @@ const TypeInfo = builtin.TypeInfo;
const std = @import("std");
const testing = std.testing;
-fn testTypes(comptime types: []const type) void {
+fn testTypes(comptime types: []const type) !void {
inline for (types) |testType| {
- testing.expect(testType == @Type(@typeInfo(testType)));
+ try testing.expect(testType == @Type(@typeInfo(testType)));
}
}
test "Type.MetaType" {
- testing.expect(type == @Type(TypeInfo{ .Type = undefined }));
- testTypes(&[_]type{type});
+ try testing.expect(type == @Type(TypeInfo{ .Type = undefined }));
+ try testTypes(&[_]type{type});
}
test "Type.Void" {
- testing.expect(void == @Type(TypeInfo{ .Void = undefined }));
- testTypes(&[_]type{void});
+ try testing.expect(void == @Type(TypeInfo{ .Void = undefined }));
+ try testTypes(&[_]type{void});
}
test "Type.Bool" {
- testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));
- testTypes(&[_]type{bool});
+ try testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));
+ try testTypes(&[_]type{bool});
}
test "Type.NoReturn" {
- testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));
- testTypes(&[_]type{noreturn});
+ try testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));
+ try testTypes(&[_]type{noreturn});
}
test "Type.Int" {
- testing.expect(u1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 1 } }));
- testing.expect(i1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 1 } }));
- testing.expect(u8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 8 } }));
- testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 8 } }));
- testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 64 } }));
- testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 64 } }));
- testTypes(&[_]type{ u8, u32, i64 });
+ try testing.expect(u1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 1 } }));
+ try testing.expect(i1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 1 } }));
+ try testing.expect(u8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 8 } }));
+ try testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 8 } }));
+ try testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 64 } }));
+ try testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 64 } }));
+ try testTypes(&[_]type{ u8, u32, i64 });
}
test "Type.Float" {
- testing.expect(f16 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 16 } }));
- testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));
- testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));
- testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));
- testTypes(&[_]type{ f16, f32, f64, f128 });
+ try testing.expect(f16 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 16 } }));
+ try testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));
+ try testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));
+ try testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));
+ try testTypes(&[_]type{ f16, f32, f64, f128 });
}
test "Type.Pointer" {
- testTypes(&[_]type{
+ try testTypes(&[_]type{
// One Value Pointer Types
*u8, *const u8,
*volatile u8, *const volatile u8,
@@ -94,41 +94,41 @@ test "Type.Pointer" {
}
test "Type.Array" {
- testing.expect([123]u8 == @Type(TypeInfo{
+ try testing.expect([123]u8 == @Type(TypeInfo{
.Array = TypeInfo.Array{
.len = 123,
.child = u8,
.sentinel = null,
},
}));
- testing.expect([2]u32 == @Type(TypeInfo{
+ try testing.expect([2]u32 == @Type(TypeInfo{
.Array = TypeInfo.Array{
.len = 2,
.child = u32,
.sentinel = null,
},
}));
- testing.expect([2:0]u32 == @Type(TypeInfo{
+ try testing.expect([2:0]u32 == @Type(TypeInfo{
.Array = TypeInfo.Array{
.len = 2,
.child = u32,
.sentinel = 0,
},
}));
- testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
+ try testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
}
test "Type.ComptimeFloat" {
- testTypes(&[_]type{comptime_float});
+ try testTypes(&[_]type{comptime_float});
}
test "Type.ComptimeInt" {
- testTypes(&[_]type{comptime_int});
+ try testTypes(&[_]type{comptime_int});
}
test "Type.Undefined" {
- testTypes(&[_]type{@TypeOf(undefined)});
+ try testTypes(&[_]type{@TypeOf(undefined)});
}
test "Type.Null" {
- testTypes(&[_]type{@TypeOf(null)});
+ try testTypes(&[_]type{@TypeOf(null)});
}
test "@Type create slice with null sentinel" {
const Slice = @Type(builtin.TypeInfo{
@@ -142,10 +142,10 @@ test "@Type create slice with null sentinel" {
.sentinel = null,
},
});
- testing.expect(Slice == []align(8) const *i32);
+ try testing.expect(Slice == []align(8) const *i32);
}
test "@Type picks up the sentinel value from TypeInfo" {
- testTypes(&[_]type{
+ try testTypes(&[_]type{
[11:0]u8, [4:10]u8,
[*:0]u8, [*:0]const u8,
[*:0]volatile u8, [*:0]const volatile u8,
@@ -173,7 +173,7 @@ test "@Type picks up the sentinel value from TypeInfo" {
}
test "Type.Optional" {
- testTypes(&[_]type{
+ try testTypes(&[_]type{
?u8,
?*u8,
?[]u8,
@@ -183,7 +183,7 @@ test "Type.Optional" {
}
test "Type.ErrorUnion" {
- testTypes(&[_]type{
+ try testTypes(&[_]type{
error{}!void,
error{Error}!void,
});
@@ -195,8 +195,8 @@ test "Type.Opaque" {
.decls = &[_]TypeInfo.Declaration{},
},
});
- testing.expect(Opaque != opaque {});
- testing.expectEqualSlices(
+ try testing.expect(Opaque != opaque {});
+ try testing.expectEqualSlices(
TypeInfo.Declaration,
&[_]TypeInfo.Declaration{},
@typeInfo(Opaque).Opaque.decls,
@@ -204,7 +204,7 @@ test "Type.Opaque" {
}
test "Type.Vector" {
- testTypes(&[_]type{
+ try testTypes(&[_]type{
@Vector(0, u8),
@Vector(4, u8),
@Vector(8, *u8),
@@ -215,7 +215,7 @@ test "Type.Vector" {
}
test "Type.AnyFrame" {
- testTypes(&[_]type{
+ try testTypes(&[_]type{
anyframe,
anyframe->u8,
anyframe->anyframe->u8,
@@ -223,7 +223,7 @@ test "Type.AnyFrame" {
}
test "Type.EnumLiteral" {
- testTypes(&[_]type{
+ try testTypes(&[_]type{
@TypeOf(.Dummy),
});
}
@@ -233,7 +233,7 @@ fn add(a: i32, b: i32) i32 {
}
test "Type.Frame" {
- testTypes(&[_]type{
+ try testTypes(&[_]type{
@Frame(add),
});
}
@@ -248,45 +248,45 @@ test "Type.ErrorSet" {
test "Type.Struct" {
const A = @Type(@typeInfo(struct { x: u8, y: u32 }));
const infoA = @typeInfo(A).Struct;
- testing.expectEqual(TypeInfo.ContainerLayout.Auto, infoA.layout);
- testing.expectEqualSlices(u8, "x", infoA.fields[0].name);
- testing.expectEqual(u8, infoA.fields[0].field_type);
- testing.expectEqual(@as(?u8, null), infoA.fields[0].default_value);
- testing.expectEqualSlices(u8, "y", infoA.fields[1].name);
- testing.expectEqual(u32, infoA.fields[1].field_type);
- testing.expectEqual(@as(?u32, null), infoA.fields[1].default_value);
- testing.expectEqualSlices(TypeInfo.Declaration, &[_]TypeInfo.Declaration{}, infoA.decls);
- testing.expectEqual(@as(bool, false), infoA.is_tuple);
+ try testing.expectEqual(TypeInfo.ContainerLayout.Auto, infoA.layout);
+ try testing.expectEqualSlices(u8, "x", infoA.fields[0].name);
+ try testing.expectEqual(u8, infoA.fields[0].field_type);
+ try testing.expectEqual(@as(?u8, null), infoA.fields[0].default_value);
+ try testing.expectEqualSlices(u8, "y", infoA.fields[1].name);
+ try testing.expectEqual(u32, infoA.fields[1].field_type);
+ try testing.expectEqual(@as(?u32, null), infoA.fields[1].default_value);
+ try testing.expectEqualSlices(TypeInfo.Declaration, &[_]TypeInfo.Declaration{}, infoA.decls);
+ try testing.expectEqual(@as(bool, false), infoA.is_tuple);
var a = A{ .x = 0, .y = 1 };
- testing.expectEqual(@as(u8, 0), a.x);
- testing.expectEqual(@as(u32, 1), a.y);
+ try testing.expectEqual(@as(u8, 0), a.x);
+ try testing.expectEqual(@as(u32, 1), a.y);
a.y += 1;
- testing.expectEqual(@as(u32, 2), a.y);
+ try testing.expectEqual(@as(u32, 2), a.y);
const B = @Type(@typeInfo(extern struct { x: u8, y: u32 = 5 }));
const infoB = @typeInfo(B).Struct;
- testing.expectEqual(TypeInfo.ContainerLayout.Extern, infoB.layout);
- testing.expectEqualSlices(u8, "x", infoB.fields[0].name);
- testing.expectEqual(u8, infoB.fields[0].field_type);
- testing.expectEqual(@as(?u8, null), infoB.fields[0].default_value);
- testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
- testing.expectEqual(u32, infoB.fields[1].field_type);
- testing.expectEqual(@as(?u32, 5), infoB.fields[1].default_value);
- testing.expectEqual(@as(usize, 0), infoB.decls.len);
- testing.expectEqual(@as(bool, false), infoB.is_tuple);
+ try testing.expectEqual(TypeInfo.ContainerLayout.Extern, infoB.layout);
+ try testing.expectEqualSlices(u8, "x", infoB.fields[0].name);
+ try testing.expectEqual(u8, infoB.fields[0].field_type);
+ try testing.expectEqual(@as(?u8, null), infoB.fields[0].default_value);
+ try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
+ try testing.expectEqual(u32, infoB.fields[1].field_type);
+ try testing.expectEqual(@as(?u32, 5), infoB.fields[1].default_value);
+ try testing.expectEqual(@as(usize, 0), infoB.decls.len);
+ try testing.expectEqual(@as(bool, false), infoB.is_tuple);
const C = @Type(@typeInfo(packed struct { x: u8 = 3, y: u32 = 5 }));
const infoC = @typeInfo(C).Struct;
- testing.expectEqual(TypeInfo.ContainerLayout.Packed, infoC.layout);
- testing.expectEqualSlices(u8, "x", infoC.fields[0].name);
- testing.expectEqual(u8, infoC.fields[0].field_type);
- testing.expectEqual(@as(?u8, 3), infoC.fields[0].default_value);
- testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
- testing.expectEqual(u32, infoC.fields[1].field_type);
- testing.expectEqual(@as(?u32, 5), infoC.fields[1].default_value);
- testing.expectEqual(@as(usize, 0), infoC.decls.len);
- testing.expectEqual(@as(bool, false), infoC.is_tuple);
+ try testing.expectEqual(TypeInfo.ContainerLayout.Packed, infoC.layout);
+ try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);
+ try testing.expectEqual(u8, infoC.fields[0].field_type);
+ try testing.expectEqual(@as(?u8, 3), infoC.fields[0].default_value);
+ try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
+ try testing.expectEqual(u32, infoC.fields[1].field_type);
+ try testing.expectEqual(@as(?u32, 5), infoC.fields[1].default_value);
+ try testing.expectEqual(@as(usize, 0), infoC.decls.len);
+ try testing.expectEqual(@as(bool, false), infoC.is_tuple);
}
test "Type.Enum" {
@@ -302,9 +302,9 @@ test "Type.Enum" {
.is_exhaustive = true,
},
});
- testing.expectEqual(true, @typeInfo(Foo).Enum.is_exhaustive);
- testing.expectEqual(@as(u8, 1), @enumToInt(Foo.a));
- testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b));
+ try testing.expectEqual(true, @typeInfo(Foo).Enum.is_exhaustive);
+ try testing.expectEqual(@as(u8, 1), @enumToInt(Foo.a));
+ try testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b));
const Bar = @Type(.{
.Enum = .{
.layout = .Extern,
@@ -317,10 +317,10 @@ test "Type.Enum" {
.is_exhaustive = false,
},
});
- testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive);
- testing.expectEqual(@as(u32, 1), @enumToInt(Bar.a));
- testing.expectEqual(@as(u32, 5), @enumToInt(Bar.b));
- testing.expectEqual(@as(u32, 6), @enumToInt(@intToEnum(Bar, 6)));
+ try testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive);
+ try testing.expectEqual(@as(u32, 1), @enumToInt(Bar.a));
+ try testing.expectEqual(@as(u32, 5), @enumToInt(Bar.b));
+ try testing.expectEqual(@as(u32, 6), @enumToInt(@intToEnum(Bar, 6)));
}
test "Type.Union" {
@@ -338,7 +338,7 @@ test "Type.Union" {
var untagged = Untagged{ .int = 1 };
untagged.float = 2.0;
untagged.int = 3;
- testing.expectEqual(@as(i32, 3), untagged.int);
+ try testing.expectEqual(@as(i32, 3), untagged.int);
const PackedUntagged = @Type(.{
.Union = .{
@@ -352,8 +352,8 @@ test "Type.Union" {
},
});
var packed_untagged = PackedUntagged{ .signed = -1 };
- testing.expectEqual(@as(i32, -1), packed_untagged.signed);
- testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned);
+ try testing.expectEqual(@as(i32, -1), packed_untagged.signed);
+ try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned);
const Tag = @Type(.{
.Enum = .{
@@ -379,9 +379,9 @@ test "Type.Union" {
},
});
var tagged = Tagged{ .signed = -1 };
- testing.expectEqual(Tag.signed, tagged);
+ try testing.expectEqual(Tag.signed, tagged);
tagged = .{ .unsigned = 1 };
- testing.expectEqual(Tag.unsigned, tagged);
+ try testing.expectEqual(Tag.unsigned, tagged);
}
test "Type.Union from Type.Enum" {
@@ -447,7 +447,7 @@ test "Type.BoundFn" {
pub fn foo(self: *const @This()) align(4) callconv(.Unspecified) void {}
};
const test_instance: TestStruct = undefined;
- testing.expect(std.meta.eql(
+ try testing.expect(std.meta.eql(
@typeName(@TypeOf(test_instance.foo)),
@typeName(@Type(@typeInfo(@TypeOf(test_instance.foo)))),
));
diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig
index f944b7904c..e8ae3827d9 100644
--- a/test/stage1/behavior/type_info.zig
+++ b/test/stage1/behavior/type_info.zig
@@ -9,151 +9,151 @@ const expect = std.testing.expect;
const expectEqualStrings = std.testing.expectEqualStrings;
test "type info: tag type, void info" {
- testBasic();
- comptime testBasic();
+ try testBasic();
+ comptime try testBasic();
}
-fn testBasic() void {
- expect(@typeInfo(TypeInfo).Union.tag_type == TypeId);
+fn testBasic() !void {
+ try expect(@typeInfo(TypeInfo).Union.tag_type == TypeId);
const void_info = @typeInfo(void);
- expect(void_info == TypeId.Void);
- expect(void_info.Void == {});
+ try expect(void_info == TypeId.Void);
+ try expect(void_info.Void == {});
}
test "type info: integer, floating point type info" {
- testIntFloat();
- comptime testIntFloat();
+ try testIntFloat();
+ comptime try testIntFloat();
}
-fn testIntFloat() void {
+fn testIntFloat() !void {
const u8_info = @typeInfo(u8);
- expect(u8_info == .Int);
- expect(u8_info.Int.signedness == .unsigned);
- expect(u8_info.Int.bits == 8);
+ try expect(u8_info == .Int);
+ try expect(u8_info.Int.signedness == .unsigned);
+ try expect(u8_info.Int.bits == 8);
const f64_info = @typeInfo(f64);
- expect(f64_info == .Float);
- expect(f64_info.Float.bits == 64);
+ try expect(f64_info == .Float);
+ try expect(f64_info.Float.bits == 64);
}
test "type info: pointer type info" {
- testPointer();
- comptime testPointer();
+ try testPointer();
+ comptime try testPointer();
}
-fn testPointer() void {
+fn testPointer() !void {
const u32_ptr_info = @typeInfo(*u32);
- expect(u32_ptr_info == .Pointer);
- expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
- expect(u32_ptr_info.Pointer.is_const == false);
- expect(u32_ptr_info.Pointer.is_volatile == false);
- expect(u32_ptr_info.Pointer.alignment == @alignOf(u32));
- expect(u32_ptr_info.Pointer.child == u32);
- expect(u32_ptr_info.Pointer.sentinel == null);
+ try expect(u32_ptr_info == .Pointer);
+ try expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
+ try expect(u32_ptr_info.Pointer.is_const == false);
+ try expect(u32_ptr_info.Pointer.is_volatile == false);
+ try expect(u32_ptr_info.Pointer.alignment == @alignOf(u32));
+ try expect(u32_ptr_info.Pointer.child == u32);
+ try expect(u32_ptr_info.Pointer.sentinel == null);
}
test "type info: unknown length pointer type info" {
- testUnknownLenPtr();
- comptime testUnknownLenPtr();
+ try testUnknownLenPtr();
+ comptime try testUnknownLenPtr();
}
-fn testUnknownLenPtr() void {
+fn testUnknownLenPtr() !void {
const u32_ptr_info = @typeInfo([*]const volatile f64);
- expect(u32_ptr_info == .Pointer);
- expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
- expect(u32_ptr_info.Pointer.is_const == true);
- expect(u32_ptr_info.Pointer.is_volatile == true);
- expect(u32_ptr_info.Pointer.sentinel == null);
- expect(u32_ptr_info.Pointer.alignment == @alignOf(f64));
- expect(u32_ptr_info.Pointer.child == f64);
+ try expect(u32_ptr_info == .Pointer);
+ try expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
+ try expect(u32_ptr_info.Pointer.is_const == true);
+ try expect(u32_ptr_info.Pointer.is_volatile == true);
+ try expect(u32_ptr_info.Pointer.sentinel == null);
+ try expect(u32_ptr_info.Pointer.alignment == @alignOf(f64));
+ try expect(u32_ptr_info.Pointer.child == f64);
}
test "type info: null terminated pointer type info" {
- testNullTerminatedPtr();
- comptime testNullTerminatedPtr();
+ try testNullTerminatedPtr();
+ comptime try testNullTerminatedPtr();
}
-fn testNullTerminatedPtr() void {
+fn testNullTerminatedPtr() !void {
const ptr_info = @typeInfo([*:0]u8);
- expect(ptr_info == .Pointer);
- expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
- expect(ptr_info.Pointer.is_const == false);
- expect(ptr_info.Pointer.is_volatile == false);
- expect(ptr_info.Pointer.sentinel.? == 0);
+ try expect(ptr_info == .Pointer);
+ try expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
+ try expect(ptr_info.Pointer.is_const == false);
+ try expect(ptr_info.Pointer.is_volatile == false);
+ try expect(ptr_info.Pointer.sentinel.? == 0);
- expect(@typeInfo([:0]u8).Pointer.sentinel != null);
+ try expect(@typeInfo([:0]u8).Pointer.sentinel != null);
}
test "type info: C pointer type info" {
- testCPtr();
- comptime testCPtr();
+ try testCPtr();
+ comptime try testCPtr();
}
-fn testCPtr() void {
+fn testCPtr() !void {
const ptr_info = @typeInfo([*c]align(4) const i8);
- expect(ptr_info == .Pointer);
- expect(ptr_info.Pointer.size == .C);
- expect(ptr_info.Pointer.is_const);
- expect(!ptr_info.Pointer.is_volatile);
- expect(ptr_info.Pointer.alignment == 4);
- expect(ptr_info.Pointer.child == i8);
+ try expect(ptr_info == .Pointer);
+ try expect(ptr_info.Pointer.size == .C);
+ try expect(ptr_info.Pointer.is_const);
+ try expect(!ptr_info.Pointer.is_volatile);
+ try expect(ptr_info.Pointer.alignment == 4);
+ try expect(ptr_info.Pointer.child == i8);
}
test "type info: slice type info" {
- testSlice();
- comptime testSlice();
+ try testSlice();
+ comptime try testSlice();
}
-fn testSlice() void {
+fn testSlice() !void {
const u32_slice_info = @typeInfo([]u32);
- expect(u32_slice_info == .Pointer);
- expect(u32_slice_info.Pointer.size == .Slice);
- expect(u32_slice_info.Pointer.is_const == false);
- expect(u32_slice_info.Pointer.is_volatile == false);
- expect(u32_slice_info.Pointer.alignment == 4);
- expect(u32_slice_info.Pointer.child == u32);
+ try expect(u32_slice_info == .Pointer);
+ try expect(u32_slice_info.Pointer.size == .Slice);
+ try expect(u32_slice_info.Pointer.is_const == false);
+ try expect(u32_slice_info.Pointer.is_volatile == false);
+ try expect(u32_slice_info.Pointer.alignment == 4);
+ try expect(u32_slice_info.Pointer.child == u32);
}
test "type info: array type info" {
- testArray();
- comptime testArray();
+ try testArray();
+ comptime try testArray();
}
-fn testArray() void {
+fn testArray() !void {
{
const info = @typeInfo([42]u8);
- expect(info == .Array);
- expect(info.Array.len == 42);
- expect(info.Array.child == u8);
- expect(info.Array.sentinel == null);
+ try expect(info == .Array);
+ try expect(info.Array.len == 42);
+ try expect(info.Array.child == u8);
+ try expect(info.Array.sentinel == null);
}
{
const info = @typeInfo([10:0]u8);
- expect(info.Array.len == 10);
- expect(info.Array.child == u8);
- expect(info.Array.sentinel.? == @as(u8, 0));
- expect(@sizeOf([10:0]u8) == info.Array.len + 1);
+ try expect(info.Array.len == 10);
+ try expect(info.Array.child == u8);
+ try expect(info.Array.sentinel.? == @as(u8, 0));
+ try expect(@sizeOf([10:0]u8) == info.Array.len + 1);
}
}
test "type info: optional type info" {
- testOptional();
- comptime testOptional();
+ try testOptional();
+ comptime try testOptional();
}
-fn testOptional() void {
+fn testOptional() !void {
const null_info = @typeInfo(?void);
- expect(null_info == .Optional);
- expect(null_info.Optional.child == void);
+ try expect(null_info == .Optional);
+ try expect(null_info.Optional.child == void);
}
test "type info: error set, error union info" {
- testErrorSet();
- comptime testErrorSet();
+ try testErrorSet();
+ comptime try testErrorSet();
}
-fn testErrorSet() void {
+fn testErrorSet() !void {
const TestErrorSet = error{
First,
Second,
@@ -161,26 +161,26 @@ fn testErrorSet() void {
};
const error_set_info = @typeInfo(TestErrorSet);
- expect(error_set_info == .ErrorSet);
- expect(error_set_info.ErrorSet.?.len == 3);
- expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));
+ try expect(error_set_info == .ErrorSet);
+ try expect(error_set_info.ErrorSet.?.len == 3);
+ try expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));
const error_union_info = @typeInfo(TestErrorSet!usize);
- expect(error_union_info == .ErrorUnion);
- expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
- expect(error_union_info.ErrorUnion.payload == usize);
+ try expect(error_union_info == .ErrorUnion);
+ try expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
+ try expect(error_union_info.ErrorUnion.payload == usize);
const global_info = @typeInfo(anyerror);
- expect(global_info == .ErrorSet);
- expect(global_info.ErrorSet == null);
+ try expect(global_info == .ErrorSet);
+ try expect(global_info.ErrorSet == null);
}
test "type info: enum info" {
- testEnum();
- comptime testEnum();
+ try testEnum();
+ comptime try testEnum();
}
-fn testEnum() void {
+fn testEnum() !void {
const Os = enum {
Windows,
Macos,
@@ -189,28 +189,28 @@ fn testEnum() void {
};
const os_info = @typeInfo(Os);
- expect(os_info == .Enum);
- expect(os_info.Enum.layout == .Auto);
- expect(os_info.Enum.fields.len == 4);
- expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
- expect(os_info.Enum.fields[3].value == 3);
- expect(os_info.Enum.tag_type == u2);
- expect(os_info.Enum.decls.len == 0);
+ try expect(os_info == .Enum);
+ try expect(os_info.Enum.layout == .Auto);
+ try expect(os_info.Enum.fields.len == 4);
+ try expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
+ try expect(os_info.Enum.fields[3].value == 3);
+ try expect(os_info.Enum.tag_type == u2);
+ try expect(os_info.Enum.decls.len == 0);
}
test "type info: union info" {
- testUnion();
- comptime testUnion();
+ try testUnion();
+ comptime try testUnion();
}
-fn testUnion() void {
+fn testUnion() !void {
const typeinfo_info = @typeInfo(TypeInfo);
- expect(typeinfo_info == .Union);
- expect(typeinfo_info.Union.layout == .Auto);
- expect(typeinfo_info.Union.tag_type.? == TypeId);
- expect(typeinfo_info.Union.fields.len == 25);
- expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int));
- expect(typeinfo_info.Union.decls.len == 22);
+ try expect(typeinfo_info == .Union);
+ try expect(typeinfo_info.Union.layout == .Auto);
+ try expect(typeinfo_info.Union.tag_type.? == TypeId);
+ try expect(typeinfo_info.Union.fields.len == 25);
+ try expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int));
+ try expect(typeinfo_info.Union.decls.len == 22);
const TestNoTagUnion = union {
Foo: void,
@@ -218,52 +218,52 @@ fn testUnion() void {
};
const notag_union_info = @typeInfo(TestNoTagUnion);
- expect(notag_union_info == .Union);
- expect(notag_union_info.Union.tag_type == null);
- expect(notag_union_info.Union.layout == .Auto);
- expect(notag_union_info.Union.fields.len == 2);
- expect(notag_union_info.Union.fields[0].alignment == @alignOf(void));
- expect(notag_union_info.Union.fields[1].field_type == u32);
- expect(notag_union_info.Union.fields[1].alignment == @alignOf(u32));
+ try expect(notag_union_info == .Union);
+ try expect(notag_union_info.Union.tag_type == null);
+ try expect(notag_union_info.Union.layout == .Auto);
+ try expect(notag_union_info.Union.fields.len == 2);
+ try expect(notag_union_info.Union.fields[0].alignment == @alignOf(void));
+ try expect(notag_union_info.Union.fields[1].field_type == u32);
+ try expect(notag_union_info.Union.fields[1].alignment == @alignOf(u32));
const TestExternUnion = extern union {
foo: *c_void,
};
const extern_union_info = @typeInfo(TestExternUnion);
- expect(extern_union_info.Union.layout == .Extern);
- expect(extern_union_info.Union.tag_type == null);
- expect(extern_union_info.Union.fields[0].field_type == *c_void);
+ try expect(extern_union_info.Union.layout == .Extern);
+ try expect(extern_union_info.Union.tag_type == null);
+ try expect(extern_union_info.Union.fields[0].field_type == *c_void);
}
test "type info: struct info" {
- testStruct();
- comptime testStruct();
+ try testStruct();
+ comptime try testStruct();
}
-fn testStruct() void {
+fn testStruct() !void {
const unpacked_struct_info = @typeInfo(TestUnpackedStruct);
- expect(unpacked_struct_info.Struct.is_tuple == false);
- expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
- expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4);
- expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?);
+ try expect(unpacked_struct_info.Struct.is_tuple == false);
+ try expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
+ try expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4);
+ try expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?);
const struct_info = @typeInfo(TestStruct);
- expect(struct_info == .Struct);
- expect(struct_info.Struct.is_tuple == false);
- expect(struct_info.Struct.layout == .Packed);
- expect(struct_info.Struct.fields.len == 4);
- expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));
- expect(struct_info.Struct.fields[2].field_type == *TestStruct);
- expect(struct_info.Struct.fields[2].default_value == null);
- expect(struct_info.Struct.fields[3].default_value.? == 4);
- expect(struct_info.Struct.fields[3].alignment == 1);
- expect(struct_info.Struct.decls.len == 2);
- expect(struct_info.Struct.decls[0].is_pub);
- expect(!struct_info.Struct.decls[0].data.Fn.is_extern);
- expect(struct_info.Struct.decls[0].data.Fn.lib_name == null);
- expect(struct_info.Struct.decls[0].data.Fn.return_type == void);
- expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void);
+ try expect(struct_info == .Struct);
+ try expect(struct_info.Struct.is_tuple == false);
+ try expect(struct_info.Struct.layout == .Packed);
+ try expect(struct_info.Struct.fields.len == 4);
+ try expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));
+ try expect(struct_info.Struct.fields[2].field_type == *TestStruct);
+ try expect(struct_info.Struct.fields[2].default_value == null);
+ try expect(struct_info.Struct.fields[3].default_value.? == 4);
+ try expect(struct_info.Struct.fields[3].alignment == 1);
+ try expect(struct_info.Struct.decls.len == 2);
+ try expect(struct_info.Struct.decls[0].is_pub);
+ try expect(!struct_info.Struct.decls[0].data.Fn.is_extern);
+ try expect(struct_info.Struct.decls[0].data.Fn.lib_name == null);
+ try expect(struct_info.Struct.decls[0].data.Fn.return_type == void);
+ try expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void);
}
const TestUnpackedStruct = struct {
@@ -282,43 +282,43 @@ const TestStruct = packed struct {
};
test "type info: opaque info" {
- testOpaque();
- comptime testOpaque();
+ try testOpaque();
+ comptime try testOpaque();
}
-fn testOpaque() void {
+fn testOpaque() !void {
const Foo = opaque {
const A = 1;
fn b() void {}
};
const foo_info = @typeInfo(Foo);
- expect(foo_info.Opaque.decls.len == 2);
+ try expect(foo_info.Opaque.decls.len == 2);
}
test "type info: function type info" {
// wasm doesn't support align attributes on functions
if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest;
- testFunction();
- comptime testFunction();
+ try testFunction();
+ comptime try testFunction();
}
-fn testFunction() void {
+fn testFunction() !void {
const fn_info = @typeInfo(@TypeOf(foo));
- expect(fn_info == .Fn);
- expect(fn_info.Fn.alignment > 0);
- expect(fn_info.Fn.calling_convention == .C);
- expect(!fn_info.Fn.is_generic);
- expect(fn_info.Fn.args.len == 2);
- expect(fn_info.Fn.is_var_args);
- expect(fn_info.Fn.return_type.? == usize);
+ try expect(fn_info == .Fn);
+ try expect(fn_info.Fn.alignment > 0);
+ try expect(fn_info.Fn.calling_convention == .C);
+ try expect(!fn_info.Fn.is_generic);
+ try expect(fn_info.Fn.args.len == 2);
+ try expect(fn_info.Fn.is_var_args);
+ try expect(fn_info.Fn.return_type.? == usize);
const fn_aligned_info = @typeInfo(@TypeOf(fooAligned));
- expect(fn_aligned_info.Fn.alignment == 4);
+ try expect(fn_aligned_info.Fn.alignment == 4);
const test_instance: TestStruct = undefined;
const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo));
- expect(bound_fn_info == .BoundFn);
- expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
+ try expect(bound_fn_info == .BoundFn);
+ try expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
}
extern fn foo(a: usize, b: bool, ...) callconv(.C) usize;
@@ -332,33 +332,33 @@ test "typeInfo with comptime parameter in struct fn def" {
}
test "type info: vectors" {
- testVector();
- comptime testVector();
+ try testVector();
+ comptime try testVector();
}
-fn testVector() void {
+fn testVector() !void {
const vec_info = @typeInfo(std.meta.Vector(4, i32));
- expect(vec_info == .Vector);
- expect(vec_info.Vector.len == 4);
- expect(vec_info.Vector.child == i32);
+ try expect(vec_info == .Vector);
+ try expect(vec_info.Vector.len == 4);
+ try expect(vec_info.Vector.child == i32);
}
test "type info: anyframe and anyframe->T" {
- testAnyFrame();
- comptime testAnyFrame();
+ try testAnyFrame();
+ comptime try testAnyFrame();
}
-fn testAnyFrame() void {
+fn testAnyFrame() !void {
{
const anyframe_info = @typeInfo(anyframe->i32);
- expect(anyframe_info == .AnyFrame);
- expect(anyframe_info.AnyFrame.child.? == i32);
+ try expect(anyframe_info == .AnyFrame);
+ try expect(anyframe_info.AnyFrame.child.? == i32);
}
{
const anyframe_info = @typeInfo(anyframe);
- expect(anyframe_info == .AnyFrame);
- expect(anyframe_info.AnyFrame.child == null);
+ try expect(anyframe_info == .AnyFrame);
+ try expect(anyframe_info.AnyFrame.child == null);
}
}
@@ -385,9 +385,9 @@ test "type info: extern fns with and without lib names" {
comptime {
for (info.Struct.decls) |decl| {
if (std.mem.eql(u8, decl.name, "bar1")) {
- expect(decl.data.Fn.lib_name == null);
+ try expect(decl.data.Fn.lib_name == null);
} else {
- expectEqualStrings("cool", decl.data.Fn.lib_name.?);
+ try expectEqualStrings("cool", decl.data.Fn.lib_name.?);
}
}
}
@@ -397,12 +397,12 @@ test "data field is a compile-time value" {
const S = struct {
const Bar = @as(isize, -1);
};
- comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize);
+ comptime try expect(@typeInfo(S).Struct.decls[0].data.Var == isize);
}
test "sentinel of opaque pointer type" {
const c_void_info = @typeInfo(*c_void);
- expect(c_void_info.Pointer.sentinel == null);
+ try expect(c_void_info.Pointer.sentinel == null);
}
test "@typeInfo does not force declarations into existence" {
@@ -413,12 +413,12 @@ test "@typeInfo does not force declarations into existence" {
@compileError("test failed");
}
};
- comptime expect(@typeInfo(S).Struct.fields.len == 1);
+ comptime try expect(@typeInfo(S).Struct.fields.len == 1);
}
test "defaut value for a var-typed field" {
const S = struct { x: anytype };
- expect(@typeInfo(S).Struct.fields[0].default_value == null);
+ try expect(@typeInfo(S).Struct.fields[0].default_value == null);
}
fn add(a: i32, b: i32) i32 {
@@ -428,7 +428,7 @@ fn add(a: i32, b: i32) i32 {
test "type info for async frames" {
switch (@typeInfo(@Frame(add))) {
.Frame => |frame| {
- expect(frame.function == add);
+ try expect(frame.function == add);
},
else => unreachable,
}
@@ -438,7 +438,7 @@ test "type info: value is correctly copied" {
comptime {
var ptrInfo = @typeInfo([]u32);
ptrInfo.Pointer.size = .One;
- expect(@typeInfo([]u32).Pointer.size == .Slice);
+ try expect(@typeInfo([]u32).Pointer.size == .Slice);
}
}
@@ -451,22 +451,22 @@ test "Declarations are returned in declaration order" {
const e = 5;
};
const d = @typeInfo(S).Struct.decls;
- expect(std.mem.eql(u8, d[0].name, "a"));
- expect(std.mem.eql(u8, d[1].name, "b"));
- expect(std.mem.eql(u8, d[2].name, "c"));
- expect(std.mem.eql(u8, d[3].name, "d"));
- expect(std.mem.eql(u8, d[4].name, "e"));
+ try expect(std.mem.eql(u8, d[0].name, "a"));
+ try expect(std.mem.eql(u8, d[1].name, "b"));
+ try expect(std.mem.eql(u8, d[2].name, "c"));
+ try expect(std.mem.eql(u8, d[3].name, "d"));
+ try expect(std.mem.eql(u8, d[4].name, "e"));
}
test "Struct.is_tuple" {
- expect(@typeInfo(@TypeOf(.{0})).Struct.is_tuple);
- expect(!@typeInfo(@TypeOf(.{ .a = 0 })).Struct.is_tuple);
+ try expect(@typeInfo(@TypeOf(.{0})).Struct.is_tuple);
+ try expect(!@typeInfo(@TypeOf(.{ .a = 0 })).Struct.is_tuple);
}
test "StructField.is_comptime" {
const info = @typeInfo(struct { x: u8 = 3, comptime y: u32 = 5 }).Struct;
- expect(!info.fields[0].is_comptime);
- expect(info.fields[1].is_comptime);
+ try expect(!info.fields[0].is_comptime);
+ try expect(info.fields[1].is_comptime);
}
test "typeInfo resolves usingnamespace declarations" {
@@ -479,6 +479,6 @@ test "typeInfo resolves usingnamespace declarations" {
usingnamespace A;
};
- expect(@typeInfo(B).Struct.decls.len == 2);
+ try expect(@typeInfo(B).Struct.decls.len == 2);
//a
}
diff --git a/test/stage1/behavior/typename.zig b/test/stage1/behavior/typename.zig
index 1abefe5b5e..bf8464244b 100644
--- a/test/stage1/behavior/typename.zig
+++ b/test/stage1/behavior/typename.zig
@@ -3,5 +3,5 @@ const expect = std.testing.expect;
const expectEqualSlices = std.testing.expectEqualSlices;
test "slice" {
- expectEqualSlices(u8, "[]u8", @typeName([]u8));
+ try expectEqualSlices(u8, "[]u8", @typeName([]u8));
}
diff --git a/test/stage1/behavior/undefined.zig b/test/stage1/behavior/undefined.zig
index 114b0262b1..a160f86221 100644
--- a/test/stage1/behavior/undefined.zig
+++ b/test/stage1/behavior/undefined.zig
@@ -12,16 +12,16 @@ fn initStaticArray() [10]i32 {
}
const static_array = initStaticArray();
test "init static array to undefined" {
- expect(static_array[0] == 1);
- expect(static_array[4] == 2);
- expect(static_array[7] == 3);
- expect(static_array[9] == 4);
+ try expect(static_array[0] == 1);
+ try expect(static_array[4] == 2);
+ try expect(static_array[7] == 3);
+ try expect(static_array[9] == 4);
comptime {
- expect(static_array[0] == 1);
- expect(static_array[4] == 2);
- expect(static_array[7] == 3);
- expect(static_array[9] == 4);
+ try expect(static_array[0] == 1);
+ try expect(static_array[4] == 2);
+ try expect(static_array[7] == 3);
+ try expect(static_array[9] == 4);
}
}
@@ -41,12 +41,12 @@ test "assign undefined to struct" {
comptime {
var foo: Foo = undefined;
setFooX(&foo);
- expect(foo.x == 2);
+ try expect(foo.x == 2);
}
{
var foo: Foo = undefined;
setFooX(&foo);
- expect(foo.x == 2);
+ try expect(foo.x == 2);
}
}
@@ -54,16 +54,16 @@ test "assign undefined to struct with method" {
comptime {
var foo: Foo = undefined;
foo.setFooXMethod();
- expect(foo.x == 3);
+ try expect(foo.x == 3);
}
{
var foo: Foo = undefined;
foo.setFooXMethod();
- expect(foo.x == 3);
+ try expect(foo.x == 3);
}
}
test "type name of undefined" {
const x = undefined;
- expect(mem.eql(u8, @typeName(@TypeOf(x)), "(undefined)"));
+ try expect(mem.eql(u8, @typeName(@TypeOf(x)), "(undefined)"));
}
diff --git a/test/stage1/behavior/union.zig b/test/stage1/behavior/union.zig
index e46b6bb6b9..66396bebb4 100644
--- a/test/stage1/behavior/union.zig
+++ b/test/stage1/behavior/union.zig
@@ -30,11 +30,11 @@ const array = [_]Value{
test "unions embedded in aggregate types" {
switch (array[1]) {
- Value.Array => |arr| expect(arr[4] == 3),
+ Value.Array => |arr| try expect(arr[4] == 3),
else => unreachable,
}
switch ((err catch unreachable).val1) {
- Value.Int => |x| expect(x == 1234),
+ Value.Int => |x| try expect(x == 1234),
else => unreachable,
}
}
@@ -46,18 +46,18 @@ const Foo = union {
test "basic unions" {
var foo = Foo{ .int = 1 };
- expect(foo.int == 1);
+ try expect(foo.int == 1);
foo = Foo{ .float = 12.34 };
- expect(foo.float == 12.34);
+ try expect(foo.float == 12.34);
}
test "comptime union field access" {
comptime {
var foo = Foo{ .int = 0 };
- expect(foo.int == 0);
+ try expect(foo.int == 0);
foo = Foo{ .float = 42.42 };
- expect(foo.float == 42.42);
+ try expect(foo.float == 42.42);
}
}
@@ -65,10 +65,10 @@ test "init union with runtime value" {
var foo: Foo = undefined;
setFloat(&foo, 12.34);
- expect(foo.float == 12.34);
+ try expect(foo.float == 12.34);
setInt(&foo, 42);
- expect(foo.int == 42);
+ try expect(foo.int == 42);
}
fn setFloat(foo: *Foo, x: f64) void {
@@ -86,9 +86,9 @@ const FooExtern = extern union {
test "basic extern unions" {
var foo = FooExtern{ .int = 1 };
- expect(foo.int == 1);
+ try expect(foo.int == 1);
foo.float = 12.34;
- expect(foo.float == 12.34);
+ try expect(foo.float == 12.34);
}
const Letter = enum {
@@ -103,16 +103,16 @@ const Payload = union(Letter) {
};
test "union with specified enum tag" {
- doTest();
- comptime doTest();
+ try doTest();
+ comptime try doTest();
}
-fn doTest() void {
- expect(bar(Payload{ .A = 1234 }) == -10);
+fn doTest() !void {
+ try expect((try bar(Payload{ .A = 1234 })) == -10);
}
-fn bar(value: Payload) i32 {
- expect(@as(Letter, value) == Letter.A);
+fn bar(value: Payload) !i32 {
+ try expect(@as(Letter, value) == Letter.A);
return switch (value) {
Payload.A => |x| return x - 1244,
Payload.B => |x| if (x == 12.34) @as(i32, 20) else 21,
@@ -128,8 +128,8 @@ const MultipleChoice = union(enum(u32)) {
};
test "simple union(enum(u32))" {
var x = MultipleChoice.C;
- expect(x == MultipleChoice.C);
- expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60);
+ try expect(x == MultipleChoice.C);
+ try expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60);
}
const MultipleChoice2 = union(enum(u32)) {
@@ -145,14 +145,14 @@ const MultipleChoice2 = union(enum(u32)) {
};
test "union(enum(u32)) with specified and unspecified tag values" {
- comptime expect(Tag(Tag(MultipleChoice2)) == u32);
- testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
- comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
+ comptime try expect(Tag(Tag(MultipleChoice2)) == u32);
+ try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
+ comptime try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
}
-fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
- expect(@enumToInt(@as(Tag(MultipleChoice2), x)) == 60);
- expect(1123 == switch (x) {
+fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) !void {
+ try expect(@enumToInt(@as(Tag(MultipleChoice2), x)) == 60);
+ try expect(1123 == switch (x) {
MultipleChoice2.A => 1,
MultipleChoice2.B => 2,
MultipleChoice2.C => |v| @as(i32, 1000) + v,
@@ -170,7 +170,7 @@ const ExternPtrOrInt = extern union {
int: u64,
};
test "extern union size" {
- comptime expect(@sizeOf(ExternPtrOrInt) == 8);
+ comptime try expect(@sizeOf(ExternPtrOrInt) == 8);
}
const PackedPtrOrInt = packed union {
@@ -178,14 +178,14 @@ const PackedPtrOrInt = packed union {
int: u64,
};
test "extern union size" {
- comptime expect(@sizeOf(PackedPtrOrInt) == 8);
+ comptime try expect(@sizeOf(PackedPtrOrInt) == 8);
}
const ZeroBits = union {
OnlyField: void,
};
test "union with only 1 field which is void should be zero bits" {
- comptime expect(@sizeOf(ZeroBits) == 0);
+ comptime try expect(@sizeOf(ZeroBits) == 0);
}
const TheTag = enum {
@@ -199,23 +199,23 @@ const TheUnion = union(TheTag) {
C: i32,
};
test "union field access gives the enum values" {
- expect(TheUnion.A == TheTag.A);
- expect(TheUnion.B == TheTag.B);
- expect(TheUnion.C == TheTag.C);
+ try expect(TheUnion.A == TheTag.A);
+ try expect(TheUnion.B == TheTag.B);
+ try expect(TheUnion.C == TheTag.C);
}
test "cast union to tag type of union" {
- testCastUnionToTag(TheUnion{ .B = 1234 });
- comptime testCastUnionToTag(TheUnion{ .B = 1234 });
+ try testCastUnionToTag(TheUnion{ .B = 1234 });
+ comptime try testCastUnionToTag(TheUnion{ .B = 1234 });
}
-fn testCastUnionToTag(x: TheUnion) void {
- expect(@as(TheTag, x) == TheTag.B);
+fn testCastUnionToTag(x: TheUnion) !void {
+ try expect(@as(TheTag, x) == TheTag.B);
}
test "cast tag type of union to union" {
var x: Value2 = Letter2.B;
- expect(@as(Letter2, x) == Letter2.B);
+ try expect(@as(Letter2, x) == Letter2.B);
}
const Letter2 = enum {
A,
@@ -230,11 +230,11 @@ const Value2 = union(Letter2) {
test "implicit cast union to its tag type" {
var x: Value2 = Letter2.B;
- expect(x == Letter2.B);
- giveMeLetterB(x);
+ try expect(x == Letter2.B);
+ try giveMeLetterB(x);
}
-fn giveMeLetterB(x: Letter2) void {
- expect(x == Value2.B);
+fn giveMeLetterB(x: Letter2) !void {
+ try expect(x == Value2.B);
}
pub const PackThis = union(enum) {
@@ -243,11 +243,11 @@ pub const PackThis = union(enum) {
};
test "constant packed union" {
- testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});
+ try testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});
}
-fn testConstPackedUnion(expected_tokens: []const PackThis) void {
- expect(expected_tokens[0].StringLiteral == 1);
+fn testConstPackedUnion(expected_tokens: []const PackThis) !void {
+ try expect(expected_tokens[0].StringLiteral == 1);
}
test "switch on union with only 1 field" {
@@ -259,7 +259,7 @@ test "switch on union with only 1 field" {
z = PartialInstWithPayload{ .Compiled = 1234 };
switch (z) {
PartialInstWithPayload.Compiled => |x| {
- expect(x == 1234);
+ try expect(x == 1234);
return;
},
}
@@ -285,11 +285,11 @@ test "access a member of tagged union with conflicting enum tag name" {
const B = void;
};
- comptime expect(Bar.A == u8);
+ comptime try expect(Bar.A == u8);
}
test "tagged union initialization with runtime void" {
- expect(testTaggedUnionInit({}));
+ try expect(testTaggedUnionInit({}));
}
const TaggedUnionWithAVoid = union(enum) {
@@ -327,9 +327,9 @@ test "union with only 1 field casted to its enum type" {
var e = Expr{ .Literal = Literal{ .Bool = true } };
const ExprTag = Tag(Expr);
- comptime expect(Tag(ExprTag) == u0);
+ comptime try expect(Tag(ExprTag) == u0);
var t = @as(ExprTag, e);
- expect(t == Expr.Literal);
+ try expect(t == Expr.Literal);
}
test "union with only 1 field casted to its enum type which has enum value specified" {
@@ -347,11 +347,11 @@ test "union with only 1 field casted to its enum type which has enum value speci
};
var e = Expr{ .Literal = Literal{ .Bool = true } };
- comptime expect(Tag(ExprTag) == comptime_int);
+ comptime try expect(Tag(ExprTag) == comptime_int);
var t = @as(ExprTag, e);
- expect(t == Expr.Literal);
- expect(@enumToInt(t) == 33);
- comptime expect(@enumToInt(t) == 33);
+ try expect(t == Expr.Literal);
+ try expect(@enumToInt(t) == 33);
+ comptime try expect(@enumToInt(t) == 33);
}
test "@enumToInt works on unions" {
@@ -364,9 +364,9 @@ test "@enumToInt works on unions" {
const a = Bar{ .A = true };
var b = Bar{ .B = undefined };
var c = Bar.C;
- expect(@enumToInt(a) == 0);
- expect(@enumToInt(b) == 1);
- expect(@enumToInt(c) == 2);
+ try expect(@enumToInt(a) == 0);
+ try expect(@enumToInt(b) == 1);
+ try expect(@enumToInt(c) == 2);
}
const Attribute = union(enum) {
@@ -393,23 +393,23 @@ test "comptime union field value equality" {
const b1 = Setter(Attribute{ .B = 9 });
const b2 = Setter(Attribute{ .B = 5 });
- expect(a0 == a0);
- expect(a1 == a1);
- expect(a0 == a2);
+ try expect(a0 == a0);
+ try expect(a1 == a1);
+ try expect(a0 == a2);
- expect(b0 == b0);
- expect(b1 == b1);
- expect(b0 == b2);
+ try expect(b0 == b0);
+ try expect(b1 == b1);
+ try expect(b0 == b2);
- expect(a0 != b0);
- expect(a0 != a1);
- expect(b0 != b1);
+ try expect(a0 != b0);
+ try expect(a0 != a1);
+ try expect(b0 != b1);
}
test "return union init with void payload" {
const S = struct {
- fn entry() void {
- expect(func().state == State.one);
+ fn entry() !void {
+ try expect(func().state == State.one);
}
const Outer = union(enum) {
state: State,
@@ -422,8 +422,8 @@ test "return union init with void payload" {
return Outer{ .state = State{ .one = {} } };
}
};
- S.entry();
- comptime S.entry();
+ try S.entry();
+ comptime try S.entry();
}
test "@unionInit can modify a union type" {
@@ -435,14 +435,14 @@ test "@unionInit can modify a union type" {
var value: UnionInitEnum = undefined;
value = @unionInit(UnionInitEnum, "Boolean", true);
- expect(value.Boolean == true);
+ try expect(value.Boolean == true);
value.Boolean = false;
- expect(value.Boolean == false);
+ try expect(value.Boolean == false);
value = @unionInit(UnionInitEnum, "Byte", 2);
- expect(value.Byte == 2);
+ try expect(value.Byte == 2);
value.Byte = 3;
- expect(value.Byte == 3);
+ try expect(value.Byte == 3);
}
test "@unionInit can modify a pointer value" {
@@ -455,10 +455,10 @@ test "@unionInit can modify a pointer value" {
var value_ptr = &value;
value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true);
- expect(value.Boolean == true);
+ try expect(value.Boolean == true);
value_ptr.* = @unionInit(UnionInitEnum, "Byte", 2);
- expect(value.Byte == 2);
+ try expect(value.Byte == 2);
}
test "union no tag with struct member" {
@@ -471,38 +471,38 @@ test "union no tag with struct member" {
u.foo();
}
-fn testComparison() void {
+fn testComparison() !void {
var x = Payload{ .A = 42 };
- expect(x == .A);
- expect(x != .B);
- expect(x != .C);
- expect((x == .B) == false);
- expect((x == .C) == false);
- expect((x != .A) == false);
+ try expect(x == .A);
+ try expect(x != .B);
+ try expect(x != .C);
+ try expect((x == .B) == false);
+ try expect((x == .C) == false);
+ try expect((x != .A) == false);
}
test "comparison between union and enum literal" {
- testComparison();
- comptime testComparison();
+ try testComparison();
+ comptime try testComparison();
}
test "packed union generates correctly aligned LLVM type" {
const U = packed union {
- f1: fn () void,
+ f1: fn () error{TestUnexpectedResult}!void,
f2: u32,
};
var foo = [_]U{
U{ .f1 = doTest },
U{ .f2 = 0 },
};
- foo[0].f1();
+ try foo[0].f1();
}
test "union with one member defaults to u0 tag type" {
const U0 = union(enum) {
X: u32,
};
- comptime expect(Tag(Tag(U0)) == u0);
+ comptime try expect(Tag(Tag(U0)) == u0);
}
test "union with comptime_int tag" {
@@ -511,7 +511,7 @@ test "union with comptime_int tag" {
Y: u16,
Z: u8,
};
- comptime expect(Tag(Tag(Union)) == comptime_int);
+ comptime try expect(Tag(Tag(Union)) == comptime_int);
}
test "extern union doesn't trigger field check at comptime" {
@@ -521,7 +521,7 @@ test "extern union doesn't trigger field check at comptime" {
};
const x = U{ .x = 0x55AAAA55 };
- comptime expect(x.y == 0x55);
+ comptime try expect(x.y == 0x55);
}
const Foo1 = union(enum) {
@@ -535,7 +535,7 @@ test "global union with single field is correctly initialized" {
glbl = Foo1{
.f = @typeInfo(Foo1).Union.fields[0].field_type{ .x = 123 },
};
- expect(glbl.f.x == 123);
+ try expect(glbl.f.x == 123);
}
pub const FooUnion = union(enum) {
@@ -548,8 +548,8 @@ var glbl_array: [2]FooUnion = undefined;
test "initialize global array of union" {
glbl_array[1] = FooUnion{ .U1 = 2 };
glbl_array[0] = FooUnion{ .U0 = 1 };
- expect(glbl_array[0].U0 == 1);
- expect(glbl_array[1].U1 == 2);
+ try expect(glbl_array[0].U0 == 1);
+ try expect(glbl_array[1].U1 == 2);
}
test "anonymous union literal syntax" {
@@ -559,19 +559,19 @@ test "anonymous union literal syntax" {
float: f64,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var i: Number = .{ .int = 42 };
var f = makeNumber();
- expect(i.int == 42);
- expect(f.float == 12.34);
+ try expect(i.int == 42);
+ try expect(f.float == 12.34);
}
fn makeNumber() Number {
return .{ .float = 12.34 };
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "update the tag value for zero-sized unions" {
@@ -580,9 +580,9 @@ test "update the tag value for zero-sized unions" {
U1: void,
};
var x = S{ .U0 = {} };
- expect(x == .U0);
+ try expect(x == .U0);
x = S{ .U1 = {} };
- expect(x == .U1);
+ try expect(x == .U1);
}
test "function call result coerces from tagged union to the tag" {
@@ -594,12 +594,12 @@ test "function call result coerces from tagged union to the tag" {
const ArchTag = Tag(Arch);
- fn doTheTest() void {
+ fn doTheTest() !void {
var x: ArchTag = getArch1();
- expect(x == .One);
+ try expect(x == .One);
var y: ArchTag = getArch2();
- expect(y == .Two);
+ try expect(y == .Two);
}
pub fn getArch1() Arch {
@@ -610,8 +610,8 @@ test "function call result coerces from tagged union to the tag" {
return .{ .Two = 99 };
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "0-sized extern union definition" {
@@ -620,7 +620,7 @@ test "0-sized extern union definition" {
const f = 1;
};
- expect(U.f == 1);
+ try expect(U.f == 1);
}
test "union initializer generates padding only if needed" {
@@ -629,7 +629,7 @@ test "union initializer generates padding only if needed" {
};
var v = U{ .A = 532 };
- expect(v.A == 532);
+ try expect(v.A == 532);
}
test "runtime tag name with single field" {
@@ -638,7 +638,7 @@ test "runtime tag name with single field" {
};
var v = U{ .A = 42 };
- expect(std.mem.eql(u8, @tagName(v), "A"));
+ try expect(std.mem.eql(u8, @tagName(v), "A"));
}
test "cast from anonymous struct to union" {
@@ -648,7 +648,7 @@ test "cast from anonymous struct to union" {
B: []const u8,
C: void,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var y: u32 = 42;
const t0 = .{ .A = 123 };
const t1 = .{ .B = "foo" };
@@ -658,14 +658,14 @@ test "cast from anonymous struct to union" {
var x1: U = t1;
const x2: U = t2;
var x3: U = t3;
- expect(x0.A == 123);
- expect(std.mem.eql(u8, x1.B, "foo"));
- expect(x2 == .C);
- expect(x3.A == y);
+ try expect(x0.A == 123);
+ try expect(std.mem.eql(u8, x1.B, "foo"));
+ try expect(x2 == .C);
+ try expect(x3.A == y);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "cast from pointer to anonymous struct to pointer to union" {
@@ -675,7 +675,7 @@ test "cast from pointer to anonymous struct to pointer to union" {
B: []const u8,
C: void,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var y: u32 = 42;
const t0 = &.{ .A = 123 };
const t1 = &.{ .B = "foo" };
@@ -685,14 +685,14 @@ test "cast from pointer to anonymous struct to pointer to union" {
var x1: *const U = t1;
const x2: *const U = t2;
var x3: *const U = t3;
- expect(x0.A == 123);
- expect(std.mem.eql(u8, x1.B, "foo"));
- expect(x2.* == .C);
- expect(x3.A == y);
+ try expect(x0.A == 123);
+ try expect(std.mem.eql(u8, x1.B, "foo"));
+ try expect(x2.* == .C);
+ try expect(x3.A == y);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "method call on an empty union" {
@@ -707,13 +707,13 @@ test "method call on an empty union" {
}
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var u = MyUnion{ .X1 = [0]u8{} };
- expect(u.useIt());
+ try expect(u.useIt());
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "switching on non exhaustive union" {
@@ -727,16 +727,16 @@ test "switching on non exhaustive union" {
a: i32,
b: u32,
};
- fn doTheTest() void {
+ fn doTheTest() !void {
var a = U{ .a = 2 };
switch (a) {
- .a => |val| expect(val == 2),
+ .a => |val| try expect(val == 2),
.b => unreachable,
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "containers with single-field enums" {
@@ -746,21 +746,21 @@ test "containers with single-field enums" {
const C = struct { a: A };
const D = struct { a: B };
- fn doTheTest() void {
+ fn doTheTest() !void {
var array1 = [1]A{A{ .f1 = {} }};
var array2 = [1]B{B{ .f1 = {} }};
- expect(array1[0] == .f1);
- expect(array2[0] == .f1);
+ try expect(array1[0] == .f1);
+ try expect(array2[0] == .f1);
var struct1 = C{ .a = A{ .f1 = {} } };
var struct2 = D{ .a = B{ .f1 = {} } };
- expect(struct1.a == .f1);
- expect(struct2.a == .f1);
+ try expect(struct1.a == .f1);
+ try expect(struct2.a == .f1);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "@unionInit on union w/ tag but no fields" {
@@ -776,18 +776,18 @@ test "@unionInit on union w/ tag but no fields" {
};
comptime {
- expect(@sizeOf(Data) != 0);
+ try expect(@sizeOf(Data) != 0);
}
- fn doTheTest() void {
+ fn doTheTest() !void {
var data: Data = .{ .no_op = .{} };
var o = Data.decode(&[_]u8{});
- expectEqual(Type.no_op, o);
+ try expectEqual(Type.no_op, o);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "union enum type gets a separate scope" {
@@ -797,10 +797,10 @@ test "union enum type gets a separate scope" {
const foo = 1;
};
- fn doTheTest() void {
- expect(!@hasDecl(Tag(U), "foo"));
+ fn doTheTest() !void {
+ try expect(!@hasDecl(Tag(U), "foo"));
}
};
- S.doTheTest();
+ try S.doTheTest();
}
diff --git a/test/stage1/behavior/usingnamespace.zig b/test/stage1/behavior/usingnamespace.zig
index a44bf1bbc3..b529b24dd4 100644
--- a/test/stage1/behavior/usingnamespace.zig
+++ b/test/stage1/behavior/usingnamespace.zig
@@ -9,8 +9,8 @@ fn Foo(comptime T: type) type {
test "usingnamespace inside a generic struct" {
const std2 = Foo(std);
const testing2 = Foo(std.testing);
- std2.testing.expect(true);
- testing2.expect(true);
+ try std2.testing.expect(true);
+ try testing2.expect(true);
}
usingnamespace struct {
@@ -18,5 +18,5 @@ usingnamespace struct {
};
test "usingnamespace does not redeclare an imported variable" {
- comptime std.testing.expect(foo == 42);
+ comptime try std.testing.expect(foo == 42);
}
diff --git a/test/stage1/behavior/var_args.zig b/test/stage1/behavior/var_args.zig
index eae8f8f888..8935877167 100644
--- a/test/stage1/behavior/var_args.zig
+++ b/test/stage1/behavior/var_args.zig
@@ -12,9 +12,9 @@ fn add(args: anytype) i32 {
}
test "add arbitrary args" {
- expect(add(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
- expect(add(.{@as(i32, 1234)}) == 1234);
- expect(add(.{}) == 0);
+ try expect(add(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
+ try expect(add(.{@as(i32, 1234)}) == 1234);
+ try expect(add(.{}) == 0);
}
fn readFirstVarArg(args: anytype) void {
@@ -26,9 +26,9 @@ test "send void arg to var args" {
}
test "pass args directly" {
- expect(addSomeStuff(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
- expect(addSomeStuff(.{@as(i32, 1234)}) == 1234);
- expect(addSomeStuff(.{}) == 0);
+ try expect(addSomeStuff(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
+ try expect(addSomeStuff(.{@as(i32, 1234)}) == 1234);
+ try expect(addSomeStuff(.{}) == 0);
}
fn addSomeStuff(args: anytype) i32 {
@@ -36,23 +36,23 @@ fn addSomeStuff(args: anytype) i32 {
}
test "runtime parameter before var args" {
- expect(extraFn(10, .{}) == 0);
- expect(extraFn(10, .{false}) == 1);
- expect(extraFn(10, .{ false, true }) == 2);
+ try expect((try extraFn(10, .{})) == 0);
+ try expect((try extraFn(10, .{false})) == 1);
+ try expect((try extraFn(10, .{ false, true })) == 2);
comptime {
- expect(extraFn(10, .{}) == 0);
- expect(extraFn(10, .{false}) == 1);
- expect(extraFn(10, .{ false, true }) == 2);
+ try expect((try extraFn(10, .{})) == 0);
+ try expect((try extraFn(10, .{false})) == 1);
+ try expect((try extraFn(10, .{ false, true })) == 2);
}
}
-fn extraFn(extra: u32, args: anytype) usize {
+fn extraFn(extra: u32, args: anytype) !usize {
if (args.len >= 1) {
- expect(args[0] == false);
+ try expect(args[0] == false);
}
if (args.len >= 2) {
- expect(args[1] == true);
+ try expect(args[1] == true);
}
return args.len;
}
@@ -70,8 +70,8 @@ fn foo2(args: anytype) bool {
}
test "array of var args functions" {
- expect(foos[0](.{}));
- expect(!foos[1](.{}));
+ try expect(foos[0](.{}));
+ try expect(!foos[1](.{}));
}
test "pass zero length array to var args param" {
diff --git a/test/stage1/behavior/vector.zig b/test/stage1/behavior/vector.zig
index 4b88ce020a..5c754dd1d0 100644
--- a/test/stage1/behavior/vector.zig
+++ b/test/stage1/behavior/vector.zig
@@ -9,104 +9,104 @@ const Vector = std.meta.Vector;
test "implicit cast vector to array - bool" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
const a: Vector(4, bool) = [_]bool{ true, false, true, false };
const result_array: [4]bool = a;
- expect(mem.eql(bool, &result_array, &[4]bool{ true, false, true, false }));
+ try expect(mem.eql(bool, &result_array, &[4]bool{ true, false, true, false }));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "vector wrap operators" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
var x: Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
- expect(mem.eql(i32, &@as([4]i32, v +% x), &[4]i32{ -2147483648, 2147483645, 33, 44 }));
- expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 }));
- expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
+ try expect(mem.eql(i32, &@as([4]i32, v +% x), &[4]i32{ -2147483648, 2147483645, 33, 44 }));
+ try expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 }));
+ try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
var z: Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };
- expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 }));
+ try expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 }));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "vector bin compares with mem.eql" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
var x: Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };
- expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false }));
- expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true }));
- expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false }));
- expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true }));
- expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false }));
- expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true }));
+ try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false }));
+ try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true }));
+ try expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false }));
+ try expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true }));
+ try expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false }));
+ try expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true }));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "vector int operators" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var v: Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
var x: Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };
- expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 }));
- expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 }));
- expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 }));
- expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 }));
+ try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 }));
+ try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 }));
+ try expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 }));
+ try expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 }));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "vector float operators" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var v: Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };
var x: Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };
- expect(mem.eql(f32, &@as([4]f32, v + x), &[4]f32{ 11, 22, 33, 44 }));
- expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 }));
- expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 }));
- expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 }));
+ try expect(mem.eql(f32, &@as([4]f32, v + x), &[4]f32{ 11, 22, 33, 44 }));
+ try expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 }));
+ try expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 }));
+ try expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 }));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "vector bit operators" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var v: Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
var x: Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };
- expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
- expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
- expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
+ try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
+ try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
+ try expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "implicit cast vector to array" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var a: Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
var result_array: [4]i32 = a;
result_array = a;
- expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 }));
+ try expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 }));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "array to vector" {
@@ -120,141 +120,141 @@ test "vector casts of sizes not divisable by 8" {
if (std.Target.current.os.tag == .dragonfly) return error.SkipZigTest;
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
{
var v: Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
var x: [4]u3 = v;
- expect(mem.eql(u3, &x, &@as([4]u3, v)));
+ try expect(mem.eql(u3, &x, &@as([4]u3, v)));
}
{
var v: Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
var x: [4]u2 = v;
- expect(mem.eql(u2, &x, &@as([4]u2, v)));
+ try expect(mem.eql(u2, &x, &@as([4]u2, v)));
}
{
var v: Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
var x: [4]u1 = v;
- expect(mem.eql(u1, &x, &@as([4]u1, v)));
+ try expect(mem.eql(u1, &x, &@as([4]u1, v)));
}
{
var v: Vector(4, bool) = [4]bool{ false, false, true, false };
var x: [4]bool = v;
- expect(mem.eql(bool, &x, &@as([4]bool, v)));
+ try expect(mem.eql(bool, &x, &@as([4]bool, v)));
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "vector @splat" {
const S = struct {
- fn testForT(comptime N: comptime_int, v: anytype) void {
+ fn testForT(comptime N: comptime_int, v: anytype) !void {
const T = @TypeOf(v);
var vec = @splat(N, v);
- expectEqual(Vector(N, T), @TypeOf(vec));
+ try expectEqual(Vector(N, T), @TypeOf(vec));
var as_array = @as([N]T, vec);
- for (as_array) |elem| expectEqual(v, elem);
+ for (as_array) |elem| try expectEqual(v, elem);
}
- fn doTheTest() void {
+ fn doTheTest() !void {
// Splats with multiple-of-8 bit types that fill a 128bit vector.
- testForT(16, @as(u8, 0xEE));
- testForT(8, @as(u16, 0xBEEF));
- testForT(4, @as(u32, 0xDEADBEEF));
- testForT(2, @as(u64, 0xCAFEF00DDEADBEEF));
+ try testForT(16, @as(u8, 0xEE));
+ try testForT(8, @as(u16, 0xBEEF));
+ try testForT(4, @as(u32, 0xDEADBEEF));
+ try testForT(2, @as(u64, 0xCAFEF00DDEADBEEF));
- testForT(8, @as(f16, 3.1415));
- testForT(4, @as(f32, 3.1415));
- testForT(2, @as(f64, 3.1415));
+ try testForT(8, @as(f16, 3.1415));
+ try testForT(4, @as(f32, 3.1415));
+ try testForT(2, @as(f64, 3.1415));
// Same but fill more than 128 bits.
- testForT(16 * 2, @as(u8, 0xEE));
- testForT(8 * 2, @as(u16, 0xBEEF));
- testForT(4 * 2, @as(u32, 0xDEADBEEF));
- testForT(2 * 2, @as(u64, 0xCAFEF00DDEADBEEF));
+ try testForT(16 * 2, @as(u8, 0xEE));
+ try testForT(8 * 2, @as(u16, 0xBEEF));
+ try testForT(4 * 2, @as(u32, 0xDEADBEEF));
+ try testForT(2 * 2, @as(u64, 0xCAFEF00DDEADBEEF));
- testForT(8 * 2, @as(f16, 3.1415));
- testForT(4 * 2, @as(f32, 3.1415));
- testForT(2 * 2, @as(f64, 3.1415));
+ try testForT(8 * 2, @as(f16, 3.1415));
+ try testForT(4 * 2, @as(f32, 3.1415));
+ try testForT(2 * 2, @as(f64, 3.1415));
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "load vector elements via comptime index" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var v: Vector(4, i32) = [_]i32{ 1, 2, 3, undefined };
- expect(v[0] == 1);
- expect(v[1] == 2);
- expect(loadv(&v[2]) == 3);
+ try expect(v[0] == 1);
+ try expect(v[1] == 2);
+ try expect(loadv(&v[2]) == 3);
}
fn loadv(ptr: anytype) i32 {
return ptr.*;
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "store vector elements via comptime index" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var v: Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
v[2] = 42;
- expect(v[1] == 5);
+ try expect(v[1] == 5);
v[3] = -364;
- expect(v[2] == 42);
- expect(-364 == v[3]);
+ try expect(v[2] == 42);
+ try expect(-364 == v[3]);
storev(&v[0], 100);
- expect(v[0] == 100);
+ try expect(v[0] == 100);
}
fn storev(ptr: anytype, x: i32) void {
ptr.* = x;
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "load vector elements via runtime index" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var v: Vector(4, i32) = [_]i32{ 1, 2, 3, undefined };
var i: u32 = 0;
- expect(v[i] == 1);
+ try expect(v[i] == 1);
i += 1;
- expect(v[i] == 2);
+ try expect(v[i] == 2);
i += 1;
- expect(v[i] == 3);
+ try expect(v[i] == 3);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "store vector elements via runtime index" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var v: Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
var i: u32 = 2;
v[i] = 1;
- expect(v[1] == 5);
- expect(v[2] == 1);
+ try expect(v[1] == 5);
+ try expect(v[2] == 1);
i += 1;
v[i] = -364;
- expect(-364 == v[3]);
+ try expect(-364 == v[3]);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "initialize vector which is a struct field" {
@@ -263,155 +263,155 @@ test "initialize vector which is a struct field" {
};
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var foo = Vec4Obj{
.data = [_]f32{ 1, 2, 3, 4 },
};
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "vector comparison operators" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
{
const v1: Vector(4, bool) = [_]bool{ true, false, true, false };
const v2: Vector(4, bool) = [_]bool{ false, true, false, true };
- expectEqual(@splat(4, true), v1 == v1);
- expectEqual(@splat(4, false), v1 == v2);
- expectEqual(@splat(4, true), v1 != v2);
- expectEqual(@splat(4, false), v2 != v2);
+ try expectEqual(@splat(4, true), v1 == v1);
+ try expectEqual(@splat(4, false), v1 == v2);
+ try expectEqual(@splat(4, true), v1 != v2);
+ try expectEqual(@splat(4, false), v2 != v2);
}
{
const v1 = @splat(4, @as(u32, 0xc0ffeeee));
const v2: Vector(4, c_uint) = v1;
const v3 = @splat(4, @as(u32, 0xdeadbeef));
- expectEqual(@splat(4, true), v1 == v2);
- expectEqual(@splat(4, false), v1 == v3);
- expectEqual(@splat(4, true), v1 != v3);
- expectEqual(@splat(4, false), v1 != v2);
+ try expectEqual(@splat(4, true), v1 == v2);
+ try expectEqual(@splat(4, false), v1 == v3);
+ try expectEqual(@splat(4, true), v1 != v3);
+ try expectEqual(@splat(4, false), v1 != v2);
}
{
// Comptime-known LHS/RHS
var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 };
const v2 = @splat(4, @as(u32, 2));
const v3: @Vector(4, bool) = [_]bool{ true, false, true, false };
- expectEqual(v3, v1 == v2);
- expectEqual(v3, v2 == v1);
+ try expectEqual(v3, v1 == v2);
+ try expectEqual(v3, v2 == v1);
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "vector division operators" {
const S = struct {
- fn doTheTestDiv(comptime T: type, x: Vector(4, T), y: Vector(4, T)) void {
+ fn doTheTestDiv(comptime T: type, x: Vector(4, T), y: Vector(4, T)) !void {
if (!comptime std.meta.trait.isSignedInt(T)) {
const d0 = x / y;
for (@as([4]T, d0)) |v, i| {
- expectEqual(x[i] / y[i], v);
+ try expectEqual(x[i] / y[i], v);
}
}
const d1 = @divExact(x, y);
for (@as([4]T, d1)) |v, i| {
- expectEqual(@divExact(x[i], y[i]), v);
+ try expectEqual(@divExact(x[i], y[i]), v);
}
const d2 = @divFloor(x, y);
for (@as([4]T, d2)) |v, i| {
- expectEqual(@divFloor(x[i], y[i]), v);
+ try expectEqual(@divFloor(x[i], y[i]), v);
}
const d3 = @divTrunc(x, y);
for (@as([4]T, d3)) |v, i| {
- expectEqual(@divTrunc(x[i], y[i]), v);
+ try expectEqual(@divTrunc(x[i], y[i]), v);
}
}
- fn doTheTestMod(comptime T: type, x: Vector(4, T), y: Vector(4, T)) void {
+ fn doTheTestMod(comptime T: type, x: Vector(4, T), y: Vector(4, T)) !void {
if ((!comptime std.meta.trait.isSignedInt(T)) and @typeInfo(T) != .Float) {
const r0 = x % y;
for (@as([4]T, r0)) |v, i| {
- expectEqual(x[i] % y[i], v);
+ try expectEqual(x[i] % y[i], v);
}
}
const r1 = @mod(x, y);
for (@as([4]T, r1)) |v, i| {
- expectEqual(@mod(x[i], y[i]), v);
+ try expectEqual(@mod(x[i], y[i]), v);
}
const r2 = @rem(x, y);
for (@as([4]T, r2)) |v, i| {
- expectEqual(@rem(x[i], y[i]), v);
+ try expectEqual(@rem(x[i], y[i]), v);
}
}
- fn doTheTest() void {
+ fn doTheTest() !void {
// https://github.com/ziglang/zig/issues/4952
if (std.builtin.os.tag != .windows) {
- doTheTestDiv(f16, [4]f16{ 4.0, -4.0, 4.0, -4.0 }, [4]f16{ 1.0, 2.0, -1.0, -2.0 });
+ try doTheTestDiv(f16, [4]f16{ 4.0, -4.0, 4.0, -4.0 }, [4]f16{ 1.0, 2.0, -1.0, -2.0 });
}
- doTheTestDiv(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, -1.0, -2.0 });
- doTheTestDiv(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, -1.0, -2.0 });
+ try doTheTestDiv(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, -1.0, -2.0 });
+ try doTheTestDiv(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, -1.0, -2.0 });
// https://github.com/ziglang/zig/issues/4952
if (std.builtin.os.tag != .windows) {
- doTheTestMod(f16, [4]f16{ 4.0, -4.0, 4.0, -4.0 }, [4]f16{ 1.0, 2.0, 0.5, 3.0 });
+ try doTheTestMod(f16, [4]f16{ 4.0, -4.0, 4.0, -4.0 }, [4]f16{ 1.0, 2.0, 0.5, 3.0 });
}
- doTheTestMod(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, 0.5, 3.0 });
- doTheTestMod(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, 0.5, 3.0 });
+ try doTheTestMod(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, 0.5, 3.0 });
+ try doTheTestMod(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, 0.5, 3.0 });
- doTheTestDiv(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, -1, -2 });
- doTheTestDiv(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, -1, -2 });
- doTheTestDiv(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, -1, -2 });
- doTheTestDiv(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, -1, -2 });
+ try doTheTestDiv(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, -1, -2 });
+ try doTheTestDiv(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, -1, -2 });
+ try doTheTestDiv(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, -1, -2 });
+ try doTheTestDiv(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, -1, -2 });
- doTheTestMod(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, 4, 8 });
- doTheTestMod(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, 4, 8 });
- doTheTestMod(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, 4, 8 });
- doTheTestMod(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, 4, 8 });
+ try doTheTestMod(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, 4, 8 });
+ try doTheTestMod(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, 4, 8 });
+ try doTheTestMod(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, 4, 8 });
+ try doTheTestMod(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, 4, 8 });
- doTheTestDiv(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 });
- doTheTestDiv(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 });
- doTheTestDiv(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 });
- doTheTestDiv(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 });
+ try doTheTestDiv(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 });
+ try doTheTestDiv(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 });
+ try doTheTestDiv(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 });
+ try doTheTestDiv(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 });
- doTheTestMod(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 });
- doTheTestMod(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 });
- doTheTestMod(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 });
- doTheTestMod(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 });
+ try doTheTestMod(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 });
+ try doTheTestMod(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 });
+ try doTheTestMod(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 });
+ try doTheTestMod(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 });
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "vector bitwise not operator" {
const S = struct {
- fn doTheTestNot(comptime T: type, x: Vector(4, T)) void {
+ fn doTheTestNot(comptime T: type, x: Vector(4, T)) !void {
var y = ~x;
for (@as([4]T, y)) |v, i| {
- expectEqual(~x[i], v);
+ try expectEqual(~x[i], v);
}
}
- fn doTheTest() void {
- doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });
- doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });
- doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });
- doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });
+ fn doTheTest() !void {
+ try doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });
+ try doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });
+ try doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });
+ try doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });
- doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });
- doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });
- doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });
- doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });
+ try doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });
+ try doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });
+ try doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });
+ try doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "vector shift operators" {
@@ -419,7 +419,7 @@ test "vector shift operators" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
const S = struct {
- fn doTheTestShift(x: anytype, y: anytype) void {
+ fn doTheTestShift(x: anytype, y: anytype) !void {
const N = @typeInfo(@TypeOf(x)).Array.len;
const TX = @typeInfo(@TypeOf(x)).Array.child;
const TY = @typeInfo(@TypeOf(y)).Array.child;
@@ -429,14 +429,14 @@ test "vector shift operators" {
var z0 = xv >> yv;
for (@as([N]TX, z0)) |v, i| {
- expectEqual(x[i] >> y[i], v);
+ try expectEqual(x[i] >> y[i], v);
}
var z1 = xv << yv;
for (@as([N]TX, z1)) |v, i| {
- expectEqual(x[i] << y[i], v);
+ try expectEqual(x[i] << y[i], v);
}
}
- fn doTheTestShiftExact(x: anytype, y: anytype, dir: enum { Left, Right }) void {
+ fn doTheTestShiftExact(x: anytype, y: anytype, dir: enum { Left, Right }) !void {
const N = @typeInfo(@TypeOf(x)).Array.len;
const TX = @typeInfo(@TypeOf(x)).Array.child;
const TY = @typeInfo(@TypeOf(y)).Array.child;
@@ -447,33 +447,33 @@ test "vector shift operators" {
var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv);
for (@as([N]TX, z)) |v, i| {
const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i];
- expectEqual(check, v);
+ try expectEqual(check, v);
}
}
- fn doTheTest() void {
- doTheTestShift([_]u8{ 0, 2, 4, math.maxInt(u8) }, [_]u3{ 2, 0, 2, 7 });
- doTheTestShift([_]u16{ 0, 2, 4, math.maxInt(u16) }, [_]u4{ 2, 0, 2, 15 });
- doTheTestShift([_]u24{ 0, 2, 4, math.maxInt(u24) }, [_]u5{ 2, 0, 2, 23 });
- doTheTestShift([_]u32{ 0, 2, 4, math.maxInt(u32) }, [_]u5{ 2, 0, 2, 31 });
- doTheTestShift([_]u64{ 0xfe, math.maxInt(u64) }, [_]u6{ 0, 63 });
+ fn doTheTest() !void {
+ try doTheTestShift([_]u8{ 0, 2, 4, math.maxInt(u8) }, [_]u3{ 2, 0, 2, 7 });
+ try doTheTestShift([_]u16{ 0, 2, 4, math.maxInt(u16) }, [_]u4{ 2, 0, 2, 15 });
+ try doTheTestShift([_]u24{ 0, 2, 4, math.maxInt(u24) }, [_]u5{ 2, 0, 2, 23 });
+ try doTheTestShift([_]u32{ 0, 2, 4, math.maxInt(u32) }, [_]u5{ 2, 0, 2, 31 });
+ try doTheTestShift([_]u64{ 0xfe, math.maxInt(u64) }, [_]u6{ 0, 63 });
- doTheTestShift([_]i8{ 0, 2, 4, math.maxInt(i8) }, [_]u3{ 2, 0, 2, 7 });
- doTheTestShift([_]i16{ 0, 2, 4, math.maxInt(i16) }, [_]u4{ 2, 0, 2, 7 });
- doTheTestShift([_]i24{ 0, 2, 4, math.maxInt(i24) }, [_]u5{ 2, 0, 2, 7 });
- doTheTestShift([_]i32{ 0, 2, 4, math.maxInt(i32) }, [_]u5{ 2, 0, 2, 7 });
- doTheTestShift([_]i64{ 0xfe, math.maxInt(i64) }, [_]u6{ 0, 63 });
+ try doTheTestShift([_]i8{ 0, 2, 4, math.maxInt(i8) }, [_]u3{ 2, 0, 2, 7 });
+ try doTheTestShift([_]i16{ 0, 2, 4, math.maxInt(i16) }, [_]u4{ 2, 0, 2, 7 });
+ try doTheTestShift([_]i24{ 0, 2, 4, math.maxInt(i24) }, [_]u5{ 2, 0, 2, 7 });
+ try doTheTestShift([_]i32{ 0, 2, 4, math.maxInt(i32) }, [_]u5{ 2, 0, 2, 7 });
+ try doTheTestShift([_]i64{ 0xfe, math.maxInt(i64) }, [_]u6{ 0, 63 });
- doTheTestShiftExact([_]u8{ 0, 1, 1 << 7, math.maxInt(u8) ^ 1 }, [_]u3{ 4, 0, 7, 1 }, .Right);
- doTheTestShiftExact([_]u16{ 0, 1, 1 << 15, math.maxInt(u16) ^ 1 }, [_]u4{ 4, 0, 15, 1 }, .Right);
- doTheTestShiftExact([_]u24{ 0, 1, 1 << 23, math.maxInt(u24) ^ 1 }, [_]u5{ 4, 0, 23, 1 }, .Right);
- doTheTestShiftExact([_]u32{ 0, 1, 1 << 31, math.maxInt(u32) ^ 1 }, [_]u5{ 4, 0, 31, 1 }, .Right);
- doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 63, 0 }, .Right);
+ try doTheTestShiftExact([_]u8{ 0, 1, 1 << 7, math.maxInt(u8) ^ 1 }, [_]u3{ 4, 0, 7, 1 }, .Right);
+ try doTheTestShiftExact([_]u16{ 0, 1, 1 << 15, math.maxInt(u16) ^ 1 }, [_]u4{ 4, 0, 15, 1 }, .Right);
+ try doTheTestShiftExact([_]u24{ 0, 1, 1 << 23, math.maxInt(u24) ^ 1 }, [_]u5{ 4, 0, 23, 1 }, .Right);
+ try doTheTestShiftExact([_]u32{ 0, 1, 1 << 31, math.maxInt(u32) ^ 1 }, [_]u5{ 4, 0, 31, 1 }, .Right);
+ try doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 63, 0 }, .Right);
- doTheTestShiftExact([_]u8{ 0, 1, 1, math.maxInt(u8) ^ (1 << 7) }, [_]u3{ 4, 0, 7, 1 }, .Left);
- doTheTestShiftExact([_]u16{ 0, 1, 1, math.maxInt(u16) ^ (1 << 15) }, [_]u4{ 4, 0, 15, 1 }, .Left);
- doTheTestShiftExact([_]u24{ 0, 1, 1, math.maxInt(u24) ^ (1 << 23) }, [_]u5{ 4, 0, 23, 1 }, .Left);
- doTheTestShiftExact([_]u32{ 0, 1, 1, math.maxInt(u32) ^ (1 << 31) }, [_]u5{ 4, 0, 31, 1 }, .Left);
- doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 0, 63 }, .Left);
+ try doTheTestShiftExact([_]u8{ 0, 1, 1, math.maxInt(u8) ^ (1 << 7) }, [_]u3{ 4, 0, 7, 1 }, .Left);
+ try doTheTestShiftExact([_]u16{ 0, 1, 1, math.maxInt(u16) ^ (1 << 15) }, [_]u4{ 4, 0, 15, 1 }, .Left);
+ try doTheTestShiftExact([_]u24{ 0, 1, 1, math.maxInt(u24) ^ (1 << 23) }, [_]u5{ 4, 0, 23, 1 }, .Left);
+ try doTheTestShiftExact([_]u32{ 0, 1, 1, math.maxInt(u32) ^ (1 << 31) }, [_]u5{ 4, 0, 31, 1 }, .Left);
+ try doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 0, 63 }, .Left);
}
};
@@ -500,19 +500,19 @@ test "vector shift operators" {
else => {},
}
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "vector reduce operation" {
const S = struct {
- fn doTheTestReduce(comptime op: builtin.ReduceOp, x: anytype, expected: anytype) void {
+ fn doTheTestReduce(comptime op: builtin.ReduceOp, x: anytype, expected: anytype) !void {
const N = @typeInfo(@TypeOf(x)).Array.len;
const TX = @typeInfo(@TypeOf(x)).Array.child;
var r = @reduce(op, @as(Vector(N, TX), x));
switch (@typeInfo(TX)) {
- .Int, .Bool => expectEqual(expected, r),
+ .Int, .Bool => try expectEqual(expected, r),
.Float => {
const expected_nan = math.isNan(expected);
const got_nan = math.isNan(r);
@@ -521,120 +521,120 @@ test "vector reduce operation" {
// Do this check explicitly as two NaN values are never
// equal.
} else {
- expectApproxEqRel(expected, r, math.sqrt(math.epsilon(TX)));
+ try expectApproxEqRel(expected, r, math.sqrt(math.epsilon(TX)));
}
},
else => unreachable,
}
}
- fn doTheTest() void {
- doTheTestReduce(.Add, [4]i16{ -9, -99, -999, -9999 }, @as(i32, -11106));
- doTheTestReduce(.Add, [4]u16{ 9, 99, 999, 9999 }, @as(u32, 11106));
- doTheTestReduce(.Add, [4]i32{ -9, -99, -999, -9999 }, @as(i32, -11106));
- doTheTestReduce(.Add, [4]u32{ 9, 99, 999, 9999 }, @as(u32, 11106));
- doTheTestReduce(.Add, [4]i64{ -9, -99, -999, -9999 }, @as(i64, -11106));
- doTheTestReduce(.Add, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 11106));
- doTheTestReduce(.Add, [4]i128{ -9, -99, -999, -9999 }, @as(i128, -11106));
- doTheTestReduce(.Add, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 11106));
- doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 42.9));
- doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 42.9));
- doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 42.9));
+ fn doTheTest() !void {
+ try doTheTestReduce(.Add, [4]i16{ -9, -99, -999, -9999 }, @as(i32, -11106));
+ try doTheTestReduce(.Add, [4]u16{ 9, 99, 999, 9999 }, @as(u32, 11106));
+ try doTheTestReduce(.Add, [4]i32{ -9, -99, -999, -9999 }, @as(i32, -11106));
+ try doTheTestReduce(.Add, [4]u32{ 9, 99, 999, 9999 }, @as(u32, 11106));
+ try doTheTestReduce(.Add, [4]i64{ -9, -99, -999, -9999 }, @as(i64, -11106));
+ try doTheTestReduce(.Add, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 11106));
+ try doTheTestReduce(.Add, [4]i128{ -9, -99, -999, -9999 }, @as(i128, -11106));
+ try doTheTestReduce(.Add, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 11106));
+ try doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 42.9));
+ try doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 42.9));
+ try doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 42.9));
- doTheTestReduce(.And, [4]bool{ true, false, true, true }, @as(bool, false));
- doTheTestReduce(.And, [4]u1{ 1, 0, 1, 1 }, @as(u1, 0));
- doTheTestReduce(.And, [4]u16{ 0xffff, 0xff55, 0xaaff, 0x1010 }, @as(u16, 0x10));
- doTheTestReduce(.And, [4]u32{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u32, 0x1010));
- doTheTestReduce(.And, [4]u64{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u64, 0x1010));
+ try doTheTestReduce(.And, [4]bool{ true, false, true, true }, @as(bool, false));
+ try doTheTestReduce(.And, [4]u1{ 1, 0, 1, 1 }, @as(u1, 0));
+ try doTheTestReduce(.And, [4]u16{ 0xffff, 0xff55, 0xaaff, 0x1010 }, @as(u16, 0x10));
+ try doTheTestReduce(.And, [4]u32{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u32, 0x1010));
+ try doTheTestReduce(.And, [4]u64{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u64, 0x1010));
- doTheTestReduce(.Min, [4]i16{ -1, 2, 3, 4 }, @as(i16, -1));
- doTheTestReduce(.Min, [4]u16{ 1, 2, 3, 4 }, @as(u16, 1));
- doTheTestReduce(.Min, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, -386));
- doTheTestReduce(.Min, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 9));
+ try doTheTestReduce(.Min, [4]i16{ -1, 2, 3, 4 }, @as(i16, -1));
+ try doTheTestReduce(.Min, [4]u16{ 1, 2, 3, 4 }, @as(u16, 1));
+ try doTheTestReduce(.Min, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, -386));
+ try doTheTestReduce(.Min, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 9));
// LLVM 11 ERROR: Cannot select type
// https://github.com/ziglang/zig/issues/7138
if (std.builtin.arch != .aarch64) {
- doTheTestReduce(.Min, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, -386));
- doTheTestReduce(.Min, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 9));
+ try doTheTestReduce(.Min, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, -386));
+ try doTheTestReduce(.Min, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 9));
}
- doTheTestReduce(.Min, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, -386));
- doTheTestReduce(.Min, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 9));
- doTheTestReduce(.Min, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, -100.0));
- doTheTestReduce(.Min, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, -100.0));
- doTheTestReduce(.Min, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, -100.0));
+ try doTheTestReduce(.Min, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, -386));
+ try doTheTestReduce(.Min, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 9));
+ try doTheTestReduce(.Min, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, -100.0));
+ try doTheTestReduce(.Min, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, -100.0));
+ try doTheTestReduce(.Min, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, -100.0));
- doTheTestReduce(.Max, [4]i16{ -1, 2, 3, 4 }, @as(i16, 4));
- doTheTestReduce(.Max, [4]u16{ 1, 2, 3, 4 }, @as(u16, 4));
- doTheTestReduce(.Max, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, 1234567));
- doTheTestReduce(.Max, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 99999));
+ try doTheTestReduce(.Max, [4]i16{ -1, 2, 3, 4 }, @as(i16, 4));
+ try doTheTestReduce(.Max, [4]u16{ 1, 2, 3, 4 }, @as(u16, 4));
+ try doTheTestReduce(.Max, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, 1234567));
+ try doTheTestReduce(.Max, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 99999));
// LLVM 11 ERROR: Cannot select type
// https://github.com/ziglang/zig/issues/7138
if (std.builtin.arch != .aarch64) {
- doTheTestReduce(.Max, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, 1234567));
- doTheTestReduce(.Max, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 99999));
+ try doTheTestReduce(.Max, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, 1234567));
+ try doTheTestReduce(.Max, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 99999));
}
- doTheTestReduce(.Max, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, 1234567));
- doTheTestReduce(.Max, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 99999));
- doTheTestReduce(.Max, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, 10.0e9));
- doTheTestReduce(.Max, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, 10.0e9));
- doTheTestReduce(.Max, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, 10.0e9));
+ try doTheTestReduce(.Max, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, 1234567));
+ try doTheTestReduce(.Max, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 99999));
+ try doTheTestReduce(.Max, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, 10.0e9));
+ try doTheTestReduce(.Max, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, 10.0e9));
+ try doTheTestReduce(.Max, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, 10.0e9));
- doTheTestReduce(.Mul, [4]i16{ -1, 2, 3, 4 }, @as(i16, -24));
- doTheTestReduce(.Mul, [4]u16{ 1, 2, 3, 4 }, @as(u16, 24));
- doTheTestReduce(.Mul, [4]i32{ -9, -99, -999, 999 }, @as(i32, -889218891));
- doTheTestReduce(.Mul, [4]u32{ 1, 2, 3, 4 }, @as(u32, 24));
- doTheTestReduce(.Mul, [4]i64{ 9, 99, 999, 9999 }, @as(i64, 8900199891));
- doTheTestReduce(.Mul, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 8900199891));
- doTheTestReduce(.Mul, [4]i128{ -9, -99, -999, 9999 }, @as(i128, -8900199891));
- doTheTestReduce(.Mul, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 8900199891));
- doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 58430.7));
- doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 58430.7));
- doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 58430.7));
+ try doTheTestReduce(.Mul, [4]i16{ -1, 2, 3, 4 }, @as(i16, -24));
+ try doTheTestReduce(.Mul, [4]u16{ 1, 2, 3, 4 }, @as(u16, 24));
+ try doTheTestReduce(.Mul, [4]i32{ -9, -99, -999, 999 }, @as(i32, -889218891));
+ try doTheTestReduce(.Mul, [4]u32{ 1, 2, 3, 4 }, @as(u32, 24));
+ try doTheTestReduce(.Mul, [4]i64{ 9, 99, 999, 9999 }, @as(i64, 8900199891));
+ try doTheTestReduce(.Mul, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 8900199891));
+ try doTheTestReduce(.Mul, [4]i128{ -9, -99, -999, 9999 }, @as(i128, -8900199891));
+ try doTheTestReduce(.Mul, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 8900199891));
+ try doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 58430.7));
+ try doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 58430.7));
+ try doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 58430.7));
- doTheTestReduce(.Or, [4]bool{ false, true, false, false }, @as(bool, true));
- doTheTestReduce(.Or, [4]u1{ 0, 1, 0, 0 }, @as(u1, 1));
- doTheTestReduce(.Or, [4]u16{ 0xff00, 0xff00, 0xf0, 0xf }, ~@as(u16, 0));
- doTheTestReduce(.Or, [4]u32{ 0xffff0000, 0xff00, 0xf0, 0xf }, ~@as(u32, 0));
- doTheTestReduce(.Or, [4]u64{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u64, 0xffffffff));
- doTheTestReduce(.Or, [4]u128{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u128, 0xffffffff));
+ try doTheTestReduce(.Or, [4]bool{ false, true, false, false }, @as(bool, true));
+ try doTheTestReduce(.Or, [4]u1{ 0, 1, 0, 0 }, @as(u1, 1));
+ try doTheTestReduce(.Or, [4]u16{ 0xff00, 0xff00, 0xf0, 0xf }, ~@as(u16, 0));
+ try doTheTestReduce(.Or, [4]u32{ 0xffff0000, 0xff00, 0xf0, 0xf }, ~@as(u32, 0));
+ try doTheTestReduce(.Or, [4]u64{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u64, 0xffffffff));
+ try doTheTestReduce(.Or, [4]u128{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u128, 0xffffffff));
- doTheTestReduce(.Xor, [4]bool{ true, true, true, false }, @as(bool, true));
- doTheTestReduce(.Xor, [4]u1{ 1, 1, 1, 0 }, @as(u1, 1));
- doTheTestReduce(.Xor, [4]u16{ 0x0000, 0x3333, 0x8888, 0x4444 }, ~@as(u16, 0));
- doTheTestReduce(.Xor, [4]u32{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, ~@as(u32, 0));
- doTheTestReduce(.Xor, [4]u64{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u64, 0xffffffff));
- doTheTestReduce(.Xor, [4]u128{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u128, 0xffffffff));
+ try doTheTestReduce(.Xor, [4]bool{ true, true, true, false }, @as(bool, true));
+ try doTheTestReduce(.Xor, [4]u1{ 1, 1, 1, 0 }, @as(u1, 1));
+ try doTheTestReduce(.Xor, [4]u16{ 0x0000, 0x3333, 0x8888, 0x4444 }, ~@as(u16, 0));
+ try doTheTestReduce(.Xor, [4]u32{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, ~@as(u32, 0));
+ try doTheTestReduce(.Xor, [4]u64{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u64, 0xffffffff));
+ try doTheTestReduce(.Xor, [4]u128{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u128, 0xffffffff));
// Test the reduction on vectors containing NaNs.
const f16_nan = math.nan(f16);
const f32_nan = math.nan(f32);
const f64_nan = math.nan(f64);
- doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
- doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
- doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
+ try doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
+ try doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
+ try doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
// LLVM 11 ERROR: Cannot select type
// https://github.com/ziglang/zig/issues/7138
if (false) {
- doTheTestReduce(.Min, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
- doTheTestReduce(.Min, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
- doTheTestReduce(.Min, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
+ try doTheTestReduce(.Min, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
+ try doTheTestReduce(.Min, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
+ try doTheTestReduce(.Min, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
- doTheTestReduce(.Max, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
- doTheTestReduce(.Max, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
- doTheTestReduce(.Max, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
+ try doTheTestReduce(.Max, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
+ try doTheTestReduce(.Max, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
+ try doTheTestReduce(.Max, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
}
- doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
- doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
- doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
+ try doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
+ try doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
+ try doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
diff --git a/test/stage1/behavior/void.zig b/test/stage1/behavior/void.zig
index 80df9fe4f9..4f49d5fca1 100644
--- a/test/stage1/behavior/void.zig
+++ b/test/stage1/behavior/void.zig
@@ -13,14 +13,14 @@ test "compare void with void compile time known" {
.b = 1,
.c = {},
};
- expect(foo.a == {});
+ try expect(foo.a == {});
}
}
test "iterate over a void slice" {
var j: usize = 0;
for (times(10)) |_, i| {
- expect(i == j);
+ try expect(i == j);
j += 1;
}
}
@@ -31,7 +31,7 @@ fn times(n: usize) []const void {
test "void optional" {
var x: ?void = {};
- expect(x != null);
+ try expect(x != null);
}
test "void array as a local variable initializer" {
diff --git a/test/stage1/behavior/wasm.zig b/test/stage1/behavior/wasm.zig
index 24557ee19b..2190295514 100644
--- a/test/stage1/behavior/wasm.zig
+++ b/test/stage1/behavior/wasm.zig
@@ -3,6 +3,6 @@ const expect = std.testing.expect;
test "memory size and grow" {
var prev = @wasmMemorySize(0);
- expect(prev == @wasmMemoryGrow(0, 1));
- expect(prev + 1 == @wasmMemorySize(0));
+ try expect(prev == @wasmMemoryGrow(0, 1));
+ try expect(prev + 1 == @wasmMemorySize(0));
}
diff --git a/test/stage1/behavior/while.zig b/test/stage1/behavior/while.zig
index c9207396f7..a237b4b866 100644
--- a/test/stage1/behavior/while.zig
+++ b/test/stage1/behavior/while.zig
@@ -6,8 +6,8 @@ test "while loop" {
while (i < 4) {
i += 1;
}
- expect(i == 4);
- expect(whileLoop1() == 1);
+ try expect(i == 4);
+ try expect(whileLoop1() == 1);
}
fn whileLoop1() i32 {
return whileLoop2();
@@ -19,7 +19,7 @@ fn whileLoop2() i32 {
}
test "static eval while" {
- expect(static_eval_while_number == 1);
+ try expect(static_eval_while_number == 1);
}
const static_eval_while_number = staticWhileLoop1();
fn staticWhileLoop1() i32 {
@@ -32,11 +32,11 @@ fn staticWhileLoop2() i32 {
}
test "continue and break" {
- runContinueAndBreakTest();
- expect(continue_and_break_counter == 8);
+ try runContinueAndBreakTest();
+ try expect(continue_and_break_counter == 8);
}
var continue_and_break_counter: i32 = 0;
-fn runContinueAndBreakTest() void {
+fn runContinueAndBreakTest() !void {
var i: i32 = 0;
while (true) {
continue_and_break_counter += 2;
@@ -46,7 +46,7 @@ fn runContinueAndBreakTest() void {
}
break;
}
- expect(i == 4);
+ try expect(i == 4);
}
test "return with implicit cast from while loop" {
@@ -67,7 +67,7 @@ test "while with continue expression" {
sum += i;
}
}
- expect(sum == 40);
+ try expect(sum == 40);
}
test "while with else" {
@@ -79,8 +79,8 @@ test "while with else" {
} else {
got_else += 1;
}
- expect(sum == 10);
- expect(got_else == 1);
+ try expect(sum == 10);
+ try expect(got_else == 1);
}
test "while with optional as condition" {
@@ -89,7 +89,7 @@ test "while with optional as condition" {
while (getNumberOrNull()) |value| {
sum += value;
}
- expect(sum == 45);
+ try expect(sum == 45);
}
test "while with optional as condition with else" {
@@ -98,12 +98,12 @@ test "while with optional as condition with else" {
var got_else: i32 = 0;
while (getNumberOrNull()) |value| {
sum += value;
- expect(got_else == 0);
+ try expect(got_else == 0);
} else {
got_else += 1;
}
- expect(sum == 45);
- expect(got_else == 1);
+ try expect(sum == 45);
+ try expect(got_else == 1);
}
test "while with error union condition" {
@@ -113,11 +113,11 @@ test "while with error union condition" {
while (getNumberOrErr()) |value| {
sum += value;
} else |err| {
- expect(err == error.OutOfNumbers);
+ try expect(err == error.OutOfNumbers);
got_else += 1;
}
- expect(sum == 45);
- expect(got_else == 1);
+ try expect(sum == 45);
+ try expect(got_else == 1);
}
var numbers_left: i32 = undefined;
@@ -137,49 +137,43 @@ fn getNumberOrNull() ?i32 {
test "while on optional with else result follow else prong" {
const result = while (returnNull()) |value| {
break value;
- } else
- @as(i32, 2);
- expect(result == 2);
+ } else @as(i32, 2);
+ try expect(result == 2);
}
test "while on optional with else result follow break prong" {
const result = while (returnOptional(10)) |value| {
break value;
- } else
- @as(i32, 2);
- expect(result == 10);
+ } else @as(i32, 2);
+ try expect(result == 10);
}
test "while on error union with else result follow else prong" {
const result = while (returnError()) |value| {
break value;
- } else |err|
- @as(i32, 2);
- expect(result == 2);
+ } else |err| @as(i32, 2);
+ try expect(result == 2);
}
test "while on error union with else result follow break prong" {
const result = while (returnSuccess(10)) |value| {
break value;
- } else |err|
- @as(i32, 2);
- expect(result == 10);
+ } else |err| @as(i32, 2);
+ try expect(result == 10);
}
test "while on bool with else result follow else prong" {
const result = while (returnFalse()) {
break @as(i32, 10);
- } else
- @as(i32, 2);
- expect(result == 2);
+ } else @as(i32, 2);
+ try expect(result == 2);
}
test "while on bool with else result follow break prong" {
const result = while (returnTrue()) {
break @as(i32, 10);
- } else
- @as(i32, 2);
- expect(result == 10);
+ } else @as(i32, 2);
+ try expect(result == 10);
}
test "break from outer while loop" {
@@ -230,60 +224,60 @@ fn returnTrue() bool {
test "while bool 2 break statements and an else" {
const S = struct {
- fn entry(t: bool, f: bool) void {
+ fn entry(t: bool, f: bool) !void {
var ok = false;
ok = while (t) {
if (f) break false;
if (t) break true;
} else false;
- expect(ok);
+ try expect(ok);
}
};
- S.entry(true, false);
- comptime S.entry(true, false);
+ try S.entry(true, false);
+ comptime try S.entry(true, false);
}
test "while optional 2 break statements and an else" {
const S = struct {
- fn entry(opt_t: ?bool, f: bool) void {
+ fn entry(opt_t: ?bool, f: bool) !void {
var ok = false;
ok = while (opt_t) |t| {
if (f) break false;
if (t) break true;
} else false;
- expect(ok);
+ try expect(ok);
}
};
- S.entry(true, false);
- comptime S.entry(true, false);
+ try S.entry(true, false);
+ comptime try S.entry(true, false);
}
test "while error 2 break statements and an else" {
const S = struct {
- fn entry(opt_t: anyerror!bool, f: bool) void {
+ fn entry(opt_t: anyerror!bool, f: bool) !void {
var ok = false;
ok = while (opt_t) |t| {
if (f) break false;
if (t) break true;
} else |_| false;
- expect(ok);
+ try expect(ok);
}
};
- S.entry(true, false);
- comptime S.entry(true, false);
+ try S.entry(true, false);
+ comptime try S.entry(true, false);
}
test "while copies its payload" {
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var tmp: ?i32 = 10;
while (tmp) |value| {
// Modify the original variable
tmp = null;
- expect(value == 10);
+ try expect(value == 10);
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
diff --git a/test/stage1/behavior/widening.zig b/test/stage1/behavior/widening.zig
index 2f215ccb11..b703291a88 100644
--- a/test/stage1/behavior/widening.zig
+++ b/test/stage1/behavior/widening.zig
@@ -9,13 +9,13 @@ test "integer widening" {
var d: u64 = c;
var e: u64 = d;
var f: u128 = e;
- expect(f == a);
+ try expect(f == a);
}
test "implicit unsigned integer to signed integer" {
var a: u8 = 250;
var b: i16 = a;
- expect(b == 250);
+ try expect(b == 250);
}
test "float widening" {
@@ -23,9 +23,9 @@ test "float widening" {
var b: f32 = a;
var c: f64 = b;
var d: f128 = c;
- expect(a == b);
- expect(b == c);
- expect(c == d);
+ try expect(a == b);
+ try expect(b == c);
+ try expect(c == d);
}
test "float widening f16 to f128" {
@@ -35,5 +35,5 @@ test "float widening f16 to f128" {
var x: f16 = 12.34;
var y: f128 = x;
- expect(x == y);
+ try expect(x == y);
}
diff --git a/test/stage1/c_abi/main.zig b/test/stage1/c_abi/main.zig
index 51fcc406ee..3be6d9c1cd 100644
--- a/test/stage1/c_abi/main.zig
+++ b/test/stage1/c_abi/main.zig
@@ -24,11 +24,11 @@ extern fn c_i64(i64) void;
extern fn c_five_integers(i32, i32, i32, i32, i32) void;
export fn zig_five_integers(a: i32, b: i32, c: i32, d: i32, e: i32) void {
- expect(a == 12);
- expect(b == 34);
- expect(c == 56);
- expect(d == 78);
- expect(e == 90);
+ expect(a == 12) catch @panic("test failure");
+ expect(b == 34) catch @panic("test failure");
+ expect(c == 56) catch @panic("test failure");
+ expect(d == 78) catch @panic("test failure");
+ expect(e == 90) catch @panic("test failure");
}
test "C ABI integers" {
@@ -45,28 +45,28 @@ test "C ABI integers" {
}
export fn zig_u8(x: u8) void {
- expect(x == 0xff);
+ expect(x == 0xff) catch @panic("test failure");
}
export fn zig_u16(x: u16) void {
- expect(x == 0xfffe);
+ expect(x == 0xfffe) catch @panic("test failure");
}
export fn zig_u32(x: u32) void {
- expect(x == 0xfffffffd);
+ expect(x == 0xfffffffd) catch @panic("test failure");
}
export fn zig_u64(x: u64) void {
- expect(x == 0xfffffffffffffffc);
+ expect(x == 0xfffffffffffffffc) catch @panic("test failure");
}
export fn zig_i8(x: i8) void {
- expect(x == -1);
+ expect(x == -1) catch @panic("test failure");
}
export fn zig_i16(x: i16) void {
- expect(x == -2);
+ expect(x == -2) catch @panic("test failure");
}
export fn zig_i32(x: i32) void {
- expect(x == -3);
+ expect(x == -3) catch @panic("test failure");
}
export fn zig_i64(x: i64) void {
- expect(x == -4);
+ expect(x == -4) catch @panic("test failure");
}
extern fn c_f32(f32) void;
@@ -76,11 +76,11 @@ extern fn c_f64(f64) void;
extern fn c_five_floats(f32, f32, f32, f32, f32) void;
export fn zig_five_floats(a: f32, b: f32, c: f32, d: f32, e: f32) void {
- expect(a == 1.0);
- expect(b == 2.0);
- expect(c == 3.0);
- expect(d == 4.0);
- expect(e == 5.0);
+ expect(a == 1.0) catch @panic("test failure");
+ expect(b == 2.0) catch @panic("test failure");
+ expect(c == 3.0) catch @panic("test failure");
+ expect(d == 4.0) catch @panic("test failure");
+ expect(e == 5.0) catch @panic("test failure");
}
test "C ABI floats" {
@@ -90,10 +90,10 @@ test "C ABI floats" {
}
export fn zig_f32(x: f32) void {
- expect(x == 12.34);
+ expect(x == 12.34) catch @panic("test failure");
}
export fn zig_f64(x: f64) void {
- expect(x == 56.78);
+ expect(x == 56.78) catch @panic("test failure");
}
extern fn c_ptr(*c_void) void;
@@ -103,7 +103,7 @@ test "C ABI pointer" {
}
export fn zig_ptr(x: *c_void) void {
- expect(@ptrToInt(x) == 0xdeadbeef);
+ expect(@ptrToInt(x) == 0xdeadbeef) catch @panic("test failure");
}
extern fn c_bool(bool) void;
@@ -113,7 +113,7 @@ test "C ABI bool" {
}
export fn zig_bool(x: bool) void {
- expect(x);
+ expect(x) catch @panic("test failure");
}
const BigStruct = extern struct {
@@ -137,11 +137,11 @@ test "C ABI big struct" {
}
export fn zig_big_struct(x: BigStruct) void {
- expect(x.a == 1);
- expect(x.b == 2);
- expect(x.c == 3);
- expect(x.d == 4);
- expect(x.e == 5);
+ expect(x.a == 1) catch @panic("test failure");
+ expect(x.b == 2) catch @panic("test failure");
+ expect(x.c == 3) catch @panic("test failure");
+ expect(x.d == 4) catch @panic("test failure");
+ expect(x.e == 5) catch @panic("test failure");
}
const BigUnion = extern union {
@@ -163,11 +163,11 @@ test "C ABI big union" {
}
export fn zig_big_union(x: BigUnion) void {
- expect(x.a.a == 1);
- expect(x.a.b == 2);
- expect(x.a.c == 3);
- expect(x.a.d == 4);
- expect(x.a.e == 5);
+ expect(x.a.a == 1) catch @panic("test failure");
+ expect(x.a.b == 2) catch @panic("test failure");
+ expect(x.a.c == 3) catch @panic("test failure");
+ expect(x.a.d == 4) catch @panic("test failure");
+ expect(x.a.e == 5) catch @panic("test failure");
}
const SmallStructInts = extern struct {
@@ -189,10 +189,10 @@ test "C ABI small struct of ints" {
}
export fn zig_small_struct_ints(x: SmallStructInts) void {
- expect(x.a == 1);
- expect(x.b == 2);
- expect(x.c == 3);
- expect(x.d == 4);
+ expect(x.a == 1) catch @panic("test failure");
+ expect(x.b == 2) catch @panic("test failure");
+ expect(x.c == 3) catch @panic("test failure");
+ expect(x.d == 4) catch @panic("test failure");
}
const SplitStructInt = extern struct {
@@ -212,9 +212,9 @@ test "C ABI split struct of ints" {
}
export fn zig_split_struct_ints(x: SplitStructInt) void {
- expect(x.a == 1234);
- expect(x.b == 100);
- expect(x.c == 1337);
+ expect(x.a == 1234) catch @panic("test failure");
+ expect(x.b == 100) catch @panic("test failure");
+ expect(x.c == 1337) catch @panic("test failure");
}
extern fn c_big_struct_both(BigStruct) BigStruct;
@@ -228,19 +228,19 @@ test "C ABI sret and byval together" {
.e = 5,
};
var y = c_big_struct_both(s);
- expect(y.a == 10);
- expect(y.b == 11);
- expect(y.c == 12);
- expect(y.d == 13);
- expect(y.e == 14);
+ try expect(y.a == 10);
+ try expect(y.b == 11);
+ try expect(y.c == 12);
+ try expect(y.d == 13);
+ try expect(y.e == 14);
}
export fn zig_big_struct_both(x: BigStruct) BigStruct {
- expect(x.a == 30);
- expect(x.b == 31);
- expect(x.c == 32);
- expect(x.d == 33);
- expect(x.e == 34);
+ expect(x.a == 30) catch @panic("test failure");
+ expect(x.b == 31) catch @panic("test failure");
+ expect(x.c == 32) catch @panic("test failure");
+ expect(x.d == 33) catch @panic("test failure");
+ expect(x.e == 34) catch @panic("test failure");
var s = BigStruct{
.a = 20,
.b = 21,
@@ -324,15 +324,15 @@ extern fn c_ret_i32() i32;
extern fn c_ret_i64() i64;
test "C ABI integer return types" {
- expect(c_ret_bool() == true);
+ try expect(c_ret_bool() == true);
- expect(c_ret_u8() == 0xff);
- expect(c_ret_u16() == 0xffff);
- expect(c_ret_u32() == 0xffffffff);
- expect(c_ret_u64() == 0xffffffffffffffff);
+ try expect(c_ret_u8() == 0xff);
+ try expect(c_ret_u16() == 0xffff);
+ try expect(c_ret_u32() == 0xffffffff);
+ try expect(c_ret_u64() == 0xffffffffffffffff);
- expect(c_ret_i8() == -1);
- expect(c_ret_i16() == -1);
- expect(c_ret_i32() == -1);
- expect(c_ret_i64() == -1);
+ try expect(c_ret_i8() == -1);
+ try expect(c_ret_i16() == -1);
+ try expect(c_ret_i32() == -1);
+ try expect(c_ret_i64() == -1);
}
diff --git a/test/standalone/brace_expansion/main.zig b/test/standalone/brace_expansion/main.zig
index 73c0e6fdae..990c2b1660 100644
--- a/test/standalone/brace_expansion/main.zig
+++ b/test/standalone/brace_expansion/main.zig
@@ -241,52 +241,52 @@ pub fn main() !void {
test "invalid inputs" {
global_allocator = std.testing.allocator;
- expectError("}ABC", error.InvalidInput);
- expectError("{ABC", error.InvalidInput);
- expectError("}{", error.InvalidInput);
- expectError("{}", error.InvalidInput);
- expectError("A,B,C", error.InvalidInput);
- expectError("{A{B,C}", error.InvalidInput);
- expectError("{A,}", error.InvalidInput);
+ try expectError("}ABC", error.InvalidInput);
+ try expectError("{ABC", error.InvalidInput);
+ try expectError("}{", error.InvalidInput);
+ try expectError("{}", error.InvalidInput);
+ try expectError("A,B,C", error.InvalidInput);
+ try expectError("{A{B,C}", error.InvalidInput);
+ try expectError("{A,}", error.InvalidInput);
- expectError("\n", error.InvalidInput);
+ try expectError("\n", error.InvalidInput);
}
-fn expectError(test_input: []const u8, expected_err: anyerror) void {
+fn expectError(test_input: []const u8, expected_err: anyerror) !void {
var output_buf = ArrayList(u8).init(global_allocator);
defer output_buf.deinit();
- testing.expectError(expected_err, expandString(test_input, &output_buf));
+ try testing.expectError(expected_err, expandString(test_input, &output_buf));
}
test "valid inputs" {
global_allocator = std.testing.allocator;
- expectExpansion("{x,y,z}", "x y z");
- expectExpansion("{A,B}{x,y}", "Ax Ay Bx By");
- expectExpansion("{A,B{x,y}}", "A Bx By");
+ try expectExpansion("{x,y,z}", "x y z");
+ try expectExpansion("{A,B}{x,y}", "Ax Ay Bx By");
+ try expectExpansion("{A,B{x,y}}", "A Bx By");
- expectExpansion("{ABC}", "ABC");
- expectExpansion("{A,B,C}", "A B C");
- expectExpansion("ABC", "ABC");
+ try expectExpansion("{ABC}", "ABC");
+ try expectExpansion("{A,B,C}", "A B C");
+ try expectExpansion("ABC", "ABC");
- expectExpansion("", "");
- expectExpansion("{A,B}{C,{x,y}}{g,h}", "ACg ACh Axg Axh Ayg Ayh BCg BCh Bxg Bxh Byg Byh");
- expectExpansion("{A,B}{C,C{x,y}}{g,h}", "ACg ACh ACxg ACxh ACyg ACyh BCg BCh BCxg BCxh BCyg BCyh");
- expectExpansion("{A,B}a", "Aa Ba");
- expectExpansion("{C,{x,y}}", "C x y");
- expectExpansion("z{C,{x,y}}", "zC zx zy");
- expectExpansion("a{b,c{d,e{f,g}}}", "ab acd acef aceg");
- expectExpansion("a{x,y}b", "axb ayb");
- expectExpansion("z{{a,b}}", "za zb");
- expectExpansion("a{b}", "ab");
+ try expectExpansion("", "");
+ try expectExpansion("{A,B}{C,{x,y}}{g,h}", "ACg ACh Axg Axh Ayg Ayh BCg BCh Bxg Bxh Byg Byh");
+ try expectExpansion("{A,B}{C,C{x,y}}{g,h}", "ACg ACh ACxg ACxh ACyg ACyh BCg BCh BCxg BCxh BCyg BCyh");
+ try expectExpansion("{A,B}a", "Aa Ba");
+ try expectExpansion("{C,{x,y}}", "C x y");
+ try expectExpansion("z{C,{x,y}}", "zC zx zy");
+ try expectExpansion("a{b,c{d,e{f,g}}}", "ab acd acef aceg");
+ try expectExpansion("a{x,y}b", "axb ayb");
+ try expectExpansion("z{{a,b}}", "za zb");
+ try expectExpansion("a{b}", "ab");
}
-fn expectExpansion(test_input: []const u8, expected_result: []const u8) void {
+fn expectExpansion(test_input: []const u8, expected_result: []const u8) !void {
var result = ArrayList(u8).init(global_allocator);
defer result.deinit();
expandString(test_input, &result) catch unreachable;
- testing.expectEqualSlices(u8, expected_result, result.items);
+ try testing.expectEqualSlices(u8, expected_result, result.items);
}
diff --git a/test/standalone/empty_env/main.zig b/test/standalone/empty_env/main.zig
index f4ebf56136..e0c647bb2c 100644
--- a/test/standalone/empty_env/main.zig
+++ b/test/standalone/empty_env/main.zig
@@ -1,6 +1,6 @@
const std = @import("std");
-pub fn main() void {
+pub fn main() !void {
const env_map = std.process.getEnvMap(std.testing.allocator) catch @panic("unable to get env map");
- std.testing.expect(env_map.count() == 0);
+ try std.testing.expect(env_map.count() == 0);
}
diff --git a/test/standalone/global_linkage/main.zig b/test/standalone/global_linkage/main.zig
index 53d953765b..cd2c1c31b2 100644
--- a/test/standalone/global_linkage/main.zig
+++ b/test/standalone/global_linkage/main.zig
@@ -4,6 +4,6 @@ extern var obj1_integer: usize;
extern var obj2_integer: usize;
test "access the external integers" {
- std.testing.expect(obj1_integer == 421);
- std.testing.expect(obj2_integer == 422);
+ try std.testing.expect(obj1_integer == 421);
+ try std.testing.expect(obj2_integer == 422);
}
diff --git a/test/standalone/issue_794/main.zig b/test/standalone/issue_794/main.zig
index 191bdc9b4f..d8c4364bf0 100644
--- a/test/standalone/issue_794/main.zig
+++ b/test/standalone/issue_794/main.zig
@@ -3,5 +3,5 @@ const std = @import("std");
const testing = std.testing;
test "c import" {
- comptime testing.expect(c.NUMBER == 1234);
+ comptime try testing.expect(c.NUMBER == 1234);
}
diff --git a/test/standalone/link_interdependent_static_c_libs/main.zig b/test/standalone/link_interdependent_static_c_libs/main.zig
index 1d8f854125..cb5d2e7b77 100644
--- a/test/standalone/link_interdependent_static_c_libs/main.zig
+++ b/test/standalone/link_interdependent_static_c_libs/main.zig
@@ -4,5 +4,5 @@ const c = @cImport(@cInclude("b.h"));
test "import C sub" {
const result = c.sub(2, 1);
- expect(result == 1);
+ try expect(result == 1);
}
diff --git a/test/standalone/static_c_lib/foo.zig b/test/standalone/static_c_lib/foo.zig
index a5ba90c95d..da02875408 100644
--- a/test/standalone/static_c_lib/foo.zig
+++ b/test/standalone/static_c_lib/foo.zig
@@ -4,9 +4,9 @@ const c = @cImport(@cInclude("foo.h"));
test "C add" {
const result = c.add(1, 2);
- expect(result == 3);
+ try expect(result == 3);
}
test "C extern variable" {
- expect(c.foo == 12345);
+ try expect(c.foo == 12345);
}
diff --git a/test/standalone/use_alias/main.zig b/test/standalone/use_alias/main.zig
index 75a8b5e81a..be9d6da6c3 100644
--- a/test/standalone/use_alias/main.zig
+++ b/test/standalone/use_alias/main.zig
@@ -6,5 +6,5 @@ test "symbol exists" {
.a = 1,
.b = 1,
};
- expect(foo.a + foo.b == 2);
+ try expect(foo.a + foo.b == 2);
}