| author | |
| committer | |
| log | 2fee64ceb08328ccc9f98879a544eae971248493 |
| tree | 5f4d947be13aebc656e30baf6502cb410d32e459 |
| parent | 0b856d12a09df8e9b3a09494ec5488b771c20d0b |
3 files changed, 26 insertions(+), 17 deletions(-)
lib/init/src/main.zig+11-9| ... | ... | @@ -3,19 +3,21 @@ const Io = std.Io; |
| 3 | 3 | |
| 4 | 4 | const _NAME = @import(".NAME"); |
| 5 | 5 | |
| 6 | pub fn main() !void { | |
| 6 | pub fn main(init: std.process.Init) !void { | |
| 7 | 7 | // Prints to stderr, unbuffered, ignoring potential errors. |
| 8 | 8 | std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); |
| 9 | 9 | |
| 10 | // In order to allocate memory we must construct an `Allocator` instance. | |
| 11 | var debug_allocator: std.heap.DebugAllocator(.{}) = .init; | |
| 12 | defer _ = debug_allocator.deinit(); // This checks for leaks. | |
| 13 | const gpa = debug_allocator.allocator(); | |
| 10 | // This is appropriate for anything that lives as long as the process. | |
| 11 | const arena: std.mem.Allocator = init.arena.allocator(); | |
| 14 | 12 | |
| 15 | // In order to do I/O operations we must construct an `Io` instance. | |
| 16 | var threaded: std.Io.Threaded = .init(gpa, .{}); | |
| 17 | defer threaded.deinit(); | |
| 18 | const io = threaded.io(); | |
| 13 | // Accessing command line arguments: | |
| 14 | const args = try init.minimal.args.toSlice(arena); | |
| 15 | for (args) |arg| { | |
| 16 | std.log.info("arg: {s}", .{arg}); | |
| 17 | } | |
| 18 | ||
| 19 | // In order to do I/O operations need an `Io` instance. | |
| 20 | const io = init.io; | |
| 19 | 21 | |
| 20 | 22 | // Stdout is for the actual output of your application, for example if you |
| 21 | 23 | // are implementing gzip, then only the compressed bytes should be sent to |
lib/std/Build/Step/Run.zig+14-7| ... | ... | @@ -603,18 +603,25 @@ pub fn removeEnvironmentVariable(run: *Run, key: []const u8) void { |
| 603 | 603 | |
| 604 | 604 | /// Adds a check for exact stderr match. Does not add any other checks. |
| 605 | 605 | pub fn expectStdErrEqual(run: *Run, bytes: []const u8) void { |
| 606 | const new_check: StdIo.Check = .{ .expect_stderr_exact = run.step.owner.dupe(bytes) }; | |
| 607 | run.addCheck(new_check); | |
| 606 | run.addCheck(.{ .expect_stderr_exact = run.step.owner.dupe(bytes) }); | |
| 607 | } | |
| 608 | ||
| 609 | pub fn expectStdErrMatch(run: *Run, bytes: []const u8) void { | |
| 610 | run.addCheck(.{ .expect_stderr_match = run.step.owner.dupe(bytes) }); | |
| 608 | 611 | } |
| 609 | 612 | |
| 610 | 613 | /// Adds a check for exact stdout match as well as a check for exit code 0, if |
| 611 | 614 | /// there is not already an expected termination check. |
| 612 | 615 | pub fn expectStdOutEqual(run: *Run, bytes: []const u8) void { |
| 613 | const new_check: StdIo.Check = .{ .expect_stdout_exact = run.step.owner.dupe(bytes) }; | |
| 614 | run.addCheck(new_check); | |
| 615 | if (!run.hasTermCheck()) { | |
| 616 | run.expectExitCode(0); | |
| 617 | } | |
| 616 | run.addCheck(.{ .expect_stdout_exact = run.step.owner.dupe(bytes) }); | |
| 617 | if (!run.hasTermCheck()) run.expectExitCode(0); | |
| 618 | } | |
| 619 | ||
| 620 | /// Adds a check for stdout match as well as a check for exit code 0, if there | |
| 621 | /// is not already an expected termination check. | |
| 622 | pub fn expectStdOutMatch(run: *Run, bytes: []const u8) void { | |
| 623 | run.addCheck(.{ .expect_stdout_match = run.step.owner.dupe(bytes) }); | |
| 624 | if (!run.hasTermCheck()) run.expectExitCode(0); | |
| 618 | 625 | } |
| 619 | 626 | |
| 620 | 627 | pub fn expectExitCode(run: *Run, code: u8) void { |
test/tests.zig+1-1| ... | ... | @@ -2062,7 +2062,7 @@ pub fn addCliTests(b: *std.Build) *Step { |
| 2062 | 2062 | run_run.setCwd(.{ .cwd_relative = tmp_path }); |
| 2063 | 2063 | run_run.setName("zig build run"); |
| 2064 | 2064 | run_run.expectStdOutEqual("Run `zig build test` to run the tests.\n"); |
| 2065 | run_run.expectStdErrEqual("All your codebase are belong to us.\n"); | |
| 2065 | run_run.expectStdErrMatch("All your codebase are belong to us.\n"); | |
| 2066 | 2066 | run_run.step.dependOn(&init_exe.step); |
| 2067 | 2067 | |
| 2068 | 2068 | const cleanup = b.addRemoveDirTree(.{ .cwd_relative = tmp_path }); |