mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
added a few tests for :pparse()
This commit is contained in:
19
spec/pparse_spec.lua
Normal file
19
spec/pparse_spec.lua
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
local Parser = require "argparse"
|
||||||
|
|
||||||
|
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)
|
||||||
|
end)
|
@@ -769,7 +769,7 @@ end
|
|||||||
function Parser:pparse(args)
|
function Parser:pparse(args)
|
||||||
local errmsg
|
local errmsg
|
||||||
local ok, result = pcall(function()
|
local ok, result = pcall(function()
|
||||||
return self:_parse(args, function(err)
|
return self:_parse(args, function(parser, err)
|
||||||
errmsg = err
|
errmsg = err
|
||||||
return error()
|
return error()
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user