From 72edf02e052f36eb01ece6de00fc232bb3022053 Mon Sep 17 00:00:00 2001 From: Oscar Lim Date: Fri, 27 May 2016 22:18:25 -0700 Subject: [PATCH 01/26] Options --sort takes precedence over --shuffle --- busted/block.lua | 6 +++--- busted/execute.lua | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/busted/block.lua b/busted/block.lua index 4eca1d91..8ecc98ae 100644 --- a/busted/block.lua +++ b/busted/block.lua @@ -144,11 +144,11 @@ return function(busted) end if busted.safe(descriptor, element.run, element):success() then - if randomize then + if busted.sort then + sort(busted.context.children(element)) + elseif randomize then element.randomseed = randomseed shuffle(busted.context.children(element), randomseed) - elseif busted.sort then - sort(busted.context.children(element)) end if block.setup(element) then diff --git a/busted/execute.lua b/busted/execute.lua index f940cf06..8e0eea8c 100644 --- a/busted/execute.lua +++ b/busted/execute.lua @@ -45,11 +45,11 @@ return function(busted) busted.safe_publish('suite', { 'suite', 'reset' }, root, i, runs) end - if options.shuffle then + if options.sort then + sort(busted.context.children(root)) + elseif options.shuffle then root.randomseed = busted.randomseed shuffle(busted.context.children(root), busted.randomseed) - elseif options.sort then - sort(busted.context.children(root)) end local seed = (busted.randomize and busted.randomseed or nil) From 0dee22955c62207956030ac77e68efe1ab69e1f3 Mon Sep 17 00:00:00 2001 From: Oscar Lim Date: Fri, 27 May 2016 22:51:19 -0700 Subject: [PATCH 02/26] Option --list honors --sort, --shuffle, --suppress-pending This updates the `--list` command-line option to honor `--sort`, `--shuffle`, and `--suppress-pending` flags. --- busted/modules/filter_loader.lua | 44 +++++++++++++++++++++++++------- busted/runner.lua | 19 +++++++------- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/busted/modules/filter_loader.lua b/busted/modules/filter_loader.lua index 1d54b485..7154ff2a 100644 --- a/busted/modules/filter_loader.lua +++ b/busted/modules/filter_loader.lua @@ -55,11 +55,13 @@ return function() return nil, (#options.filter == 0) end - local printNameOnly = function(name, fn, trace) - local fullname = getFullName(name) - if trace and trace.what == 'Lua' then - print(trace.short_src .. ':' .. trace.currentline .. ': ' .. fullname) - else + local printTestName = function(element, parent, status) + if not (options.suppressPending and status == 'pending') then + local fullname = getFullName() + local trace = element.trace + if trace and trace.what == 'Lua' then + fullname = trace.short_src .. ':' .. trace.currentline .. ': ' .. fullname + end print(fullname) end return nil, false @@ -69,6 +71,15 @@ return function() return nil, false end + local noop = function() end + local stubOut = function(descriptor, name, fn, ...) + if fn == noop then + return nil, true + end + busted.publish({ 'register', descriptor }, name, noop, ...) + return nil, false + end + local skipOnError = function() return nil, not busted.skipAll end @@ -81,13 +92,28 @@ return function() end end + local applyDescFilter = function(descriptors, name, fn) + if options[name] and options[name] ~= '' then + for _, descriptor in ipairs(descriptors) do + local f = function(...) return fn(descriptor, ...) end + busted.subscribe({ 'register', descriptor }, f, { priority = 1 }) + end + end + end + if options.list then busted.subscribe({ 'suite', 'start' }, ignoreAll, { priority = 1 }) busted.subscribe({ 'suite', 'end' }, ignoreAll, { priority = 1 }) - applyFilter({ 'setup', 'teardown', 'before_each', 'after_each' }, 'list', ignoreAll) - applyFilter({ 'lazy_setup', 'lazy_teardown' }, 'list', ignoreAll) - applyFilter({ 'strict_setup', 'strict_teardown' }, 'list', ignoreAll) - applyFilter({ 'it', 'pending' }, 'list', printNameOnly) + busted.subscribe({ 'file', 'start' }, ignoreAll, { priority = 1 }) + busted.subscribe({ 'file', 'end' }, ignoreAll, { priority = 1 }) + busted.subscribe({ 'describe', 'start' }, ignoreAll, { priority = 1 }) + busted.subscribe({ 'describe', 'end' }, ignoreAll, { priority = 1 }) + busted.subscribe({ 'test', 'start' }, ignoreAll, { priority = 1 }) + busted.subscribe({ 'test', 'end' }, printTestName, { priority = 1 }) + applyDescFilter({ 'setup', 'teardown', 'before_each', 'after_each' }, 'list', stubOut) + applyDescFilter({ 'lazy_setup', 'lazy_teardown' }, 'list', stubOut) + applyDescFilter({ 'strict_setup', 'strict_teardown' }, 'list', stubOut) + applyDescFilter({ 'it', 'pending' }, 'list', stubOut) end applyFilter({ 'lazy_setup', 'lazy_teardown' }, 'nokeepgoing', skipOnError) diff --git a/busted/runner.lua b/busted/runner.lua index 59529c95..2c9df674 100644 --- a/busted/runner.lua +++ b/busted/runner.lua @@ -132,6 +132,15 @@ return function(options) arguments = cliArgs.Xoutput, }) + -- Set up helper script + if cliArgs.helper and cliArgs.helper ~= '' then + helperLoader(busted, cliArgs.helper, { + verbose = cliArgs.verbose, + language = cliArgs.lang, + arguments = cliArgs.Xhelper + }) + end + -- Load tag and test filters filterLoader(busted, { tags = cliArgs.tags, @@ -140,17 +149,9 @@ return function(options) filterOut = cliArgs['filter-out'], list = cliArgs.list, nokeepgoing = not cliArgs['keep-going'], + suppressPending = cliArgs['suppress-pending'], }) - -- Set up helper script - if cliArgs.helper and cliArgs.helper ~= '' then - helperLoader(busted, cliArgs.helper, { - verbose = cliArgs.verbose, - language = cliArgs.lang, - arguments = cliArgs.Xhelper - }) - end - -- Load test directory local rootFiles = cliArgs.ROOT or { fileName } local patterns = cliArgs.pattern From aa6f4c92d9477630fffc2bc6b3f67226aabf3ed2 Mon Sep 17 00:00:00 2001 From: Oscar Lim Date: Thu, 26 May 2016 13:47:55 -0700 Subject: [PATCH 03/26] Support running standalone tests from stdin This adds support for running standalone tests via stdin to the Lua interpreter. For example: lua < standalone_spec.lua or cat standalone_spec.lua | lua --- busted-2.0.rc12-1.rockspec | 1 + busted-scm-0.rockspec | 1 + busted/compatibility.lua | 4 +-- busted/modules/standalone_loader.lua | 28 ++++++++++++++++++ busted/runner.lua | 43 ++++++++++++++-------------- spec/cl_spec.lua | 6 ++++ 6 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 busted/modules/standalone_loader.lua diff --git a/busted-2.0.rc12-1.rockspec b/busted-2.0.rc12-1.rockspec index ca58a92d..5af0dfb4 100644 --- a/busted-2.0.rc12-1.rockspec +++ b/busted-2.0.rc12-1.rockspec @@ -48,6 +48,7 @@ build = { ['busted.modules.configuration_loader'] = 'busted/modules/configuration_loader.lua', ['busted.modules.luacov'] = 'busted/modules/luacov.lua', + ['busted.modules.standalone_loader'] = 'busted/modules/standalone_loader.lua', ['busted.modules.test_file_loader'] = 'busted/modules/test_file_loader.lua', ['busted.modules.output_handler_loader'] = 'busted/modules/output_handler_loader.lua', ['busted.modules.helper_loader'] = 'busted/modules/helper_loader.lua', diff --git a/busted-scm-0.rockspec b/busted-scm-0.rockspec index f96e98ae..ff9a435a 100644 --- a/busted-scm-0.rockspec +++ b/busted-scm-0.rockspec @@ -48,6 +48,7 @@ build = { ['busted.modules.configuration_loader'] = 'busted/modules/configuration_loader.lua', ['busted.modules.luacov'] = 'busted/modules/luacov.lua', + ['busted.modules.standalone_loader'] = 'busted/modules/standalone_loader.lua', ['busted.modules.test_file_loader'] = 'busted/modules/test_file_loader.lua', ['busted.modules.output_handler_loader'] = 'busted/modules/output_handler_loader.lua', ['busted.modules.helper_loader'] = 'busted/modules/helper_loader.lua', diff --git a/busted/compatibility.lua b/busted/compatibility.lua index d8816a9a..39371ea6 100644 --- a/busted/compatibility.lua +++ b/busted/compatibility.lua @@ -33,8 +33,8 @@ return { loadstring = loadstring or load, unpack = table.unpack or unpack, - exit = function(code) - if code ~= 0 and _VERSION:match('^Lua 5%.[12]$') then + exit = function(code, force) + if not force and code ~= 0 and _VERSION:match('^Lua 5%.[12]$') then error() elseif code ~= 0 then code = 1 diff --git a/busted/modules/standalone_loader.lua b/busted/modules/standalone_loader.lua new file mode 100644 index 00000000..6299aa5f --- /dev/null +++ b/busted/modules/standalone_loader.lua @@ -0,0 +1,28 @@ +local getTrace = function(filename, info) + local index = info.traceback:find('\n%s*%[C]') + info.traceback = info.traceback:sub(1, index) + return info +end + +return function(busted) + local loadCurrentFile = function(info, options) + local filename = 'string' + if info.source:sub(1,1) == '@' or info.source:sub(1,1) == '=' then + filename = info.source:sub(2) + end + + -- Setup test file to be compatible with live coding + if info.func then + local file = setmetatable({ + getTrace = getTrace, + rewriteMessage = nil + }, { + __call = info.func + }) + + busted.executors.file(filename, file) + end + end + + return loadCurrentFile +end diff --git a/busted/runner.lua b/busted/runner.lua index 2c9df674..92c25246 100644 --- a/busted/runner.lua +++ b/busted/runner.lua @@ -29,28 +29,29 @@ return function(options) local level = 2 local info = debug.getinfo(level, 'Sf') local source = info.source - local fileName = source:sub(1,1) == '@' and source:sub(2) or source + local fileName = source:sub(1,1) == '@' and source:sub(2) or nil + local forceExit = fileName == nil -- Parse the cli arguments - local appName = path.basename(fileName) + local appName = path.basename(fileName or 'busted') cli:set_name(appName) local cliArgs, err = cli:parse(arg) if not cliArgs then io.stderr:write(err .. '\n') - exit(1) + exit(1, forceExit) end if cliArgs.version then -- Return early if asked for the version print(busted.version) - exit(0) + exit(0, forceExit) end -- Load current working directory local _, err = path.chdir(path.normpath(cliArgs.directory)) if err then io.stderr:write(appName .. ': error: ' .. err .. '\n') - exit(1) + exit(1, forceExit) end -- If coverage arg is passed in, load LuaCovsupport @@ -152,22 +153,20 @@ return function(options) suppressPending = cliArgs['suppress-pending'], }) - -- Load test directory - local rootFiles = cliArgs.ROOT or { fileName } - local patterns = cliArgs.pattern - local testFileLoader = require 'busted.modules.test_file_loader'(busted, cliArgs.loaders) - testFileLoader(rootFiles, patterns, { - excludes = cliArgs['exclude-pattern'], - verbose = cliArgs.verbose, - recursive = cliArgs['recursive'], - }) - - -- If running standalone, setup test file to be compatible with live coding - if options.standalone then - local ctx = busted.context.get() - local children = busted.context.children(ctx) - local file = children[#children] - debug.getmetatable(file.run).__call = info.func + if cliArgs.ROOT then + -- Load test directories/files + local rootFiles = cliArgs.ROOT + local patterns = cliArgs.pattern + local testFileLoader = require 'busted.modules.test_file_loader'(busted, cliArgs.loaders) + testFileLoader(rootFiles, patterns, { + excludes = cliArgs['exclude-pattern'], + verbose = cliArgs.verbose, + recursive = cliArgs['recursive'], + }) + else + -- Running standalone, use standalone loader + local testFileLoader = require 'busted.modules.standalone_loader'(busted) + testFileLoader(info, { verbose = cliArgs.verbose }) end local runs = cliArgs['repeat'] @@ -181,6 +180,6 @@ return function(options) busted.publish({ 'exit' }) if options.standalone or failures > 0 or errors > 0 then - exit(failures + errors) + exit(failures + errors, forceExit) end end diff --git a/spec/cl_spec.lua b/spec/cl_spec.lua index 2bfa915c..36c15ecd 100644 --- a/spec/cl_spec.lua +++ b/spec/cl_spec.lua @@ -300,6 +300,12 @@ describe('Test busted running standalone', function() local success, errcnt = executeLua('spec/cl_standalone.lua --help') assert.is_false(success) end) + + it('tests running with via stdin', function() + local success, errcnt = executeLua('< spec/cl_standalone.lua') + assert.is_false(success) + assert.is_equal(3, errcnt) + end) end) describe('Test busted command-line runner', function() From 2734e084f9026a6c2672c5714075d8d63169eabf Mon Sep 17 00:00:00 2001 From: Oscar Lim Date: Fri, 27 May 2016 10:09:11 -0700 Subject: [PATCH 04/26] Rename output handler option for runner This renames the output handler option passed to `busted.runner` as `output` rather than `defaultOutput`. --- busted/modules/cli.lua | 2 +- busted/options.lua | 2 +- busted/runner.lua | 6 +++--- spec/modules/cli_spec.lua | 16 ++++++++-------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/busted/modules/cli.lua b/busted/modules/cli.lua index e2b4cfc8..cbc1a8bd 100644 --- a/busted/modules/cli.lua +++ b/busted/modules/cli.lua @@ -12,7 +12,7 @@ return function(options) local configLoader = require 'busted.modules.configuration_loader'() -- Default cli arg values - local defaultOutput = options.defaultOutput + local defaultOutput = options.output or 'utfTerminal' local defaultLoaders = 'lua,moonscript' local defaultPattern = '_spec' local defaultSeed = '/dev/urandom or os.time()' diff --git a/busted/options.lua b/busted/options.lua index a3b62bfa..c6f5d6cc 100644 --- a/busted/options.lua +++ b/busted/options.lua @@ -1,4 +1,4 @@ return { standalone = true, - defaultOutput = 'utfTerminal', + output = nil, } diff --git a/busted/runner.lua b/busted/runner.lua index 92c25246..d5d4d499 100644 --- a/busted/runner.lua +++ b/busted/runner.lua @@ -9,11 +9,11 @@ local loadstring = require 'busted.compatibility'.loadstring local loaded = false return function(options) - if loaded then return else loaded = true end + if loaded then return function() end else loaded = true end local isatty = io.type(io.stdout) == 'file' and term.isatty(io.stdout) options = tablex.update(require 'busted.options', options or {}) - options.defaultOutput = isatty and 'utfTerminal' or 'plainTerminal' + options.output = options.output or (isatty and 'utfTerminal' or 'plainTerminal') local busted = require 'busted.core'() @@ -124,7 +124,7 @@ return function(options) -- Set up output handler to listen to events outputHandlerLoader(busted, cliArgs.output, { - defaultOutput = options.defaultOutput, + defaultOutput = options.output, enableSound = cliArgs['enable-sound'], verbose = cliArgs.verbose, suppressPending = cliArgs['suppress-pending'], diff --git a/spec/modules/cli_spec.lua b/spec/modules/cli_spec.lua index c8d6d0d7..b70dfcb7 100644 --- a/spec/modules/cli_spec.lua +++ b/spec/modules/cli_spec.lua @@ -6,7 +6,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'({ standalone = false, defaultOutput = defaultOutput }) + local cli = require 'busted.modules.cli'({ standalone = false, output = defaultOutput }) local args = cli:parse({}) assert.is_equal(defaultOutput, args.o) assert.is_equal(defaultOutput, args.output) @@ -330,7 +330,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'({ standalone = false, defaultOutput = defaultOutput }) + local cli = require 'busted.modules.cli'({ standalone = false, output = defaultOutput }) local args = cli:parse({ '--directory=spec/.hidden' }) assert.is_equal(defaultOutput, args.o) assert.is_equal(defaultOutput, args.output) @@ -389,7 +389,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'({ standalone = false, defaultOutput = defaultOutput }) + local cli = require 'busted.modules.cli'({ standalone = false, output = defaultOutput }) local args = cli:parse({ '--config-file', 'spec/.hidden/.busted' }) assert.is_equal(defaultOutput, args.o) assert.is_equal(defaultOutput, args.output) @@ -444,7 +444,7 @@ describe('Tests using .busted tasks', function() end) it('load configuration options', function() - local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput }) + local cli = require 'busted.modules.cli'({ standalone = false, output = defaultOutput }) local args = cli:parse({ '--directory=spec/.hidden', '--run=test' }) assert.is_same({'_test1%.lua$', '_test2%.lua$'}, args.pattern) assert.is_same({'_exclude1', '_exclude2'}, args['exclude-pattern']) @@ -459,7 +459,7 @@ describe('Tests using .busted tasks', function() end) it('load configuration options and override with command-line', function() - local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput }) + local cli = require 'busted.modules.cli'({ standalone = false, output = defaultOutput }) local args = cli:parse({ '--directory=spec/.hidden', '--run=test', '-t', 'tag1', '-p', 'patt', '--filter=fin', '--filter-out=fout', '--exclude-pattern', '', '--loaders=moonscript' }) assert.is_same({'patt'}, args.pattern) assert.is_same({''}, args['exclude-pattern']) @@ -473,7 +473,7 @@ describe('Tests using .busted tasks', function() end) it('detects error in configuration file', function() - local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput }) + local cli = require 'busted.modules.cli'({ standalone = false, output = defaultOutput }) cli:set_name('app') local args, err = cli:parse({ '--config-file=spec/.hidden/.busted_bad', '--run=test' }) assert.is_nil(args) @@ -483,7 +483,7 @@ describe('Tests using .busted tasks', function() end) it('detects invalid configuration file', function() - local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput }) + local cli = require 'busted.modules.cli'({ standalone = false, output = defaultOutput }) cli:set_name('myapp') local args, err = cli:parse({ '--config-file=spec/.hidden/.busted_empty' }) assert.is_nil(args) @@ -491,7 +491,7 @@ describe('Tests using .busted tasks', function() end) it('detects unknown/invalid task', function() - local cli = require 'busted.modules.cli'({ standalone = false, defaultOutput = defaultOutput }) + local cli = require 'busted.modules.cli'({ standalone = false, output = defaultOutput }) cli:set_name('appname') local args, err = cli:parse({ '--config-file=spec/.hidden/.busted', '--run=invalid' }) assert.is_nil(args) From 830f175c57ca3f9e79f95b8c4eaacf58252453d7 Mon Sep 17 00:00:00 2001 From: Chris Tallman Date: Fri, 10 Jun 2016 12:04:14 -0700 Subject: [PATCH 05/26] Fix testcase time --- busted/outputHandlers/junit.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/busted/outputHandlers/junit.lua b/busted/outputHandlers/junit.lua index ceafc289..f1d28a5f 100644 --- a/busted/outputHandlers/junit.lua +++ b/busted/outputHandlers/junit.lua @@ -101,7 +101,7 @@ return function(options) handler.testEnd = function(element, parent, status) top.xml_doc.attr.tests = top.xml_doc.attr.tests + 1 - testcase_node.time = formatDuration(element.duration) + testcase_node:set_attrib("time", formatDuration(element.duration)) if status == 'success' then testStatus(element, parent, nil, 'success') From 4e4df7a2bd7a8d52f4b09fa68fdaacbefda43d7f Mon Sep 17 00:00:00 2001 From: Oscar Lim Date: Fri, 15 Jul 2016 13:20:53 -0700 Subject: [PATCH 06/26] Use '%u' to format unsigned numbers This fixes a bug when trying to display an unsigned value using '%d', which will print a negative value when the value is too large. --- busted/outputHandlers/gtest.lua | 22 +++++++++++----------- busted/outputHandlers/plainTerminal.lua | 2 +- busted/outputHandlers/utfTerminal.lua | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/busted/outputHandlers/gtest.lua b/busted/outputHandlers/gtest.lua index dd246b8b..1b940a4f 100644 --- a/busted/outputHandlers/gtest.lua +++ b/busted/outputHandlers/gtest.lua @@ -17,8 +17,8 @@ return function(options) local busted = require 'busted' local handler = require 'busted.outputHandlers.base'() - local repeatSuiteString = '\nRepeating all tests (run %d of %d) . . .\n\n' - local randomizeString = colors.yellow('Note: Randomizing test order with a seed of %d.\n') + local repeatSuiteString = '\nRepeating all tests (run %u of %u) . . .\n\n' + local randomizeString = colors.yellow('Note: Randomizing test order with a seed of %u.\n') local suiteStartString = colors.green ('[==========]') .. ' Running tests from scanned files.\n' local globalSetup = colors.green ('[----------]') .. ' Global test environment setup.\n' local fileStartString = colors.green ('[----------]') .. ' Running tests from %s\n' @@ -27,28 +27,28 @@ return function(options) local skippedString = colors.yellow ('[ SKIPPED ]') .. ' %s (%.2f ms)\n' local failureString = colors.red ('[ FAILED ]') .. ' %s (%.2f ms)\n' local errorString = colors.magenta('[ ERROR ]') .. ' %s (%.2f ms)\n' - local fileEndString = colors.green ('[----------]') .. ' %d %s from %s (%.2f ms total)\n\n' + local fileEndString = colors.green ('[----------]') .. ' %u %s from %s (%.2f ms total)\n\n' local globalTeardown = colors.green ('[----------]') .. ' Global test environment teardown.\n' - local suiteEndString = colors.green ('[==========]') .. ' %d %s from %d test %s ran. (%.2f ms total)\n' - local successStatus = colors.green ('[ PASSED ]') .. ' %d %s.\n' + local suiteEndString = colors.green ('[==========]') .. ' %u %s from %u test %s ran. (%.2f ms total)\n' + local successStatus = colors.green ('[ PASSED ]') .. ' %u %s.\n' local summaryStrings = { skipped = { - header = colors.yellow ('[ SKIPPED ]') .. ' %d %s, listed below:\n', + header = colors.yellow ('[ SKIPPED ]') .. ' %u %s, listed below:\n', test = colors.yellow ('[ SKIPPED ]') .. ' %s\n', - footer = ' %d SKIPPED %s\n', + footer = ' %u SKIPPED %s\n', }, failure = { - header = colors.red ('[ FAILED ]') .. ' %d %s, listed below:\n', + header = colors.red ('[ FAILED ]') .. ' %u %s, listed below:\n', test = colors.red ('[ FAILED ]') .. ' %s\n', - footer = ' %d FAILED %s\n', + footer = ' %u FAILED %s\n', }, error = { - header = colors.magenta('[ ERROR ]') .. ' %d %s, listed below:\n', + header = colors.magenta('[ ERROR ]') .. ' %u %s, listed below:\n', test = colors.magenta('[ ERROR ]') .. ' %s\n', - footer = ' %d %s\n', + footer = ' %u %s\n', }, } diff --git a/busted/outputHandlers/plainTerminal.lua b/busted/outputHandlers/plainTerminal.lua index 1378b71d..e15f9879 100644 --- a/busted/outputHandlers/plainTerminal.lua +++ b/busted/outputHandlers/plainTerminal.lua @@ -130,7 +130,7 @@ return function(options) end handler.suiteStart = function(suite, count, total) - local runString = (total > 1 and '\nRepeating all tests (run %d of %d) . . .\n\n' or '') + local runString = (total > 1 and '\nRepeating all tests (run %u of %u) . . .\n\n' or '') io.write(runString:format(count, total)) io.flush() diff --git a/busted/outputHandlers/utfTerminal.lua b/busted/outputHandlers/utfTerminal.lua index 3a2c0456..fa38c958 100644 --- a/busted/outputHandlers/utfTerminal.lua +++ b/busted/outputHandlers/utfTerminal.lua @@ -139,7 +139,7 @@ return function(options) end handler.suiteStart = function(suite, count, total) - local runString = (total > 1 and '\nRepeating all tests (run %d of %d) . . .\n\n' or '') + local runString = (total > 1 and '\nRepeating all tests (run %u of %u) . . .\n\n' or '') io.write(runString:format(count, total)) io.flush() From ed3f70805ac0e30bf14f6a5850e873329f5e337c Mon Sep 17 00:00:00 2001 From: Oscar Lim Date: Mon, 29 Aug 2016 11:54:59 -0700 Subject: [PATCH 07/26] Fix failing tests after penlight upgrade This fixes failing unit tests after upgrading `penlight`. Apparently, the new version of `penlight` uses `pl.List` internally when traversing a directory. Hence, we cannot use `pl.List` in any of the insulation tests. --- spec/insulate-expose_spec.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/insulate-expose_spec.lua b/spec/insulate-expose_spec.lua index 0409a3d1..bba84bd6 100644 --- a/spec/insulate-expose_spec.lua +++ b/spec/insulate-expose_spec.lua @@ -13,9 +13,9 @@ describe('Tests insulation', function() it('updates package.loaded', function() assert.is_not_nil(pl) - assert.is_not_nil(List) + assert.is_not_nil(Date) assert.is_not_nil(package.loaded.pl) - assert.is_not_nil(package.loaded['pl.List']) + assert.is_not_nil(package.loaded['pl.Date']) end) end) @@ -27,9 +27,9 @@ describe('Tests insulation', function() it('restores package.loaded', function() assert.is_nil(pl) - assert.is_nil(List) + assert.is_nil(Date) assert.is_nil(package.loaded.pl) - assert.is_nil(package.loaded['pl.List']) + assert.is_nil(package.loaded['pl.Date']) end) end) end) @@ -54,9 +54,9 @@ insulate('', function() it('updates package.loaded', function() assert.is_not_nil(pl) - assert.is_not_nil(List) + assert.is_not_nil(Date) assert.is_not_nil(package.loaded.pl) - assert.is_not_nil(package.loaded['pl.List']) + assert.is_not_nil(package.loaded['pl.Date']) end) end) end) @@ -74,9 +74,9 @@ insulate('', function() it('does not restore package.loaded', function() assert.is_not_nil(pl) - assert.is_not_nil(List) + assert.is_not_nil(Date) assert.is_not_nil(package.loaded.pl) - assert.is_not_nil(package.loaded['pl.List']) + assert.is_not_nil(package.loaded['pl.Date']) end) end) end) @@ -93,9 +93,9 @@ insulate('', function() end) it('Tests package.loaded persists without insulate', function() - assert.is_not_nil(List) + assert.is_not_nil(Date) assert.is_not_nil(package.loaded.pl) - assert.is_not_nil(package.loaded['pl.List']) + assert.is_not_nil(package.loaded['pl.Date']) end) end) @@ -107,9 +107,9 @@ describe('Tests after insulating an expose block', function() it('restores package.loaded', function() assert.is_nil(pl) - assert.is_nil(List) + assert.is_nil(Date) assert.is_nil(package.loaded.pl) - assert.is_nil(package.loaded['pl.List']) + assert.is_nil(package.loaded['pl.Date']) end) end) From 8ff1fc97d25d2ab1a6d49b03d8be556925c6c0a4 Mon Sep 17 00:00:00 2001 From: Oscar Lim Date: Mon, 29 Aug 2016 11:01:04 -0700 Subject: [PATCH 08/26] Forward non-positive arg keys This updates the helper loader and output handler loader to forward non-positive command-line argument keys, that are automatically inserted by the Lua interpreter, to the helper and output handler, respectively. --- busted/modules/helper_loader.lua | 6 ++++-- busted/modules/output_handler_loader.lua | 2 ++ busted/utils.lua | 11 +++++++++++ spec/cl_spec.lua | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/busted/modules/helper_loader.lua b/busted/modules/helper_loader.lua index 693b903d..56ae6673 100644 --- a/busted/modules/helper_loader.lua +++ b/busted/modules/helper_loader.lua @@ -1,11 +1,13 @@ local path = require 'pl.path' local hasMoon, moonscript = pcall(require, 'moonscript') +local utils = require 'busted.utils' return function() local loadHelper = function(busted, helper, options) - local old_arg = arg + local old_arg = _G.arg local success, err = pcall(function() - arg = options.arguments + utils.copy_interpreter_args(options.arguments) + _G.arg = options.arguments if helper:match('%.lua$') then dofile(path.normpath(helper)) elseif hasMoon and helper:match('%.moon$') then diff --git a/busted/modules/output_handler_loader.lua b/busted/modules/output_handler_loader.lua index 41c45d4e..ab93e4c6 100644 --- a/busted/modules/output_handler_loader.lua +++ b/busted/modules/output_handler_loader.lua @@ -1,10 +1,12 @@ local path = require 'pl.path' local hasMoon, moonscript = pcall(require, 'moonscript') +local utils = require 'busted.utils' return function() local loadOutputHandler = function(busted, output, options) local handler + utils.copy_interpreter_args(options.arguments) local success, err = pcall(function() if output:match('%.lua$') then handler = dofile(path.normpath(output)) diff --git a/busted/utils.lua b/busted/utils.lua index 75f4b5d9..bf771487 100644 --- a/busted/utils.lua +++ b/busted/utils.lua @@ -1,4 +1,15 @@ return { + copy_interpreter_args = function(arguments) + -- copy non-positive command-line args auto-inserted by Lua interpreter + if arguments and _G.arg then + local i = 0 + while _G.arg[i] do + arguments[i] = _G.arg[i] + i = i - 1 + end + end + end, + split = require 'pl.utils'.split, shuffle = function(t, seed) diff --git a/spec/cl_spec.lua b/spec/cl_spec.lua index 36c15ecd..46441421 100644 --- a/spec/cl_spec.lua +++ b/spec/cl_spec.lua @@ -301,7 +301,7 @@ describe('Test busted running standalone', function() assert.is_false(success) end) - it('tests running with via stdin', function() + it('tests running via stdin', function() local success, errcnt = executeLua('< spec/cl_standalone.lua') assert.is_false(success) assert.is_equal(3, errcnt) From b5060dd6f154807c152ee64e9919258c1728a7f8 Mon Sep 17 00:00:00 2001 From: Oscar Lim Date: Mon, 29 Aug 2016 10:11:03 -0700 Subject: [PATCH 09/26] Output error message when test file/dir not found Previously, if a test file or directory specified on the command-line is not found, the test file loader would silently fail without reporting an error. Hence, leading the user to think all requested tests were run, when, in fact, either an entire test file or directory was skipped. This updates the test file loader to report an error in the event a requested file or directory is not found. --- busted/languages/en.lua | 1 + busted/modules/test_file_loader.lua | 1 + spec/cl_spec.lua | 14 ++++++++++++++ 3 files changed, 16 insertions(+) diff --git a/busted/languages/en.lua b/busted/languages/en.lua index 285d1ba1..dcfb4cce 100644 --- a/busted/languages/en.lua +++ b/busted/languages/en.lua @@ -26,6 +26,7 @@ s:set('output.success_single', 'success') s:set('output.seconds', 'seconds') s:set('output.no_test_files_match', 'No test files found matching Lua pattern: %s') +s:set('output.file_not_found', 'Cannot find file or directory: %s') -- definitions following are not used within the 'say' namespace return { diff --git a/busted/modules/test_file_loader.lua b/busted/modules/test_file_loader.lua index a6b9b68b..6f2e83d8 100644 --- a/busted/modules/test_file_loader.lua +++ b/busted/modules/test_file_loader.lua @@ -43,6 +43,7 @@ return function(busted, loaders) end end) else + busted.publish({ 'error' }, {}, nil, s('output.file_not_found'):format(rootFile), {}) fileList = {} end diff --git a/spec/cl_spec.lua b/spec/cl_spec.lua index 36c15ecd..8fbf1e70 100644 --- a/spec/cl_spec.lua +++ b/spec/cl_spec.lua @@ -454,6 +454,20 @@ describe('Tests error messages through the command line', function() assert.is_equal(expectedMsg, errmsg) end) + it('when test file not found', function() + local _, _, result = executeBusted('--output=plainTerminal does_not_exist.lua') + local errmsg = result:match('Error %-> (.-)\n') + local expected = 'Cannot find file or directory: does_not_exist.lua' + assert.is_equal(expected, errmsg) + end) + + it('when test directory not found', function() + local _, _, result = executeBusted('--output=plainTerminal does_not_exist') + local errmsg = result:match('Error %-> (.-)\n') + local expected = 'Cannot find file or directory: does_not_exist' + assert.is_equal(expected, errmsg) + end) + it('when no test files matching Lua pattern', function() local _, _, result = executeBusted('--output=plainTerminal --pattern=this_filename_does_simply_not_exist$') local errmsg = result:match('Error %-> (.-)\n') From 907cd546e55597ad8fadc925fd16611f5564f132 Mon Sep 17 00:00:00 2001 From: Enea Scioni Date: Tue, 4 Oct 2016 16:20:59 +0200 Subject: [PATCH 10/26] add italian language support --- busted/languages/it.lua | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 busted/languages/it.lua diff --git a/busted/languages/it.lua b/busted/languages/it.lua new file mode 100644 index 00000000..a073bfe3 --- /dev/null +++ b/busted/languages/it.lua @@ -0,0 +1,50 @@ +local s = require('say') + +s:set_namespace('it') + +-- 'Pending: test.lua @ 12 \n description +s:set('output.pending', 'In attesa') +s:set('output.failure', 'Fallimento') +s:set('output.error', 'Errore') +s:set('output.success', 'Successo') + +s:set('output.pending_plural', 'in attesa') +s:set('output.failure_plural', 'fallimenti') +s:set('output.error_plural', 'errori') +s:set('output.success_plural', 'successi') + +s:set('output.pending_zero', 'in attesa') +s:set('output.failure_zero', 'fallimenti') +s:set('output.error_zero', 'errori') +s:set('output.success_zero', 'successi') + +s:set('output.pending_single', 'in attesa') +s:set('output.failure_single', 'fallimento') +s:set('output.error_single', 'errore') +s:set('output.success_single', 'successo') + +s:set('output.seconds', 'secondi') + +s:set('output.no_test_files_match', 'Nessun file di test trovat che corrisponde al pattern Lua: %s') +s:set('output.file_not_found', 'Nessun file o cartella trovato: %s') + +-- definitions following are not used within the 'say' namespace +return { + failure_messages = { + "Hai %d specifiche non conformi", + "Le tue specifiche non sono conformi", + "Il tuo codice fa schifo e dovresti sentirti male per questo", + "Il tuo codice è in pericolo", + "Strano. Il solo modo per terminare con successo i tuoi test è fare nessun test", + "Mia nonna ha scritto migliori specifiche su un 3 86", + "Ogni volta che trovi un errore, bevi un'altra birra", + "I fallimenti fanno male alla salute" + }, + success_messages = { + "Ma andiamo! Specifiche Ok!", + "Non importa, avevi le specifiche", + "Bella zio", + "Gran successo", + "Test passato, hai vinto una birra" + } +} From dcd49b0f57e52b46184b5df2b5e42f5cd855e9ee Mon Sep 17 00:00:00 2001 From: Enea Scioni Date: Tue, 4 Oct 2016 16:34:51 +0200 Subject: [PATCH 11/26] add it lang rockspec support --- busted-2.0.rc12-1.rockspec | 1 + busted-scm-0.rockspec | 1 + 2 files changed, 2 insertions(+) diff --git a/busted-2.0.rc12-1.rockspec b/busted-2.0.rc12-1.rockspec index 5af0dfb4..08d86dda 100644 --- a/busted-2.0.rc12-1.rockspec +++ b/busted-2.0.rc12-1.rockspec @@ -79,6 +79,7 @@ build = { ['busted.languages.th'] = 'busted/languages/th.lua', ['busted.languages.ua'] = 'busted/languages/ua.lua', ['busted.languages.zh'] = 'busted/languages/zh.lua', + ['busted.languages.it'] = 'busted/languages/it.lua', }, install = { bin = { diff --git a/busted-scm-0.rockspec b/busted-scm-0.rockspec index ff9a435a..4bb668f6 100644 --- a/busted-scm-0.rockspec +++ b/busted-scm-0.rockspec @@ -79,6 +79,7 @@ build = { ['busted.languages.th'] = 'busted/languages/th.lua', ['busted.languages.ua'] = 'busted/languages/ua.lua', ['busted.languages.zh'] = 'busted/languages/zh.lua', + ['busted.languages.it'] = 'busted/languages/it.lua', }, install = { bin = { From 30020208fe9c19e5078cb4666aabd71b61c7b60e Mon Sep 17 00:00:00 2001 From: Elaina Martineau Date: Sun, 1 Jan 2017 14:04:35 -0700 Subject: [PATCH 12/26] Make busted capitalization more consistent It appears that "busted" is normally spelled with a lowercase 'b' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 232978e6..cc932118 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Busted +busted ====== [![Join the chat at https://gitter.im/Olivine-Labs/busted](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Olivine-Labs/busted?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) From f9db364291cfd7fe51b5c2b8132974fdc76aed73 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 1 Jul 2017 21:54:14 +0200 Subject: [PATCH 13/26] TAP handler: flush output immediately 8a4d223c5ae4ace8d88d4ee3ca79020f6e67ae21 changed the TAP handler to write results after each test, but the output is still buffered. If a test hangs, the buffered results of many previous tests will never be printed, and it's not clear which test caused the hang. Flushing the output avoids this. --- busted/outputHandlers/TAP.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/busted/outputHandlers/TAP.lua b/busted/outputHandlers/TAP.lua index 72dc9c8f..6e1cdebc 100644 --- a/busted/outputHandlers/TAP.lua +++ b/busted/outputHandlers/TAP.lua @@ -16,6 +16,7 @@ return function(options) handler.suiteEnd = function() print('1..' .. counter) + io.flush() return nil, true end @@ -45,6 +46,7 @@ return function(options) local testName = fileline .. handler.getFullName(element) print('# ' .. testName) end + io.flush() return nil, true end @@ -62,6 +64,7 @@ return function(options) elseif status == 'error' then showFailure(handler.errors[#handler.errors]) end + io.flush() return nil, true end @@ -71,6 +74,7 @@ return function(options) counter = counter + 1 showFailure(handler.errors[#handler.errors]) end + io.flush() return nil, true end From db6d8b4be8fd099ab387efeb8232cfd905912abb Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Mon, 17 Jul 2017 02:40:42 +0200 Subject: [PATCH 14/26] fix LuaJIT segfaults due to ffi reloading --- busted/modules/configuration_loader.lua | 2 +- busted/runner.lua | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/busted/modules/configuration_loader.lua b/busted/modules/configuration_loader.lua index c2504dce..9ad0b487 100644 --- a/busted/modules/configuration_loader.lua +++ b/busted/modules/configuration_loader.lua @@ -7,7 +7,7 @@ return function() return nil, '.busted file does not return a table.' end - local defaults = defaults or {} + defaults = defaults or {} local run = config.run or defaults.run if run and run ~= '' then diff --git a/busted/runner.lua b/busted/runner.lua index d5d4d499..eefac142 100644 --- a/busted/runner.lua +++ b/busted/runner.lua @@ -133,6 +133,25 @@ return function(options) arguments = cliArgs.Xoutput, }) + -- Pre-load the LuaJIT 'ffi' module if applicable + local isJit = (tostring(assert):match('builtin') ~= nil) + if isJit then + -- pre-load the ffi module, such that it becomes part of the environment + -- and Busted will not try to GC and reload it. The ffi is not suited + -- for that and will occasionally segfault if done so. + local ffi = require "ffi" + + -- Now patch ffi.cdef to only be called once with each definition, as it + -- will error on re-registering. + local old_cdef = ffi.cdef + local exists = {} + ffi.cdef = function(def) + if exists[def] then return end + exists[def] = true + return old_cdef(def) + end + end + -- Set up helper script if cliArgs.helper and cliArgs.helper ~= '' then helperLoader(busted, cliArgs.helper, { From 636773639ffa3a1da2b535148d13c6c895a45bc9 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Mon, 16 Jul 2018 15:31:14 +0200 Subject: [PATCH 15/26] fix(cli) fail if LuaCov is specified but unavailable Fails with an error (to stderr) if `-c` was specified, but LuaCov is not available. Previously it would just print to stdout and continue without coverage reporting. --- busted/modules/luacov.lua | 3 ++- busted/runner.lua | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/busted/modules/luacov.lua b/busted/modules/luacov.lua index 99cfc8f5..51a9ad33 100644 --- a/busted/modules/luacov.lua +++ b/busted/modules/luacov.lua @@ -4,7 +4,7 @@ return function() local result, luacov = pcall(require, 'luacov.runner') if not result then - return print('LuaCov not found on the system, try running without --coverage option, or install LuaCov first') + return nil, 'LuaCov not found on the system, try running without --coverage option, or install LuaCov first' end -- call it to start @@ -16,6 +16,7 @@ return function() table.insert(luacov.configuration.exclude, 'luassert%.') table.insert(luacov.configuration.exclude, 'say%.') table.insert(luacov.configuration.exclude, 'pl%.') + return true end return loadLuaCov diff --git a/busted/runner.lua b/busted/runner.lua index eefac142..6605eec1 100644 --- a/busted/runner.lua +++ b/busted/runner.lua @@ -56,7 +56,11 @@ return function(options) -- If coverage arg is passed in, load LuaCovsupport if cliArgs.coverage then - luacov() + local ok, err = luacov() + if not ok then + io.stderr:write(appName .. ': error: ' .. err .. '\n') + exit(1, forceExit) + end end -- If auto-insulate is disabled, re-register file without insulation From a3c62fed45e178c33e236cdf2a15fcf23a976f86 Mon Sep 17 00:00:00 2001 From: Jack Lawson Date: Mon, 24 Sep 2018 10:08:01 -0400 Subject: [PATCH 16/26] Release 2.0.rc13-0 --- busted-2.0.rc12-1.rockspec => busted-2.0.rc13-0.rockspec | 6 +++--- busted/core.lua | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename busted-2.0.rc12-1.rockspec => busted-2.0.rc13-0.rockspec (98%) diff --git a/busted-2.0.rc12-1.rockspec b/busted-2.0.rc13-0.rockspec similarity index 98% rename from busted-2.0.rc12-1.rockspec rename to busted-2.0.rc13-0.rockspec index 08d86dda..72d6a359 100644 --- a/busted-2.0.rc12-1.rockspec +++ b/busted-2.0.rc13-0.rockspec @@ -1,8 +1,8 @@ package = 'busted' -version = '2.0.rc12-1' +version = '2.0.rc13-0' source = { - url = 'https://github.com/Olivine-Labs/busted/archive/v2.0.rc12-1.tar.gz', - dir = 'busted-2.0.rc12-1' + url = 'https://github.com/Olivine-Labs/busted/archive/v2.0.rc13-0.tar.gz', + dir = 'busted-2.0.rc13-0' } description = { summary = 'Elegant Lua unit testing.', diff --git a/busted/core.lua b/busted/core.lua index f9b869bf..8e6d564d 100644 --- a/busted/core.lua +++ b/busted/core.lua @@ -45,7 +45,7 @@ return function() local mediator = require 'mediator'() local busted = {} - busted.version = '2.0.rc12-0' + busted.version = '2.0.rc13-0' local root = require 'busted.context'() busted.context = root.ref() From fd939b711599b9f43fea63e7db4c008d986d5bb1 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Thu, 6 Dec 2018 05:56:21 +0100 Subject: [PATCH 17/26] allow parameters when testing busted itself The 'try' and 'try.bat' scripts will now pass their parameters on to Busted when testing. --- try | 2 +- try.bat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/try b/try index fe04aa13..b2239ba3 100755 --- a/try +++ b/try @@ -1,4 +1,4 @@ #!/bin/sh sudo luarocks remove busted --force sudo luarocks make busted-scm-0.rockspec -busted +busted $@ diff --git a/try.bat b/try.bat index 0d4dba36..6cbe1b02 100644 --- a/try.bat +++ b/try.bat @@ -1,4 +1,4 @@ call luarocks remove busted --force call luarocks make busted-scm-0.rockspec cls -call busted +call busted %* From 85daab63bd3ba5d4a12724fb99cd366e6a962447 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Thu, 6 Dec 2018 06:04:47 +0100 Subject: [PATCH 18/26] move rockspecs into separate directory This allows the test scripts to not have a literal version in them, but always use the one in the repo --- .../busted-2.0.rc13-0.rockspec | 0 try | 2 +- try.bat | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename busted-2.0.rc13-0.rockspec => rockspecs/busted-2.0.rc13-0.rockspec (100%) diff --git a/busted-2.0.rc13-0.rockspec b/rockspecs/busted-2.0.rc13-0.rockspec similarity index 100% rename from busted-2.0.rc13-0.rockspec rename to rockspecs/busted-2.0.rc13-0.rockspec diff --git a/try b/try index b2239ba3..5566fd10 100755 --- a/try +++ b/try @@ -1,4 +1,4 @@ #!/bin/sh sudo luarocks remove busted --force -sudo luarocks make busted-scm-0.rockspec +sudo luarocks make busted $@ diff --git a/try.bat b/try.bat index 6cbe1b02..d06a8233 100644 --- a/try.bat +++ b/try.bat @@ -1,4 +1,4 @@ call luarocks remove busted --force -call luarocks make busted-scm-0.rockspec +call luarocks make cls call busted %* From c8eefaed4e9f9812b98db9cb5caba50debd35bb2 Mon Sep 17 00:00:00 2001 From: Calle Englund Date: Sun, 3 Feb 2019 16:58:09 +0100 Subject: [PATCH 19/26] Fix typo in cli option processing for config-file --- busted/modules/cli.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/busted/modules/cli.lua b/busted/modules/cli.lua index cbc1a8bd..db4a2d67 100644 --- a/busted/modules/cli.lua +++ b/busted/modules/cli.lua @@ -124,7 +124,7 @@ return function(options) cli:option('-e STATEMENT', 'execute statement STATEMENT', nil, processMultiOption) cli:option('-o, --output=LIBRARY', 'output library to load', defaultOutput, processOption) cli:option('-C, --directory=DIR', 'change to directory DIR before running tests. If multiple options are specified, each is interpreted relative to the previous one.', './', processDir) - cli:option('-f, --config-file=FILE', 'load configuration options from FILE', nil, processOptions) + cli:option('-f, --config-file=FILE', 'load configuration options from FILE', nil, processOption) cli:option('-t, --tags=TAGS', 'only run tests with these #tags', {}, processList) cli:option('--exclude-tags=TAGS', 'do not run tests with these #tags, takes precedence over --tags', {}, processList) cli:option('--filter=PATTERN', 'only run test names matching the Lua pattern', {}, processMultiOption) From 452b76358b0597372e948ebdb6621d9a1661d6f7 Mon Sep 17 00:00:00 2001 From: William Gladen Date: Sun, 2 Jun 2019 12:27:54 -0600 Subject: [PATCH 20/26] Allow ROOT to contain hidden directories. --- busted/modules/test_file_loader.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/busted/modules/test_file_loader.lua b/busted/modules/test_file_loader.lua index 6f2e83d8..3a6be09b 100644 --- a/busted/modules/test_file_loader.lua +++ b/busted/modules/test_file_loader.lua @@ -37,9 +37,9 @@ return function(busted, loaders) fileList = tablex.filter(fileList, function(filename) if path.is_windows then - return not filename:find('%\\%.%w+.%w+') + return not filename:find('%\\%.%w+.%w+', #rootFile) else - return not filename:find('/%.%w+.%w+') + return not filename:find('/%.%w+.%w+', #rootFile) end end) else From 72cad533e9266b2ecfaa8f07454a1b246c93d246 Mon Sep 17 00:00:00 2001 From: William Gladen Date: Mon, 3 Jun 2019 08:51:55 -0600 Subject: [PATCH 21/26] Added test case. --- spec/cl_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/cl_spec.lua b/spec/cl_spec.lua index 30e83040..5db71c61 100644 --- a/spec/cl_spec.lua +++ b/spec/cl_spec.lua @@ -767,3 +767,12 @@ describe('Tests execute option', function() assert.is_equal('hello world', result:match('(.-)\n')) end) end) + +describe('Tests root specification', function() + it('allows hidden directories in root path', function() + local success, errcnt, result = executeBusted('spec/.hidden') + assert.is_false(success) + assert.is_equal(1, errcnt) + assert.is_truthy(result:find('should not be executed')) + end) +end) From ff7304216a133a655d904e6e36b0a137a9321afc Mon Sep 17 00:00:00 2001 From: Michael Pankov Date: Mon, 24 Jun 2019 10:54:59 +0300 Subject: [PATCH 22/26] Cache io to be robust about mocking io in tests --- busted/outputHandlers/TAP.lua | 1 + busted/outputHandlers/gtest.lua | 1 + busted/outputHandlers/junit.lua | 1 + busted/outputHandlers/plainTerminal.lua | 1 + busted/outputHandlers/sound.lua | 2 ++ busted/outputHandlers/utfTerminal.lua | 1 + 6 files changed, 7 insertions(+) diff --git a/busted/outputHandlers/TAP.lua b/busted/outputHandlers/TAP.lua index 6e1cdebc..cd0e7407 100644 --- a/busted/outputHandlers/TAP.lua +++ b/busted/outputHandlers/TAP.lua @@ -1,4 +1,5 @@ local pretty = require 'pl.pretty' +local io = io return function(options) local busted = require 'busted' diff --git a/busted/outputHandlers/gtest.lua b/busted/outputHandlers/gtest.lua index 1b940a4f..b7930f74 100644 --- a/busted/outputHandlers/gtest.lua +++ b/busted/outputHandlers/gtest.lua @@ -1,6 +1,7 @@ local s = require 'say' local pretty = require 'pl.pretty' local term = require 'term' +local io = io local colors diff --git a/busted/outputHandlers/junit.lua b/busted/outputHandlers/junit.lua index f1d28a5f..7ea3aafd 100644 --- a/busted/outputHandlers/junit.lua +++ b/busted/outputHandlers/junit.lua @@ -1,5 +1,6 @@ local xml = require 'pl.xml' local string = require("string") +local io = io return function(options) local busted = require 'busted' diff --git a/busted/outputHandlers/plainTerminal.lua b/busted/outputHandlers/plainTerminal.lua index e15f9879..b0a73242 100644 --- a/busted/outputHandlers/plainTerminal.lua +++ b/busted/outputHandlers/plainTerminal.lua @@ -1,5 +1,6 @@ local s = require 'say' local pretty = require 'pl.pretty' +local io = io return function(options) local busted = require 'busted' diff --git a/busted/outputHandlers/sound.lua b/busted/outputHandlers/sound.lua index 8a749693..84fa7c8b 100644 --- a/busted/outputHandlers/sound.lua +++ b/busted/outputHandlers/sound.lua @@ -1,4 +1,6 @@ local app = require 'pl.app' +local io = io + return function(options) local busted = require 'busted' local handler = require 'busted.outputHandlers.base'() diff --git a/busted/outputHandlers/utfTerminal.lua b/busted/outputHandlers/utfTerminal.lua index fa38c958..ca32b8aa 100644 --- a/busted/outputHandlers/utfTerminal.lua +++ b/busted/outputHandlers/utfTerminal.lua @@ -1,5 +1,6 @@ local s = require 'say' local pretty = require 'pl.pretty' +local io = io local colors From 9d49231e3efe25b3501859babbe6c61340ec7b64 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Mon, 24 Jun 2019 11:36:30 +0200 Subject: [PATCH 23/26] fix: properly error out on bad config files --- busted/modules/cli.lua | 37 ++++++++++++++++++++++++--------- spec/.hidden/.busted_bad | 2 +- spec/.hidden/.busted_bad_syntax | 14 +++++++++++++ spec/cl_spec.lua | 18 ++++++++++++++++ 4 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 spec/.hidden/.busted_bad_syntax diff --git a/busted/modules/cli.lua b/busted/modules/cli.lua index cbc1a8bd..89982ef5 100644 --- a/busted/modules/cli.lua +++ b/busted/modules/cli.lua @@ -168,17 +168,34 @@ return function(options) end -- Load busted config file if available - local bustedConfigFilePath = cliArgs.f or path.normpath(path.join(cliArgs.directory, '.busted')) - local bustedConfigFile = loadfile(bustedConfigFilePath) - if bustedConfigFile then - local ok, config = pcall(function() - local conf, err = configLoader(bustedConfigFile(), cliArgsParsed, cliArgs) - return conf or error(err, 0) - end) - if not ok then - return nil, appName .. ': error: ' .. config + local bustedConfigFilePath + if cliArgs.f then + -- if the file is given, then we require it to exist + if not path.isfile(cliArgs.f) then + return nil, ("specified config file '%s' not found"):format(cliArgs.f) + end + bustedConfigFilePath = cliArgs.f + else + -- try default file + bustedConfigFilePath = path.normpath(path.join(cliArgs.directory, '.busted')) + if not path.isfile(bustedConfigFilePath) then + bustedConfigFilePath = nil -- clear default file, since it doesn't exist + end + end + if bustedConfigFilePath then + local bustedConfigFile, err = loadfile(bustedConfigFilePath) + if not bustedConfigFile then + return nil, ("failed loading config file `%s`: %s"):format(bustedConfigFilePath, err) else - cliArgs = config + local ok, config = pcall(function() + local conf, err = configLoader(bustedConfigFile(), cliArgsParsed, cliArgs) + return conf or error(err, 0) + end) + if not ok then + return nil, appName .. ': error: ' .. config + else + cliArgs = config + end end else cliArgs = tablex.merge(cliArgs, cliArgsParsed, true) diff --git a/spec/.hidden/.busted_bad b/spec/.hidden/.busted_bad index b1df1c77..e80083a0 100644 --- a/spec/.hidden/.busted_bad +++ b/spec/.hidden/.busted_bad @@ -5,7 +5,7 @@ return { default = { ['ROOT'] = {'specs'}, ['pattern'] = '_spec%.lua$', - ['loaders'] = doesnotexist.loaders, + ['loaders'] = doesnotexist.loaders, -- errors when run ['verbose'] = true, }, test = { diff --git a/spec/.hidden/.busted_bad_syntax b/spec/.hidden/.busted_bad_syntax new file mode 100644 index 00000000..5acd1c3b --- /dev/null +++ b/spec/.hidden/.busted_bad_syntax @@ -0,0 +1,14 @@ +return { + _all = { + ['ROOT'] = {'tests'}, + }, + default = { + ['ROOT'] = {'specs'}, + ['pattern'] = '_spec%.lua$', + ['loaders'] = doesnotexist.loaders, + ['verbose'] = true, + }, + test = { + ['pattern'] = '_test%.lua$', + } +-- } -- missing bracket, errors when compiled diff --git a/spec/cl_spec.lua b/spec/cl_spec.lua index 30e83040..c5c2f89d 100644 --- a/spec/cl_spec.lua +++ b/spec/cl_spec.lua @@ -211,6 +211,24 @@ describe('Tests the busted command-line options', function() assert.is_equal(1, errcnt) end) + it('tests running a non-existing configfile', function() + local success, errcnt = executeBusted('--config-file=spec/.hidden/.this_one_does_not_exist --pattern=cl_execute_fail.lua$') + assert.is_false(success) + assert.is_equal(0, errcnt) + end) + + it('tests running a non-compiling configfile', function() + local success, errcnt = executeBusted('--config-file=spec/.hidden/.busted_bad_syntax --pattern=cl_execute_fail.lua$') + assert.is_false(success) + assert.is_equal(0, errcnt) + end) + + it('tests running a configfile throwing errors when being run', function() + local success, errcnt, out, err = executeBusted('--config-file=spec/.hidden/.busted_bad --pattern=cl_execute_fail.lua$') + assert.is_false(success) + assert.is_equal(0, errcnt) + end) + it('tests running with --output specified', function() local success, errcnt = executeBusted('--pattern=cl_success.lua$ --output=TAP') assert.is_true(success) From 1f1934735258bf3ee8a3bc2b2eb003bce916f0ab Mon Sep 17 00:00:00 2001 From: Jack Lawson Date: Fri, 28 Jun 2019 14:50:36 -0400 Subject: [PATCH 24/26] v2.0.0; luassert 1.8 --- busted/core.lua | 2 +- ...busted-2.0.rc13-0.rockspec => busted-2.0.0-0.rockspec} | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) rename rockspecs/{busted-2.0.rc13-0.rockspec => busted-2.0.0-0.rockspec} (96%) diff --git a/busted/core.lua b/busted/core.lua index 8e6d564d..4d3678e5 100644 --- a/busted/core.lua +++ b/busted/core.lua @@ -45,7 +45,7 @@ return function() local mediator = require 'mediator'() local busted = {} - busted.version = '2.0.rc13-0' + busted.version = '2.0.0-0' local root = require 'busted.context'() busted.context = root.ref() diff --git a/rockspecs/busted-2.0.rc13-0.rockspec b/rockspecs/busted-2.0.0-0.rockspec similarity index 96% rename from rockspecs/busted-2.0.rc13-0.rockspec rename to rockspecs/busted-2.0.0-0.rockspec index 72d6a359..a70a88f8 100644 --- a/rockspecs/busted-2.0.rc13-0.rockspec +++ b/rockspecs/busted-2.0.0-0.rockspec @@ -1,8 +1,8 @@ package = 'busted' -version = '2.0.rc13-0' +version = '2.0.0-0' source = { - url = 'https://github.com/Olivine-Labs/busted/archive/v2.0.rc13-0.tar.gz', - dir = 'busted-2.0.rc13-0' + url = 'https://github.com/Olivine-Labs/busted/archive/v2.0.0-0.tar.gz', + dir = 'busted-2.0.0-0' } description = { summary = 'Elegant Lua unit testing.', @@ -24,7 +24,7 @@ dependencies = { 'luasystem >= 0.2.0-0', 'dkjson >= 2.1.0', 'say >= 1.3-0', - 'luassert >= 1.7.8-0', + 'luassert >= 1.8.0-0', 'lua-term >= 0.1-1', 'penlight >= 1.3.2-2', 'mediator_lua >= 1.1.1-0', From bf3405cbcc651fbc3fa3ee223cf8a556f1a564a6 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Mon, 1 Jul 2019 09:19:14 +0200 Subject: [PATCH 25/26] fix(rockspecs) proper usage of rockspec revision numbers --- ...ed-scm-0.rockspec => busted-scm-1.rockspec | 16 ++-- rockspecs/busted-2.0.0-1.rockspec | 89 +++++++++++++++++++ 2 files changed, 97 insertions(+), 8 deletions(-) rename busted-scm-0.rockspec => busted-scm-1.rockspec (95%) create mode 100644 rockspecs/busted-2.0.0-1.rockspec diff --git a/busted-scm-0.rockspec b/busted-scm-1.rockspec similarity index 95% rename from busted-scm-0.rockspec rename to busted-scm-1.rockspec index 4bb668f6..d45f4275 100644 --- a/busted-scm-0.rockspec +++ b/busted-scm-1.rockspec @@ -1,5 +1,5 @@ package = 'busted' -version = 'scm-0' +version = 'scm-1' source = { url = "git://github.com/Olivine-Labs/busted", branch = "master" @@ -19,15 +19,15 @@ description = { } dependencies = { 'lua >= 5.1', - 'lua_cliargs = 3.0-1', + 'lua_cliargs = 3.0', 'luafilesystem >= 1.5.0', - 'luasystem >= 0.2.0-0', + 'luasystem >= 0.2.0', 'dkjson >= 2.1.0', - 'say >= 1.3-0', - 'luassert >= 1.7.8-0', - 'lua-term >= 0.1-1', - 'penlight >= 1.3.2-2', - 'mediator_lua >= 1.1.1-0', + 'say >= 1.3', + 'luassert >= 1.7.8', + 'lua-term >= 0.1', + 'penlight >= 1.3.2', + 'mediator_lua >= 1.1.1', } build = { diff --git a/rockspecs/busted-2.0.0-1.rockspec b/rockspecs/busted-2.0.0-1.rockspec new file mode 100644 index 00000000..7d2fc389 --- /dev/null +++ b/rockspecs/busted-2.0.0-1.rockspec @@ -0,0 +1,89 @@ +package = 'busted' +version = '2.0.0-1' +source = { + url = 'https://github.com/Olivine-Labs/busted/archive/v2.0.0.tar.gz', + dir = 'busted-2.0.0' +} +description = { + summary = 'Elegant Lua unit testing.', + detailed = [[ + An elegant, extensible, testing framework. + Ships with a large amount of useful asserts, + plus the ability to write your own. Output + in pretty or plain terminal format, JSON, + or TAP for CI integration. Great for TDD + and unit, integration, and functional tests. + ]], + homepage = 'http://olivinelabs.com/busted/', + license = 'MIT ' +} +dependencies = { + 'lua >= 5.1', + 'lua_cliargs = 3.0', + 'luafilesystem >= 1.5.0', + 'luasystem >= 0.2.0', + 'dkjson >= 2.1.0', + 'say >= 1.3', + 'luassert >= 1.8.0', + 'lua-term >= 0.1', + 'penlight >= 1.3.2', + 'mediator_lua >= 1.1.1', +} + +build = { + type = 'builtin', + modules = { + ['busted.core'] = 'busted/core.lua', + ['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', + ['busted.utils'] = 'busted/utils.lua', + ['busted.block'] = 'busted/block.lua', + ['busted.execute'] = 'busted/execute.lua', + ['busted.init'] = 'busted/init.lua', + + ['busted.modules.configuration_loader'] = 'busted/modules/configuration_loader.lua', + ['busted.modules.luacov'] = 'busted/modules/luacov.lua', + ['busted.modules.standalone_loader'] = 'busted/modules/standalone_loader.lua', + ['busted.modules.test_file_loader'] = 'busted/modules/test_file_loader.lua', + ['busted.modules.output_handler_loader'] = 'busted/modules/output_handler_loader.lua', + ['busted.modules.helper_loader'] = 'busted/modules/helper_loader.lua', + ['busted.modules.filter_loader'] = 'busted/modules/filter_loader.lua', + ['busted.modules.cli'] = 'busted/modules/cli.lua', + + ['busted.modules.files.lua'] = 'busted/modules/files/lua.lua', + ['busted.modules.files.moonscript'] = 'busted/modules/files/moonscript.lua', + ['busted.modules.files.terra'] = 'busted/modules/files/terra.lua', + + ['busted.outputHandlers.base'] = 'busted/outputHandlers/base.lua', + ['busted.outputHandlers.utfTerminal'] = 'busted/outputHandlers/utfTerminal.lua', + ['busted.outputHandlers.plainTerminal'] = 'busted/outputHandlers/plainTerminal.lua', + ['busted.outputHandlers.TAP'] = 'busted/outputHandlers/TAP.lua', + ['busted.outputHandlers.json'] = 'busted/outputHandlers/json.lua', + ['busted.outputHandlers.junit'] = 'busted/outputHandlers/junit.lua', + ['busted.outputHandlers.gtest'] = 'busted/outputHandlers/gtest.lua', + ['busted.outputHandlers.sound'] = 'busted/outputHandlers/sound.lua', + + ['busted.languages.en'] = 'busted/languages/en.lua', + ['busted.languages.ar'] = 'busted/languages/ar.lua', + ['busted.languages.de'] = 'busted/languages/de.lua', + ['busted.languages.es'] = 'busted/languages/es.lua', + ['busted.languages.fr'] = 'busted/languages/fr.lua', + ['busted.languages.ja'] = 'busted/languages/ja.lua', + ['busted.languages.nl'] = 'busted/languages/nl.lua', + ['busted.languages.ru'] = 'busted/languages/ru.lua', + ['busted.languages.th'] = 'busted/languages/th.lua', + ['busted.languages.ua'] = 'busted/languages/ua.lua', + ['busted.languages.zh'] = 'busted/languages/zh.lua', + ['busted.languages.it'] = 'busted/languages/it.lua', + }, + install = { + bin = { + ['busted'] = 'bin/busted' + } + } +} From 045d0882243f539b4f3ea30ac60144cabdb33e65 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Mon, 1 Jul 2019 13:29:46 +0200 Subject: [PATCH 26/26] fix(ci) do not specify a rockspec, just build the only one there --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c2125f70..7891c871 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ before_install: - luarocks install moonscript install: - - luarocks make busted-scm-0.rockspec + - luarocks make script: busted