authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-27 21:47:17-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-12-27 21:47:17-05:00
log3f1cfcbea873263c480696288d8cacd288a9c919
treecfccfbb8cde780c15723ba173a6a0bdd03ee8b9e
parentb1207b3293968da4da12c26c85384f10ff4d1c06
parent357235d9de9feb9d5b29d40574bce10e23382c79
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #14091 from ziglang/stage1-test-coverage

add more behavior test coverage

5 files changed, 55 insertions(+), 0 deletions(-)

test/behavior/array.zig+1
......@@ -61,6 +61,7 @@ test "array concat with undefined" {
6161}
6262
6363test "array concat with tuple" {
64 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
6465 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
6566 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
6667
test/behavior/bugs/12571.zig+1
......@@ -14,6 +14,7 @@ const Entry = packed struct {
1414test {
1515 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1616 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
17 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1718
1819 const frame = Frame{ .num = 0x7FDE };
1920 var entry = Entry{ .other = 0, .frame = .{ .num = 0xFFFFF } };
test/behavior/error.zig+13
......@@ -889,3 +889,16 @@ test "field access of anyerror results in smaller error set" {
889889 try expect(@TypeOf(E2.A) == E2);
890890 try expect(@TypeOf(@field(anyerror, "NotFound")) == error{NotFound});
891891}
892
893test "optional error union return type" {
894 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
895 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
896
897 const S = struct {
898 fn foo() ?anyerror!u32 {
899 var x: u32 = 1234;
900 return @as(anyerror!u32, x);
901 }
902 };
903 try expect(1234 == try S.foo().?);
904}
test/behavior/fn.zig+27
......@@ -457,3 +457,30 @@ test "method call with optional and error union first param" {
457457 try s.opt();
458458 try s.errUnion();
459459}
460
461test "using @ptrCast on function pointers" {
462 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
463 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
464 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
465 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
466
467 const S = struct {
468 const A = struct { data: [4]u8 };
469
470 fn at(arr: *const A, index: usize) *const u8 {
471 return &arr.data[index];
472 }
473
474 fn run() !void {
475 const a = A{ .data = "abcd".* };
476 const casted_fn = @ptrCast(*const fn (*const anyopaque, usize) *const u8, &at);
477 const casted_impl = @ptrCast(*const anyopaque, &a);
478 const ptr = casted_fn(casted_impl, 2);
479 try expect(ptr.* == 'c');
480 }
481 };
482
483 try S.run();
484 // https://github.com/ziglang/zig/issues/2626
485 // try comptime S.run();
486}
test/behavior/ptrcast.zig+13
......@@ -257,3 +257,16 @@ test "@ptrCast slice to slice" {
257257 try expect(buf[1] == 42);
258258 try expect(alias.len == 4);
259259}
260
261test "comptime @ptrCast a subset of an array, then write through it" {
262 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
263 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
264 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
265
266 comptime {
267 var buff: [16]u8 align(4) = undefined;
268 const len_bytes = @ptrCast(*u32, &buff);
269 len_bytes.* = 16;
270 std.mem.copy(u8, buff[4..], "abcdef");
271 }
272}