mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Add coverage gathering
This commit is contained in:
@@ -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] <input> [<command>] ...
|
||||
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||
|
||||
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] <input> [<command>] ...
|
||||
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||
|
||||
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] <input> [<command>] ...
|
||||
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||
|
||||
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] <input> [<command>] ...
|
||||
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||
|
||||
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] <input> [<command>] ...
|
||||
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||
|
||||
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 <from>] [-h] <rock> [<version>]
|
||||
Usage: ]]..script..[[ install [-f <from>] [-h] <rock> [<version>]
|
||||
|
||||
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 <from>] [-h] <rock> [<version>]
|
||||
Usage: ]]..script..[[ install [-f <from>] [-h] <rock> [<version>]
|
||||
|
||||
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] <input> [<command>] ...
|
||||
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||
|
||||
A testing program.
|
||||
|
||||
@@ -88,7 +97,7 @@ Commands:
|
||||
|
||||
it("generates correct help message for command", function()
|
||||
assert.equal([[
|
||||
Usage: ./spec/script install [-f <from>] [-h] <rock> [<version>]
|
||||
Usage: ]]..script..[[ install [-f <from>] [-h] <rock> [<version>]
|
||||
|
||||
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")
|
||||
|
Reference in New Issue
Block a user