2016-05-16 20:27:14 +00:00
|
|
|
---
|
|
|
|
-- self-test/self-test.lua
|
|
|
|
--
|
|
|
|
-- An automated test framework for Premake and its add-on modules.
|
|
|
|
--
|
|
|
|
-- Author Jason Perkins
|
|
|
|
-- Copyright (c) 2008-2016 Jason Perkins and the Premake project.
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
local p = premake
|
|
|
|
|
|
|
|
p.modules.self_test = {}
|
|
|
|
local m = p.modules.self_test
|
|
|
|
|
|
|
|
m._VERSION = p._VERSION
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newaction {
|
|
|
|
trigger = "self-test",
|
|
|
|
shortname = "Test Premake",
|
|
|
|
description = "Run Premake's own local unit test suites",
|
|
|
|
execute = function()
|
|
|
|
m.executeSelfTest()
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newoption {
|
|
|
|
trigger = "test-only",
|
|
|
|
value = "suite[.test]",
|
|
|
|
description = "For self-test action; run specific suite or test"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function m.executeSelfTest()
|
2018-04-30 13:40:49 +00:00
|
|
|
m.detectDuplicateTests = true
|
2016-05-18 19:56:04 +00:00
|
|
|
m.loadTestsFromManifests()
|
2018-04-30 13:40:49 +00:00
|
|
|
m.detectDuplicateTests = false
|
2016-05-18 19:56:04 +00:00
|
|
|
|
2018-06-14 14:51:36 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
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)
|
2016-05-16 20:27:14 +00:00
|
|
|
end
|
|
|
|
|
2018-06-14 14:51:36 +00:00
|
|
|
local passed, failed = m.runTest(tests)
|
2016-05-25 20:55:49 +00:00
|
|
|
|
|
|
|
if failed > 0 then
|
2018-04-30 13:41:45 +00:00
|
|
|
printf("\n %d FAILED TEST%s", failed, iif(failed > 1, "S", ""))
|
2016-05-18 19:56:04 +00:00
|
|
|
os.exit(5)
|
|
|
|
end
|
|
|
|
end
|
2016-05-16 20:27:14 +00:00
|
|
|
|
|
|
|
|
2016-05-18 19:56:04 +00:00
|
|
|
|
|
|
|
function m.loadTestsFromManifests()
|
|
|
|
local mask = path.join(_MAIN_SCRIPT_DIR, "**/tests/_tests.lua")
|
2016-05-16 20:27:14 +00:00
|
|
|
local manifests = os.matchfiles(mask)
|
|
|
|
|
2016-05-18 19:56:04 +00:00
|
|
|
-- TODO: "**" should also match "." but doesn't currently
|
2016-05-16 20:27:14 +00:00
|
|
|
local top = path.join(_MAIN_SCRIPT_DIR, "tests/_tests.lua")
|
|
|
|
if os.isfile(top) then
|
|
|
|
table.insert(manifests, 1, top)
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 1, #manifests do
|
|
|
|
local manifest = manifests[i]
|
2016-05-18 19:56:04 +00:00
|
|
|
|
2016-05-16 20:27:14 +00:00
|
|
|
_TESTS_DIR = path.getdirectory(manifest)
|
2016-05-18 19:56:04 +00:00
|
|
|
|
2016-05-16 20:27:14 +00:00
|
|
|
local files = dofile(manifest)
|
2016-05-18 19:56:04 +00:00
|
|
|
for i = 1, #files do
|
|
|
|
local filename = path.join(_TESTS_DIR, files[i])
|
|
|
|
dofile(filename)
|
2016-05-16 20:27:14 +00:00
|
|
|
end
|
|
|
|
end
|
2016-05-18 19:56:04 +00:00
|
|
|
end
|
2016-05-16 20:27:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-26 23:57:27 +00:00
|
|
|
dofile("test_assertions.lua")
|
2016-05-18 19:56:04 +00:00
|
|
|
dofile("test_declare.lua")
|
2016-05-26 23:57:27 +00:00
|
|
|
dofile("test_helpers.lua")
|
2016-05-25 20:55:49 +00:00
|
|
|
dofile("test_runner.lua")
|
2016-05-16 20:27:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return m
|