Testing a command line argument parser

I wrote a small command line argument parser and I would now like to test it. The parser takes a std.process.Args.Iterator for initialization like so:

const args: std.process.Args = .{
    .vector = &.{ "--asdf", "--qwerty", "--", "-abc", "waow", "woah", "hmmm" },
};
var iter: ArgsIterator = .init(args.iterate());

Which works great… on linux. But this test can’t run on windows and some other targets because the type of .vector is different.
Is there any platform-agnostic way to create a std.process.Args instance for testing purposes?

1 Like

I think it should be somewhat manual, I was looking at the code for std.process.Args.zig

fn testIteratorWindows(cmd_line: []const u8, expected_args: []const []const u8) !void {
    const cmd_line_w = try std.unicode.wtf8ToWtf16LeAllocZ(testing.allocator, cmd_line);
    defer testing.allocator.free(cmd_line_w);

    // next
    {
        var it = try Iterator.Windows.init(testing.allocator, cmd_line_w);
        defer it.deinit();
...

line 669