mirror of
https://github.com/ziglang/zig.git
synced 2026-01-04 04:25:05 +00:00
add failAllocator to enable some regression tests
This commit is contained in:
parent
0c7397b49f
commit
0a76e11617
@ -281,6 +281,22 @@ pub const Allocator = struct {
|
||||
}
|
||||
};
|
||||
|
||||
var failAllocator = Allocator {
|
||||
.reallocFn = failAllocatorRealloc,
|
||||
.shrinkFn = failAllocatorShrink,
|
||||
};
|
||||
fn failAllocatorRealloc(self: *Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) ![]u8 {
|
||||
return error.OutOfMemory;
|
||||
}
|
||||
fn failAllocatorShrink(self: *Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 {
|
||||
@panic("failAllocatorShrink should never be called because it cannot allocate");
|
||||
}
|
||||
|
||||
test "mem.Allocator basics" {
|
||||
testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
|
||||
testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
|
||||
}
|
||||
|
||||
/// Copy all of source into dest at position 0.
|
||||
/// dest.len must be >= source.len.
|
||||
/// dest.ptr must be <= src.ptr.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user