From a311fa83a32644f4923c97fd83beb77a3b998ce6 Mon Sep 17 00:00:00 2001 From: Vexu Date: Tue, 7 Apr 2020 15:24:49 +0300 Subject: [PATCH] fix broken tests --- lib/std/json.zig | 11 ++++++----- lib/std/testing.zig | 3 ++- test/compile_errors.zig | 10 +++++----- test/stage1/behavior/for.zig | 4 ++-- test/stage1/behavior/pointers.zig | 6 +++--- test/stage1/behavior/slice.zig | 4 ++-- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/std/json.zig b/lib/std/json.zig index 79830d8a2c45..d271b6c19fd5 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -1327,12 +1327,13 @@ test "Value.jsonStringify" { { var buffer: [10]u8 = undefined; var fbs = std.io.fixedBufferStream(&buffer); + var vals = [_]Value{ + .{ .Integer = 1 }, + .{ .Integer = 2 }, + .{ .Integer = 3 }, + }; try (Value{ - .Array = Array.fromOwnedSlice(undefined, &[_]Value{ - .{ .Integer = 1 }, - .{ .Integer = 2 }, - .{ .Integer = 3 }, - }), + .Array = Array.fromOwnedSlice(undefined, &vals), }).jsonStringify(.{}, fbs.outStream()); testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]"); } diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 4f527ba700ab..4b629156f6e2 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -7,7 +7,8 @@ pub const FailingAllocator = @import("testing/failing_allocator.zig").FailingAll pub const allocator = &allocator_instance.allocator; pub var allocator_instance = LeakCountAllocator.init(&base_allocator_instance.allocator); -pub const failing_allocator = &FailingAllocator.init(&base_allocator_instance.allocator, 0).allocator; +pub const failing_allocator = &failing_allocator_instance.allocator; +pub var failing_allocator_instance = FailingAllocator.init(&base_allocator_instance.allocator, 0); pub var base_allocator_instance = std.heap.ThreadSafeFixedBufferAllocator.init(allocator_mem[0..]); var allocator_mem: [1024 * 1024]u8 = undefined; diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 696ef1f6ceb8..1d8f5e17f98e 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -997,7 +997,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const x = 1 << &@as(u8, 10); \\} , &[_][]const u8{ - "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'", + "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'", "tmp.zig:2:17: note: referenced here", }); @@ -1006,7 +1006,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const x = &@as(u8, 1) << 10; \\} , &[_][]const u8{ - "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'", + "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'", "tmp.zig:2:27: note: referenced here", }); @@ -6033,7 +6033,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ fn bar(self: *const Foo) void {} \\}; , &[_][]const u8{ - "tmp.zig:2:4: error: variable of type '*comptime_int' must be const or comptime", + "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime", "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime", "tmp.zig:8:4: error: variable of type 'comptime_int' must be const or comptime", "tmp.zig:11:4: error: variable of type 'comptime_float' must be const or comptime", @@ -6877,12 +6877,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const word: u16 = @bitCast(u16, bytes[0..]); \\} \\export fn foo2() void { - \\ var bytes: []u8 = &[_]u8{1, 2}; + \\ var bytes: []const u8 = &[_]u8{1, 2}; \\ const word: u16 = @bitCast(u16, bytes); \\} , &[_][]const u8{ "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'", - "tmp.zig:7:32: error: destination type 'u16' has size 2 but source type '[]u8' has size 16", + "tmp.zig:7:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16", "tmp.zig:7:37: note: referenced here", }); diff --git a/test/stage1/behavior/for.zig b/test/stage1/behavior/for.zig index c0b1cf264afa..fd98ec48dee5 100644 --- a/test/stage1/behavior/for.zig +++ b/test/stage1/behavior/for.zig @@ -161,8 +161,8 @@ test "for copies its payload" { test "for on slice with allowzero ptr" { const S = struct { - fn doTheTest(slice: []u8) void { - var ptr = @ptrCast([*]allowzero u8, slice.ptr)[0..slice.len]; + fn doTheTest(slice: []const u8) void { + var ptr = @ptrCast([*]const allowzero u8, slice.ptr)[0..slice.len]; for (ptr) |x, i| expect(x == i + 1); for (ptr) |*x, i| expect(x.* == i + 1); } diff --git a/test/stage1/behavior/pointers.zig b/test/stage1/behavior/pointers.zig index 6b86c2f6ac84..fa5f2a469db1 100644 --- a/test/stage1/behavior/pointers.zig +++ b/test/stage1/behavior/pointers.zig @@ -253,7 +253,7 @@ test "pointer sentinel with enums" { }; fn doTheTest() void { - var ptr: [*:.sentinel]Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; + var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731 } }; @@ -264,7 +264,7 @@ test "pointer sentinel with enums" { test "pointer sentinel with optional element" { const S = struct { fn doTheTest() void { - var ptr: [*:null]?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; + var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; expect(ptr[4] == null); // TODO this should be comptime expect, see #3731 } }; @@ -276,7 +276,7 @@ test "pointer sentinel with +inf" { const S = struct { fn doTheTest() void { const inf = std.math.inf_f32; - var ptr: [*:inf]f32 = &[_:inf]f32{ 1.1, 2.2, 3.3, 4.4 }; + var ptr: [*:inf]const f32 = &[_:inf]f32{ 1.1, 2.2, 3.3, 4.4 }; expect(ptr[4] == inf); // TODO this should be comptime expect, see #3731 } }; diff --git a/test/stage1/behavior/slice.zig b/test/stage1/behavior/slice.zig index e357ad2f0f30..9819d8571e6b 100644 --- a/test/stage1/behavior/slice.zig +++ b/test/stage1/behavior/slice.zig @@ -218,9 +218,9 @@ test "slice syntax resulting in pointer-to-array" { } fn testPointer0() void { - var pointer: [*]u0 = &[1]u0{0}; + var pointer: [*]const u0 = &[1]u0{0}; var slice = pointer[0..1]; - comptime expect(@TypeOf(slice) == *[1]u0); + comptime expect(@TypeOf(slice) == *[1]const u0); expect(slice[0] == 0); }