Skip to content

Commit 91fc966

Browse files
committed
Zig Build System > Testing: fix code examples
This follows up on #545. Although it did fix one compile error, fixing it actually revealed other issues that are addressed by this pull request: 1. Both versions of `main.zig` were using the old `std.ArrayList` API from when it was managed, but as of Zig 0.15.1, it is no longer managed: https://ziglang.org/download/0.15.1/release-notes.html#ArrayList-make-unmanaged-the-default 2. The file `unit-testing-skip-foreign/build.zig` was missing `additional_option=test`, so the command `zig build --summary all` was run instead of the intended command `zig build test --summary all`.
1 parent 414c98a commit 91fc966

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

zig-code/build-system/unit-testing-skip-foreign/build.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ pub fn build(b: *std.Build) void {
2929
}
3030
}
3131

32-
// zig-doctest: build-system --collapseable -- test --summary all
33-
3432
// build=succeed
33+
// additional_option=test
3534
// additional_option=--summary
3635
// additional_option=all
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
// zig-doctest: syntax --name main
21
const std = @import("std");
32

43
test "simple test" {
5-
var list = std.ArrayList(i32).init(std.testing.allocator);
6-
defer list.deinit();
7-
try list.append(42);
4+
const allocator = std.testing.allocator;
5+
6+
var list: std.ArrayList(i32) = .empty;
7+
defer list.deinit(allocator);
8+
9+
try list.append(allocator, 42);
810
try std.testing.expectEqual(@as(i32, 42), list.pop());
911
}
12+
13+
// syntax

zig-code/build-system/unit-testing/main.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
const std = @import("std");
22

33
test "simple test" {
4-
var list = std.ArrayList(i32).init(std.testing.allocator);
5-
defer list.deinit();
6-
try list.append(42);
4+
const allocator = std.testing.allocator;
5+
6+
var list: std.ArrayList(i32) = .empty;
7+
defer list.deinit(allocator);
8+
9+
try list.append(allocator, 42);
710
try std.testing.expectEqual(@as(i32, 42), list.pop());
811
}
912

0 commit comments

Comments
 (0)