authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-08-04 20:08:11+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-08-04 20:10:43+02:00
logfb0b9f05b3dbf394f92fac7c36189f054fc68b41
tree8eaeeec2b7bfb980f6db5e6bfaef69c1922deff3
parent4a4f3c50ce3b0c32f19a3649c6e0768b1c57218f

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

1 files changed, 17 insertions(+), 6 deletions(-)

lib/init-exe/src/main.zig+17-6
...@@ -1,11 +1,22 @@...@@ -1,11 +1,22 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn main() anyerror!void {3pub fn main() !void {
4 // Note that info level log messages are by default printed only in Debug4 // 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}
816
9test "basic test" {17test "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}