diff --git a/busted/modules/cli.lua b/busted/modules/cli.lua index 0cca3e2b..64e50d40 100644 --- a/busted/modules/cli.lua +++ b/busted/modules/cli.lua @@ -168,6 +168,10 @@ return function(options) -- Parse the cli arguments local cliArgs, cliErr = cli:parse(args) if not cliArgs then + if cliErr:match("^Usage") then + return { help = true, helpText = cliErr }, nil + end + return nil, appName .. ': error: ' .. cliErr .. '; re-run with --help for usage.' end diff --git a/busted/runner.lua b/busted/runner.lua index ce4a4830..ad8257af 100644 --- a/busted/runner.lua +++ b/busted/runner.lua @@ -41,9 +41,14 @@ return function(options) exit(1, forceExit) end + if cliArgs.help then + io.stdout:write(cliArgs.helpText .. '\n') + exit(0, forceExit) + end + if cliArgs.version then -- Return early if asked for the version - print(busted.version) + io.stdout:write(busted.version .. '\n') exit(0, forceExit) end diff --git a/spec/cl_spec.lua b/spec/cl_spec.lua index c631e09d..d5a6df28 100644 --- a/spec/cl_spec.lua +++ b/spec/cl_spec.lua @@ -219,7 +219,7 @@ describe('Tests the busted command-line options', function() it('tests running with --help specified', function() local success, _ = executeBusted('--help') - assert.is_false(success) + assert.is_true(success) end) it('tests running a non-compiling testfile', function() @@ -353,7 +353,7 @@ describe('Test busted running standalone', function() it('tests running with --help specified', function() local success = executeLua('spec/cl_standalone.lua --help') - assert.is_false(success) + assert.is_true(success) end) it('tests running via stdin', function()