diff --git a/lib/init/src/main.zig b/lib/init/src/main.zig index 865e6c5322..2c6df25be5 100644 --- a/lib/init/src/main.zig +++ b/lib/init/src/main.zig @@ -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 diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index 7ae9849f64..1084c7fbfd 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -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 { diff --git a/test/tests.zig b/test/tests.zig index 1634112dae..5fc4a967af 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -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 });