Merge pull request #13810 from r00ster91/old

Re-enable many previously failing tests and add test coverage
This commit is contained in:
Andrew Kelley 2022-12-10 15:07:51 -05:00 committed by GitHub
commit f1f17dc1c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 289 additions and 62 deletions

View File

@ -6242,10 +6242,6 @@ test "implicit unsigned integer to signed integer" {
}
test "float widening" {
// Note: there is an open issue preventing this from working on aarch64:
// https://github.com/ziglang/zig/issues/3282
if (builtin.target.cpu.arch == .aarch64) return error.SkipZigTest;
var a: f16 = 12.34;
var b: f32 = a;
var c: f64 = b;

View File

@ -70,11 +70,6 @@ test "fmt.parseFloat" {
}
test "fmt.parseFloat nan and inf" {
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
// https://github.com/ziglang/zig/issues/12027
return error.SkipZigTest;
}
inline for ([_]type{ f16, f32, f64, f128 }) |T| {
const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);

View File

@ -523,10 +523,6 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
}
test "shl" {
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
// https://github.com/ziglang/zig/issues/12012
return error.SkipZigTest;
}
try testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
try testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
try testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
@ -567,10 +563,6 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
}
test "shr" {
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
// https://github.com/ziglang/zig/issues/12012
return error.SkipZigTest;
}
try testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
try testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
try testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
@ -612,10 +604,6 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
}
test "rotr" {
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
// https://github.com/ziglang/zig/issues/12012
return error.SkipZigTest;
}
try testing.expect(rotr(u0, 0b0, @as(usize, 3)) == 0b0);
try testing.expect(rotr(u5, 0b00001, @as(usize, 0)) == 0b00001);
try testing.expect(rotr(u6, 0b000001, @as(usize, 7)) == 0b100000);
@ -656,10 +644,6 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
}
test "rotl" {
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
// https://github.com/ziglang/zig/issues/12012
return error.SkipZigTest;
}
try testing.expect(rotl(u0, 0b0, @as(usize, 3)) == 0b0);
try testing.expect(rotl(u5, 0b00001, @as(usize, 0)) == 0b00001);
try testing.expect(rotl(u6, 0b000001, @as(usize, 7)) == 0b000010);

View File

