Skip to content

Commit

Permalink
conf(cli) add support for luacov config path (lunarmodules#660)
Browse files Browse the repository at this point in the history
adds new option `--coverage-config-file=FILE`
  • Loading branch information
nicholaschiasson authored Mar 15, 2021
1 parent c75bc4b commit 2e4799e
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/busted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
luarocks install moonscript
luarocks install copas
luarocks install lua-ev
luarocks install luacov
- name: Cache Lua machinery
uses: actions/cache@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.swp
/luacov.report.out
/.ignore*
1 change: 1 addition & 0 deletions busted/modules/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ return function(options)
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, processOption)
cli:option('--coverage-config-file=FILE', 'load luacov 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)
Expand Down
4 changes: 2 additions & 2 deletions busted/modules/luacov.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
return function()
-- Function to initialize luacov if available
local loadLuaCov = function()
local loadLuaCov = function(config)
local result, luacov = pcall(require, 'luacov.runner')

if not result then
return nil, 'LuaCov not found on the system, try running without --coverage option, or install LuaCov first'
end

-- call it to start
luacov()
luacov(config)

-- exclude busted files
table.insert(luacov.configuration.exclude, 'busted_bootstrap$')
Expand Down
2 changes: 1 addition & 1 deletion busted/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ return function(options)

-- If coverage arg is passed in, load LuaCovsupport
if cliArgs.coverage then
local ok, err = luacov()
local ok, err = luacov(cliArgs['coverage-config-file'])
if not ok then
io.stderr:write(appName .. ': error: ' .. err .. '\n')
exit(1, forceExit)
Expand Down
52 changes: 52 additions & 0 deletions spec/.hidden/.luacov
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--- Global configuration file. Copy, customize and store in your
-- project folder as '.luacov' for project specific configuration
-- @class module
-- @name luacov.defaults
return {

-- default filename to load for config options if not provided
-- only has effect in 'luacov.defaults.lua'
['configfile'] = '.luacov',

-- filename to store stats collected
['statsfile'] = '.ignore.luacov.stats.out',

-- filename to store report
['reportfile'] = '.ignore.luacov.report.out',

-- Run reporter on completion? (won't work for ticks)
runreport = true,

-- Delete stats file after reporting?
deletestats = true,

-- Patterns for files to include when reporting
-- all will be included if nothing is listed
-- (exclude overrules include, do not include
-- the .lua extension)
['include'] = {
},

-- Patterns for files to exclude when reporting
-- all will be included if nothing is listed
-- (exclude overrules include, do not include
-- the .lua extension)
['exclude'] = {
'luacov$',
'luacov.reporter$',
'luacov.defaults$',
'luacov.runner$',
'luacov.stats$',
'luacov.tick$',
'term$',
'term.colors$',
'term.cursor$',
'term.init$',
'copas$',
'coxpcall$',
'mediator$',
'moonscript.*$',
},


}
15 changes: 15 additions & 0 deletions spec/cl_spec.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local utils = require 'pl.utils'
local file = require 'pl.file'
local path = require 'pl.path'
local normpath = path.normpath
local busted_cmd = path.is_windows and 'lua bin/busted' or 'bin/busted'
Expand Down Expand Up @@ -257,6 +258,20 @@ describe('Tests the busted command-line options', function()
assert.is_equal(0, errcnt)
assert.equal('bin/busted --ignore-lua --lua=' .. lua_exe .. ' spec/cl_success.lua\n', out)
end)

it('tests running a configfile for luacov', function()
local custom_config = normpath('spec/.hidden/.luacov')
local custom_report = normpath('.ignore.luacov.report.out')
local success, errcnt = executeBusted('--coverage-config-file=' .. custom_config .. ' spec/cl_success.lua')
assert.is_true(success)
assert.is_equal(0, errcnt)
assert.is_false(path.isfile(custom_report))
success, errcnt = executeBusted('--coverage --coverage-config-file=' .. custom_config .. ' spec/cl_success.lua')
assert.is_true(success)
assert.is_equal(0, errcnt)
assert.is_true(path.isfile(custom_report))
file.delete(custom_report)
end)
end)

describe('Tests failing tests through the commandline', function()
Expand Down
3 changes: 3 additions & 0 deletions spec/modules/cli_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('Tests command-line interface', function()
assert.is_false(args['defer-print'])
assert.is_nil(args.f)
assert.is_nil(args['config-file'])
assert.is_nil(args['coverage-config-file'])
assert.is_nil(args.shuffle)
assert.is_nil(args['shuffle-files'])
assert.is_nil(args['shuffle-tests'])
Expand Down Expand Up @@ -362,6 +363,7 @@ describe('Tests using .busted tasks', function()
assert.is_false(args['defer-print'])
assert.is_nil(args.f)
assert.is_nil(args['config-file'])
assert.is_nil(args['coverage-config-file'])
assert.is_nil(args.shuffle)
assert.is_nil(args['shuffle-files'])
assert.is_nil(args['shuffle-tests'])
Expand Down Expand Up @@ -421,6 +423,7 @@ describe('Tests using .busted tasks', function()
assert.is_false(args['enable-sound'])
assert.is_false(args['suppress-pending'])
assert.is_false(args['defer-print'])
assert.is_nil(args['coverage-config-file'])
assert.is_nil(args.shuffle)
assert.is_nil(args['shuffle-files'])
assert.is_nil(args['shuffle-tests'])
Expand Down

0 comments on commit 2e4799e

Please sign in to comment.