2015-07-10 09:33:23 +00:00
|
|
|
--
|
|
|
|
-- tests/project/test_sources.lua
|
|
|
|
-- Automated test suite for the source tree, including tokens and wildcards.
|
|
|
|
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
|
|
|
|
--
|
|
|
|
|
2017-04-25 05:44:13 +00:00
|
|
|
local p = premake
|
2015-07-10 09:33:23 +00:00
|
|
|
local suite = test.declare("project_sources")
|
2017-04-25 05:44:13 +00:00
|
|
|
local project = p.project
|
2015-07-10 09:33:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Setup and teardown
|
|
|
|
--
|
|
|
|
|
2015-08-28 20:16:14 +00:00
|
|
|
local wks, prj
|
2015-07-10 09:33:23 +00:00
|
|
|
|
|
|
|
local cwd = os.getcwd()
|
|
|
|
local oldcwd
|
|
|
|
|
|
|
|
function suite.setup()
|
2015-08-28 20:16:14 +00:00
|
|
|
wks, prj = test.createWorkspace()
|
2015-07-10 09:33:23 +00:00
|
|
|
|
|
|
|
-- We change the directory to get nice relative paths
|
|
|
|
oldcwd = os.getcwd()
|
|
|
|
os.chdir(cwd)
|
|
|
|
|
|
|
|
-- Create a token to be used in search paths
|
2017-04-25 05:44:13 +00:00
|
|
|
p.api.register { name = "mytoken", kind = "string", scope = "config" }
|
2015-07-10 09:33:23 +00:00
|
|
|
mytoken "test"
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.teardown()
|
|
|
|
mytoken = nil
|
|
|
|
os.chdir(oldcwd)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function run()
|
|
|
|
local cfg = test.getconfig(prj, "Debug")
|
|
|
|
|
|
|
|
local files = {}
|
|
|
|
for _, file in ipairs(cfg.files) do
|
|
|
|
table.insert(files, path.getrelative(cwd, file))
|
|
|
|
end
|
|
|
|
|
|
|
|
return files
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Test single file
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.SingleFile()
|
|
|
|
files { "test_sources.lua" }
|
|
|
|
test.isequal({"test_sources.lua"}, run())
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Test tokens
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.SingleFileWithToken()
|
|
|
|
files { "%{cfg.mytoken}_sources.lua" }
|
|
|
|
test.isequal({"test_sources.lua"}, run())
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Test wildcards
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.FilesWithWildcard()
|
|
|
|
files { "test_*.lua" }
|
|
|
|
test.contains("test_sources.lua", run())
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.FilesWithRecursiveWildcard()
|
|
|
|
files { "../**_sources.lua" }
|
|
|
|
test.contains("test_sources.lua", run())
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Test wildcards and tokens combined
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.FilesWithWildcardAndToken()
|
|
|
|
files { "%{cfg.mytoken}_*.lua" }
|
|
|
|
test.contains("test_sources.lua", run())
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.FilesWithRecursiveWildcardAndToken()
|
|
|
|
files { "../**/%{cfg.mytoken}_sources.lua" }
|
|
|
|
test.contains("test_sources.lua", run())
|
|
|
|
end
|