authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-22 14:50:31+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-22 14:52:26+03:00
log3f4197906190fe39d75f5e9bee2d9a7e5813f800
tree0876bb53a1d83e84fee1ef22ed2f502fe5bf0847
parent5e0b4836a1f48181b0d6df2b272add5aa79654c3

replace some panics with try in C ABI tests


1 files changed, 34 insertions(+), 34 deletions(-)

test/c_abi/main.zig+34-34
...@@ -181,8 +181,8 @@ test "C ABI complex float" {...@@ -181,8 +181,8 @@ test "C ABI complex float" {
181 const b = ComplexFloat{ .real = 11.3, .imag = -1.5 };181 const b = ComplexFloat{ .real = 11.3, .imag = -1.5 };
182182
183 const z = c_cmultf(a, b);183 const z = c_cmultf(a, b);
184 expect(z.real == 1.5) catch @panic("test failure: zig_complex_float 1");184 try expect(z.real == 1.5);
185 expect(z.imag == 13.5) catch @panic("test failure: zig_complex_float 2");185 try expect(z.imag == 13.5);
186}186}
187187
188test "C ABI complex float by component" {188test "C ABI complex float by component" {
...@@ -192,8 +192,8 @@ test "C ABI complex float by component" {...@@ -192,8 +192,8 @@ test "C ABI complex float by component" {
192 const b = ComplexFloat{ .real = 11.3, .imag = -1.5 };192 const b = ComplexFloat{ .real = 11.3, .imag = -1.5 };
193193
194 const z2 = c_cmultf_comp(a.real, a.imag, b.real, b.imag);194 const z2 = c_cmultf_comp(a.real, a.imag, b.real, b.imag);
195 expect(z2.real == 1.5) catch @panic("test failure: zig_complex_float 3");195 try expect(z2.real == 1.5);
196 expect(z2.imag == 13.5) catch @panic("test failure: zig_complex_float 4");196 try expect(z2.imag == 13.5);
197}197}
198198
199test "C ABI complex double" {199test "C ABI complex double" {
...@@ -203,8 +203,8 @@ test "C ABI complex double" {...@@ -203,8 +203,8 @@ test "C ABI complex double" {
203 const b = ComplexDouble{ .real = 11.3, .imag = -1.5 };203 const b = ComplexDouble{ .real = 11.3, .imag = -1.5 };
204204
205 const z = c_cmultd(a, b);205 const z = c_cmultd(a, b);
206 expect(z.real == 1.5) catch @panic("test failure: zig_complex_double 1");206 try expect(z.real == 1.5);
207 expect(z.imag == 13.5) catch @panic("test failure: zig_complex_double 2");207 try expect(z.imag == 13.5);
208}208}
209209
210test "C ABI complex double by component" {210test "C ABI complex double by component" {
...@@ -214,8 +214,8 @@ test "C ABI complex double by component" {...@@ -214,8 +214,8 @@ test "C ABI complex double by component" {
214 const b = ComplexDouble{ .real = 11.3, .imag = -1.5 };214 const b = ComplexDouble{ .real = 11.3, .imag = -1.5 };
215215
216 const z = c_cmultd_comp(a.real, a.imag, b.real, b.imag);216 const z = c_cmultd_comp(a.real, a.imag, b.real, b.imag);
217 expect(z.real == 1.5) catch @panic("test failure: zig_complex_double 3");217 try expect(z.real == 1.5);
218 expect(z.imag == 13.5) catch @panic("test failure: zig_complex_double 4");218 try expect(z.imag == 13.5);
219}219}
220220
221export fn zig_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat {221export fn zig_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat {
...@@ -335,9 +335,9 @@ test "C ABI medium struct of ints and floats" {...@@ -335,9 +335,9 @@ test "C ABI medium struct of ints and floats" {
335 };335 };
336 c_med_struct_mixed(s);336 c_med_struct_mixed(s);
337 var s2 = c_ret_med_struct_mixed();337 var s2 = c_ret_med_struct_mixed();
338 expect(s2.a == 1234) catch @panic("test failure");338 try expect(s2.a == 1234);
339 expect(s2.b == 100.0) catch @panic("test failure");339 try expect(s2.b == 100.0);
340 expect(s2.c == 1337.0) catch @panic("test failure");340 try expect(s2.c == 1337.0);
341}341}
342342
343export fn zig_med_struct_mixed(x: MedStructMixed) void {343export fn zig_med_struct_mixed(x: MedStructMixed) void {
...@@ -369,10 +369,10 @@ test "C ABI small struct of ints" {...@@ -369,10 +369,10 @@ test "C ABI small struct of ints" {
369 };369 };
370 c_small_struct_ints(s);370 c_small_struct_ints(s);
371 var s2 = c_ret_small_struct_ints();371 var s2 = c_ret_small_struct_ints();
372 expect(s2.a == 1) catch @panic("test failure");372 try expect(s2.a == 1);
373 expect(s2.b == 2) catch @panic("test failure");373 try expect(s2.b == 2);
374 expect(s2.c == 3) catch @panic("test failure");374 try expect(s2.c == 3);
375 expect(s2.d == 4) catch @panic("test failure");375 try expect(s2.d == 4);
376}376}
377377
378export fn zig_small_struct_ints(x: SmallStructInts) void {378export fn zig_small_struct_ints(x: SmallStructInts) void {
...@@ -478,9 +478,9 @@ test "C ABI split struct of ints and floats" {...@@ -478,9 +478,9 @@ test "C ABI split struct of ints and floats" {
478 };478 };
479 c_split_struct_mixed(s);479 c_split_struct_mixed(s);
480 var s2 = c_ret_split_struct_mixed();480 var s2 = c_ret_split_struct_mixed();
481 expect(s2.a == 1234) catch @panic("test failure");481 try expect(s2.a == 1234);
482 expect(s2.b == 100) catch @panic("test failure");482 try expect(s2.b == 100);
483 expect(s2.c == 1337.0) catch @panic("test failure");483 try expect(s2.c == 1337.0);
484}484}
485485
486export fn zig_split_struct_mixed(x: SplitStructMixed) void {486export fn zig_split_struct_mixed(x: SplitStructMixed) void {
...@@ -737,8 +737,8 @@ test "Struct with array as padding." {...@@ -737,8 +737,8 @@ test "Struct with array as padding." {
737 c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 });737 c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 });
738738
739 var x = c_ret_struct_with_array();739 var x = c_ret_struct_with_array();
740 try std.testing.expect(x.a == 4);740 try expect(x.a == 4);
741 try std.testing.expect(x.b == 155);741 try expect(x.b == 155);
742}742}
743743
744const FloatArrayStruct = extern struct {744const FloatArrayStruct = extern struct {
...@@ -771,10 +771,10 @@ test "Float array like struct" {...@@ -771,10 +771,10 @@ test "Float array like struct" {
771 });771 });
772772
773 var x = c_ret_float_array_struct();773 var x = c_ret_float_array_struct();
774 try std.testing.expect(x.origin.x == 1);774 try expect(x.origin.x == 1);
775 try std.testing.expect(x.origin.y == 2);775 try expect(x.origin.y == 2);
776 try std.testing.expect(x.size.width == 3);776 try expect(x.size.width == 3);
777 try std.testing.expect(x.size.height == 4);777 try expect(x.size.height == 4);
778}778}
779779
780const SmallVec = @Vector(2, u32);780const SmallVec = @Vector(2, u32);
...@@ -789,8 +789,8 @@ test "small simd vector" {...@@ -789,8 +789,8 @@ test "small simd vector" {
789 c_small_vec(.{ 1, 2 });789 c_small_vec(.{ 1, 2 });
790790
791 var x = c_ret_small_vec();791 var x = c_ret_small_vec();
792 try std.testing.expect(x[0] == 3);792 try expect(x[0] == 3);
793 try std.testing.expect(x[1] == 4);793 try expect(x[1] == 4);
794}794}
795795
796const BigVec = @Vector(8, usize);796const BigVec = @Vector(8, usize);
...@@ -804,12 +804,12 @@ test "big simd vector" {...@@ -804,12 +804,12 @@ test "big simd vector" {
804 c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 });804 c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 });
805805
806 var x = c_ret_big_vec();806 var x = c_ret_big_vec();
807 try std.testing.expect(x[0] == 9);807 try expect(x[0] == 9);
808 try std.testing.expect(x[1] == 10);808 try expect(x[1] == 10);
809 try std.testing.expect(x[2] == 11);809 try expect(x[2] == 11);
810 try std.testing.expect(x[3] == 12);810 try expect(x[3] == 12);
811 try std.testing.expect(x[4] == 13);811 try expect(x[4] == 13);
812 try std.testing.expect(x[5] == 14);812 try expect(x[5] == 14);
813 try std.testing.expect(x[6] == 15);813 try expect(x[6] == 15);
814 try std.testing.expect(x[7] == 16);814 try expect(x[7] == 16);
815}815}