From cbe400c9a48bf6236b7cf4a857ba7d15e7413d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Wi=C5=9Bniewski?= Date: Wed, 21 May 2025 20:43:03 +0200 Subject: [PATCH] Migrate all the test to use `main.heap.testingAllocator` (#1487) Resolves: #1432 --- src/blueprint.zig | 29 +++++++++++++---------------- src/utils.zig | 5 +---- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/blueprint.zig b/src/blueprint.zig index f7c6452a..12dd07a9 100644 --- a/src/blueprint.zig +++ b/src/blueprint.zig @@ -520,9 +520,6 @@ fn parseBlockLike(block: []const u8) error{DataParsingFailed, IdParsingFailed}!M } const Test = struct { - var testingAllocator = main.heap.ErrorHandlingAllocator.init(std.testing.allocator); - var allocator = testingAllocator.allocator(); - var parseBlockLikeTest: *const @TypeOf(parseBlockLike) = &defaultParseBlockLike; fn defaultParseBlockLike(_: []const u8) !Mask.Entry.Inner { @@ -551,8 +548,8 @@ test "Mask match block type with any data" { Test.parseBlockLikeTest = &Test.@"parseBlockLike 1 null"; defer Test.parseBlockLikeTest = &Test.defaultParseBlockLike; - const mask = try Mask.initFromString(Test.allocator, "addon:dummy"); - defer mask.deinit(Test.allocator); + const mask = try Mask.initFromString(main.heap.testingAllocator, "addon:dummy"); + defer mask.deinit(main.heap.testingAllocator); try std.testing.expect(mask.match(.{.typ = 1, .data = 0})); try std.testing.expect(mask.match(.{.typ = 1, .data = 1})); @@ -563,43 +560,43 @@ test "Mask empty negative case" { Test.parseBlockLikeTest = &Test.@"parseBlockLike 1 null"; defer Test.parseBlockLikeTest = &Test.defaultParseBlockLike; - try std.testing.expectError(error.MissingExpression, Mask.initFromString(Test.allocator, "")); + try std.testing.expectError(error.MissingExpression, Mask.initFromString(main.heap.testingAllocator, "")); } test "Mask half-or negative case" { Test.parseBlockLikeTest = &Test.@"parseBlockLike 1 null"; defer Test.parseBlockLikeTest = &Test.defaultParseBlockLike; - try std.testing.expectError(error.MissingExpression, Mask.initFromString(Test.allocator, "addon:dummy|")); + try std.testing.expectError(error.MissingExpression, Mask.initFromString(main.heap.testingAllocator, "addon:dummy|")); } test "Mask half-or negative case 2" { Test.parseBlockLikeTest = &Test.@"parseBlockLike 1 null"; defer Test.parseBlockLikeTest = &Test.defaultParseBlockLike; - try std.testing.expectError(error.MissingExpression, Mask.initFromString(Test.allocator, "|addon:dummy")); + try std.testing.expectError(error.MissingExpression, Mask.initFromString(main.heap.testingAllocator, "|addon:dummy")); } test "Mask half-and negative case" { Test.parseBlockLikeTest = &Test.@"parseBlockLike 1 null"; defer Test.parseBlockLikeTest = &Test.defaultParseBlockLike; - try std.testing.expectError(error.MissingExpression, Mask.initFromString(Test.allocator, "addon:dummy&")); + try std.testing.expectError(error.MissingExpression, Mask.initFromString(main.heap.testingAllocator, "addon:dummy&")); } test "Mask half-and negative case 2" { Test.parseBlockLikeTest = &Test.@"parseBlockLike 1 null"; defer Test.parseBlockLikeTest = &Test.defaultParseBlockLike; - try std.testing.expectError(error.MissingExpression, Mask.initFromString(Test.allocator, "&addon:dummy")); + try std.testing.expectError(error.MissingExpression, Mask.initFromString(main.heap.testingAllocator, "&addon:dummy")); } test "Mask inverse match block type with any data" { Test.parseBlockLikeTest = &Test.@"parseBlockLike 1 null"; defer Test.parseBlockLikeTest = &Test.defaultParseBlockLike; - const mask = try Mask.initFromString(Test.allocator, "!addon:dummy"); - defer mask.deinit(Test.allocator); + const mask = try Mask.initFromString(main.heap.testingAllocator, "!addon:dummy"); + defer mask.deinit(main.heap.testingAllocator); try std.testing.expect(!mask.match(.{.typ = 1, .data = 0})); try std.testing.expect(!mask.match(.{.typ = 1, .data = 1})); @@ -610,8 +607,8 @@ test "Mask match block type with exact data" { Test.parseBlockLikeTest = &Test.@"parseBlockLike 1 1"; defer Test.parseBlockLikeTest = &Test.defaultParseBlockLike; - const mask = try Mask.initFromString(Test.allocator, "addon:dummy"); - defer mask.deinit(Test.allocator); + const mask = try Mask.initFromString(main.heap.testingAllocator, "addon:dummy"); + defer mask.deinit(main.heap.testingAllocator); try std.testing.expect(!mask.match(.{.typ = 1, .data = 0})); try std.testing.expect(mask.match(.{.typ = 1, .data = 1})); @@ -622,8 +619,8 @@ test "Mask match type 0 or type 1 with exact data" { Test.parseBlockLikeTest = &Test.@"parseBlockLike foo or bar"; defer Test.parseBlockLikeTest = &Test.defaultParseBlockLike; - const mask = try Mask.initFromString(Test.allocator, "addon:foo|addon:bar"); - defer mask.deinit(Test.allocator); + const mask = try Mask.initFromString(main.heap.testingAllocator, "addon:foo|addon:bar"); + defer mask.deinit(main.heap.testingAllocator); try std.testing.expect(mask.match(.{.typ = 1, .data = 0})); try std.testing.expect(mask.match(.{.typ = 2, .data = 0})); diff --git a/src/utils.zig b/src/utils.zig index b7d4a99b..4bb083d0 100644 --- a/src/utils.zig +++ b/src/utils.zig @@ -1719,11 +1719,8 @@ pub const BinaryWriter = struct { }; const ReadWriteTest = struct { - var testingAllocator = main.heap.ErrorHandlingAllocator.init(std.testing.allocator); - var allocator = testingAllocator.allocator(); - fn getWriter() BinaryWriter { - return .init(ReadWriteTest.allocator); + return .init(main.heap.testingAllocator); } fn getReader(data: []const u8) BinaryReader { return .init(data);