Add tests for help command

This commit is contained in:
Paul Ouellette
2019-05-25 00:24:49 -04:00
parent 55acc1689c
commit 24398b67ce
2 changed files with 40 additions and 2 deletions

View File

@@ -77,7 +77,7 @@ Did you mean '--from'?
end)
describe("help messages", function()
it("generates correct help message", function()
it("generates correct help message using help flag", function()
assert.equal([[
Usage: ]]..script..[[ [-h] [-v] <input> [<command>] ...
@@ -91,11 +91,31 @@ Options:
-v, --verbose Sets verbosity level.
Commands:
help Show help for commands.
install Install a rock.
]], get_output("--help"))
end)
it("generates correct help message for command", function()
it("generates correct help message using help command", function()
assert.equal([[
Usage: ]]..script..[[ [-h] [-v] <input> [<command>] ...
A testing program.
Arguments:
input
Options:
-h, --help Show this help message and exit.
-v, --verbose Sets verbosity level.
Commands:
help Show help for commands.
install Install a rock.
]], get_output("foo help"))
end)
it("generates correct help message for command using help flag", function()
assert.equal([[
Usage: ]]..script..[[ install [-h] [-f <from>] <rock> [<version>]
@@ -111,6 +131,23 @@ Options:
--from <from>
]], get_output("foo install --help"))
end)
it("generates correct help message for command using help command", function()
assert.equal([[
Usage: ]]..script..[[ install [-h] [-f <from>] <rock> [<version>]
Install a rock.
Arguments:
rock Name of the rock.
version Version of the rock.
Options:
-h, --help Show this help message and exit.
-f <from>, Fetch the rock from this server.
--from <from>
]], get_output("foo help install"))
end)
end)
describe("data flow", function()

View File

@@ -3,6 +3,7 @@ local Parser = require "argparse"
local parser = Parser()
:description "A testing program."
:add_help_command(true)
:require_command(false)
parser:argument "input"