authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-05-29 17:12:19+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-05-29 17:12:19+02:00
log6e347e6180077b2b4243b6dd2cd1ef7a811e7881
treed3eeb35182e0adbd26a26b4e03909c685eb6ddc1
parent6f48842ddb2d8ca8fec639dc11a47753058ae325

Fix args iterator test


1 files changed, 9 insertions(+), 6 deletions(-)

lib/std/process.zig+9-6
...@@ -484,25 +484,28 @@ pub fn argsWithAllocator(allocator: *mem.Allocator) ArgIterator.InitError!ArgIte...@@ -484,25 +484,28 @@ pub fn argsWithAllocator(allocator: *mem.Allocator) ArgIterator.InitError!ArgIte
484484
485test "args iterator" {485test "args iterator" {
486 var ga = std.testing.allocator;486 var ga = std.testing.allocator;
487 var it = if (builtin.os.tag == .wasi) argsWithAllocator(ga) else args();487 var it = if (builtin.os.tag == .wasi) try argsWithAllocator(ga) else args();
488 defer it.deinit(); // no-op unless WASI488 defer it.deinit(); // no-op unless WASI
489489
490 testing.expect(it.skip());490 const prog_name = try it.next(ga) orelse unreachable;
491 const prog_name = it.next(ga) orelse unreachable;
492 defer ga.free(prog_name);491 defer ga.free(prog_name);
493492
494 const expected_bin_name = switch (builtin.os.tag) {493 const expected_suffix = switch (builtin.os.tag) {
495 .wasi => "test.wasm",494 .wasi => "test.wasm",
496 .windows => "test.exe",495 .windows => "test.exe",
497 else => "test",496 else => "test",
498 };497 };
499 testing.expect(mem.eql(u8, expected_bin_name, prog_name));498 const given_suffix = std.fs.path.basename(prog_name);
499
500 testing.expect(mem.eql(u8, expected_suffix, given_suffix));
501 testing.expectEqual(it.next(ga), null);
502 testing.expect(!it.skip());
500}503}
501504
502/// Caller must call argsFree on result.505/// Caller must call argsFree on result.
503pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {506pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
504 // TODO refactor to only make 1 allocation.507 // TODO refactor to only make 1 allocation.
505 var it = if (builtin.os.tag == .wasi) argsWithAllocator(allocator) else args();508 var it = if (builtin.os.tag == .wasi) try argsWithAllocator(allocator) else args();
506 defer it.deinit();509 defer it.deinit();
507510
508 var contents = std.ArrayList(u8).init(allocator);511 var contents = std.ArrayList(u8).init(allocator);