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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dofile("testfx.lua")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
2016-05-18 19:56:04 +00:00
|
|
|
m.loadTestsFromManifests()
|
|
|
|
|
2016-05-25 20:55:49 +00:00
|
|
|
local test, err = m.getTestWithIdentifier(_OPTIONS["test-only"])
|
2016-05-18 19:56:04 +00:00
|
|
|
if err then
|
|
|
|
error(err, 0)
|
2016-05-16 20:27:14 +00:00
|
|
|
end
|
|
|
|
|
2016-05-25 20:55:49 +00:00
|
|
|
local startTime = os.clock()
|
2016-05-18 19:56:04 +00:00
|
|
|
|
2016-05-25 20:55:49 +00:00
|
|
|
local passed, failed = m.runTest(test)
|
|
|
|
|
|
|
|
local elapsed = os.clock() - startTime
|
|
|
|
|
|
|
|
printf("%d tests passed, %d failed in %0.02f seconds", passed, failed, elapsed)
|
|
|
|
|
|
|
|
if failed > 0 then
|
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-18 19:56:04 +00:00
|
|
|
dofile("test_declare.lua")
|
2016-05-25 20:55:49 +00:00
|
|
|
dofile("test_runner.lua")
|
2016-05-16 20:27:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return m
|