#test command line inputs
1 messages · Page 1 of 1 (latest)
const args: []const [:0]const u8 = &.{"--thing"}
or if you really want it to be mutable, var args = [_][:0]u8{try std.testing.allocator.dupe(u8, "--thing")} and then pass &args
chances are you're not actually using the mutability tho, so the first option should be fine :)
I'm getting "error: expected type '[][:0]u8', found '[]const [:0]const u8'" - even trickier!
you'll need to change the argument type of the function you're passing it to
The function I'm testing has a signature like this: error: expected type '[][:0]u8', found '[]const [:0]const u8'"
ok, change the signature, ok - i got it from doing @midnight moth
pub fn doArgs(args: []const [:0]const u8) !u8 {
this is the new signature of my little function
here's the test:
const args: []const [:0]const u8 = &.{"--help"};
try expect(doArgs(args) == 4);
but it gives this:
error: operator == not allowed for type
I checked that the function is returning a u8
try doArgs
also use std.testing.expectEqual instead of expect, it'll print a more useful message :)
ok
mm, this is bothersome - when I debug print a zig build run I see that my state returned from doArgs is a 4 but when run from a test it gives back a 0. There's some difference when entering the function from the testing line 'const args..etc..' At least it's a bit further ahead now.
oh, maybe i need to add the default prog name as the first arg
yep, that's probably at least part of it :)