Skip to content

Commit

Permalink
Validate the tests directory before trying collection. (#24)
Browse files Browse the repository at this point in the history
Fixes #23
  • Loading branch information
mblayman committed Jul 16, 2023
1 parent 2769cae commit a1b2966
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2 - To Be Released

* Validate the tests directory before trying collection.

## v0.1 - 2023-07-14

* Initial release
Expand Down
11 changes: 10 additions & 1 deletion lua/luatest/collection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ local function report_errors(errors, reporter)
end
end

-- Validate the tests directory.
local function validate_tests_dir(tests_dir, reporter)
if not path.isdir(tests_dir) then
report_errors({tests_dir .. " is not a valid directory."}, reporter)
end
end

-- Process module and store it with the collected modules.
local function process_module(relpath, test_module, test_meta, test_modules,
reporter)
Expand Down Expand Up @@ -171,6 +178,7 @@ end
local function collect(config, reporter)
local cwd = path.currentdir()
local tests_dir = path.join(cwd, config.tests_dir)
validate_tests_dir(tests_dir, reporter)

reporter:start_collection(tests_dir)

Expand Down Expand Up @@ -216,5 +224,6 @@ return {
check_files_are_tests = check_files_are_tests,
clean_test = clean_tests,
process_module = process_module,
report_errors = report_errors
report_errors = report_errors,
validate_tests_dir = validate_tests_dir
}
13 changes: 13 additions & 0 deletions tests/test_collection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,17 @@ function tests.test_invalid_user_file()
assert.spy(reporter.error).was_called_with(reporter, expected)
end

-- An invalid tests directory is an error.
function tests.test_invalid_tests_dir()
local tests_dir = "/not/real"
local reporter = {}
spy.on(reporter, "error")
spy.on(reporter, "fatal")

collection.validate_tests_dir(tests_dir, reporter)

local expected = "/not/real is not a valid directory."
assert.spy(reporter.error).was_called_with(reporter, expected)
end

return tests

0 comments on commit a1b2966

Please sign in to comment.