Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Commit b7f643d

Browse files
committed
Refactor default options
1 parent 37589d8 commit b7f643d

File tree

7 files changed

+18
-11
lines changed

7 files changed

+18
-11
lines changed

bin/busted

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env lua
22
-- Busted command-line runner
3-
require 'busted.runner'({ batch = true })
3+
require 'busted.runner'({ standalone = false })

busted-2.0.rc10-0.rockspec

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ build = {
3636
['busted.context'] = 'busted/context.lua',
3737
['busted.environment'] = 'busted/environment.lua',
3838
['busted.compatibility'] = 'busted/compatibility.lua',
39+
['busted.options'] = 'busted/options.lua',
3940
['busted.done'] = 'busted/done.lua',
4041
['busted.runner'] = 'busted/runner.lua',
4142
['busted.status'] = 'busted/status.lua',

busted-scm-0.rockspec

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ build = {
3636
['busted.context'] = 'busted/context.lua',
3737
['busted.environment'] = 'busted/environment.lua',
3838
['busted.compatibility'] = 'busted/compatibility.lua',
39+
['busted.options'] = 'busted/options.lua',
3940
['busted.done'] = 'busted/done.lua',
4041
['busted.runner'] = 'busted/runner.lua',
4142
['busted.status'] = 'busted/status.lua',

busted/modules/cli.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ return function(options)
108108
-- Load up the command-line interface options
109109
cli:add_flag('--version', 'prints the program version and exits', false, processOption)
110110

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

114114
cli:add_option('-p, --pattern=PATTERN', 'only run test files matching the Lua pattern', defaultPattern, processOption)

busted/options.lua

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
return {
2+
standalone = true,
3+
defaultOutput = 'utfTerminal',
4+
}

busted/runner.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- Busted command-line runner
22

33
local path = require 'pl.path'
4+
local tablex = require 'pl.tablex'
45
local term = require 'term'
56
local utils = require 'busted.utils'
67
local osexit = require 'busted.compatibility'.osexit
@@ -9,7 +10,7 @@ local loaded = false
910
return function(options)
1011
if loaded then return else loaded = true end
1112

12-
local options = options or {}
13+
options = tablex.update(require 'busted.options', options or {})
1314
options.defaultOutput = term.isatty(io.stdout) and 'utfTerminal' or 'plainTerminal'
1415

1516
local busted = require 'busted.core'()

spec/modules/cli_spec.lua

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('Tests command-line interface', function()
55
local defaultOutput = 'default_output_handler'
66
local lpath = './src/?.lua;./src/?/?.lua;./src/?/init.lua'
77
local cpath = path.is_windows and './csrc/?.dll;./csrc/?/?.dll;' or './csrc/?.so;./csrc/?/?.so;'
8-
local cli = require 'busted.modules.cli'({ batch = true, defaultOutput = defaultOutput })
8+
local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput })
99
local args = cli:parse({})
1010
assert.is_equal(defaultOutput, args.o)
1111
assert.is_equal(defaultOutput, args.output)
@@ -59,7 +59,7 @@ describe('Tests command-line interface', function()
5959
end)
6060

6161
it('standalone options disables ROOT and --pattern', function()
62-
local cli = require 'busted.modules.cli'()
62+
local cli = require 'busted.modules.cli'({ standalone = true })
6363
local args = cli:parse({})
6464
assert.is_nil(args.ROOT)
6565
assert.is_nil(args.p)
@@ -197,15 +197,15 @@ describe('Tests command-line interface', function()
197197
end)
198198

199199
it('specify ROOT arg and --pattern', function()
200-
local cli = require 'busted.modules.cli'({ batch = true })
200+
local cli = require 'busted.modules.cli'({ standalone = false })
201201
local args = cli:parse({ '-p', 'match_files', 'root_is_here' })
202202
assert.is_same({'root_is_here'}, args.ROOT)
203203
assert.is_equal('match_files', args.p)
204204
assert.is_equal('match_files', args.pattern)
205205
end)
206206

207207
it('specify multiple root paths', function()
208-
local cli = require 'busted.modules.cli'({ batch = true })
208+
local cli = require 'busted.modules.cli'({ standalone = false })
209209
local args = cli:parse({'root1_path', 'root2_path', 'root3_path'})
210210
assert.is_same({'root1_path', 'root2_path', 'root3_path'}, args.ROOT)
211211
end)
@@ -313,7 +313,7 @@ describe('Tests using .busted tasks', function()
313313
local defaultOutput = 'default_output_handler'
314314
local lpath = './src/?.lua;./src/?/?.lua;./src/?/init.lua'
315315
local cpath = path.is_windows and './csrc/?.dll;./csrc/?/?.dll;' or './csrc/?.so;./csrc/?/?.so;'
316-
local cli = require 'busted.modules.cli'({ batch = true, defaultOutput = defaultOutput })
316+
local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput })
317317
local args = cli:parse({ '--directory=spec/.hidden' })
318318
assert.is_equal(defaultOutput, args.o)
319319
assert.is_equal(defaultOutput, args.output)
@@ -370,7 +370,7 @@ describe('Tests using .busted tasks', function()
370370
local defaultOutput = 'default_output_handler'
371371
local lpath = './src/?.lua;./src/?/?.lua;./src/?/init.lua'
372372
local cpath = path.is_windows and './csrc/?.dll;./csrc/?/?.dll;' or './csrc/?.so;./csrc/?/?.so;'
373-
local cli = require 'busted.modules.cli'({ batch = true, defaultOutput = defaultOutput })
373+
local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput })
374374
local args = cli:parse({ '--config-file', 'spec/.hidden/.busted' })
375375
assert.is_equal(defaultOutput, args.o)
376376
assert.is_equal(defaultOutput, args.output)
@@ -424,7 +424,7 @@ describe('Tests using .busted tasks', function()
424424
end)
425425

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

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

0 commit comments

Comments
 (0)