diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-07-26 12:18:23 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-07-26 12:18:23 -0700 |
| commit | 5d3a1cfdf576dfc4fc40c3f9f352e0fc613f0fee (patch) | |
| tree | 28b7a57ffc40cf991c93aee2976c528465d02696 /lib | |
| parent | 208baa37caa3830fbdf2b809ed663cec2c5585cc (diff) | |
| download | zig-5d3a1cfdf576dfc4fc40c3f9f352e0fc613f0fee.tar.gz zig-5d3a1cfdf576dfc4fc40c3f9f352e0fc613f0fee.zip | |
update init template
* add fuzz example
* explain that you might want to delete main.zig or root.zig
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/init/src/main.zig | 13 | ||||
| -rw-r--r-- | lib/init/src/root.zig | 3 |
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/init/src/main.zig b/lib/init/src/main.zig index c8a3f67dd0..a347913094 100644 --- a/lib/init/src/main.zig +++ b/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)); +} diff --git a/lib/init/src/root.zig b/lib/init/src/root.zig index ecfeade1a3..2e09025c9b 100644 --- a/lib/init/src/root.zig +++ b/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; |
