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