| ... | @@ -1,11 +1,22 @@ | ... | @@ -1,11 +1,22 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | | 2 | |
| 3 | pub fn main() anyerror!void { | 3 | pub fn main() !void { |
| 4 | // Note that info level log messages are by default printed only in Debug | 4 | // Prints to stderr |
| 5 | // and ReleaseSafe build modes. | 5 | std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); |
| 6 | std.log.info("All your codebase are belong to us.", .{}); | 6 | |
| | 7 | // Prints to stdout |
| | 8 | const unbuffered_out = std.io.getStdOut().writer(); |
| | 9 | const out = std.io.bufferedWriter(unbuffered_out).writer(); |
| | 10 | try out.print("Run `zig build test` to run the tests.\n", .{}); |
| | 11 | |
| | 12 | // Stdout is for the actual output of your application, for example if you |
| | 13 | // are implementing gzip, then only the compressed bytes should be sent to |
| | 14 | // stdout, not any debugging messages! |
| 7 | } | 15 | } |
| 8 | | 16 | |
| 9 | test "basic test" { | 17 | test "simple test" { |
| 10 | try std.testing.expectEqual(10, 3 + 7); | 18 | var list = std.ArrayList(i32).init(std.testing.allocator); |
| | 19 | defer list.deinit(); // try commenting this out and see if zig detects the memory leak! |
| | 20 | try list.append(42); |
| | 21 | try std.testing.expectEqual(list.pop(), 42); |
| 11 | } | 22 | } |