@ -412,10 +412,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
}
test "SegmentedList basic usage" {
if (false) {
// https://github.com/ziglang/zig/issues/11787
try testSegmentedList(0);
}
try testSegmentedList(0);
try testSegmentedList(1);
try testSegmentedList(2);
try testSegmentedList(4);

View File

@ -191,10 +191,6 @@ pub fn extract(
}
test "vector patterns" {
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
// https://github.com/ziglang/zig/issues/12012
return error.SkipZigTest;
}
const base = @Vector(4, u32){ 10, 20, 30, 40 };
const other_base = @Vector(4, u32){ 55, 66, 77, 88 };

View File

@ -43,7 +43,9 @@ test {
_ = @import("behavior/bugs/2346.zig");
_ = @import("behavior/bugs/2557.zig");
_ = @import("behavior/bugs/2578.zig");
_ = @import("behavior/bugs/2622.zig");
_ = @import("behavior/bugs/2692.zig");
_ = @import("behavior/bugs/2727.zig");
_ = @import("behavior/bugs/2889.zig");
_ = @import("behavior/bugs/3007.zig");
_ = @import("behavior/bugs/3046.zig");
@ -62,16 +64,22 @@ test {
_ = @import("behavior/bugs/5413.zig");
_ = @import("behavior/bugs/5474.zig");
_ = @import("behavior/bugs/5487.zig");
_ = @import("behavior/bugs/6047.zig");
_ = @import("behavior/bugs/6456.zig");
_ = @import("behavior/bugs/6781.zig");
_ = @import("behavior/bugs/6850.zig");
_ = @import("behavior/bugs/6905.zig");
_ = @import("behavior/bugs/6947.zig");
_ = @import("behavior/bugs/7003.zig");
_ = @import("behavior/bugs/7047.zig");
_ = @import("behavior/bugs/7187.zig");
_ = @import("behavior/bugs/7325.zig");
_ = @import("behavior/bugs/8646.zig");
_ = @import("behavior/bugs/9584.zig");
_ = @import("behavior/bugs/10138.zig");
_ = @import("behavior/bugs/10147.zig");
_ = @import("behavior/bugs/10970.zig");
_ = @import("behavior/bugs/10684.zig");
_ = @import("behavior/bugs/11046.zig");
_ = @import("behavior/bugs/11100.zig");
_ = @import("behavior/bugs/11139.zig");
@ -81,6 +89,7 @@ test {
_ = @import("behavior/bugs/11179.zig");
_ = @import("behavior/bugs/11181.zig");
_ = @import("behavior/bugs/11213.zig");
_ = @import("behavior/bugs/11787.zig");
_ = @import("behavior/bugs/11816.zig");
_ = @import("behavior/bugs/12003.zig");
_ = @import("behavior/bugs/12025.zig");

View File

@ -151,11 +151,6 @@ test "cmpxchg on a global variable" {
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
// https://github.com/ziglang/zig/issues/10627
return error.SkipZigTest;
}
_ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);
try expect(a_global_variable == 42);
}
@ -218,12 +213,6 @@ test "atomicrmw with floats" {
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if ((builtin.zig_backend == .stage2_llvm or builtin.zig_backend == .stage2_c) and
builtin.cpu.arch == .aarch64)
{
// https://github.com/ziglang/zig/issues/10627
return error.SkipZigTest;
}
try testAtomicRmwFloat();
comptime try testAtomicRmwFloat();
}

View File

@ -0,0 +1,19 @@
const std = @import("std");
const builtin = @import("builtin");
const expectEqualStrings = std.testing.expectEqualStrings;
test "slicing slices" {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
const foo = "1234";
const bar = foo[0..4];
try expectEqualStrings("1234", bar);
try expectEqualStrings("2", bar[1..2]);
try expectEqualStrings("3", bar[2..3]);
try expectEqualStrings("4", bar[3..4]);
try expectEqualStrings("34", bar[2..4]);
}

View File

@ -0,0 +1,20 @@
const std = @import("std");
const builtin = @import("builtin");
const testing = std.testing;
test "slicing zero length array field of struct" {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
const S = struct {
a: [0]usize,
fn foo(self: *@This(), start: usize, end: usize) []usize {
return self.a[start..end];
}
};
var s: S = undefined;
try testing.expect(s.foo(0, 0).len == 0);
}

View File

@ -0,0 +1,16 @@
const builtin = @import("builtin");
var buf: []u8 = undefined;
test "reslice of undefined global var slice" {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
var mem: [100]u8 = [_]u8{0} ** 100;
buf = &mem;
const x = buf[0..1];
try @import("std").testing.expect(x.len == 1 and x[0] == 0);
}

View File

@ -0,0 +1,18 @@
const builtin = @import("builtin");
fn t() bool {
return true;
}
test {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
comptime var i: usize = 0;
inline while (i < 2) : (i += 1) {
if (t()) {} else return;
}
}

View File

@ -0,0 +1,20 @@
const builtin = @import("builtin");
fn getError() !void {
return error.Test;
}
fn getError2() !void {
var a: u8 = 'c';
try if (a == 'a') getError() else if (a == 'b') getError() else getError();
}
test "`try`ing an if/else expression" {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
try @import("std").testing.expectError(error.Test, getError2());
}

View File

@ -0,0 +1,23 @@
const expect = @import("std").testing.expect;
const builtin = @import("builtin");
test "sentinel-terminated 0-length slices" {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
var u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 };
var index: u8 = 2;
var slice = u32s[index..index :2];
var array_ptr = u32s[2..2 :2];
const comptime_known_array_value = u32s[2..2 :2].*;
var runtime_array_value = u32s[2..2 :2].*;
try expect(slice[0] == 2);
try expect(array_ptr[0] == 2);
try expect(comptime_known_array_value[0] == 2);
try expect(runtime_array_value[0] == 2);
}

View File

@ -0,0 +1,16 @@
const builtin = @import("builtin");
fn destroy(ptr: *void) void {
_ = ptr;
}
test {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
var slice: []void = undefined;
destroy(&slice[0]);
}

113
test/behavior/bugs/7325.zig Normal file
View File

@ -0,0 +1,113 @@
const std = @import("std");
const builtin = @import("builtin");
const testing = std.testing;
const string = "hello world";
const TempRef = struct {
index: usize,
is_weak: bool,
};
const BuiltinEnum = struct {
name: []const u8,
};
const ParamType = union(enum) {
boolean,
buffer,
one_of: BuiltinEnum,
};
const CallArg = struct {
value: Expression,
};
const Expression = union(enum) {
literal_boolean: bool,
literal_enum_value: EnumLiteral,
};
const EnumLiteral = struct {
label: []const u8,
};
const ExpressionResult = union(enum) {
temp_buffer: TempRef,
literal_boolean: bool,
literal_enum_value: []const u8,
};
fn commitCalleeParam(result: ExpressionResult, callee_param_type: ParamType) ExpressionResult {
switch (callee_param_type) {
.boolean => {
return result;
},
.buffer => {
return ExpressionResult{
.temp_buffer = .{ .index = 0, .is_weak = false },
};
},
.one_of => {
return result;
},
}
}
fn genExpression(expr: Expression) !ExpressionResult {
switch (expr) {
.literal_boolean => |value| {
return ExpressionResult{
.literal_boolean = value,
};
},
.literal_enum_value => |v| {
try testing.expectEqualStrings(string, v.label);
const result: ExpressionResult = .{
.literal_enum_value = v.label,
};
switch (result) {
.literal_enum_value => |w| {
try testing.expectEqualStrings(string, w);
},
else => {},
}
return result;
},
}
}
test {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
var param: ParamType = .{
.one_of = .{ .name = "name" },
};
var arg: CallArg = .{
.value = .{
.literal_enum_value = .{
.label = string,
},
},
};
const result = try genExpression(arg.value);
switch (result) {
.literal_enum_value => |w| {
try testing.expectEqualStrings(string, w);
},
else => {},
}
const derp = commitCalleeParam(result, param);
switch (derp) {
.literal_enum_value => |w| {
try testing.expectEqualStrings(string, w);
},
else => {},
}
}

View File

@ -0,0 +1,18 @@
const std = @import("std");
const builtin = @import("builtin");
const array = [_][]const []const u8{
&.{"hello"},
&.{ "world", "hello" },
};
test {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
try std.testing.expect(array[0].len == 1);
try std.testing.expectEqualStrings("hello", array[0][0]);
}

View File

@ -53,6 +53,11 @@ test "int128" {
buff = -0x12341234123412341234123412341234;
try expect(-buff == 0x12341234123412341234123412341234);
const a: i128 = -170141183460469231731687303715884105728;
const b: i128 = -0x8000_0000_0000_0000_0000_0000_0000_0000;
try expect(@divFloor(b, 1_000_000) == -170141183460469231731687303715885);
try expect(a == b);
}
test "truncate int128" {

View File

@ -161,12 +161,6 @@ test "@ctz vectors" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
// This regressed with LLVM 14:
// https://github.com/ziglang/zig/issues/12013
return error.SkipZigTest;
}
try testCtzVectors();
comptime try testCtzVectors();
}

