mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01:00
update init template for new main API
This commit is contained in:
parent
0b856d12a0
commit
2fee64ceb0
3 changed files with 26 additions and 17 deletions
|
|
@ -3,19 +3,21 @@ const Io = std.Io;
|
|||
|
||||
const _NAME = @import(".NAME");
|
||||
|
||||
pub fn main() !void {
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
// Prints to stderr, unbuffered, ignoring potential errors.
|
||||
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
|
||||
|
||||
// In order to allocate memory we must construct an `Allocator` instance.
|
||||
var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
|
||||
defer _ = debug_allocator.deinit(); // This checks for leaks.
|
||||
const gpa = debug_allocator.allocator();
|
||||
// This is appropriate for anything that lives as long as the process.
|
||||
const arena: std.mem.Allocator = init.arena.allocator();
|
||||
|
||||
// In order to do I/O operations we must construct an `Io` instance.
|
||||
var threaded: std.Io.Threaded = .init(gpa, .{});
|
||||
defer threaded.deinit();
|
||||
const io = threaded.io();
|
||||
// Accessing command line arguments:
|
||||
const args = try init.minimal.args.toSlice(arena);
|
||||
for (args) |arg| {
|
||||
std.log.info("arg: {s}", .{arg});
|
||||
}
|
||||
|
||||
// In order to do I/O operations need an `Io` instance.
|
||||
const io = init.io;
|
||||
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -603,18 +603,25 @@ pub fn removeEnvironmentVariable(run: *Run, key: []const u8) void {
|
|||
|
||||
/// Adds a check for exact stderr match. Does not add any other checks.
|
||||
pub fn expectStdErrEqual(run: *Run, bytes: []const u8) void {
|
||||
const new_check: StdIo.Check = .{ .expect_stderr_exact = run.step.owner.dupe(bytes) };
|
||||
run.addCheck(new_check);
|
||||
run.addCheck(.{ .expect_stderr_exact = run.step.owner.dupe(bytes) });
|
||||
}
|
||||
|
||||
pub fn expectStdErrMatch(run: *Run, bytes: []const u8) void {
|
||||
run.addCheck(.{ .expect_stderr_match = run.step.owner.dupe(bytes) });
|
||||
}
|
||||
|
||||
/// Adds a check for exact stdout match as well as a check for exit code 0, if
|
||||
/// there is not already an expected termination check.
|
||||
pub fn expectStdOutEqual(run: *Run, bytes: []const u8) void {
|
||||
const new_check: StdIo.Check = .{ .expect_stdout_exact = run.step.owner.dupe(bytes) };
|
||||
run.addCheck(new_check);
|
||||
if (!run.hasTermCheck()) {
|
||||
run.expectExitCode(0);
|
||||
}
|
||||
run.addCheck(.{ .expect_stdout_exact = run.step.owner.dupe(bytes) });
|
||||
if (!run.hasTermCheck()) run.expectExitCode(0);
|
||||
}
|
||||
|
||||
/// Adds a check for stdout match as well as a check for exit code 0, if there
|
||||
/// is not already an expected termination check.
|
||||
pub fn expectStdOutMatch(run: *Run, bytes: []const u8) void {
|
||||
run.addCheck(.{ .expect_stdout_match = run.step.owner.dupe(bytes) });
|
||||
if (!run.hasTermCheck()) run.expectExitCode(0);
|
||||
}
|
||||
|
||||
pub fn expectExitCode(run: *Run, code: u8) void {
|
||||
|
|
|
|||
|
|
@ -2062,7 +2062,7 @@ pub fn addCliTests(b: *std.Build) *Step {
|
|||
run_run.setCwd(.{ .cwd_relative = tmp_path });
|
||||
run_run.setName("zig build run");
|
||||
run_run.expectStdOutEqual("Run `zig build test` to run the tests.\n");
|
||||
run_run.expectStdErrEqual("All your codebase are belong to us.\n");
|
||||
run_run.expectStdErrMatch("All your codebase are belong to us.\n");
|
||||
run_run.step.dependOn(&init_exe.step);
|
||||
|
||||
const cleanup = b.addRemoveDirTree(.{ .cwd_relative = tmp_path });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue