Improved test runner usage
This commit is contained in:
parent
b5471154a6
commit
c85e8203d0
@ -41,12 +41,27 @@
|
||||
m.loadTestsFromManifests()
|
||||
m.detectDuplicateTests = false
|
||||
|
||||
local test, err = m.getTestWithIdentifier(_OPTIONS["test-only"])
|
||||
if err then
|
||||
error(err, 0)
|
||||
local tests = {}
|
||||
local isAction = true
|
||||
for i, arg in ipairs(_ARGS) do
|
||||
local _tests, err = m.getTestsWithIdentifier(arg)
|
||||
if err then
|
||||
error(err, 0)
|
||||
end
|
||||
|
||||
tests = table.join(tests, _tests)
|
||||
end
|
||||
|
||||
local passed, failed = m.runTest(test)
|
||||
if #tests == 0 or _OPTIONS["test-only"] ~= nil then
|
||||
local _tests, err = m.getTestsWithIdentifier(_OPTIONS["test-only"])
|
||||
if err then
|
||||
error(err, 0)
|
||||
end
|
||||
|
||||
tests = table.join(tests, _tests)
|
||||
end
|
||||
|
||||
local passed, failed = m.runTest(tests)
|
||||
|
||||
if failed > 0 then
|
||||
printf("\n %d FAILED TEST%s", failed, iif(failed > 1, "S", ""))
|
||||
|
@ -112,31 +112,79 @@
|
||||
|
||||
|
||||
---
|
||||
-- Fetch a test object via its string identifier.
|
||||
-- Fetch test objects via the string identifier.
|
||||
--
|
||||
-- @param identifier
|
||||
-- An optional test or suite identifier, indicating which tests should be
|
||||
-- run, in the form "suiteName" or "suiteName.testName". If not specified,
|
||||
-- the global test object, representing all test suites, will be returned.
|
||||
-- Use "*" to match any part of a suite or test name
|
||||
-- @return
|
||||
-- On success, returns a test object, which should be considered opaque.
|
||||
-- On success, returns an array of test objects, which should be considered opaque.
|
||||
-- On failure, returns `nil` and an error.
|
||||
---
|
||||
|
||||
function m.getTestWithIdentifier(identifier)
|
||||
function m.getTestsWithIdentifier(identifier)
|
||||
local suiteName, testName = m.parseTestIdentifier(identifier)
|
||||
|
||||
local suite, test, err = _.checkTestIdentifier(_.suites, suiteName, testName)
|
||||
if err then
|
||||
return nil, err
|
||||
end
|
||||
if suiteName ~= nil and string.contains(suiteName, "*") then
|
||||
local tests = {}
|
||||
|
||||
return {
|
||||
suiteName = suiteName,
|
||||
suite = suite,
|
||||
testName = testName,
|
||||
testFunction = test
|
||||
}
|
||||
local pattern = string.gsub(suiteName, "*", ".*")
|
||||
for _suiteName, suite in pairs(_.suites) do
|
||||
local length = string.len(_suiteName)
|
||||
local start, finish = string.find(_suiteName, pattern)
|
||||
if start == 1 and finish == length then
|
||||
if testName ~= nil then
|
||||
if string.contains(testName, "*") then
|
||||
local testPattern = string.gsub(testName, "*", ".*")
|
||||
for _testName, test in pairs(suite) do
|
||||
length = string.len(_testName)
|
||||
start, finish = string.find(_testName, testPattern)
|
||||
if start == 1 and finish == length then
|
||||
table.insert(tests, {
|
||||
suiteName = _suiteName,
|
||||
suite = suite,
|
||||
testName = _testName,
|
||||
testFunction = test,
|
||||
})
|
||||
end
|
||||
end
|
||||
else
|
||||
table.insert(tests, {
|
||||
suiteName = _suiteName,
|
||||
suite = suite,
|
||||
testName = testName,
|
||||
testFunction = suite[testName],
|
||||
})
|
||||
end
|
||||
else
|
||||
table.insert(tests, {
|
||||
suiteName = _suiteName,
|
||||
suite = suite,
|
||||
testName = nil,
|
||||
testFunction = nil,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return tests
|
||||
else
|
||||
local suite, test, err = _.checkTestIdentifier(_.suites, suiteName, testName)
|
||||
if err then
|
||||
return nil, err
|
||||
end
|
||||
|
||||
return {
|
||||
{
|
||||
suiteName = suiteName,
|
||||
suite = suite,
|
||||
testName = testName,
|
||||
testFunction = test
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -15,12 +15,12 @@
|
||||
|
||||
|
||||
|
||||
function m.runTest(test)
|
||||
function m.runTest(tests)
|
||||
local failed = 0
|
||||
local failedTests = {}
|
||||
|
||||
local suites = m.getSuites()
|
||||
local suitesKeys, suiteTestsKeys, totalTestCount = _.preprocessTests(suites, test)
|
||||
local suitesKeys, suiteTestsKeys, totalTestCount = _.preprocessTests(suites, tests)
|
||||
|
||||
_.log(term.lightGreen, "[==========]", string.format(" Running %d tests from %d test suites.", totalTestCount, #suitesKeys))
|
||||
local startTime = os.clock()
|
||||
@ -128,30 +128,36 @@
|
||||
|
||||
|
||||
|
||||
function _.preprocessTests(suites, filter)
|
||||
function _.preprocessTests(suites, filters)
|
||||
local suitesKeys = {}
|
||||
local suiteTestsKeys = {}
|
||||
local totalTestCount = 0
|
||||
|
||||
for suiteName, suite in pairs(suites) do
|
||||
if not m.isSuppressed(suiteName) and suite ~= nil and (not filter.suiteName or filter.suiteName == suiteName) then
|
||||
local test = {}
|
||||
for i, filter in ipairs(filters) do
|
||||
for suiteName, suite in pairs(suites) do
|
||||
if not m.isSuppressed(suiteName) and suite ~= nil and (not filter.suiteName or filter.suiteName == suiteName) then
|
||||
local test = {}
|
||||
|
||||
table.insertsorted(suitesKeys, suiteName)
|
||||
test.suiteName = suiteName
|
||||
test.suite = suite
|
||||
|
||||
test.suiteName = suiteName
|
||||
test.suite = suite
|
||||
if not table.contains(suitesKeys, suiteName) then
|
||||
table.insertsorted(suitesKeys, suiteName)
|
||||
suiteTestsKeys[suiteName] = {}
|
||||
end
|
||||
|
||||
suiteTestsKeys[suiteName] = {}
|
||||
for testName, testFunction in pairs(suite) do
|
||||
test.testName = testName
|
||||
test.testFunction = testFunction
|
||||
for testName, testFunction in pairs(suite) do
|
||||
test.testName = testName
|
||||
test.testFunction = testFunction
|
||||
|
||||
if m.isValid(test) and not m.isSuppressed(test.suiteName .. "." .. test.testName) and (not filter.testName or filter.testName == testName) then
|
||||
table.insertsorted(suiteTestsKeys[suiteName], testName)
|
||||
if m.isValid(test) and not m.isSuppressed(test.suiteName .. "." .. test.testName) and (not filter.testName or filter.testName == testName) then
|
||||
if not table.contains(suiteTestsKeys[suiteName], testName) then
|
||||
table.insertsorted(suiteTestsKeys[suiteName], testName)
|
||||
totalTestCount = totalTestCount + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
totalTestCount = totalTestCount + #suiteTestsKeys[suiteName]
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user