My omnium-gatherom of scripts and source code.
at main 24 lines 915 B view raw
1const std = @import("std"); 2 3pub fn main() !void { 4 // Prints to stderr (it's a shortcut based on `std.io.getStdErr()`) 5 std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); 6 7 // stdout is for the actual output of your application, for example if you 8 // are implementing gzip, then only the compressed bytes should be sent to 9 // stdout, not any debugging messages. 10 const stdout_file = std.io.getStdOut().writer(); 11 var bw = std.io.bufferedWriter(stdout_file); 12 const stdout = bw.writer(); 13 14 try stdout.print("Run `zig build test` to run the tests.\n", .{}); 15 16 try bw.flush(); // don't forget to flush! 17} 18 19test "simple test" { 20 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! 22 try list.append(42); 23 try std.testing.expectEqual(@as(i32, 42), list.pop()); 24}