mirror of
https://github.com/xenia-project/premake-core.git
synced 2024-10-07 00:53:28 +00:00
Move testing framework into a core module
This commit is contained in:
parent
780cd5f717
commit
e0e988eccb
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,7 +8,6 @@ syntax: glob
|
||||
|
||||
build
|
||||
bin
|
||||
modules
|
||||
obj
|
||||
release
|
||||
ipch
|
||||
|
4
modules/self-test/_manifest.lua
Normal file
4
modules/self-test/_manifest.lua
Normal file
@ -0,0 +1,4 @@
|
||||
return {
|
||||
"self-test.lua",
|
||||
"testfx.lua",
|
||||
}
|
87
modules/self-test/self-test.lua
Normal file
87
modules/self-test/self-test.lua
Normal file
@ -0,0 +1,87 @@
|
||||
---
|
||||
-- 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()
|
||||
local focus = {}
|
||||
if _OPTIONS["test"] then
|
||||
focus = string.explode(_OPTIONS["test"] or "", ".", true)
|
||||
end
|
||||
|
||||
local mask = path.join(_MAIN_SCRIPT_DIR, "**/tests/_tests.lua")
|
||||
|
||||
--
|
||||
|
||||
local manifests = os.matchfiles(mask)
|
||||
|
||||
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]
|
||||
_TESTS_DIR = path.getdirectory(manifest)
|
||||
local files = dofile(manifest)
|
||||
for f = 1, #files do
|
||||
dofile(path.join(_TESTS_DIR, files[f]))
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
|
||||
local startTime = os.clock()
|
||||
|
||||
passed, failed = test.runall(focus[1], focus[2])
|
||||
|
||||
io.write('running time : ', os.clock() - startTime,'\n')
|
||||
|
||||
msg = string.format("%d tests passed, %d failed", passed, failed)
|
||||
if (failed > 0) then
|
||||
print(msg)
|
||||
os.exit(5)
|
||||
else
|
||||
print(msg)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return m
|
@ -6,12 +6,13 @@
|
||||
|
||||
local p = premake
|
||||
|
||||
local test = p.modules.self_test
|
||||
|
||||
|
||||
--
|
||||
-- Define a namespace for the testing functions
|
||||
--
|
||||
|
||||
test = {}
|
||||
test.suppressed = {}
|
||||
|
||||
|
@ -44,7 +44,8 @@
|
||||
trigger = "test",
|
||||
description = "Run the automated test suite",
|
||||
execute = function ()
|
||||
include (path.join(corePath, "scripts/test.lua"))
|
||||
test = require "self-test"
|
||||
premake.action.call("self-test")
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -1,53 +0,0 @@
|
||||
---
|
||||
-- Premake automated test runner.
|
||||
---
|
||||
|
||||
include "../tests/testfx.lua"
|
||||
|
||||
|
||||
local focus = {}
|
||||
if _OPTIONS["test"] then
|
||||
focus = string.explode(_OPTIONS["test"] or "", ".", true)
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Find and load all of the test file manifests
|
||||
--
|
||||
|
||||
local mask = path.join(_MAIN_SCRIPT_DIR, "**/tests/_tests.lua")
|
||||
local manifests = os.matchfiles(mask)
|
||||
|
||||
-- Hmm, "**" should probably also match against "."?
|
||||
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]
|
||||
_TESTS_DIR = path.getdirectory(manifest)
|
||||
local files = dofile(manifest)
|
||||
for f = 1, #files do
|
||||
dofile(path.join(_TESTS_DIR, files[f]))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Run them and show the results
|
||||
--
|
||||
|
||||
local startTime = os.clock()
|
||||
|
||||
passed, failed = test.runall(focus[1], focus[2])
|
||||
|
||||
io.write('running time : ', os.clock() - startTime,'\n')
|
||||
|
||||
msg = string.format("%d tests passed, %d failed", passed, failed)
|
||||
if (failed > 0) then
|
||||
print(msg)
|
||||
os.exit(5)
|
||||
else
|
||||
print(msg)
|
||||
end
|
@ -68,7 +68,7 @@
|
||||
|
||||
function suite.matchfiles_OnNonRecursive()
|
||||
local result = os.matchfiles("*.lua")
|
||||
test.istrue(table.contains(result, "testfx.lua"))
|
||||
test.istrue(table.contains(result, "_tests.lua"))
|
||||
test.isfalse(table.contains(result, "folder/ok.lua"))
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user