diff --git a/.luacov b/.luacov
new file mode 100644
index 0000000..b6e9823
--- /dev/null
+++ b/.luacov
@@ -0,0 +1 @@
+return {modules = {argparse = "src/argparse.lua"}}
diff --git a/.travis.yml b/.travis.yml
index e3bafd7..952f5ea 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,10 +14,14 @@ before_install:
- luarocks install luacheck
- luarocks install dkjson --deps-mode=none
- luarocks install busted
+ - luarocks install luacov-coveralls
install:
- luarocks make
script:
- - busted
- luacheck src spec
+ - busted -c
+
+after_success:
+ - luacov-coveralls
diff --git a/README.md b/README.md
index b89bf35..a2b9824 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
# 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.
@@ -113,7 +114,7 @@ The tutorial is available [online](http://argparse.readthedocs.org) and in the `
## 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
diff --git a/spec/integrity_spec.lua b/spec/integrity_spec.lua
index 8797639..c81abbf 100644
--- a/spec/integrity_spec.lua
+++ b/spec/integrity_spec.lua
@@ -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 handler = io.popen("./spec/script " .. args .. " 2>&1", "r")
+ local handler = io.popen(script_cmd .. " " .. args .. " 2>&1", "r")
local output = handler:read("*a")
handler:close()
return output
@@ -9,7 +18,7 @@ describe("tests related to CLI behaviour #unsafe", function()
describe("error messages", function()
it("generates correct error message without arguments", function()
assert.equal([[
-Usage: ./spec/script [-v] [-h] [] ...
+Usage: ]]..script..[[ [-v] [-h] [] ...
Error: too few arguments
]], get_output(""))
@@ -17,7 +26,7 @@ Error: too few arguments
it("generates correct error message with too many arguments", function()
assert.equal([[
-Usage: ./spec/script [-v] [-h] [] ...
+Usage: ]]..script..[[ [-v] [-h] [] ...
Error: unknown command 'bar'
]], get_output("foo bar"))
@@ -25,7 +34,7 @@ Error: unknown command 'bar'
it("generates correct error message with unexpected argument", function()
assert.equal([[
-Usage: ./spec/script [-v] [-h] [] ...
+Usage: ]]..script..[[ [-v] [-h] [] ...
Error: option '--verbose' does not take arguments
]], get_output("--verbose=true"))
@@ -33,7 +42,7 @@ Error: option '--verbose' does not take arguments
it("generates correct error message with unexpected option", function()
assert.equal([[
-Usage: ./spec/script [-v] [-h] [] ...
+Usage: ]]..script..[[ [-v] [-h] [] ...
Error: unknown option '-q'
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()
assert.equal([[
-Usage: ./spec/script [-v] [-h] [] ...
+Usage: ]]..script..[[ [-v] [-h] [] ...
Error: unknown command 'nstall'
Did you mean 'install'?
@@ -51,7 +60,7 @@ Did you mean 'install'?
it("generates correct error message without arguments in command", function()
assert.equal([[
-Usage: ./spec/script install [-f ] [-h] []
+Usage: ]]..script..[[ install [-f ] [-h] []
Error: too few arguments
]], get_output("foo install"))
@@ -59,7 +68,7 @@ Error: too few arguments
it("generates correct error message and tip in command", function()
assert.equal([[
-Usage: ./spec/script install [-f ] [-h] []
+Usage: ]]..script..[[ install [-f ] [-h] []
Error: unknown option '--form'
Did you mean '--from'?
@@ -70,7 +79,7 @@ Did you mean '--from'?
describe("help messages", function()
it("generates correct help message", function()
assert.equal([[
-Usage: ./spec/script [-v] [-h] [] ...
+Usage: ]]..script..[[ [-v] [-h] [] ...
A testing program.
@@ -88,7 +97,7 @@ Commands:
it("generates correct help message for command", function()
assert.equal([[
-Usage: ./spec/script install [-f ] [-h] []
+Usage: ]]..script..[[ install [-f ] [-h] []
Install a rock.
@@ -106,21 +115,21 @@ Options:
describe("data flow", 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("0", handler:read "*l")
handler:close()
end)
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("2", handler:read "*l")
handler:close()
end)
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("1", handler:read "*l")
assert.equal("true", handler:read "*l")
@@ -131,7 +140,7 @@ Options:
end)
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("2", handler:read "*l")
assert.equal("true", handler:read "*l")
diff --git a/spec/script b/spec/script.lua
similarity index 92%
rename from spec/script
rename to spec/script.lua
index 506f08d..ea666c9 100755
--- a/spec/script
+++ b/spec/script.lua
@@ -26,8 +26,8 @@ install:option "-f" "--from"
:description "Fetch the rock from this server. "
:target "server"
-local usage = parser:get_usage()
-local help = parser:get_help()
+parser:get_usage()
+parser:get_help()
local args = parser:parse()
print(args.input)