mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
update init template
* add fuzz example * explain that you might want to delete main.zig or root.zig
This commit is contained in:
parent
208baa37ca
commit
5d3a1cfdf5
2 changed files with 14 additions and 2 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue