forked from mpeterv/argparse
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpparse_spec.lua
More file actions
27 lines (24 loc) · 923 Bytes
/
pparse_spec.lua
File metadata and controls
27 lines (24 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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("missing argument 'foo'", errmsg)
end)
it("rethrows errors from callbacks", function()
local parser = Parser()
parser:flag "--foo"
:action(function() error("some error message") end)
assert.error_matches(function() parser:pparse{"--foo"} end, "some error message")
end)
end)