mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
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
This commit is contained in:
parent
4a4f3c50ce
commit
fb0b9f05b3
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user