Move testing framework into a core module

This commit is contained in:
Jason Perkins 2016-05-16 16:27:14 -04:00
parent 780cd5f717
commit e0e988eccb
7 changed files with 96 additions and 57 deletions

1
.gitignore vendored
View File

@ -8,7 +8,6 @@ syntax: glob
build
bin
modules
obj
release
ipch

View File

@ -0,0 +1,4 @@
return {
"self-test.lua",
"testfx.lua",
}

View 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

View File

@ -6,12 +6,13 @@
local p = premake
local test = p.modules.self_test
--
-- Define a namespace for the testing functions
--
test = {}
test.suppressed = {}

View File

@ -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
}

View File

@ -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

View File

@ -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