| ... | ... | @@ -484,25 +484,28 @@ pub fn argsWithAllocator(allocator: *mem.Allocator) ArgIterator.InitError!ArgIte |
| 484 | 484 | |
| 485 | 485 | test "args iterator" { |
| 486 | 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 | 488 | defer it.deinit(); // no-op unless WASI |
| 489 | 489 | |
| 490 | | testing.expect(it.skip()); |
| 491 | | const prog_name = it.next(ga) orelse unreachable; |
| 490 | const prog_name = try it.next(ga) orelse unreachable; |
| 492 | 491 | defer ga.free(prog_name); |
| 493 | 492 | |
| 494 | | const expected_bin_name = switch (builtin.os.tag) { |
| 493 | const expected_suffix = switch (builtin.os.tag) { |
| 495 | 494 | .wasi => "test.wasm", |
| 496 | 495 | .windows => "test.exe", |
| 497 | 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 | } |
| 501 | 504 | |
| 502 | 505 | /// Caller must call argsFree on result. |
| 503 | 506 | pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 { |
| 504 | 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 | 509 | defer it.deinit(); |
| 507 | 510 | |
| 508 | 511 | var contents = std.ArrayList(u8).init(allocator); |