# Creating a \`std.process.Args.Iterator\` in testing

**URL:** <https://ziggit.dev/t/creating-a-std-process-args-iterator-in-testing/14124>\
**Category:** Help\
**Tags:** standard-library\
**Created:** [January 29, 2026, 7:05pm UTC](https://ziggit.dev/t/creating-a-std-process-args-iterator-in-testing/14124 "2026-01-29T19:05:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![PauSolerValades](https://ziggit.dev/user_avatar/ziggit.dev/pausolervalades/32/7429_2.png) [@PauSolerValades](https://ziggit.dev/u/PauSolerValades)\
**Post date:** [January 29, 2026, 7:05pm UTC](https://ziggit.dev/t/creating-a-std-process-args-iterator-in-testing/14124/1 "2026-01-29T19:05:47Z")

</div>

Hello everyone!

Making my [parsing library](https://github.com/PauSolerValades/eazy-args) I’ve decided to have two parse functions

1. `parseArgs(gpa: Allocator, definition: anytype, args: []const []const u8, ...)` for a very freestyle parsing. As I have to iterate over the arguments lots of times, the function requires `args` to be provided as in `const args = init.minimal.args.toSlice(init.gpa)`. To test it is no problem, I just declare a `const args = &[_][]u8{ "utility", "arg1", "--flag" }` and I test it.
2. A POSIX style `parseArgsPosix(definition: anytype, args: *Args.Iterator, ...)`. Here is the question:

Is there someway to create the `Args.Iterator` object in the test itself given a string as it would be obtained from argv? Like this:

```zig
test "posix parses test" {
    const def = .{
        .options = .{ Opt(u64, "port", "p", 8080, "Port to connect") },
        .flags = .{ Flag("verbose", "v", "Print details") },
    };
    const args = createIterator("utility -v -p 100");
    const arguments = parseValuePosix(def, args, nullout, nullout);

    // your tests here
}

```

I’ve take a look at the std.process.Args, and I’ve found the `IteratorGeneral`, but that’s not a `*Args.Iterator` type so it’s not exactly what I am looking for, and if would like to avoid changing the type of args to `anytype` and maybe both would work? Also, if to ask for an `Iterator` is not what I should do, feel free to tell me 🙂

Thank you!

---

<div class="post-metadata">

**Author:** ![PauSolerValades](https://ziggit.dev/user_avatar/ziggit.dev/pausolervalades/32/7429_2.png) [@PauSolerValades](https://ziggit.dev/u/PauSolerValades)\
**Post date:** [January 29, 2026, 7:21pm UTC](https://ziggit.dev/t/creating-a-std-process-args-iterator-in-testing/14124/2 "2026-01-29T19:21:39Z")

</div>

Actually, I’ve managed it on my own by reading the std with a little bit more of attention. If someone is interested this works:

```zig
test "alone" {
    const def = .{
        .required = .{ Arg(u32, "count", "The number of items") },
        .flags = .{ Flag("verbose", "v", "Enable verbose output") },
        .options = .{ Opt([]const u8, "mode", "m", "default", "Operation mode") },
    };

    const fake_argv = &[_][*:0]const u8{ "utility", "-v", "-p", "diablo", "500"};
    const args = Args{ .vector = fake_argv };
    var iter = Args.Iterator.init(args);
    
    const result = try parseArgsPosix(def, &iter, nullout, nullout);

    try testing.expectEqual(@as(u32, 500), result.count);
    try testing.expectEqual(true, result.verbose);
    try testing.expectEqualStrings("diablo", result.mode);
}

```

---

<div class="post-metadata">

**Author:** ![tranzystorekk](https://ziggit.dev/user_avatar/ziggit.dev/tranzystorekk/32/5318_2.png) [@tranzystorekk](https://ziggit.dev/u/tranzystorekk)\
**Post date:** [April 16, 2026, 3:56pm UTC](https://ziggit.dev/t/creating-a-std-process-args-iterator-in-testing/14124/3 "2026-04-16T15:56:15Z")

</div>

I was just looking for exactly this problem, thank you!

---

<div class="post-metadata">

**Author:** ![ieh3oh](https://ziggit.dev/letter_avatar_proxy/v4/letter/i/c5a1d2/32.png) [@ieh3oh](https://ziggit.dev/u/ieh3oh)\
**Post date:** [August 7, 2026, 5:20pm UTC](https://ziggit.dev/t/creating-a-std-process-args-iterator-in-testing/14124/4 "2026-08-07T17:20:58Z")

</div>

Woo! I had the same question!

One question I had was if this code worked on different OSes.

```zig
    const fake_argv = &[_][*:0]const u8{ "utility", "-v", "-p", "diablo", "500"};
    const args = Args{ .vector = fake_argv };

```

Because `Vector` seems to be a different type depending on the OS: [std.process.Args.Vector](https://ziglang.org/documentation/master/std/#std.process.Args.Vector)

```zig
pub const Vector = switch (native_os) {
    .windows => []const u16, // WTF-16 encoded
    .wasi => switch (builtin.link_libc) {
        false => void,
        true => []const [*:0]const u8,
    },
    .freestanding, .other => void,
    else => []const [*:0]const u8,
}

```

Although, maybe I’m overthinking this, since Linux is the best OS. 😄

---

<div class="post-metadata">

**Author:** ![PauSolerValades](https://ziggit.dev/user_avatar/ziggit.dev/pausolervalades/32/7429_2.png) [@PauSolerValades](https://ziggit.dev/u/PauSolerValades)\
**Post date:** [August 13, 2026, 11:19am UTC](https://ziggit.dev/t/creating-a-std-process-args-iterator-in-testing/14124/5 "2026-08-13T11:19:37Z")

</div>

tbh i dunno! I recall that iterator needs heap memory in windows, but maybe vector will just work as we are not really parsing forom the terminal

I can’t try it on windows as i actively switched to linux in the past 2 years haha soooo no way to try it xD

---

<div class="post-metadata">

**Author:** ![ppipelin](https://ziggit.dev/user_avatar/ziggit.dev/ppipelin/32/4631_2.png) [@ppipelin](https://ziggit.dev/u/ppipelin)\
**Post date:** [August 20, 2026, 1:55pm UTC](https://ziggit.dev/t/creating-a-std-process-args-iterator-in-testing/14124/6 "2026-08-20T13:55:35Z")

</div>

I can confirm this does not work for windows which uses u16.

In my case I just need an empty iterator  
So something like that would be convenient:

```zig
const args: std.process.Args = .{};
var iter = std.process.Args.Iterator.initAllocator(args, allocator);

```

but fails as Args needs vector to be initialized.

---

<div class="post-metadata">

**Author:** ![PauSolerValades](https://ziggit.dev/user_avatar/ziggit.dev/pausolervalades/32/7429_2.png) [@PauSolerValades](https://ziggit.dev/u/PauSolerValades)\
**Post date:** [August 21, 2026, 7:47am UTC](https://ziggit.dev/t/creating-a-std-process-args-iterator-in-testing/14124/7 "2026-08-21T07:47:43Z")

</div>

thank you m8
