| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | | const expectEqual = @import("std").testing.expectEqual; |
| 1 | const expect = @import("std").testing.expect; |
| 2 | const builtin = @import("builtin"); |
| 2 | 3 | |
| 3 | 4 | const FILE = extern struct { |
| 4 | 5 | dummy_field: u8, |
| ... | ... | @@ -16,18 +17,20 @@ const S = extern struct { |
| 16 | 17 | }; |
| 17 | 18 | |
| 18 | 19 | test "Extern function calls in @TypeOf" { |
| 20 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 21 | |
| 19 | 22 | const Test = struct { |
| 20 | 23 | fn test_fn_1(a: anytype, b: anytype) @TypeOf(printf("%d %s\n", a, b)) { |
| 21 | 24 | return 0; |
| 22 | 25 | } |
| 23 | 26 | |
| 24 | | fn test_fn_2(a: anytype) @TypeOf((S{ .state = 0 }).s_do_thing(a)) { |
| 27 | fn test_fn_2(s: anytype, a: anytype) @TypeOf(s.s_do_thing(a)) { |
| 25 | 28 | return 1; |
| 26 | 29 | } |
| 27 | 30 | |
| 28 | 31 | fn doTheTest() !void { |
| 29 | | try expectEqual(c_int, @TypeOf(test_fn_1(0, 42))); |
| 30 | | try expectEqual(c_short, @TypeOf(test_fn_2(0))); |
| 32 | try expect(@TypeOf(test_fn_1(0, 42)) == c_int); |
| 33 | try expect(@TypeOf(test_fn_2(&S{ .state = 1 }, 0)) == c_short); |
| 31 | 34 | } |
| 32 | 35 | }; |
| 33 | 36 | |
| ... | ... | @@ -36,13 +39,15 @@ test "Extern function calls in @TypeOf" { |
| 36 | 39 | } |
| 37 | 40 | |
| 38 | 41 | test "Peer resolution of extern function calls in @TypeOf" { |
| 42 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 43 | |
| 39 | 44 | const Test = struct { |
| 40 | 45 | fn test_fn() @TypeOf(ftell(null), fputs(null, null)) { |
| 41 | 46 | return 0; |
| 42 | 47 | } |
| 43 | 48 | |
| 44 | 49 | fn doTheTest() !void { |
| 45 | | try expectEqual(c_long, @TypeOf(test_fn())); |
| 50 | try expect(@TypeOf(test_fn()) == c_long); |
| 46 | 51 | } |
| 47 | 52 | }; |
| 48 | 53 | |
| ... | ... | @@ -51,6 +56,10 @@ test "Peer resolution of extern function calls in @TypeOf" { |
| 51 | 56 | } |
| 52 | 57 | |
| 53 | 58 | test "Extern function calls, dereferences and field access in @TypeOf" { |
| 59 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 60 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 61 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 62 | |
| 54 | 63 | const Test = struct { |
| 55 | 64 | fn test_fn_1(a: c_long) @TypeOf(fopen("test", "r").*) { |
| 56 | 65 | _ = a; |
| ... | ... | @@ -63,8 +72,8 @@ test "Extern function calls, dereferences and field access in @TypeOf" { |
| 63 | 72 | } |
| 64 | 73 | |
| 65 | 74 | fn doTheTest() !void { |
| 66 | | try expectEqual(FILE, @TypeOf(test_fn_1(0))); |
| 67 | | try expectEqual(u8, @TypeOf(test_fn_2(0))); |
| 75 | try expect(@TypeOf(test_fn_1(0)) == FILE); |
| 76 | try expect(@TypeOf(test_fn_2(0)) == u8); |
| 68 | 77 | } |
| 69 | 78 | }; |
| 70 | 79 | |