mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-27 18:42:20 +00:00
Add coverage gathering
This commit is contained in:
@@ -14,10 +14,14 @@ before_install:
|
|||||||
- luarocks install luacheck
|
- luarocks install luacheck
|
||||||
- luarocks install dkjson --deps-mode=none
|
- luarocks install dkjson --deps-mode=none
|
||||||
- luarocks install busted
|
- luarocks install busted
|
||||||
|
- luarocks install luacov-coveralls
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- luarocks make
|
- luarocks make
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- busted
|
|
||||||
- luacheck src spec
|
- luacheck src spec
|
||||||
|
- busted -c
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- luacov-coveralls
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
# argparse
|
# argparse
|
||||||
|
|
||||||
[](https://travis-ci.org/mpeterv/argparse)
|
[](https://travis-ci.org/mpeterv/argparse)
|
||||||
|
[](https://coveralls.io/github/mpeterv/argparse?branch=master)
|
||||||
|
|
||||||
Argparse is a feature-rich command line parser for Lua inspired by argparse for Python.
|
Argparse is a feature-rich command line parser for Lua inspired by argparse for Python.
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ The tutorial is available [online](http://argparse.readthedocs.org) and in the `
|
|||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
argparse comes with a testing suite located in `spec` directory. [busted](http://olivinelabs.com/busted/) is required for testing, it can be installed using LuaRocks. Run the tests using `busted spec` command from the argparse folder.
|
argparse comes with a testing suite located in `spec` directory. [busted](http://olivinelabs.com/busted/) is required for testing, it can be installed using LuaRocks. Run the tests using `busted` command from the argparse folder.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@@ -1,5 +1,14 @@
|
|||||||
|
local script = "./spec/script.lua"
|
||||||
|
local script_cmd = "lua"
|
||||||
|
|
||||||
|
if package.loaded["luacov.runner"] then
|
||||||
|
script_cmd = script_cmd .. " -lluacov"
|
||||||
|
end
|
||||||
|
|
||||||
|
script_cmd = script_cmd .. " " .. script
|
||||||
|
|
||||||
local function get_output(args)
|
local function get_output(args)
|
||||||
local handler = io.popen("./spec/script " .. args .. " 2>&1", "r")
|
local handler = io.popen(script_cmd .. " " .. args .. " 2>&1", "r")
|
||||||
local output = handler:read("*a")
|
local output = handler:read("*a")
|
||||||
handler:close()
|
handler:close()
|
||||||
return output
|
return output
|
||||||
@@ -9,7 +18,7 @@ describe("tests related to CLI behaviour #unsafe", function()
|
|||||||
describe("error messages", function()
|
describe("error messages", function()
|
||||||
it("generates correct error message without arguments", function()
|
it("generates correct error message without arguments", function()
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
Usage: ./spec/script [-v] [-h] <input> [<command>] ...
|
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||||
|
|
||||||
Error: too few arguments
|
Error: too few arguments
|
||||||
]], get_output(""))
|
]], get_output(""))
|
||||||
@@ -17,7 +26,7 @@ Error: too few arguments
|
|||||||
|
|
||||||
it("generates correct error message with too many arguments", function()
|
it("generates correct error message with too many arguments", function()
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
Usage: ./spec/script [-v] [-h] <input> [<command>] ...
|
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||||
|
|
||||||
Error: unknown command 'bar'
|
Error: unknown command 'bar'
|
||||||
]], get_output("foo bar"))
|
]], get_output("foo bar"))
|
||||||
@@ -25,7 +34,7 @@ Error: unknown command 'bar'
|
|||||||
|
|
||||||
it("generates correct error message with unexpected argument", function()
|
it("generates correct error message with unexpected argument", function()
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
Usage: ./spec/script [-v] [-h] <input> [<command>] ...
|
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||||
|
|
||||||
Error: option '--verbose' does not take arguments
|
Error: option '--verbose' does not take arguments
|
||||||
]], get_output("--verbose=true"))
|
]], get_output("--verbose=true"))
|
||||||
@@ -33,7 +42,7 @@ Error: option '--verbose' does not take arguments
|
|||||||
|
|
||||||
it("generates correct error message with unexpected option", function()
|
it("generates correct error message with unexpected option", function()
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
Usage: ./spec/script [-v] [-h] <input> [<command>] ...
|
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||||
|
|
||||||
Error: unknown option '-q'
|
Error: unknown option '-q'
|
||||||
Did you mean one of these: '-h' '-v'?
|
Did you mean one of these: '-h' '-v'?
|
||||||
@@ -42,7 +51,7 @@ Did you mean one of these: '-h' '-v'?
|
|||||||
|
|
||||||
it("generates correct error message and tip with unexpected command", function()
|
it("generates correct error message and tip with unexpected command", function()
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
Usage: ./spec/script [-v] [-h] <input> [<command>] ...
|
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||||
|
|
||||||
Error: unknown command 'nstall'
|
Error: unknown command 'nstall'
|
||||||
Did you mean 'install'?
|
Did you mean 'install'?
|
||||||
@@ -51,7 +60,7 @@ Did you mean 'install'?
|
|||||||
|
|
||||||
it("generates correct error message without arguments in command", function()
|
it("generates correct error message without arguments in command", function()
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
Usage: ./spec/script install [-f <from>] [-h] <rock> [<version>]
|
Usage: ]]..script..[[ install [-f <from>] [-h] <rock> [<version>]
|
||||||
|
|
||||||
Error: too few arguments
|
Error: too few arguments
|
||||||
]], get_output("foo install"))
|
]], get_output("foo install"))
|
||||||
@@ -59,7 +68,7 @@ Error: too few arguments
|
|||||||
|
|
||||||
it("generates correct error message and tip in command", function()
|
it("generates correct error message and tip in command", function()
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
Usage: ./spec/script install [-f <from>] [-h] <rock> [<version>]
|
Usage: ]]..script..[[ install [-f <from>] [-h] <rock> [<version>]
|
||||||
|
|
||||||
Error: unknown option '--form'
|
Error: unknown option '--form'
|
||||||
Did you mean '--from'?
|
Did you mean '--from'?
|
||||||
@@ -70,7 +79,7 @@ Did you mean '--from'?
|
|||||||
describe("help messages", function()
|
describe("help messages", function()
|
||||||
it("generates correct help message", function()
|
it("generates correct help message", function()
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
Usage: ./spec/script [-v] [-h] <input> [<command>] ...
|
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||||
|
|
||||||
A testing program.
|
A testing program.
|
||||||
|
|
||||||
@@ -88,7 +97,7 @@ Commands:
|
|||||||
|
|
||||||
it("generates correct help message for command", function()
|
it("generates correct help message for command", function()
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
Usage: ./spec/script install [-f <from>] [-h] <rock> [<version>]
|
Usage: ]]..script..[[ install [-f <from>] [-h] <rock> [<version>]
|
||||||
|
|
||||||
Install a rock.
|
Install a rock.
|
||||||
|
|
||||||
@@ -106,21 +115,21 @@ Options:
|
|||||||
|
|
||||||
describe("data flow", function()
|
describe("data flow", function()
|
||||||
it("works with one argument", function()
|
it("works with one argument", function()
|
||||||
local handler = io.popen("./spec/script foo 2>&1", "r")
|
local handler = io.popen(script_cmd .. " foo 2>&1", "r")
|
||||||
assert.equal("foo", handler:read "*l")
|
assert.equal("foo", handler:read "*l")
|
||||||
assert.equal("0", handler:read "*l")
|
assert.equal("0", handler:read "*l")
|
||||||
handler:close()
|
handler:close()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("works with one argument and a flag", function()
|
it("works with one argument and a flag", function()
|
||||||
local handler = io.popen("./spec/script -v foo --verbose 2>&1", "r")
|
local handler = io.popen(script_cmd .. " -v foo --verbose 2>&1", "r")
|
||||||
assert.equal("foo", handler:read "*l")
|
assert.equal("foo", handler:read "*l")
|
||||||
assert.equal("2", handler:read "*l")
|
assert.equal("2", handler:read "*l")
|
||||||
handler:close()
|
handler:close()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("works with command", function()
|
it("works with command", function()
|
||||||
local handler = io.popen("./spec/script foo -v install bar 2>&1", "r")
|
local handler = io.popen(script_cmd .. " foo -v install bar 2>&1", "r")
|
||||||
assert.equal("foo", handler:read "*l")
|
assert.equal("foo", handler:read "*l")
|
||||||
assert.equal("1", handler:read "*l")
|
assert.equal("1", handler:read "*l")
|
||||||
assert.equal("true", handler:read "*l")
|
assert.equal("true", handler:read "*l")
|
||||||
@@ -131,7 +140,7 @@ Options:
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("works with command and options", function()
|
it("works with command and options", function()
|
||||||
local handler = io.popen("./spec/script foo --verbose install bar 0.1 --from=there -vv 2>&1", "r")
|
local handler = io.popen(script_cmd .. " foo --verbose install bar 0.1 --from=there -vv 2>&1", "r")
|
||||||
assert.equal("foo", handler:read "*l")
|
assert.equal("foo", handler:read "*l")
|
||||||
assert.equal("2", handler:read "*l")
|
assert.equal("2", handler:read "*l")
|
||||||
assert.equal("true", handler:read "*l")
|
assert.equal("true", handler:read "*l")
|
||||||
|
@@ -26,8 +26,8 @@ install:option "-f" "--from"
|
|||||||
:description "Fetch the rock from this server. "
|
:description "Fetch the rock from this server. "
|
||||||
:target "server"
|
:target "server"
|
||||||
|
|
||||||
local usage = parser:get_usage()
|
parser:get_usage()
|
||||||
local help = parser:get_help()
|
parser:get_help()
|
||||||
local args = parser:parse()
|
local args = parser:parse()
|
||||||
|
|
||||||
print(args.input)
|
print(args.input)
|
Reference in New Issue
Block a user