authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-26 12:18:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-26 12:18:23-07:00
log5d3a1cfdf576dfc4fc40c3f9f352e0fc613f0fee
tree28b7a57ffc40cf991c93aee2976c528465d02696
parent208baa37caa3830fbdf2b809ed663cec2c5585cc

update init template

* add fuzz example * explain that you might want to delete main.zig or root.zig

2 files changed, 14 insertions(+), 2 deletions(-)

lib/init/src/main.zig+11-2
......@@ -1,3 +1,6 @@
1//! By convention, main.zig is where your main function lives in the case that
2//! you are building an executable. If you are making a library, the convention
3//! is to delete this file and start with root.zig instead.
14const std = @import("std");
25
36pub fn main() !void {
......@@ -13,12 +16,18 @@ pub fn main() !void {
1316
1417 try stdout.print("Run `zig build test` to run the tests.\n", .{});
1518
16 try bw.flush(); // don't forget to flush!
19 try bw.flush(); // Don't forget to flush!
1720}
1821
1922test "simple test" {
2023 var list = std.ArrayList(i32).init(std.testing.allocator);
21 defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
24 defer list.deinit(); // Try commenting this out and see if zig detects the memory leak!
2225 try list.append(42);
2326 try std.testing.expectEqual(@as(i32, 42), list.pop());
2427}
28
29test "fuzz example" {
30 // Try passing `--fuzz` to `zig build` and see if it manages to fail this test case!
31 const input_bytes = std.testing.fuzzInput(.{});
32 try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input_bytes));
33}
lib/init/src/root.zig+3
......@@ -1,3 +1,6 @@
1//! By convention, root.zig is the root source file when making a library. If
2//! you are making an executable, the convention is to delete this file and
3//! start with root.zig instead.
14const std = @import("std");
25const testing = std.testing;
36