mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Allow setting several names using 'name' property instead, e.g. ':name "-f --foo"' instead of ':aliases {"-f", "--foo"}'. This change breaks documented interface of 0.3.x.
28 lines
882 B
Lua
28 lines
882 B
Lua
local Parser = require "argparse"
|
|
getmetatable(Parser()).error = function(_, msg) error(msg) end
|
|
|
|
describe("tests related to :pparse()", function()
|
|
it("returns true and result on success", function()
|
|
local parser = Parser()
|
|
parser:option "-s --server"
|
|
local ok, args = parser:pparse{"--server", "foo"}
|
|
assert.is_true(ok)
|
|
assert.same({server = "foo"}, args)
|
|
end)
|
|
|
|
it("returns false and bare error message on failure", function()
|
|
local parser = Parser()
|
|
parser:argument "foo"
|
|
local ok, errmsg = parser:pparse{}
|
|
assert.is_false(ok)
|
|
assert.equal("too few arguments", errmsg)
|
|
end)
|
|
|
|
it("still raises an error if it is caused by misconfiguration", function()
|
|
local parser = Parser()
|
|
parser:flag "--foo"
|
|
:action(error)
|
|
assert.has_error(function() parser:pparse{"--foo"} end)
|
|
end)
|
|
end)
|