Commit 5d3a1cfdf5

Andrew Kelley <andrew@ziglang.org>
2024-07-26 21:18:23
update init template
* add fuzz example * explain that you might want to delete main.zig or root.zig
1 parent 208baa3
Changed files (2)
lib
lib/init/src/main.zig
@@ -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));
+}
lib/init/src/root.zig
@@ -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;