diff --git a/test/behavior.zig b/test/behavior.zig index 1579a97cbc..f288606a07 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -161,6 +161,7 @@ test { _ = @import("behavior/enum.zig"); _ = @import("behavior/error.zig"); _ = @import("behavior/eval.zig"); + _ = @import("behavior/export_builtin.zig"); _ = @import("behavior/export_self_referential_type_info.zig"); _ = @import("behavior/field_parent_ptr.zig"); _ = @import("behavior/floatop.zig"); @@ -169,6 +170,7 @@ test { _ = @import("behavior/fn_in_struct_in_comptime.zig"); _ = @import("behavior/for.zig"); _ = @import("behavior/generics.zig"); + _ = @import("behavior/globals.zig"); _ = @import("behavior/hasdecl.zig"); _ = @import("behavior/hasfield.zig"); _ = @import("behavior/if.zig"); @@ -188,6 +190,7 @@ test { _ = @import("behavior/merge_error_sets.zig"); _ = @import("behavior/muladd.zig"); _ = @import("behavior/namespace_depends_on_compile_var.zig"); + _ = @import("behavior/nan.zig"); _ = @import("behavior/null.zig"); _ = @import("behavior/optional.zig"); _ = @import("behavior/packed-struct.zig"); @@ -252,9 +255,6 @@ test { builtin.zig_backend != .stage2_c and builtin.zig_backend != .stage2_spirv64) { - _ = @import("behavior/bugs/13063.zig"); - _ = @import("behavior/bugs/11227.zig"); - _ = @import("behavior/bugs/14198.zig"); - _ = @import("behavior/export.zig"); + _ = @import("behavior/export_keyword.zig"); } } diff --git a/test/behavior/bugs/11227.zig b/test/behavior/bugs/11227.zig deleted file mode 100644 index b65a64c69c..0000000000 --- a/test/behavior/bugs/11227.zig +++ /dev/null @@ -1,11 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); - -fn foo() u32 { - return 11227; -} -const bar = foo; -test "pointer to alias behaves same as pointer to function" { - var a = &bar; - try std.testing.expect(foo() == a()); -} diff --git a/test/behavior/bugs/13063.zig b/test/behavior/bugs/13063.zig deleted file mode 100644 index 30b086e721..0000000000 --- a/test/behavior/bugs/13063.zig +++ /dev/null @@ -1,21 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const expect = std.testing.expect; - -var pos = [2]f32{ 0.0, 0.0 }; -test "store to global array" { - if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - - try expect(pos[1] == 0.0); - pos = [2]f32{ 0.0, 1.0 }; - try expect(pos[1] == 1.0); -} - -var vpos = @Vector(2, f32){ 0.0, 0.0 }; -test "store to global vector" { - if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - - try expect(vpos[1] == 0.0); - vpos = @Vector(2, f32){ 0.0, 1.0 }; - try expect(vpos[1] == 1.0); -} diff --git a/test/behavior/export.zig b/test/behavior/export.zig deleted file mode 100644 index d10743206d..0000000000 --- a/test/behavior/export.zig +++ /dev/null @@ -1,95 +0,0 @@ -const std = @import("std"); -const expect = std.testing.expect; -const expectEqualSlices = std.testing.expectEqualSlices; -const expectEqualStrings = std.testing.expectEqualStrings; -const mem = std.mem; -const builtin = @import("builtin"); - -// can't really run this test but we can make sure it has no compile error -// and generates code -const vram = @as([*]volatile u8, @ptrFromInt(0x20000000))[0..0x8000]; -export fn writeToVRam() void { - vram[0] = 'X'; -} - -const PackedStruct = packed struct { - a: u8, - b: u8, -}; -const PackedUnion = packed union { - a: u8, - b: u32, -}; - -test "packed struct, enum, union parameters in extern function" { - if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - - testPackedStuff(&(PackedStruct{ - .a = 1, - .b = 2, - }), &(PackedUnion{ .a = 1 })); -} - -export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion) void { - if (false) { - a; - b; - } -} - -test "exporting enum type and value" { - const S = struct { - const E = enum(c_int) { one, two }; - const e: E = .two; - comptime { - @export(e, .{ .name = "e" }); - } - }; - try expect(S.e == .two); -} - -test "exporting with internal linkage" { - const S = struct { - fn foo() callconv(.C) void {} - comptime { - @export(foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .Internal }); - } - }; - S.foo(); -} - -test "exporting using field access" { - const S = struct { - const Inner = struct { - const x: u32 = 5; - }; - comptime { - @export(Inner.x, .{ .name = "foo", .linkage = .Internal }); - } - }; - - _ = S.Inner.x; -} - -test "exporting comptime-known value" { - if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; - - const x: u32 = 10; - @export(x, .{ .name = "exporting_comptime_known_value_foo" }); - const S = struct { - extern const exporting_comptime_known_value_foo: u32; - }; - try expect(S.exporting_comptime_known_value_foo == 10); -} - -test "exporting comptime var" { - if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; - - comptime var x: u32 = 5; - @export(x, .{ .name = "exporting_comptime_var_foo" }); - x = 7; // modifying this now shouldn't change anything - const S = struct { - extern const exporting_comptime_var_foo: u32; - }; - try expect(S.exporting_comptime_var_foo == 5); -} diff --git a/test/behavior/export_builtin.zig b/test/behavior/export_builtin.zig new file mode 100644 index 0000000000..f4c5c607ee --- /dev/null +++ b/test/behavior/export_builtin.zig @@ -0,0 +1,88 @@ +const builtin = @import("builtin"); +const std = @import("std"); +const expect = std.testing.expect; + +test "exporting enum type and value" { + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + + const S = struct { + const E = enum(c_int) { one, two }; + const e: E = .two; + comptime { + @export(e, .{ .name = "e" }); + } + }; + try expect(S.e == .two); +} + +test "exporting with internal linkage" { + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + + const S = struct { + fn foo() callconv(.C) void {} + comptime { + @export(foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .Internal }); + } + }; + S.foo(); +} + +test "exporting using field access" { + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + + const S = struct { + const Inner = struct { + const x: u32 = 5; + }; + comptime { + @export(Inner.x, .{ .name = "foo", .linkage = .Internal }); + } + }; + + _ = S.Inner.x; +} + +test "exporting comptime-known value" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + + const x: u32 = 10; + @export(x, .{ .name = "exporting_comptime_known_value_foo" }); + const S = struct { + extern const exporting_comptime_known_value_foo: u32; + }; + try expect(S.exporting_comptime_known_value_foo == 10); +} + +test "exporting comptime var" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + + comptime var x: u32 = 5; + @export(x, .{ .name = "exporting_comptime_var_foo" }); + x = 7; // modifying this now shouldn't change anything + const S = struct { + extern const exporting_comptime_var_foo: u32; + }; + try expect(S.exporting_comptime_var_foo == 5); +} diff --git a/test/behavior/export_keyword.zig b/test/behavior/export_keyword.zig new file mode 100644 index 0000000000..34228c8e7f --- /dev/null +++ b/test/behavior/export_keyword.zig @@ -0,0 +1,38 @@ +const std = @import("std"); +const expect = std.testing.expect; +const expectEqualSlices = std.testing.expectEqualSlices; +const expectEqualStrings = std.testing.expectEqualStrings; +const mem = std.mem; +const builtin = @import("builtin"); + +// can't really run this test but we can make sure it has no compile error +// and generates code +const vram = @as([*]volatile u8, @ptrFromInt(0x20000000))[0..0x8000]; +export fn writeToVRam() void { + vram[0] = 'X'; +} + +const PackedStruct = packed struct { + a: u8, + b: u8, +}; +const PackedUnion = packed union { + a: u8, + b: u32, +}; + +test "packed struct, enum, union parameters in extern function" { + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO + + testPackedStuff(&(PackedStruct{ + .a = 1, + .b = 2, + }), &(PackedUnion{ .a = 1 })); +} + +export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion) void { + if (false) { + a; + b; + } +} diff --git a/test/behavior/fn.zig b/test/behavior/fn.zig index 859be1efda..3792087426 100644 --- a/test/behavior/fn.zig +++ b/test/behavior/fn.zig @@ -574,3 +574,20 @@ test "pass and return comptime-only types" { try expectEqual(null, S.returnNull(null)); try expectEqual(@as(u0, 0), S.returnUndefined(undefined)); } + +test "pointer to alias behaves same as pointer to function" { + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + + const S = struct { + fn foo() u32 { + return 11227; + } + const bar = foo; + }; + var a = &S.bar; + try std.testing.expect(S.foo() == a()); +} diff --git a/test/behavior/globals.zig b/test/behavior/globals.zig new file mode 100644 index 0000000000..2dc2b904d2 --- /dev/null +++ b/test/behavior/globals.zig @@ -0,0 +1,31 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const expect = std.testing.expect; + +var pos = [2]f32{ 0.0, 0.0 }; +test "store to global array" { + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + + try expect(pos[1] == 0.0); + pos = [2]f32{ 0.0, 1.0 }; + try expect(pos[1] == 1.0); +} + +var vpos = @Vector(2, f32){ 0.0, 0.0 }; +test "store to global vector" { + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + + try expect(vpos[1] == 0.0); + vpos = @Vector(2, f32){ 0.0, 1.0 }; + try expect(vpos[1] == 1.0); +} diff --git a/test/behavior/bugs/14198.zig b/test/behavior/nan.zig similarity index 78% rename from test/behavior/bugs/14198.zig rename to test/behavior/nan.zig index 5a4a515810..32cd6af0d4 100644 --- a/test/behavior/bugs/14198.zig +++ b/test/behavior/nan.zig @@ -1,3 +1,4 @@ +const builtin = @import("builtin"); const std = @import("std"); const math = std.math; const mem = std.mem; @@ -21,6 +22,12 @@ const qnan_f128: f128 = math.nan(f128); const snan_f128: f128 = math.snan(f128); test "nan memory equality" { + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + // signaled try testing.expect(mem.eql(u8, mem.asBytes(&snan_u16), mem.asBytes(&snan_f16))); try testing.expect(mem.eql(u8, mem.asBytes(&snan_u32), mem.asBytes(&snan_f32)));