Skip to content

Commit

Permalink
Output error message when test file/dir not found
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
o-lim committed Aug 29, 2016
1 parent ed3f708 commit b5060dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions busted/languages/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions busted/modules/test_file_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ return function(busted, loaders)
end
end)
else
busted.publish({ 'error' }, {}, nil, s('output.file_not_found'):format(rootFile), {})
fileList = {}
end

Expand Down
14 changes: 14 additions & 0 deletions spec/cl_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit b5060dd

Please sign in to comment.