View File

@ -174,12 +174,6 @@ test "tuple to vector" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
// Regressed with LLVM 14:
// https://github.com/ziglang/zig/issues/12012
return error.SkipZigTest;
}
const S = struct {
fn doTheTest() !void {
const Vec3 = @Vector(3, i32);

View File

@ -60,10 +60,6 @@ test "float widening f16 to f128" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
// TODO https://github.com/ziglang/zig/issues/3282
if (builtin.cpu.arch == .aarch64) return error.SkipZigTest;
if (builtin.cpu.arch == .powerpc64le) return error.SkipZigTest;
var x: f16 = 12.34;
var y: f128 = x;
try expect(x == y);

View File

@ -41,7 +41,7 @@ pub export fn entry4() void {
_ = U.foo(.{ .foo = 2, .bar = 2 });
}
pub export fn entry5() void {
comptime var y = .{ 1, 2};
comptime var y = .{ 1, 2 };
y = .{ 3, 4 };
}
// pub export fn entry5() void {
@ -52,7 +52,15 @@ pub export fn entry5() void {
// };
// _ = S.foo(.{ -1234, 5679, x });
// }
pub export fn entry6() void {
const State = struct {
comptime id: bool = true,
fn init(comptime id: bool) @This() {
return @This(){ .id = id };
}
};
_ = State.init(false);
}
// error
// target=native
@ -65,3 +73,4 @@ pub export fn entry5() void {
// :25:29: note: default value set here
// :41:16: error: value stored in comptime field does not match the default value of the field
// :45:12: error: value stored in comptime field does not match the default value of the field
// :59:35: error: value stored in comptime field does not match the default value of the field