| ... | @@ -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 |
| 484 | | 484 | |
| 485 | test "args iterator" { | 485 | test "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 WASI | 488 | defer it.deinit(); // no-op unless WASI |
| 489 | | 489 | |
| 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); |
| 493 | | 492 | |
| 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 | } |
| 501 | | 504 | |
| 502 | /// Caller must call argsFree on result. | 505 | /// Caller must call argsFree on result. |
| 503 | pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 { | 506 | pub 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(); |
| 507 | | 510 | |
| 508 | var contents = std.ArrayList(u8).init(allocator); | 511 | var contents = std.ArrayList(u8).init(allocator); |