update init template

* add fuzz example
* explain that you might want to delete main.zig or root.zig
This commit is contained in:
Andrew Kelley 2024-07-26 12:18:23 -07:00
parent 208baa37ca
commit 5d3a1cfdf5
2 changed files with 14 additions and 2 deletions

View file

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

View file

@ -1,3 +1,6 @@
//! By convention, root.zig is the root source file when making a library. If
//! you are making an executable, the convention is to delete this file and
//! start with root.zig instead.
const std = @import("std");
const testing = std.testing;