diff options
| author | Loris Cro <kappaloris@gmail.com> | 2022-08-04 20:08:11 +0200 |
|---|---|---|
| committer | Loris Cro <kappaloris@gmail.com> | 2022-08-04 20:10:43 +0200 |
| commit | fb0b9f05b3dbf394f92fac7c36189f054fc68b41 (patch) | |
| tree | 8eaeeec2b7bfb980f6db5e6bfaef69c1922deff3 /lib/init-exe | |
| parent | 4a4f3c50ce3b0c32f19a3649c6e0768b1c57218f (diff) | |
| download | zig-fb0b9f05b3dbf394f92fac7c36189f054fc68b41.tar.gz zig-fb0b9f05b3dbf394f92fac7c36189f054fc68b41.zip | |
new init-exe template
- removed an unnecessary (and confusing) `anyerror` fronm the function
signature of `main`
- replaced the call to std.log with two prints: one to stderr and one to
stdout
- replaced the test code with a better example
Diffstat (limited to 'lib/init-exe')
| -rw-r--r-- | lib/init-exe/src/main.zig | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/init-exe/src/main.zig b/lib/init-exe/src/main.zig index c2f93f4771..433d311599 100644 --- a/lib/init-exe/src/main.zig +++ b/lib/init-exe/src/main.zig @@ -1,11 +1,22 @@ const std = @import("std"); -pub fn main() anyerror!void { - // Note that info level log messages are by default printed only in Debug - // and ReleaseSafe build modes. - std.log.info("All your codebase are belong to us.", .{}); +pub fn main() !void { + // Prints to stderr + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + + // Prints to stdout + const unbuffered_out = std.io.getStdOut().writer(); + const out = std.io.bufferedWriter(unbuffered_out).writer(); + try out.print("Run `zig build test` to run the tests.\n", .{}); + + // Stdout is for the actual output of your application, for example if you + // are implementing gzip, then only the compressed bytes should be sent to + // stdout, not any debugging messages! } -test "basic test" { - try std.testing.expectEqual(10, 3 + 7); +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! + try list.append(42); + try std.testing.expectEqual(list.pop(), 42); } |
