diff options
| author | 2021-05-26 21:06:10 +0200 | |
|---|---|---|
| committer | 2021-05-26 21:06:10 +0200 | |
| commit | c7d83fcce1739271e399260b50c5f68aa03c5908 (patch) | |
| tree | f859d081955e5c8c3bc329008837d351606ec19c /clap | |
| parent | Merge branch 'master' into zig-master (diff) | |
| download | zig-clap-c7d83fcce1739271e399260b50c5f68aa03c5908.tar.gz zig-clap-c7d83fcce1739271e399260b50c5f68aa03c5908.tar.xz zig-clap-c7d83fcce1739271e399260b50c5f68aa03c5908.zip | |
Update to latest zig in preperation for 0.8.0
Diffstat (limited to 'clap')
| -rw-r--r-- | clap/args.zig | 86 | ||||
| -rw-r--r-- | clap/comptime.zig | 70 | ||||
| -rw-r--r-- | clap/streaming.zig | 66 |
3 files changed, 118 insertions, 104 deletions
diff --git a/clap/args.zig b/clap/args.zig index f9ad218..555e8ab 100644 --- a/clap/args.zig +++ b/clap/args.zig | |||
| @@ -34,8 +34,8 @@ pub const SliceIterator = struct { | |||
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | test "SliceIterator" { | 36 | test "SliceIterator" { |
| 37 | const args = &[_][]const u8{ "A", "BB", "CCC" }; | 37 | const args = [_][]const u8{ "A", "BB", "CCC" }; |
| 38 | var iter = SliceIterator{ .args = args }; | 38 | var iter = SliceIterator{ .args = &args }; |
| 39 | 39 | ||
| 40 | for (args) |a| { | 40 | for (args) |a| { |
| 41 | const b = try iter.next(); | 41 | const b = try iter.next(); |
| @@ -266,76 +266,76 @@ pub const ShellIterator = struct { | |||
| 266 | } | 266 | } |
| 267 | }; | 267 | }; |
| 268 | 268 | ||
| 269 | fn testShellIteratorOk(str: []const u8, allocations: usize, expect: []const []const u8) void { | 269 | fn testShellIteratorOk(str: []const u8, allocations: usize, expect: []const []const u8) !void { |
| 270 | var allocator = testing.FailingAllocator.init(testing.allocator, allocations); | 270 | var allocator = testing.FailingAllocator.init(testing.allocator, allocations); |
| 271 | var it = ShellIterator.init(&allocator.allocator, str); | 271 | var it = ShellIterator.init(&allocator.allocator, str); |
| 272 | defer it.deinit(); | 272 | defer it.deinit(); |
| 273 | 273 | ||
| 274 | for (expect) |e| { | 274 | for (expect) |e| { |
| 275 | if (it.next()) |actual| { | 275 | if (it.next()) |actual| { |
| 276 | testing.expect(actual != null); | 276 | try testing.expect(actual != null); |
| 277 | testing.expectEqualStrings(e, actual.?); | 277 | try testing.expectEqualStrings(e, actual.?); |
| 278 | } else |err| testing.expectEqual(@as(anyerror![]const u8, e), err); | 278 | } else |err| try testing.expectEqual(@as(anyerror![]const u8, e), err); |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | if (it.next()) |actual| { | 281 | if (it.next()) |actual| { |
| 282 | testing.expectEqual(@as(?[]const u8, null), actual); | 282 | try testing.expectEqual(@as(?[]const u8, null), actual); |
| 283 | testing.expectEqual(allocations, allocator.allocations); | 283 | try testing.expectEqual(allocations, allocator.allocations); |
| 284 | } else |err| testing.expectEqual(@as(anyerror!void, {}), err); | 284 | } else |err| try testing.expectEqual(@as(anyerror!void, {}), err); |
| 285 | } | 285 | } |
| 286 | 286 | ||
| 287 | fn testShellIteratorErr(str: []const u8, expect: anyerror) void { | 287 | fn testShellIteratorErr(str: []const u8, expect: anyerror) !void { |
| 288 | var it = ShellIterator.init(testing.allocator, str); | 288 | var it = ShellIterator.init(testing.allocator, str); |
| 289 | defer it.deinit(); | 289 | defer it.deinit(); |
| 290 | 290 | ||
| 291 | while (it.next() catch |err| { | 291 | while (it.next() catch |err| { |
| 292 | testing.expectError(expect, @as(anyerror!void, err)); | 292 | try testing.expectError(expect, @as(anyerror!void, err)); |
| 293 | return; | 293 | return; |
| 294 | }) |_| {} | 294 | }) |_| {} |
| 295 | 295 | ||
| 296 | testing.expectError(expect, @as(anyerror!void, {})); | 296 | try testing.expectError(expect, @as(anyerror!void, {})); |
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | test "ShellIterator" { | 299 | test "ShellIterator" { |
| 300 | testShellIteratorOk("a", 0, &[_][]const u8{"a"}); | 300 | try testShellIteratorOk("a", 0, &.{"a"}); |
| 301 | testShellIteratorOk("'a'", 0, &[_][]const u8{"a"}); | 301 | try testShellIteratorOk("'a'", 0, &.{"a"}); |
| 302 | testShellIteratorOk("\"a\"", 0, &[_][]const u8{"a"}); | 302 | try testShellIteratorOk("\"a\"", 0, &.{"a"}); |
| 303 | testShellIteratorOk("a b", 0, &[_][]const u8{ "a", "b" }); | 303 | try testShellIteratorOk("a b", 0, &.{ "a", "b" }); |
| 304 | testShellIteratorOk("'a' b", 0, &[_][]const u8{ "a", "b" }); | 304 | try testShellIteratorOk("'a' b", 0, &.{ "a", "b" }); |
| 305 | testShellIteratorOk("\"a\" b", 0, &[_][]const u8{ "a", "b" }); | 305 | try testShellIteratorOk("\"a\" b", 0, &.{ "a", "b" }); |
| 306 | testShellIteratorOk("a 'b'", 0, &[_][]const u8{ "a", "b" }); | 306 | try testShellIteratorOk("a 'b'", 0, &.{ "a", "b" }); |
| 307 | testShellIteratorOk("a \"b\"", 0, &[_][]const u8{ "a", "b" }); | 307 | try testShellIteratorOk("a \"b\"", 0, &.{ "a", "b" }); |
| 308 | testShellIteratorOk("'a b'", 0, &[_][]const u8{"a b"}); | 308 | try testShellIteratorOk("'a b'", 0, &.{"a b"}); |
| 309 | testShellIteratorOk("\"a b\"", 0, &[_][]const u8{"a b"}); | 309 | try testShellIteratorOk("\"a b\"", 0, &.{"a b"}); |
| 310 | testShellIteratorOk("\"a\"\"b\"", 1, &[_][]const u8{"ab"}); | 310 | try testShellIteratorOk("\"a\"\"b\"", 1, &.{"ab"}); |
| 311 | testShellIteratorOk("'a''b'", 1, &[_][]const u8{"ab"}); | 311 | try testShellIteratorOk("'a''b'", 1, &.{"ab"}); |
| 312 | testShellIteratorOk("'a'b", 1, &[_][]const u8{"ab"}); | 312 | try testShellIteratorOk("'a'b", 1, &.{"ab"}); |
| 313 | testShellIteratorOk("a'b'", 1, &[_][]const u8{"ab"}); | 313 | try testShellIteratorOk("a'b'", 1, &.{"ab"}); |
| 314 | testShellIteratorOk("a\\ b", 1, &[_][]const u8{"a b"}); | 314 | try testShellIteratorOk("a\\ b", 1, &.{"a b"}); |
| 315 | testShellIteratorOk("\"a\\ b\"", 1, &[_][]const u8{"a b"}); | 315 | try testShellIteratorOk("\"a\\ b\"", 1, &.{"a b"}); |
| 316 | testShellIteratorOk("'a\\ b'", 0, &[_][]const u8{"a\\ b"}); | 316 | try testShellIteratorOk("'a\\ b'", 0, &.{"a\\ b"}); |
| 317 | testShellIteratorOk(" a b ", 0, &[_][]const u8{ "a", "b" }); | 317 | try testShellIteratorOk(" a b ", 0, &.{ "a", "b" }); |
| 318 | testShellIteratorOk("\\ \\ ", 0, &[_][]const u8{ " ", " " }); | 318 | try testShellIteratorOk("\\ \\ ", 0, &.{ " ", " " }); |
| 319 | 319 | ||
| 320 | testShellIteratorOk( | 320 | try testShellIteratorOk( |
| 321 | \\printf 'run\nuninstall\n' | 321 | \\printf 'run\nuninstall\n' |
| 322 | , 0, &[_][]const u8{ "printf", "run\\nuninstall\\n" }); | 322 | , 0, &.{ "printf", "run\\nuninstall\\n" }); |
| 323 | testShellIteratorOk( | 323 | try testShellIteratorOk( |
| 324 | \\setsid -f steam "steam://$action/$id" | 324 | \\setsid -f steam "steam://$action/$id" |
| 325 | , 0, &[_][]const u8{ "setsid", "-f", "steam", "steam://$action/$id" }); | 325 | , 0, &.{ "setsid", "-f", "steam", "steam://$action/$id" }); |
| 326 | testShellIteratorOk( | 326 | try testShellIteratorOk( |
| 327 | \\xargs -I% rg --no-heading --no-line-number --only-matching | 327 | \\xargs -I% rg --no-heading --no-line-number --only-matching |
| 328 | \\ --case-sensitive --multiline --text --byte-offset '(?-u)%' $@ | 328 | \\ --case-sensitive --multiline --text --byte-offset '(?-u)%' $@ |
| 329 | \\ | 329 | \\ |
| 330 | , 0, &[_][]const u8{ | 330 | , 0, &.{ |
| 331 | "xargs", "-I%", "rg", "--no-heading", | 331 | "xargs", "-I%", "rg", "--no-heading", |
| 332 | "--no-line-number", "--only-matching", "--case-sensitive", "--multiline", | 332 | "--no-line-number", "--only-matching", "--case-sensitive", "--multiline", |
| 333 | "--text", "--byte-offset", "(?-u)%", "$@", | 333 | "--text", "--byte-offset", "(?-u)%", "$@", |
| 334 | }); | 334 | }); |
| 335 | 335 | ||
| 336 | testShellIteratorErr("'a", error.QuoteNotClosed); | 336 | try testShellIteratorErr("'a", error.QuoteNotClosed); |
| 337 | testShellIteratorErr("'a\\", error.QuoteNotClosed); | 337 | try testShellIteratorErr("'a\\", error.QuoteNotClosed); |
| 338 | testShellIteratorErr("\"a", error.QuoteNotClosed); | 338 | try testShellIteratorErr("\"a", error.QuoteNotClosed); |
| 339 | testShellIteratorErr("\"a\\", error.QuoteNotClosed); | 339 | try testShellIteratorErr("\"a\\", error.QuoteNotClosed); |
| 340 | testShellIteratorErr("a\\", error.DanglingEscape); | 340 | try testShellIteratorErr("a\\", error.DanglingEscape); |
| 341 | } | 341 | } |
diff --git a/clap/comptime.zig b/clap/comptime.zig index 122ff16..7808f52 100644 --- a/clap/comptime.zig +++ b/clap/comptime.zig | |||
| @@ -14,7 +14,7 @@ pub fn ComptimeClap( | |||
| 14 | var flags: usize = 0; | 14 | var flags: usize = 0; |
| 15 | var single_options: usize = 0; | 15 | var single_options: usize = 0; |
| 16 | var multi_options: usize = 0; | 16 | var multi_options: usize = 0; |
| 17 | var converted_params: []const clap.Param(usize) = &[_]clap.Param(usize){}; | 17 | var converted_params: []const clap.Param(usize) = &.{}; |
| 18 | for (params) |param| { | 18 | for (params) |param| { |
| 19 | var index: usize = 0; | 19 | var index: usize = 0; |
| 20 | if (param.names.long != null or param.names.short != null) { | 20 | if (param.names.long != null or param.names.short != null) { |
| @@ -27,18 +27,18 @@ pub fn ComptimeClap( | |||
| 27 | ptr.* += 1; | 27 | ptr.* += 1; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | const converted = clap.Param(usize){ | 30 | converted_params = converted_params ++ [_]clap.Param(usize){.{ |
| 31 | .id = index, | 31 | .id = index, |
| 32 | .names = param.names, | 32 | .names = param.names, |
| 33 | .takes_value = param.takes_value, | 33 | .takes_value = param.takes_value, |
| 34 | }; | 34 | }}; |
| 35 | converted_params = converted_params ++ [_]clap.Param(usize){converted}; | ||
| 36 | } | 35 | } |
| 37 | 36 | ||
| 38 | return struct { | 37 | return struct { |
| 39 | single_options: [single_options]?[]const u8, | ||
| 40 | multi_options: [multi_options][]const []const u8, | 38 | multi_options: [multi_options][]const []const u8, |
| 41 | flags: [flags]bool, | 39 | single_options: [single_options][]const u8, |
| 40 | single_options_is_set: std.PackedIntArray(u1, single_options), | ||
| 41 | flags: std.PackedIntArray(u1, flags), | ||
| 42 | pos: []const []const u8, | 42 | pos: []const []const u8, |
| 43 | allocator: *mem.Allocator, | 43 | allocator: *mem.Allocator, |
| 44 | 44 | ||
| @@ -52,9 +52,12 @@ pub fn ComptimeClap( | |||
| 52 | var pos = std.ArrayList([]const u8).init(allocator); | 52 | var pos = std.ArrayList([]const u8).init(allocator); |
| 53 | 53 | ||
| 54 | var res = @This(){ | 54 | var res = @This(){ |
| 55 | .single_options = [_]?[]const u8{null} ** single_options, | 55 | .multi_options = .{undefined} ** multi_options, |
| 56 | .multi_options = [_][]const []const u8{undefined} ** multi_options, | 56 | .single_options = .{undefined} ** single_options, |
| 57 | .flags = [_]bool{false} ** flags, | 57 | .single_options_is_set = std.PackedIntArray(u1, single_options).init( |
| 58 | .{0} ** single_options, | ||
| 59 | ), | ||
| 60 | .flags = std.PackedIntArray(u1, flags).init(.{0} ** flags), | ||
| 58 | .pos = undefined, | 61 | .pos = undefined, |
| 59 | .allocator = allocator, | 62 | .allocator = allocator, |
| 60 | }; | 63 | }; |
| @@ -69,16 +72,18 @@ pub fn ComptimeClap( | |||
| 69 | try pos.append(arg.value.?); | 72 | try pos.append(arg.value.?); |
| 70 | } else if (param.takes_value == .one) { | 73 | } else if (param.takes_value == .one) { |
| 71 | debug.assert(res.single_options.len != 0); | 74 | debug.assert(res.single_options.len != 0); |
| 72 | if (res.single_options.len != 0) | 75 | if (res.single_options.len != 0) { |
| 73 | res.single_options[param.id] = arg.value.?; | 76 | res.single_options[param.id] = arg.value.?; |
| 77 | res.single_options_is_set.set(param.id, 1); | ||
| 78 | } | ||
| 74 | } else if (param.takes_value == .many) { | 79 | } else if (param.takes_value == .many) { |
| 75 | debug.assert(multis.len != 0); | 80 | debug.assert(multis.len != 0); |
| 76 | if (multis.len != 0) | 81 | if (multis.len != 0) |
| 77 | try multis[param.id].append(arg.value.?); | 82 | try multis[param.id].append(arg.value.?); |
| 78 | } else { | 83 | } else { |
| 79 | debug.assert(res.flags.len != 0); | 84 | debug.assert(res.flags.len() != 0); |
| 80 | if (res.flags.len != 0) | 85 | if (res.flags.len() != 0) |
| 81 | res.flags[param.id] = true; | 86 | res.flags.set(param.id, 1); |
| 82 | } | 87 | } |
| 83 | } | 88 | } |
| 84 | 89 | ||
| @@ -100,7 +105,7 @@ pub fn ComptimeClap( | |||
| 100 | if (param.takes_value != .none) | 105 | if (param.takes_value != .none) |
| 101 | @compileError(name ++ " is an option and not a flag."); | 106 | @compileError(name ++ " is an option and not a flag."); |
| 102 | 107 | ||
| 103 | return parser.flags[param.id]; | 108 | return parser.flags.get(param.id) != 0; |
| 104 | } | 109 | } |
| 105 | 110 | ||
| 106 | pub fn option(parser: @This(), comptime name: []const u8) ?[]const u8 { | 111 | pub fn option(parser: @This(), comptime name: []const u8) ?[]const u8 { |
| @@ -109,6 +114,8 @@ pub fn ComptimeClap( | |||
| 109 | @compileError(name ++ " is a flag and not an option."); | 114 | @compileError(name ++ " is a flag and not an option."); |
| 110 | if (param.takes_value == .many) | 115 | if (param.takes_value == .many) |
| 111 | @compileError(name ++ " takes many options, not one."); | 116 | @compileError(name ++ " takes many options, not one."); |
| 117 | if (parser.single_options_is_set.get(param.id) == 0) | ||
| 118 | return null; | ||
| 112 | return parser.single_options[param.id]; | 119 | return parser.single_options[param.id]; |
| 113 | } | 120 | } |
| 114 | 121 | ||
| @@ -146,30 +153,37 @@ pub fn ComptimeClap( | |||
| 146 | } | 153 | } |
| 147 | 154 | ||
| 148 | test "" { | 155 | test "" { |
| 149 | const Clap = ComptimeClap(clap.Help, comptime &[_]clap.Param(clap.Help){ | 156 | const Clap = ComptimeClap(clap.Help, comptime &.{ |
| 150 | clap.parseParam("-a, --aa ") catch unreachable, | 157 | clap.parseParam("-a, --aa") catch unreachable, |
| 151 | clap.parseParam("-b, --bb ") catch unreachable, | 158 | clap.parseParam("-b, --bb") catch unreachable, |
| 152 | clap.parseParam("-c, --cc <V>") catch unreachable, | 159 | clap.parseParam("-c, --cc <V>") catch unreachable, |
| 153 | clap.parseParam("-d, --dd <V>...") catch unreachable, | 160 | clap.parseParam("-d, --dd <V>...") catch unreachable, |
| 154 | clap.parseParam("<P>") catch unreachable, | 161 | clap.parseParam("<P>") catch unreachable, |
| 155 | }); | 162 | }); |
| 156 | 163 | ||
| 157 | var iter = clap.args.SliceIterator{ | 164 | var iter = clap.args.SliceIterator{ |
| 158 | .args = &[_][]const u8{ | 165 | .args = &.{ |
| 159 | "-a", "-c", "0", "something", "-d", "a", "--dd", "b", | 166 | "-a", "-c", "0", "something", "-d", "a", "--dd", "b", |
| 160 | }, | 167 | }, |
| 161 | }; | 168 | }; |
| 162 | var args = try Clap.parse(&iter, .{ .allocator = testing.allocator }); | 169 | var args = try Clap.parse(&iter, .{ .allocator = testing.allocator }); |
| 163 | defer args.deinit(); | 170 | defer args.deinit(); |
| 164 | 171 | ||
| 165 | testing.expect(args.flag("-a")); | 172 | try testing.expect(args.flag("-a")); |
| 166 | testing.expect(args.flag("--aa")); | 173 | try testing.expect(args.flag("--aa")); |
| 167 | testing.expect(!args.flag("-b")); | 174 | try testing.expect(!args.flag("-b")); |
| 168 | testing.expect(!args.flag("--bb")); | 175 | try testing.expect(!args.flag("--bb")); |
| 169 | testing.expectEqualStrings("0", args.option("-c").?); | 176 | try testing.expectEqualStrings("0", args.option("-c").?); |
| 170 | testing.expectEqualStrings("0", args.option("--cc").?); | 177 | try testing.expectEqualStrings("0", args.option("--cc").?); |
| 171 | testing.expectEqual(@as(usize, 1), args.positionals().len); | 178 | try testing.expectEqual(@as(usize, 1), args.positionals().len); |
| 172 | testing.expectEqualStrings("something", args.positionals()[0]); | 179 | try testing.expectEqualStrings("something", args.positionals()[0]); |
| 173 | testing.expectEqualSlices([]const u8, &[_][]const u8{ "a", "b" }, args.options("-d")); | 180 | try testing.expectEqualSlices([]const u8, &.{ "a", "b" }, args.options("-d")); |
| 174 | testing.expectEqualSlices([]const u8, &[_][]const u8{ "a", "b" }, args.options("--dd")); | 181 | try testing.expectEqualSlices([]const u8, &.{ "a", "b" }, args.options("--dd")); |
| 182 | } | ||
| 183 | |||
| 184 | test "empty" { | ||
| 185 | const Clap = ComptimeClap(clap.Help, comptime &.{}); | ||
| 186 | var iter = clap.args.SliceIterator{ .args = &.{} }; | ||
| 187 | var args = try Clap.parse(&iter, .{ .allocator = testing.allocator }); | ||
| 188 | defer args.deinit(); | ||
| 175 | } | 189 | } |
diff --git a/clap/streaming.zig b/clap/streaming.zig index a2a0ca8..e2f1311 100644 --- a/clap/streaming.zig +++ b/clap/streaming.zig | |||
| @@ -203,7 +203,7 @@ pub fn StreamingClap(comptime Id: type, comptime ArgIterator: type) type { | |||
| 203 | }; | 203 | }; |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | fn testNoErr(params: []const clap.Param(u8), args_strings: []const []const u8, results: []const Arg(u8)) void { | 206 | fn testNoErr(params: []const clap.Param(u8), args_strings: []const []const u8, results: []const Arg(u8)) !void { |
| 207 | var iter = args.SliceIterator{ .args = args_strings }; | 207 | var iter = args.SliceIterator{ .args = args_strings }; |
| 208 | var c = StreamingClap(u8, args.SliceIterator){ | 208 | var c = StreamingClap(u8, args.SliceIterator){ |
| 209 | .params = params, | 209 | .params = params, |
| @@ -211,22 +211,22 @@ fn testNoErr(params: []const clap.Param(u8), args_strings: []const []const u8, r | |||
| 211 | }; | 211 | }; |
| 212 | 212 | ||
| 213 | for (results) |res| { | 213 | for (results) |res| { |
| 214 | const arg = (c.next() catch unreachable) orelse unreachable; | 214 | const arg = (try c.next()) orelse return error.TestFailed; |
| 215 | testing.expectEqual(res.param, arg.param); | 215 | try testing.expectEqual(res.param, arg.param); |
| 216 | const expected_value = res.value orelse { | 216 | const expected_value = res.value orelse { |
| 217 | testing.expectEqual(@as(@TypeOf(arg.value), null), arg.value); | 217 | try testing.expectEqual(@as(@TypeOf(arg.value), null), arg.value); |
| 218 | continue; | 218 | continue; |
| 219 | }; | 219 | }; |
| 220 | const actual_value = arg.value orelse unreachable; | 220 | const actual_value = arg.value orelse return error.TestFailed; |
| 221 | testing.expectEqualSlices(u8, expected_value, actual_value); | 221 | try testing.expectEqualSlices(u8, expected_value, actual_value); |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | if (c.next() catch unreachable) |_| | 224 | if (try c.next()) |_| |
| 225 | unreachable; | 225 | return error.TestFailed; |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | fn testErr(params: []const clap.Param(u8), args_strings: []const []const u8, expected: []const u8) void { | 228 | fn testErr(params: []const clap.Param(u8), args_strings: []const []const u8, expected: []const u8) !void { |
| 229 | var diag = clap.Diagnostic{}; | 229 | var diag: clap.Diagnostic = undefined; |
| 230 | var iter = args.SliceIterator{ .args = args_strings }; | 230 | var iter = args.SliceIterator{ .args = args_strings }; |
| 231 | var c = StreamingClap(u8, args.SliceIterator){ | 231 | var c = StreamingClap(u8, args.SliceIterator){ |
| 232 | .params = params, | 232 | .params = params, |
| @@ -236,12 +236,12 @@ fn testErr(params: []const clap.Param(u8), args_strings: []const []const u8, exp | |||
| 236 | while (c.next() catch |err| { | 236 | while (c.next() catch |err| { |
| 237 | var buf: [1024]u8 = undefined; | 237 | var buf: [1024]u8 = undefined; |
| 238 | var fbs = io.fixedBufferStream(&buf); | 238 | var fbs = io.fixedBufferStream(&buf); |
| 239 | diag.report(fbs.writer(), err) catch unreachable; | 239 | diag.report(fbs.writer(), err) catch return error.TestFailed; |
| 240 | testing.expectEqualStrings(expected, fbs.getWritten()); | 240 | try testing.expectEqualStrings(expected, fbs.getWritten()); |
| 241 | return; | 241 | return; |
| 242 | }) |_| {} | 242 | }) |_| {} |
| 243 | 243 | ||
| 244 | testing.expect(false); | 244 | try testing.expect(false); |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | test "short params" { | 247 | test "short params" { |
| @@ -265,14 +265,14 @@ test "short params" { | |||
| 265 | const c = ¶ms[2]; | 265 | const c = ¶ms[2]; |
| 266 | const d = ¶ms[3]; | 266 | const d = ¶ms[3]; |
| 267 | 267 | ||
| 268 | testNoErr( | 268 | try testNoErr( |
| 269 | ¶ms, | 269 | ¶ms, |
| 270 | &[_][]const u8{ | 270 | &.{ |
| 271 | "-a", "-b", "-ab", "-ba", | 271 | "-a", "-b", "-ab", "-ba", |
| 272 | "-c", "0", "-c=0", "-ac", | 272 | "-c", "0", "-c=0", "-ac", |
| 273 | "0", "-ac=0", "-d=0", | 273 | "0", "-ac=0", "-d=0", |
| 274 | }, | 274 | }, |
| 275 | &[_]Arg(u8){ | 275 | &.{ |
| 276 | .{ .param = a }, | 276 | .{ .param = a }, |
| 277 | .{ .param = b }, | 277 | .{ .param = b }, |
| 278 | .{ .param = a }, | 278 | .{ .param = a }, |
| @@ -311,14 +311,14 @@ test "long params" { | |||
| 311 | const cc = ¶ms[2]; | 311 | const cc = ¶ms[2]; |
| 312 | const dd = ¶ms[3]; | 312 | const dd = ¶ms[3]; |
| 313 | 313 | ||
| 314 | testNoErr( | 314 | try testNoErr( |
| 315 | ¶ms, | 315 | ¶ms, |
| 316 | &[_][]const u8{ | 316 | &.{ |
| 317 | "--aa", "--bb", | 317 | "--aa", "--bb", |
| 318 | "--cc", "0", | 318 | "--cc", "0", |
| 319 | "--cc=0", "--dd=0", | 319 | "--cc=0", "--dd=0", |
| 320 | }, | 320 | }, |
| 321 | &[_]Arg(u8){ | 321 | &.{ |
| 322 | .{ .param = aa }, | 322 | .{ .param = aa }, |
| 323 | .{ .param = bb }, | 323 | .{ .param = bb }, |
| 324 | .{ .param = cc, .value = "0" }, | 324 | .{ .param = cc, .value = "0" }, |
| @@ -334,10 +334,10 @@ test "positional params" { | |||
| 334 | .takes_value = .one, | 334 | .takes_value = .one, |
| 335 | }}; | 335 | }}; |
| 336 | 336 | ||
| 337 | testNoErr( | 337 | try testNoErr( |
| 338 | ¶ms, | 338 | ¶ms, |
| 339 | &[_][]const u8{ "aa", "bb" }, | 339 | &.{ "aa", "bb" }, |
| 340 | &[_]Arg(u8){ | 340 | &.{ |
| 341 | .{ .param = ¶ms[0], .value = "aa" }, | 341 | .{ .param = ¶ms[0], .value = "aa" }, |
| 342 | .{ .param = ¶ms[0], .value = "bb" }, | 342 | .{ .param = ¶ms[0], .value = "bb" }, |
| 343 | }, | 343 | }, |
| @@ -367,16 +367,16 @@ test "all params" { | |||
| 367 | const cc = ¶ms[2]; | 367 | const cc = ¶ms[2]; |
| 368 | const positional = ¶ms[3]; | 368 | const positional = ¶ms[3]; |
| 369 | 369 | ||
| 370 | testNoErr( | 370 | try testNoErr( |
| 371 | ¶ms, | 371 | ¶ms, |
| 372 | &[_][]const u8{ | 372 | &.{ |
| 373 | "-a", "-b", "-ab", "-ba", | 373 | "-a", "-b", "-ab", "-ba", |
| 374 | "-c", "0", "-c=0", "-ac", | 374 | "-c", "0", "-c=0", "-ac", |
| 375 | "0", "-ac=0", "--aa", "--bb", | 375 | "0", "-ac=0", "--aa", "--bb", |
| 376 | "--cc", "0", "--cc=0", "something", | 376 | "--cc", "0", "--cc=0", "something", |
| 377 | "-", "--", "--cc=0", "-a", | 377 | "-", "--", "--cc=0", "-a", |
| 378 | }, | 378 | }, |
| 379 | &[_]Arg(u8){ | 379 | &.{ |
| 380 | .{ .param = aa }, | 380 | .{ .param = aa }, |
| 381 | .{ .param = bb }, | 381 | .{ .param = bb }, |
| 382 | .{ .param = aa }, | 382 | .{ .param = aa }, |
| @@ -413,12 +413,12 @@ test "errors" { | |||
| 413 | .takes_value = .one, | 413 | .takes_value = .one, |
| 414 | }, | 414 | }, |
| 415 | }; | 415 | }; |
| 416 | testErr(¶ms, &[_][]const u8{"q"}, "Invalid argument 'q'\n"); | 416 | try testErr(¶ms, &.{"q"}, "Invalid argument 'q'\n"); |
| 417 | testErr(¶ms, &[_][]const u8{"-q"}, "Invalid argument '-q'\n"); | 417 | try testErr(¶ms, &.{"-q"}, "Invalid argument '-q'\n"); |
| 418 | testErr(¶ms, &[_][]const u8{"--q"}, "Invalid argument '--q'\n"); | 418 | try testErr(¶ms, &.{"--q"}, "Invalid argument '--q'\n"); |
| 419 | testErr(¶ms, &[_][]const u8{"--q=1"}, "Invalid argument '--q'\n"); | 419 | try testErr(¶ms, &.{"--q=1"}, "Invalid argument '--q'\n"); |
| 420 | testErr(¶ms, &[_][]const u8{"-a=1"}, "The argument '-a' does not take a value\n"); | 420 | try testErr(¶ms, &.{"-a=1"}, "The argument '-a' does not take a value\n"); |
| 421 | testErr(¶ms, &[_][]const u8{"--aa=1"}, "The argument '--aa' does not take a value\n"); | 421 | try testErr(¶ms, &.{"--aa=1"}, "The argument '--aa' does not take a value\n"); |
| 422 | testErr(¶ms, &[_][]const u8{"-c"}, "The argument '-c' requires a value but none was supplied\n"); | 422 | try testErr(¶ms, &.{"-c"}, "The argument '-c' requires a value but none was supplied\n"); |
| 423 | testErr(¶ms, &[_][]const u8{"--cc"}, "The argument '--cc' requires a value but none was supplied\n"); | 423 | try testErr(¶ms, &.{"--cc"}, "The argument '--cc' requires a value but none was supplied\n"); |
| 424 | } | 424 | } |