Merge remote-tracking branch 'luarocks/refs/pull/3/head'

This commit is contained in:
daurnimator
2019-05-31 22:40:18 +10:00
8 changed files with 151 additions and 3 deletions

View File

@@ -161,5 +161,15 @@ describe("tests related to positional arguments", function()
}
assert.has_error(function() parser:parse{} end, "missing argument 'foo1'")
end)
it("handles invalid argument choices correctly", function()
local parse = Parser()
parse:argument "foo" {
choices = {"bar", "baz", "qu"}
}
assert.has_error(function()
parse:parse{"foo", "quu"}
end, "argument 'foo' must be one of 'bar', 'baz', 'qu'")
end)
end)
end)

View File

@@ -77,6 +77,34 @@ Options:
--config <config>]], parser:get_help())
end)
it("creates correct help message for arguments with choices", function()
local parser = Parser "foo"
parser:argument "move"
:choices {"rock", "paper", "scissors"}
assert.equal([[
Usage: foo [-h] {rock,paper,scissors}
Arguments:
{rock,paper,scissors}
Options:
-h, --help Show this help message and exit.]], parser:get_help())
end)
it("creates correct help message for options with argument choices", function()
local parser = Parser "foo"
parser:option "--format"
:choices {"short", "medium", "full"}
assert.equal([[
Usage: foo [-h] [--format {short,medium,full}]
Options:
-h, --help Show this help message and exit.
--format {short,medium,full}]], parser:get_help())
end)
it("adds margin for multiline descriptions", function()
local parser = Parser "foo"
parser:flag "-v"

View File

@@ -290,6 +290,16 @@ describe("tests related to options", function()
end, "too many arguments")
end)
it("handles invalid argument choices correctly", function()
local parse = Parser()
parse:option "-s" "--server" {
choices = {"foo", "bar", "baz"}
}
assert.has_error(function()
parse:parse{"-slocalhost"}
end, "argument for option '-s' must be one of 'foo', 'bar', 'baz'")
end)
it("doesn't accept GNU-like long options when it doesn't need arguments", function()
local parser = Parser()
parser:flag "-q" "--quiet"

View File

@@ -89,6 +89,30 @@ Usage: foo <first> <second-and-third> <second-and-third>
)
end)
it("creates correct usage message for arguments with choices", function()
local parser = Parser "foo"
:add_help(false)
parser:argument "move"
:choices {"rock", "paper", "scissors"}
assert.equal(
[=[Usage: foo {rock,paper,scissors}]=],
parser:get_usage()
)
end)
it("creates correct usage message for options with argument choices", function()
local parser = Parser "foo"
:add_help(false)
parser:option "--format"
:choices {"short", "medium", "full"}
assert.equal(
[=[Usage: foo [--format {short,medium,full}]]=],
parser:get_usage()
)
end)
it("creates correct usage message for commands", function()
local parser = Parser "foo"
:add_help(false)