Skip to content

Commit

Permalink
Refactor default options
Browse files Browse the repository at this point in the history
  • Loading branch information
o-lim committed Jul 5, 2015
1 parent 37589d8 commit b7f643d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bin/busted
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env lua
-- Busted command-line runner
require 'busted.runner'({ batch = true })
require 'busted.runner'({ standalone = false })
1 change: 1 addition & 0 deletions busted-2.0.rc10-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ build = {
['busted.context'] = 'busted/context.lua',
['busted.environment'] = 'busted/environment.lua',
['busted.compatibility'] = 'busted/compatibility.lua',
['busted.options'] = 'busted/options.lua',
['busted.done'] = 'busted/done.lua',
['busted.runner'] = 'busted/runner.lua',
['busted.status'] = 'busted/status.lua',
Expand Down
1 change: 1 addition & 0 deletions busted-scm-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ build = {
['busted.context'] = 'busted/context.lua',
['busted.environment'] = 'busted/environment.lua',
['busted.compatibility'] = 'busted/compatibility.lua',
['busted.options'] = 'busted/options.lua',
['busted.done'] = 'busted/done.lua',
['busted.runner'] = 'busted/runner.lua',
['busted.status'] = 'busted/status.lua',
Expand Down
2 changes: 1 addition & 1 deletion busted/modules/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ return function(options)
-- Load up the command-line interface options
cli:add_flag('--version', 'prints the program version and exits', false, processOption)

if options.batch then
if not options.standalone then
cli:optarg('ROOT', 'test script file/folder. Folders will be traversed for any file that matches the --pattern option.', 'spec', 999, processArgList)

cli:add_option('-p, --pattern=PATTERN', 'only run test files matching the Lua pattern', defaultPattern, processOption)
Expand Down
4 changes: 4 additions & 0 deletions busted/options.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
return {
standalone = true,
defaultOutput = 'utfTerminal',
}
3 changes: 2 additions & 1 deletion busted/runner.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- Busted command-line runner

local path = require 'pl.path'
local tablex = require 'pl.tablex'
local term = require 'term'
local utils = require 'busted.utils'
local osexit = require 'busted.compatibility'.osexit
Expand All @@ -9,7 +10,7 @@ local loaded = false
return function(options)
if loaded then return else loaded = true end

local options = options or {}
options = tablex.update(require 'busted.options', options or {})
options.defaultOutput = term.isatty(io.stdout) and 'utfTerminal' or 'plainTerminal'

local busted = require 'busted.core'()
Expand Down
16 changes: 8 additions & 8 deletions spec/modules/cli_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('Tests command-line interface', function()
local defaultOutput = 'default_output_handler'
local lpath = './src/?.lua;./src/?/?.lua;./src/?/init.lua'
local cpath = path.is_windows and './csrc/?.dll;./csrc/?/?.dll;' or './csrc/?.so;./csrc/?/?.so;'
local cli = require 'busted.modules.cli'({ batch = true, defaultOutput = defaultOutput })
local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput })
local args = cli:parse({})
assert.is_equal(defaultOutput, args.o)
assert.is_equal(defaultOutput, args.output)
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('Tests command-line interface', function()
end)

it('standalone options disables ROOT and --pattern', function()
local cli = require 'busted.modules.cli'()
local cli = require 'busted.modules.cli'({ standalone = true })
local args = cli:parse({})
assert.is_nil(args.ROOT)
assert.is_nil(args.p)
Expand Down Expand Up @@ -197,15 +197,15 @@ describe('Tests command-line interface', function()
end)

it('specify ROOT arg and --pattern', function()
local cli = require 'busted.modules.cli'({ batch = true })
local cli = require 'busted.modules.cli'({ standalone = false })
local args = cli:parse({ '-p', 'match_files', 'root_is_here' })
assert.is_same({'root_is_here'}, args.ROOT)
assert.is_equal('match_files', args.p)
assert.is_equal('match_files', args.pattern)
end)

it('specify multiple root paths', function()
local cli = require 'busted.modules.cli'({ batch = true })
local cli = require 'busted.modules.cli'({ standalone = false })
local args = cli:parse({'root1_path', 'root2_path', 'root3_path'})
assert.is_same({'root1_path', 'root2_path', 'root3_path'}, args.ROOT)
end)
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('Tests using .busted tasks', function()
local defaultOutput = 'default_output_handler'
local lpath = './src/?.lua;./src/?/?.lua;./src/?/init.lua'
local cpath = path.is_windows and './csrc/?.dll;./csrc/?/?.dll;' or './csrc/?.so;./csrc/?/?.so;'
local cli = require 'busted.modules.cli'({ batch = true, defaultOutput = defaultOutput })
local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput })
local args = cli:parse({ '--directory=spec/.hidden' })
assert.is_equal(defaultOutput, args.o)
assert.is_equal(defaultOutput, args.output)
Expand Down Expand Up @@ -370,7 +370,7 @@ describe('Tests using .busted tasks', function()
local defaultOutput = 'default_output_handler'
local lpath = './src/?.lua;./src/?/?.lua;./src/?/init.lua'
local cpath = path.is_windows and './csrc/?.dll;./csrc/?/?.dll;' or './csrc/?.so;./csrc/?/?.so;'
local cli = require 'busted.modules.cli'({ batch = true, defaultOutput = defaultOutput })
local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput })
local args = cli:parse({ '--config-file', 'spec/.hidden/.busted' })
assert.is_equal(defaultOutput, args.o)
assert.is_equal(defaultOutput, args.output)
Expand Down Expand Up @@ -424,7 +424,7 @@ describe('Tests using .busted tasks', function()
end)

it('load configuration options', function()
local cli = require 'busted.modules.cli'({ batch = true, defaultOutput = defaultOutput })
local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput })
local args = cli:parse({ '--directory=spec/.hidden', '--run=test' })
assert.is_equal('_test%.lua$', args.pattern)
assert.is_same({'tests'}, args.ROOT)
Expand All @@ -436,7 +436,7 @@ describe('Tests using .busted tasks', function()
end)

it('load configuration options and override with command-line', function()
local cli = require 'busted.modules.cli'({ batch = true, defaultOutput = defaultOutput })
local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput })
local args = cli:parse({ '--directory=spec/.hidden', '--run=test', '-t', 'tag1', '-p', 'patt', '--loaders=moonscript' })
assert.is_equal('patt', args.pattern)
assert.is_same({'tag1'}, args.tags)
Expand Down

0 comments on commit b7f643d

Please sign in to comment.