| ... | @@ -1,3 +1,6 @@ | ... | @@ -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. |
| 1 | const std = @import("std"); | 4 | const std = @import("std"); |
| 2 | | 5 | |
| 3 | pub fn main() !void { | 6 | pub fn main() !void { |
| ... | @@ -13,12 +16,18 @@ pub fn main() !void { | ... | @@ -13,12 +16,18 @@ pub fn main() !void { |
| 13 | | 16 | |
| 14 | try stdout.print("Run `zig build test` to run the tests.\n", .{}); | 17 | try stdout.print("Run `zig build test` to run the tests.\n", .{}); |
| 15 | | 18 | |
| 16 | try bw.flush(); // don't forget to flush! | 19 | try bw.flush(); // Don't forget to flush! |
| 17 | } | 20 | } |
| 18 | | 21 | |
| 19 | test "simple test" { | 22 | test "simple test" { |
| 20 | var list = std.ArrayList(i32).init(std.testing.allocator); | 23 | 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! |
| 22 | try list.append(42); | 25 | try list.append(42); |
| 23 | try std.testing.expectEqual(@as(i32, 42), list.pop()); | 26 | try std.testing.expectEqual(@as(i32, 42), list.pop()); |
| 24 | } | 27 | } |
| | 28 | |
| | 29 | test "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 | } |