Skip to content

Commit

Permalink
fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu committed Apr 7, 2020
1 parent e62671f commit a311fa8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
11 changes: 6 additions & 5 deletions lib/std/json.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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]");
}
Expand Down
3 changes: 2 additions & 1 deletion lib/std/testing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions test/compile_errors.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});

Expand All @@ -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",
});

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
});

Expand Down
4 changes: 2 additions & 2 deletions test/stage1/behavior/for.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions test/stage1/behavior/pointers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
Expand All @@ -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
}
};
Expand All @@ -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
}
};
Expand Down
4 changes: 2 additions & 2 deletions test/stage1/behavior/slice.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit a311fa8

Please sign in to comment.