comparison spec/util_argparse_spec.lua @ 13762:81856814d74f 13.0

util.argparse: Fix bug (regression?) in argument parsing with --foo=bar After recent changes, '--foo bar' was working, but '--foo=bar' was not. The test had a typo (?) (bar != baz) and because util.argparse is not strict by default, the typo was not caught. The typo caused the code to take a different path, and bypassed the buggy handling of --foo=bar options. I've preserved the existing test (typo and all!) because it's still an interesting test, and ensures no unintended behaviour changes compared to the old code. However I've added a new variant of the test, with strict mode enabled and the typo fixed. This test failed due to the bug, and this commit introduces a fix.
author Matthew Wild <mwild1@gmail.com>
date Tue, 11 Mar 2025 18:27:36 +0000
parents 48c056c10e5a
children aac30c5ee334
comparison
equal deleted inserted replaced
13761:8f516d20d288 13762:81856814d74f
52 local opts, err = parse({ "--foo"; "bar"; "--baz=moo" }, { value_params = { foo = true; bar = true } }); 52 local opts, err = parse({ "--foo"; "bar"; "--baz=moo" }, { value_params = { foo = true; bar = true } });
53 assert.falsy(err); 53 assert.falsy(err);
54 assert.same({ foo = "bar"; baz = "moo" }, opts); 54 assert.same({ foo = "bar"; baz = "moo" }, opts);
55 end); 55 end);
56 56
57 it("supports value arguments in strict mode", function()
58 local opts, err = parse({ "--foo"; "bar"; "--baz=moo" }, { strict = true, value_params = { foo = true; baz = true } });
59 assert.falsy(err);
60 assert.same({ foo = "bar"; baz = "moo" }, opts);
61 end);
62
57 it("demands values for value params", function() 63 it("demands values for value params", function()
58 local opts, err, where = parse({ "--foo" }, { value_params = { foo = true } }); 64 local opts, err, where = parse({ "--foo" }, { value_params = { foo = true } });
59 assert.falsy(opts); 65 assert.falsy(opts);
60 assert.equal("missing-value", err); 66 assert.equal("missing-value", err);
61 assert.equal("--foo", where); 67 assert.equal("--foo", where);