mirror of
https://github.com/ziglang/zig.git
synced 2024-11-24 13:20:14 +00:00
Compare commits
3 Commits
c18d0890f9
...
636ed6e3cf
Author | SHA1 | Date | |
---|---|---|---|
|
636ed6e3cf | ||
|
f845fa04a0 | ||
|
e723106522 |
@ -48,7 +48,8 @@ fn read(ma: *MemoryAccessor, address: usize, buf: []u8) bool {
|
|||||||
switch (linux.E.init(bytes_read)) {
|
switch (linux.E.init(bytes_read)) {
|
||||||
.SUCCESS => return bytes_read == buf.len,
|
.SUCCESS => return bytes_read == buf.len,
|
||||||
.FAULT => return false,
|
.FAULT => return false,
|
||||||
.INVAL, .PERM, .SRCH => unreachable, // own pid is always valid
|
.INVAL, .SRCH => unreachable, // own pid is always valid
|
||||||
|
.PERM => {}, // Known to happen in containers.
|
||||||
.NOMEM => {},
|
.NOMEM => {},
|
||||||
.NOSYS => {}, // QEMU is known not to implement this syscall.
|
.NOSYS => {}, // QEMU is known not to implement this syscall.
|
||||||
else => unreachable, // unexpected
|
else => unreachable, // unexpected
|
||||||
|
@ -125,7 +125,7 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
|
|||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
while (i < info.len) : (i += 1) {
|
while (i < info.len) : (i += 1) {
|
||||||
if (!std.meta.eql(expected[i], actual[i])) {
|
if (!std.meta.eql(expected[i], actual[i])) {
|
||||||
print("index {} incorrect. expected {}, found {}\n", .{
|
print("index {d} incorrect. expected {any}, found {any}\n", .{
|
||||||
i, expected[i], actual[i],
|
i, expected[i], actual[i],
|
||||||
});
|
});
|
||||||
return error.TestExpectedEqual;
|
return error.TestExpectedEqual;
|
||||||
@ -214,6 +214,34 @@ test "expectEqual union with comptime-only field" {
|
|||||||
try expectEqual(U{ .a = {} }, .a);
|
try expectEqual(U{ .a = {} }, .a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "expectEqual nested array" {
|
||||||
|
const a = [2][2]f32{
|
||||||
|
[_]f32{ 1.0, 0.0 },
|
||||||
|
[_]f32{ 0.0, 1.0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
const b = [2][2]f32{
|
||||||
|
[_]f32{ 1.0, 0.0 },
|
||||||
|
[_]f32{ 0.0, 1.0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
try expectEqual(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "expectEqual vector" {
|
||||||
|
const a: @Vector(4, u32) = @splat(4);
|
||||||
|
const b: @Vector(4, u32) = @splat(4);
|
||||||
|
|
||||||
|
try expectEqual(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "expectEqual null" {
|
||||||
|
const a = .{null};
|
||||||
|
const b = @Vector(1, ?*u8){null};
|
||||||
|
|
||||||
|
try expectEqual(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
/// This function is intended to be used only in tests. When the formatted result of the template
|
/// This function is intended to be used only in tests. When the formatted result of the template
|
||||||
/// and its arguments does not equal the expected text, it prints diagnostics to stderr to show how
|
/// and its arguments does not equal the expected text, it prints diagnostics to stderr to show how
|
||||||
/// they are not equal, then returns an error. It depends on `expectEqualStrings()` for printing
|
/// they are not equal, then returns an error. It depends on `expectEqualStrings()` for printing
|
||||||
@ -584,27 +612,6 @@ pub fn tmpDir(opts: std.fs.Dir.OpenOptions) TmpDir {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
test "expectEqual nested array" {
|
|
||||||
const a = [2][2]f32{
|
|
||||||
[_]f32{ 1.0, 0.0 },
|
|
||||||
[_]f32{ 0.0, 1.0 },
|
|
||||||
};
|
|
||||||
|
|
||||||
const b = [2][2]f32{
|
|
||||||
[_]f32{ 1.0, 0.0 },
|
|
||||||
[_]f32{ 0.0, 1.0 },
|
|
||||||
};
|
|
||||||
|
|
||||||
try expectEqual(a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
test "expectEqual vector" {
|
|
||||||
const a: @Vector(4, u32) = @splat(4);
|
|
||||||
const b: @Vector(4, u32) = @splat(4);
|
|
||||||
|
|
||||||
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| {
|
if (std.mem.indexOfDiff(u8, actual, expected)) |diff_index| {
|
||||||
print("\n====== expected this output: =========\n", .{});
|
print("\n====== expected this output: =========\n", .{});
|
||||||
|
Loading…
Reference in New Issue
Block a user