authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-19 01:11:35-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-12-19 01:11:35-05:00
log3bfae2a0d9503dbd832774c3b39a74dbd55e8b6e
tree241f91342fc5c646939ee7ed9d8446c4b6a14433
parentd1f61f2d6801240c593bcf5a3219020ecae0e736
parent6018a3ad397ad2104762b1c548866c2c2df2ac77
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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

add behavior test coverage

2 files changed, 52 insertions(+), 0 deletions(-)

test/behavior/error.zig+21
...@@ -287,6 +287,27 @@ test "inferred empty error set comptime catch" {...@@ -287,6 +287,27 @@ test "inferred empty error set comptime catch" {
287 S.foo() catch @compileError("fail");287 S.foo() catch @compileError("fail");
288}288}
289289
290test "error inference with an empty set" {
291 const S = struct {
292 const Struct = struct {
293 pub fn func() (error{})!usize {
294 return 0;
295 }
296 };
297
298 fn AnotherStruct(comptime SubStruct: type) type {
299 return struct {
300 fn anotherFunc() !void {
301 try expect(0 == (try SubStruct.func()));
302 }
303 };
304 }
305 };
306
307 const GeneratedStruct = S.AnotherStruct(S.Struct);
308 try GeneratedStruct.anotherFunc();
309}
310
290test "error union peer type resolution" {311test "error union peer type resolution" {
291 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO312 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
292 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO313 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
test/behavior/ptrcast.zig+31
...@@ -203,6 +203,37 @@ test "comptime ptrcast keeps larger alignment" {...@@ -203,6 +203,37 @@ test "comptime ptrcast keeps larger alignment" {
203 }203 }
204}204}
205205
206test "ptrcast of const integer has the correct object size" {
207 const is_value = ~@intCast(isize, std.math.minInt(isize));
208 const is_bytes = @ptrCast([*]const u8, &is_value)[0..@sizeOf(isize)];
209 if (@sizeOf(isize) == 8) {
210 switch (native_endian) {
211 .Little => {
212 try expect(is_bytes[0] == 0xff);
213 try expect(is_bytes[1] == 0xff);
214 try expect(is_bytes[2] == 0xff);
215 try expect(is_bytes[3] == 0xff);
216
217 try expect(is_bytes[4] == 0xff);
218 try expect(is_bytes[5] == 0xff);
219 try expect(is_bytes[6] == 0xff);
220 try expect(is_bytes[7] == 0x7f);
221 },
222 .Big => {
223 try expect(is_bytes[0] == 0x7f);
224 try expect(is_bytes[1] == 0xff);
225 try expect(is_bytes[2] == 0xff);
226 try expect(is_bytes[3] == 0xff);
227
228 try expect(is_bytes[4] == 0xff);
229 try expect(is_bytes[5] == 0xff);
230 try expect(is_bytes[6] == 0xff);
231 try expect(is_bytes[7] == 0xff);
232 },
233 }
234 }
235}
236
206test "implicit optional pointer to optional anyopaque pointer" {237test "implicit optional pointer to optional anyopaque pointer" {
207 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO238 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
208 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO239 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO