Initial community commit

This commit is contained in:
Jef 2024-09-24 14:54:57 +02:00
parent 537bcbc862
commit fc06254474
16440 changed files with 4239995 additions and 2 deletions

View file

@ -0,0 +1,165 @@
--
-- tests/project/test_config_maps.lua
-- Test mapping from workspace to project configurations.
-- Copyright (c) 2012-2014 Jason Perkins and the Premake project
--
local suite = test.declare("project_config_maps")
--
-- Setup and teardown
--
local wks, prj, cfg
function suite.setup()
wks = workspace("MyWorkspace")
configurations { "Debug", "Release" }
end
local function prepare(buildcfg, platform)
prj = wks.projects[1]
cfg = test.getconfig(prj, buildcfg or "Debug", platform)
end
--
-- When no configuration is specified in the project, the workspace
-- settings should map directly to a configuration object.
--
function suite.workspaceConfig_onNoProjectConfigs()
project ("MyProject")
prepare()
test.isequal("Debug", cfg.buildcfg)
end
--
-- If a project configuration mapping exists, it should be taken into
-- account when fetching the configuration object.
--
function suite.appliesCfgMapping_onBuildCfgMap()
project ("MyProject")
configmap { ["Debug"] = "Development" }
prepare()
test.isequal("Development", cfg.buildcfg)
end
function suite.appliesCfgMapping_onPlatformMap()
platforms { "Shared", "Static" }
project ("MyProject")
configmap { ["Shared"] = "DLL" }
prepare("Debug", "Shared")
test.isequal("DLL", cfg.platform)
end
--
-- If a configuration mapping exists, can also use the mapped value
-- to fetch the configuration.
--
function suite.fetchesMappedCfg_onBuildCfgMap()
project ("MyProject")
configmap { ["Debug"] = "Development" }
prepare("Development")
test.isequal("Development", cfg.buildcfg)
end
function suite.fetchesMappedCfg_onPlatformMap()
platforms { "Shared", "Static" }
project ("MyProject")
configmap { ["Shared"] = "DLL" }
prepare("Debug", "DLL")
test.isequal("DLL", cfg.platform)
end
--
-- If the specified configuration has been removed from the project,
-- then nil should be returned.
--
function suite.returnsNil_onRemovedBuildCfg()
project ("MyProject")
removeconfigurations { "Debug" }
prepare()
test.isnil(cfg)
end
function suite.returnsNil_onRemovedPlatform()
platforms { "Shared", "Static" }
project ("MyProject")
removeplatforms { "Shared" }
prepare("Debug", "Shared")
test.isnil(cfg)
end
--
-- Check mapping from a buildcfg-platform tuple to a simple single
-- value platform configuration.
--
function suite.canMap_tupleToSingle()
platforms { "Win32", "Linux" }
project ("MyProject")
removeconfigurations "*"
removeplatforms "*"
configurations { "Debug Win32", "Release Win32", "Debug Linux", "Release Linux" }
configmap {
[{"Debug", "Win32"}] = "Debug Win32",
[{"Debug", "Linux"}] = "Debug Linux",
[{"Release", "Win32"}] = "Release Win32",
[{"Release", "Linux"}] = "Release Linux"
}
prepare("Debug", "Linux")
test.isequal("Debug Linux", cfg.buildcfg)
end
--
-- Check mapping from a buildcfg-platform tuple to new project
-- configuration tuple.
--
function suite.canMap_tupleToTuple()
platforms { "Win32", "Linux" }
project ("MyProject")
removeconfigurations "*"
removeplatforms "*"
configurations { "Development", "Production" }
platforms { "x86", "x86_64" }
configmap {
[{"Debug", "Win32"}] = { "Development", "x86" },
[{"Debug", "Linux"}] = { "Development", "x86_64" },
[{"Release", "Win32"}] = { "Production", "x86" },
[{"Release", "Linux"}] = { "Production", "x86_64" },
}
prepare("Debug", "Linux")
test.isequal({ "Development", "x86_64" }, { cfg.buildcfg, cfg.platform })
end
--
-- To allow some measure of global configuration, config maps that are contained
-- in configuration blocks are allowed to bubble up to the project level.
--
function suite.canBubbleUp_onConfiguration()
platforms { "XCUA", "XCUB" }
filter { "platforms:CCU" }
configmap { XCUA = "CCU", XCUB = "CCU" }
project "MyProject"
platforms { "CCU" }
prepare("Debug", "XCUA")
test.isequal({"Debug", "CCU"}, {cfg.buildcfg, cfg.platform})
end

View file

@ -0,0 +1,173 @@
--
-- tests/project/test_eachconfig.lua
-- Test the project object configuration iterator function.
-- Copyright (c) 2011-2015 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("project_eachconfig")
--
-- Setup and teardown
--
local wks, prj
function suite.setup()
wks = workspace("MyWorkspace")
end
local function prepare(buildcfgs)
project("MyProject")
if buildcfgs then
configurations ( buildcfgs )
end
prj = test.getproject(wks, 1)
for cfg in p.project.eachconfig(prj) do
_p(2,'%s:%s', cfg.buildcfg or "", cfg.platform or "")
end
end
--
-- If no configurations have been defined, the iterator
-- should not return any values.
--
function suite.returnsNoValues_onNoConfigurationsAndNoPlatforms()
prepare()
test.isemptycapture()
end
--
-- If platforms have been defined, but no configurations, the
-- iterator should still not return any values.
--
function suite.returnsNoValues_onNoConfigurationsButPlatforms()
platforms { "x86", "x86_64" }
prepare()
test.isemptycapture()
end
--
-- Configurations should be iterated in the order in which they
-- appear in the script.
--
function suite.iteratesConfigsInOrder()
configurations { "Debug", "Profile", "Release", "Deploy" }
prepare()
test.capture [[
Debug:
Profile:
Release:
Deploy:
]]
end
--
-- If platforms are supplied, they should be paired with build
-- configurations, with the order of both maintained.
--
function suite.pairsConfigsAndPlatformsInOrder()
configurations { "Debug", "Release" }
platforms { "x86", "x86_64" }
prepare()
test.capture [[
Debug:x86
Debug:x86_64
Release:x86
Release:x86_64
]]
end
--
-- Test the mapping of a build configuration from workspace to project.
--
function suite.mapsBuildCfg_toBuildCfg()
configurations { "Debug", "Release" }
configmap { ["Debug"] = "ProjectDebug" }
prepare()
test.capture [[
ProjectDebug:
Release:
]]
end
--
-- Test mapping a platform from workspace to project.
--
function suite.mapsPlatform_toPlatform()
configurations { "Debug", "Release" }
platforms { "Win32" }
configmap { ["Win32"] = "x86_64" }
prepare()
test.capture [[
Debug:x86_64
Release:x86_64
]]
end
--
-- Test mapping a build configuration to a build config/platform pair.
-- This will cause a second platform to appear in the project, alongside
-- the one defined by the workspace.
--
function suite.mapsBuildCfg_toBuildCfgAndPlatform()
configurations { "Debug", "Release" }
platforms { "Win32" }
configmap { ["Debug"] = { "ProjectDebug", "x86_64" } }
prepare()
test.capture [[
ProjectDebug:x86_64
ProjectDebug:Win32
Release:x86_64
Release:Win32
]]
end
--
-- Any duplicate configurations created by the mapping should be removed.
--
function suite.removesDups_onConfigMapping()
configurations { "Debug", "Development", "Release" }
configmap { ["Development"] = "Debug" }
prepare()
test.capture [[
Debug:
Release:
]]
end
--
-- If there is overlap in the workspace and project configuration lists,
-- the ordering at the project level should be maintained to avoid
-- unnecessarily dirtying the project file.
--
function suite.maintainsProjectOrdering_onWorkspaceOverlap()
configurations { "Debug", "Release" }
prepare { "Debug", "Development", "Profile", "Release" }
test.capture [[
Debug:
Development:
Profile:
Release:
]]
end

View file

@ -0,0 +1,114 @@
--
-- tests/project/test_getconfig.lua
-- Test the project object configuration accessor.
-- Copyright (c) 2011-2014 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("project_getconfig")
--
-- Setup and teardown
--
local wks, prj, cfg
function suite.setup()
wks = workspace("MyWorkspace")
configurations { "Debug", "Release" }
end
local function prepare(buildcfg, platform)
prj = wks.projects[1]
cfg = test.getconfig(prj, buildcfg or "Debug", platform)
end
--
-- If the target system is not specified, the current operating environment
-- should be used as the default.
--
function suite.usesCurrentOS_onNoSystemSpecified()
_TARGET_OS = "linux"
project ("MyProject")
filter { "system:linux" }
defines { "correct" }
prepare()
test.isequal("correct", cfg.defines[1])
end
--
-- If the current action specifies a target operating environment (i.e.
-- Visual Studio targets Windows), that should override the current
-- operating environment.
--
function suite.actionOverridesOS()
_TARGET_OS = "linux"
p.action.set("vs2005")
project ("MyProject")
filter { "system:windows" }
defines { "correct" }
prepare()
test.isequal("correct", cfg.defines[1])
end
--
-- If a target system is specified in a configuration, it should override
-- the current operating environment, as well as the tool's target OS.
--
function suite.usesCfgSystem()
_TARGET_OS = "linux"
p.action.set("vs2005")
project ("MyProject")
system "macosx"
filter { "system:macosx" }
defines { "correct" }
prepare()
test.isequal("correct", cfg.defines[1])
end
--
-- The current action should be taken into account.
--
function suite.appliesActionToFilters()
p.action.set("vs2005")
project ("MyProject")
filter { "action:vs2005" }
defines { "correct" }
prepare()
test.isequal("correct", cfg.defines[1])
end
--
-- If the platform matches an architecture identifier, and none was set,
-- the configuration's architecture should be set to match.
--
function suite.setsArchitecture_onMatchingPlatform()
platforms { "x86", "x86_64" }
project ("MyProject")
prepare("Debug", "x86")
test.isequal("x86", cfg.architecture)
end
--
-- If the platform matches an architecture, it should not modify any
-- currently set value.
--
function suite.doesNotOverride_onMatchingPlatform()
platforms { "x86", "x64" }
project ("MyProject")
architecture "x86_64"
prepare("Debug", "x86")
test.isequal("x86_64", cfg.architecture)
end

View file

@ -0,0 +1,57 @@
--
-- tests/project/test_location.lua
-- Test handling of the projects's location field.
-- Copyright (c) 2013 Jason Perkins and the Premake project
--
local suite = test.declare("project_location")
--
-- Setup and teardown
--
local wks, prj
function suite.setup()
wks = test.createWorkspace()
end
local function prepare()
prj = test.getproject(wks, 1)
end
--
-- If no explicit location is set, the location should be set to the
-- directory containing the script which defined the project.
--
function suite.usesScriptLocation_onNoLocation()
prepare()
test.isequal(os.getcwd(), prj.location)
end
--
-- If an explicit location has been set, use it.
--
function suite.usesLocation_onLocationSet()
location "build"
prepare()
test.isequal(path.join(os.getcwd(), "build"), prj.location)
end
--
-- If the workspace sets a location, and the project does not, it should
-- inherit the value from the workspace.
--
function suite.inheritsWorkspaceLocation_onNoProjectLocation()
workspace ()
location "build"
prepare()
test.isequal(path.join(os.getcwd(), "build"), prj.location)
end

View file

@ -0,0 +1,94 @@
--
-- 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
--
local p = premake
local suite = test.declare("project_sources")
local project = p.project
--
-- Setup and teardown
--
local wks, prj
local cwd = os.getcwd()
local oldcwd
function suite.setup()
wks, prj = test.createWorkspace()
-- We change the directory to get nice relative paths
oldcwd = os.getcwd()
os.chdir(cwd)
-- Create a token to be used in search paths
p.api.register { name = "mytoken", kind = "string", scope = "config" }
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

View file

@ -0,0 +1,151 @@
--
-- tests/project/test_vpaths.lua
-- Automated test suite for the project support functions.
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("project_vpaths")
local project = p.project
--
-- Setup and teardown
--
local wks, prj
function suite.setup()
wks, prj = test.createWorkspace()
end
local function run()
local cfg = test.getconfig(prj, "Debug")
return project.getvpath(prj, cfg.files[1])
end
--
-- Test simple replacements
--
function suite.ReturnsOriginalPath_OnNoVpaths()
files { "hello.c" }
test.isequal(path.join(os.getcwd(), "hello.c"), run())
end
function suite.ReturnsOriginalPath_OnNoMatches()
files { "hello.c" }
vpaths { ["Headers"] = "**.h" }
test.isequal(path.join(os.getcwd(), "hello.c"), run())
end
function suite.CanStripPaths()
files { "src/myproject/hello.c" }
vpaths { [""] = "src" }
run()
test.isequal("hello.c", run())
end
function suite.CanTrimLeadingPaths()
files { "src/myproject/hello.c" }
vpaths { ["*"] = "src" }
test.isequal("myproject/hello.c", run())
end
function suite.PatternMayIncludeTrailingSlash()
files { "src/myproject/hello.c" }
vpaths { [""] = "src/myproject/" }
test.isequal("hello.c", run())
end
function suite.SimpleReplacementPatterns()
files { "src/myproject/hello.c" }
vpaths { ["sources"] = "src/myproject" }
test.isequal("sources/hello.c", run())
end
function suite.ExactFilenameMatch()
files { "src/hello.c" }
vpaths { ["sources"] = "src/hello.c" }
test.isequal("sources/hello.c", run())
end
--
-- Test wildcard patterns
--
function suite.MatchFilePattern_ToGroup_Flat()
files { "src/myproject/hello.h" }
vpaths { ["Headers"] = "**.h" }
test.isequal("Headers/hello.h", run())
end
function suite.MatchFilePattern_ToNone_Flat()
files { "src/myproject/hello.h" }
vpaths { [""] = "**.h" }
test.isequal("hello.h", run())
end
function suite.MatchFilePattern_ToNestedGroup_Flat()
files { "src/myproject/hello.h" }
vpaths { ["Source/Headers"] = "**.h" }
test.isequal("Source/Headers/hello.h", run())
end
function suite.MatchFilePattern_ToGroup_WithTrailingSlash()
files { "src/myproject/hello.h" }
vpaths { ["Headers/"] = "**.h" }
test.isequal("Headers/hello.h", run())
end
function suite.MatchFilePattern_ToGroup_Nested()
files { "src/myproject/hello.h" }
vpaths { ["Headers/*"] = "**.h" }
test.isequal("Headers/src/myproject/hello.h", run())
end
function suite.MatchFilePattern_ToGroup_Nested_OneStar()
files { "src/myproject/hello.h" }
vpaths { ["Headers/*"] = "**.h" }
test.isequal("Headers/src/myproject/hello.h", run())
end
function suite.MatchFilePatternWithPath_ToGroup_Nested()
files { "src/myproject/hello.h" }
vpaths { ["Headers/*"] = "src/**.h" }
test.isequal("Headers/myproject/hello.h", run())
end
function suite.matchBaseFileName_onWildcardExtension()
files { "hello.cpp" }
vpaths { ["Sources"] = "hello.*" }
test.isequal("Sources/hello.cpp", run())
end
--
-- Test with project locations
--
function suite.MatchPath_OnProjectLocationSet()
location "build"
files "src/hello.h"
vpaths { [""] = "src" }
test.isequal("hello.h", run())
end
function suite.MatchFilePattern_OnProjectLocationSet()
location "build"
files "src/hello.h"
vpaths { ["Headers"] = "**.h" }
test.isequal("Headers/hello.h", run())
end
function suite.MatchFilePatternWithPath_OnProjectLocationSet()
location "build"
files "src/hello.h"
vpaths { ["Headers"] = "src/**.h" }
test.isequal("Headers/hello.h", run())
end