Initial community commit

This commit is contained in:
Jef
2024-09-24 14:54:57 +02:00
parent 537bcbc862
commit 20d28e80a5
16810 changed files with 4640254 additions and 2 deletions
@@ -0,0 +1,30 @@
--
-- tests/actions/make/test_make_escaping.lua
-- Validate the escaping of literal values in Makefiles.
-- Copyright (c) 2010 Jason Perkins and the Premake project
--
T.make_escaping = { }
local suite = T.make_escaping
function suite.Escapes_Spaces()
test.isequal("Program\\ Files", _MAKE.esc("Program Files"))
end
function suite.Escapes_Backslashes()
test.isequal("Program\\\\Files", _MAKE.esc("Program\\Files"))
end
function suite.Escapes_Parens()
test.isequal("Debug\\(x86\\)", _MAKE.esc("Debug(x86)"))
end
function suite.DoesNotEscape_ShellReplacements()
test.isequal("-L$(NVSDKCUDA_ROOT)/C/lib", _MAKE.esc("-L$(NVSDKCUDA_ROOT)/C/lib"))
end
function suite.CanEscape_ShellReplacementCapturesShortest()
test.isequal("a\\(x\\)b$(ROOT)c\\(y\\)d", _MAKE.esc("a(x)b$(ROOT)c(y)d"))
end
@@ -0,0 +1,126 @@
--
-- tests/actions/make/test_make_linking.lua
-- Validate library references in makefiles.
-- Copyright (c) 2010-2013 Jason Perkins and the Premake project
--
T.gcc_linking = {}
local suite = T.gcc_linking
local cpp = premake.make.cpp
--
-- Setup
--
local sln, prj
function suite.setup()
_OS = "linux"
sln, prj = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
cfg = premake.getconfig(prj, "Debug")
cpp.linker(cfg, premake.gcc)
end
--
-- Check linking to a shared library sibling project. In order to support
-- custom target prefixes and extensions, use the full, relative path
-- to the library.
--
function suite.onSharedLibrarySibling()
links { "MyProject2" }
test.createproject(sln)
kind "SharedLib"
targetdir "libs"
prepare()
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -Llibs -s
LDDEPS += libs/libMyProject2.so
LIBS += $(LDDEPS)
]]
end
--
-- Check linking to a static library sibling project. As with shared
-- libraries, it should list out the full relative path.
--
function suite.onStaticLibrarySibling()
links { "MyProject2" }
test.createproject(sln)
kind "StaticLib"
targetdir "libs"
prepare()
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -Llibs -s
LDDEPS += libs/libMyProject2.a
LIBS += $(LDDEPS)
]]
end
--
-- If an executable is listed in the links, no linking should happen (a
-- build dependency would have been created at the solution level)
--
function suite.onConsoleAppSibling()
links { "MyProject2" }
test.createproject(sln)
kind "ConsoleApp"
targetdir "libs"
prepare()
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s
LDDEPS +=
LIBS += $(LDDEPS)
]]
end
--
-- Make sure that project locations are taken into account when building
-- the path to the library.
--
function suite.onProjectLocations()
location "MyProject"
links { "MyProject2" }
test.createproject(sln)
kind "SharedLib"
location "MyProject2"
targetdir "MyProject2"
prepare()
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -L../MyProject2 -s
LDDEPS += ../MyProject2/libMyProject2.so
LIBS += $(LDDEPS)
]]
end
--
-- When referencing an external library via a path, the directory
-- should be added to the library search paths, and the library
-- itself included via an -l flag.
--
function suite.onExternalLibraryWithPath()
location "MyProject"
links { "libs/SomeLib" }
prepare()
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -L../libs -s
LDDEPS +=
LIBS += $(LDDEPS) -lSomeLib
]]
end
@@ -0,0 +1,120 @@
--
-- tests/actions/make/test_make_pch.lua
-- Validate the setup for precompiled headers in makefiles.
-- Copyright (c) 2010 Jason Perkins and the Premake project
--
T.make_pch = { }
local suite = T.make_pch
local _ = premake.make.cpp
--
-- Setup and teardown
--
local sln, prj, cfg
function suite.setup()
sln, prj = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.getconfig(prj)
cfg = premake.getconfig(prj, "Debug")
end
--
-- Configuration block tests
--
function suite.NoConfig_OnNoHeaderSet()
prepare()
_.pchconfig(cfg)
test.capture [[]]
end
function suite.NoConfig_OnHeaderAndNoPCHFlag()
pchheader "include/myproject.h"
flags { NoPCH }
prepare()
_.pchconfig(cfg)
test.capture [[]]
end
function suite.ConfigBlock_OnPchEnabled()
pchheader "include/myproject.h"
prepare()
_.pchconfig(cfg)
test.capture [[
PCH = include/myproject.h
GCH = $(OBJDIR)/$(notdir $(PCH)).gch
]]
end
--
-- Build rule tests
--
function suite.BuildRules_OnCpp()
pchheader "include/myproject.h"
prepare()
_.pchrules(prj)
test.capture [[
ifneq (,$(PCH))
$(GCH): $(PCH)
@echo $(notdir $<)
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
]]
end
function suite.BuildRules_OnC()
language "C"
pchheader "include/myproject.h"
prepare()
_.pchrules(prj)
test.capture [[
ifneq (,$(PCH))
$(GCH): $(PCH)
@echo $(notdir $<)
$(SILENT) $(CC) -x c-header $(ALL_CFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
]]
end
--
-- Ensure that PCH is included on all files that use it.
--
function suite.includesPCH_onUse()
pchheader "include/myproject.h"
files { "main.cpp" }
prepare()
_.fileRules(prj)
test.capture [[
$(OBJDIR)/main.o: main.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF $(@:%.o=%.d) -c "$<"
]]
end
--
-- If the header is located on one of the include file
-- search directories, it should get found automatically.
--
function suite.findsPCH_onIncludeDirs()
location "MyProject"
pchheader "premake.h"
includedirs { "../src/host" }
prepare()
_.pchconfig(cfg)
test.capture [[
PCH = ../../src/host/premake.h
]]
end
@@ -0,0 +1,51 @@
--
-- tests/actions/make/test_makesettings.lua
-- Tests makesettings lists in generated makefiles.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.make_settings = { }
local suite = T.make_settings
local make = premake.make
local sln, prj, cfg
function suite.setup()
_ACTION = "gmake"
sln = solution("MySolution")
configurations { "Debug", "Release" }
makesettings { "SOLUTION_LEVEL_SETTINGS" }
project("MyProject")
makesettings { "PROJECT_LEVEL_SETTINGS" }
configuration { "Debug" }
makesettings { "DEBUG_LEVEL_SETTINGS" }
configuration { "Release" }
makesettings { "RELEASE_LEVEL_SETTINGS" }
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
cfg = premake.getconfig(prj, "Debug")
end
function suite.writesProjectSettings()
make.settings(prj, premake.gcc)
test.capture [[
SOLUTION_LEVEL_SETTINGS
PROJECT_LEVEL_SETTINGS
]]
end
function suite.writesConfigSettings()
make.settings(cfg, premake.gcc)
test.capture [[
DEBUG_LEVEL_SETTINGS
]]
end
@@ -0,0 +1,62 @@
--
-- tests/actions/make/test_wiidev.lua
-- Tests for Wii homebrew support in makefiles.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.make_wiidev = { }
local suite = T.make_wiidev
local make = premake.make
local cpp = premake.make.cpp
local sln, prj, cfg
function suite.setup()
_ACTION = "gmake"
sln = solution("MySolution")
configurations { "Debug", "Release" }
platforms { "WiiDev" }
prj = project("MyProject")
premake.bake.buildconfigs()
cfg = premake.getconfig(prj, "Debug", "WiiDev")
end
--
-- Make sure that the Wii-specific flags are passed to the tools.
--
function suite.writesCorrectFlags()
cpp.flags(cfg, premake.gcc)
test.capture [[
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -I$(LIBOGC_INC) $(MACHDEP) -MP $(DEFINES) $(INCLUDES)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
]]
end
function suite.writesCorrectLinkFlags()
cpp.linker(cfg, premake.gcc)
test.capture [[
ALL_LDFLAGS += $(LDFLAGS) -s -L$(LIBOGC_LIB) $(MACHDEP)
]]
end
--
-- Make sure the dev kit include is written to each Wii build configuration.
--
function suite.writesIncludeBlock()
make.settings(cfg, premake.gcc)
test.capture [[
ifeq ($(strip $(DEVKITPPC)),)
$(error "DEVKITPPC environment variable is not set")'
endif
include $(DEVKITPPC)/wii_rules'
]]
end
@@ -0,0 +1,197 @@
--
-- tests/actions/test_clean.lua
-- Automated test suite for the "clean" action.
-- Copyright (c) 2009 Jason Perkins and the Premake project
--
T.clean = { }
--
-- Replacement functions for remove() and rmdir() for testing
--
local os_remove, os_rmdir, cwd
local removed
local function test_remove(fn)
if not cwd then cwd = os.getcwd() end
table.insert(removed, path.getrelative(cwd, fn))
end
--
-- Setup/teardown
--
local sln
function T.clean.setup()
_ACTION = "clean"
os_remove = os.remove
os_rmdir = os.rmdir
os.remove = test_remove
os.rmdir = test_remove
removed = {}
sln = solution "MySolution"
configurations { "Debug", "Release" }
end
function T.clean.teardown()
os.remove = os_remove
os.rmdir = os_rmdir
end
local function prepare()
premake.bake.buildconfigs()
premake.action.call("clean")
end
--
-- Tests
--
function T.clean.SolutionFiles()
prepare()
test.contains(removed, "MySolution.sln")
test.contains(removed, "MySolution.suo")
test.contains(removed, "MySolution.ncb")
test.contains(removed, "MySolution.userprefs")
test.contains(removed, "MySolution.usertasks")
test.contains(removed, "MySolution.workspace")
test.contains(removed, "MySolution_wsp.mk")
test.contains(removed, "MySolution.tags")
test.contains(removed, "Makefile")
end
function T.clean.CppProjectFiles()
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
prepare()
test.contains(removed, "MyProject.vcproj")
test.contains(removed, "MyProject.pdb")
test.contains(removed, "MyProject.idb")
test.contains(removed, "MyProject.ilk")
test.contains(removed, "MyProject.cbp")
test.contains(removed, "MyProject.depend")
test.contains(removed, "MyProject.layout")
test.contains(removed, "MyProject.mk")
test.contains(removed, "MyProject.list")
test.contains(removed, "MyProject.out")
test.contains(removed, "MyProject.make")
end
function T.clean.CsProjectFiles()
prj = project "MyProject"
language "C#"
kind "ConsoleApp"
prepare()
test.contains(removed, "MyProject.csproj")
test.contains(removed, "MyProject.csproj.user")
test.contains(removed, "MyProject.pdb")
test.contains(removed, "MyProject.idb")
test.contains(removed, "MyProject.ilk")
test.contains(removed, "MyProject.make")
end
function T.clean.ObjectDirsAndFiles()
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
prepare()
test.contains(removed, "obj/Debug")
test.contains(removed, "obj/Release")
end
function T.clean.CppConsoleAppFiles()
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
prepare()
test.contains(removed, "MyProject")
test.contains(removed, "MyProject.exe")
test.contains(removed, "MyProject.elf")
test.contains(removed, "MyProject.vshost.exe")
test.contains(removed, "MyProject.exe.manifest")
end
function T.clean.CppWindowedAppFiles()
prj = project "MyProject"
language "C++"
kind "WindowedApp"
prepare()
test.contains(removed, "MyProject")
test.contains(removed, "MyProject.exe")
test.contains(removed, "MyProject.app")
end
function T.clean.CppSharedLibFiles()
prj = project "MyProject"
language "C++"
kind "SharedLib"
prepare()
test.contains(removed, "MyProject.dll")
test.contains(removed, "libMyProject.so")
test.contains(removed, "MyProject.lib")
test.contains(removed, "libMyProject.dylib")
end
function T.clean.CppBundleFiles()
prj = project "MyProject"
language "C++"
kind "Bundle"
prepare()
test.contains(removed, "MyProject.dll")
test.contains(removed, "libMyProject.so")
test.contains(removed, "MyProject.lib")
test.contains(removed, "MyProject.bundle")
end
function T.clean.CppStaticLibFiles()
prj = project "MyProject"
language "C++"
kind "StaticLib"
prepare()
test.contains(removed, "MyProject.lib")
test.contains(removed, "libMyProject.a")
end
function T.clean.PlatformObjects()
platforms { "Native", "x32" }
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
prepare()
test.contains(removed, "obj/Debug")
test.contains(removed, "obj/Release")
test.contains(removed, "obj/x32/Debug")
test.contains(removed, "obj/x32/Release")
end
function T.clean.CppConsoleAppFiles_OnSuffix()
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
targetsuffix "_x"
prepare()
test.contains(removed, "MyProject_x")
test.contains(removed, "MyProject_x.exe")
test.contains(removed, "MyProject_x.elf")
test.contains(removed, "MyProject_x.vshost.exe")
test.contains(removed, "MyProject_x.exe.manifest")
end
@@ -0,0 +1,141 @@
--
-- tests/actions/vstudio/cs2002/test_files.lua
-- Validate generation of <Files/> block in Visual Studio 2002 .csproj
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
--
T.vstudio_cs2002_files = { }
local suite = T.vstudio_cs2002_files
local cs2002 = premake.vstudio.cs2002
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
cs2002.Files(prj)
end
--
-- Test grouping and nesting
--
function suite.SimpleSourceFile()
files { "Hello.cs" }
prepare()
test.capture [[
<File
RelPath = "Hello.cs"
BuildAction = "Compile"
SubType = "Code"
/>
]]
end
function suite.NestedSourceFile()
files { "Src/Hello.cs" }
prepare()
test.capture [[
<File
RelPath = "Src\Hello.cs"
BuildAction = "Compile"
SubType = "Code"
/>
]]
end
--
-- The relative path to the file is correct for files that live outside
-- the project's folder.
--
function suite.filesUseRelativePath_onOutOfTreePath()
files { "../Src/Hello.cs" }
prepare()
test.capture [[
<File
RelPath = "..\Src\Hello.cs"
BuildAction = "Compile"
SubType = "Code"
/>
]]
end
--
-- Test file dependencies
--
function suite.SimpleResourceDependency()
files { "Resources.resx", "Resources.cs" }
prepare()
test.capture [[
<File
RelPath = "Resources.cs"
BuildAction = "Compile"
SubType = "Code"
/>
<File
RelPath = "Resources.resx"
BuildAction = "EmbeddedResource"
DependentUpon = "Resources.cs"
/>
]]
end
--
-- Test build actions
--
function suite.BuildAction_Compile()
files { "Hello.png" }
configuration "*.png"
buildaction "Compile"
prepare()
test.capture [[
<File
RelPath = "Hello.png"
BuildAction = "Compile"
/>
]]
end
function suite.BuildAction_Copy()
files { "Hello.png" }
configuration "*.png"
buildaction "Copy"
prepare()
test.capture [[
<File
RelPath = "Hello.png"
BuildAction = "Content"
/>
]]
end
function suite.BuildAction_Embed()
files { "Hello.png" }
configuration "*.png"
buildaction "Embed"
prepare()
test.capture [[
<File
RelPath = "Hello.png"
BuildAction = "EmbeddedResource"
/>
]]
end
@@ -0,0 +1,74 @@
--
-- tests/actions/vstudio/cs2005/projectelement.lua
-- Validate generation of <Project/> element in Visual Studio 2005+ .csproj
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.vstudio_cs2005_projectelement = { }
local suite = T.vstudio_cs2005_projectelement
local cs2005 = premake.vstudio.cs2005
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
cs2005.projectelement(prj)
end
--
-- Tests
--
function suite.On2005()
_ACTION = "vs2005"
prepare()
test.capture [[
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
]]
end
function suite.On2008()
_ACTION = "vs2008"
prepare()
test.capture [[
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
]]
end
function suite.On2010()
_ACTION = "vs2010"
prepare()
test.capture [[
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
]]
end
function suite.On2012()
_ACTION = "vs2012"
prepare()
test.capture [[
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
]]
end
function suite.On2013()
_ACTION = "vs2013"
prepare()
test.capture [[
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
]]
end
@@ -0,0 +1,139 @@
--
-- tests/actions/vstudio/cs2005/projectsettings.lua
-- Validate generation of root <PropertyGroup/> in Visual Studio 2005+ .csproj
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.vstudio_cs2005_projectsettings = { }
local suite = T.vstudio_cs2005_projectsettings
local cs2005 = premake.vstudio.cs2005
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
language "C#"
uuid "AE61726D-187C-E440-BD07-2556188A6565"
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
cs2005.projectsettings(prj)
end
--
-- Version Tests
--
function suite.OnVs2005()
_ACTION = "vs2005"
prepare()
test.capture [[
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AE61726D-187C-E440-BD07-2556188A6565}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MyProject</RootNamespace>
<AssemblyName>MyProject</AssemblyName>
</PropertyGroup>
]]
end
function suite.OnVs2008()
_ACTION = "vs2008"
prepare()
test.capture [[
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AE61726D-187C-E440-BD07-2556188A6565}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MyProject</RootNamespace>
<AssemblyName>MyProject</AssemblyName>
</PropertyGroup>
]]
end
function suite.OnVs2010()
_ACTION = "vs2010"
prepare()
test.capture [[
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AE61726D-187C-E440-BD07-2556188A6565}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MyProject</RootNamespace>
<AssemblyName>MyProject</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile></TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
]]
end
function suite.OnVs2012()
_ACTION = "vs2012"
prepare()
test.capture [[
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AE61726D-187C-E440-BD07-2556188A6565}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MyProject</RootNamespace>
<AssemblyName>MyProject</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
]]
end
--
-- Framework Tests
--
function suite.OnFrameworkVersion()
_ACTION = "vs2005"
framework "3.0"
prepare()
test.capture [[
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AE61726D-187C-E440-BD07-2556188A6565}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MyProject</RootNamespace>
<AssemblyName>MyProject</AssemblyName>
<TargetFrameworkVersion>v3.0</TargetFrameworkVersion>
</PropertyGroup>
]]
end
@@ -0,0 +1,59 @@
--
-- tests/actions/vstudio/cs2005/propertygroup.lua
-- Validate configuration <PropertyGroup/> elements in Visual Studio 2005+ .csproj
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.vstudio_cs2005_propertygroup = { }
local suite = T.vstudio_cs2005_propertygroup
local cs2005 = premake.vstudio.cs2005
--
-- Setup
--
local sln, prj, cfg
function suite.setup()
sln = test.createsolution()
language "C#"
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
cfg = premake.getconfig(prj, "Debug")
cs2005.propertygroup(cfg)
end
--
-- Version Tests
--
function suite.OnVs2005()
_ACTION = "vs2005"
prepare()
test.capture [[
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
]]
end
function suite.OnVs2008()
_ACTION = "vs2008"
prepare()
test.capture [[
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
]]
end
function suite.OnVs2010()
_ACTION = "vs2010"
prepare()
test.capture [[
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
]]
end
@@ -0,0 +1,83 @@
--
-- tests/actions/vstudio/cs2005/test_files.lua
-- Validate generation of <Files/> block in Visual Studio 2005 .csproj
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
--
T.vstudio_cs2005_files = { }
local suite = T.vstudio_cs2005_files
local cs2005 = premake.vstudio.cs2005
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
cs2005.files(prj)
end
--
-- Test grouping and nesting
--
function suite.SimpleSourceFile()
files { "Hello.cs" }
prepare()
test.capture [[
<Compile Include="Hello.cs" />
]]
end
function suite.NestedSourceFile()
files { "Src/Hello.cs" }
prepare()
test.capture [[
<Compile Include="Src\Hello.cs" />
]]
end
--
-- The relative path to the file is correct for files that live outside
-- the project's folder.
--
function suite.filesUseRelativePath_onOutOfTreePath()
files { "../Src/Hello.cs" }
prepare()
test.capture [[
<Compile Include="..\Src\Hello.cs" />
]]
end
--
-- Test file dependencies
--
function suite.SimpleResourceDependency()
files { "Resources.resx", "Resources.Designer.cs" }
prepare()
test.capture [[
<Compile Include="Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="Resources.resx">
<SubType>Designer</SubType>
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
]]
end
@@ -0,0 +1,58 @@
--
-- tests/actions/vstudio/sln2005/dependencies.lua
-- Validate generation of Visual Studio 2005+ solution project dependencies.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.vstudio_sln2005_dependencies = { }
local suite = T.vstudio_sln2005_dependencies
local sln2005 = premake.vstudio.sln2005
--
-- Setup
--
local sln, prj1, prj2
function suite.setup()
_ACTION = "vs2005"
sln, prj1 = test.createsolution()
uuid "AE61726D-187C-E440-BD07-2556188A6565"
prj2 = test.createproject(sln)
uuid "2151E83B-997F-4A9D-955D-380157E88C31"
links "MyProject"
end
local function prepare(language)
prj1.language = language
prj2.language = language
premake.bake.buildconfigs()
prj1 = premake.solution.getproject(sln, 1)
prj2 = premake.solution.getproject(sln, 2)
sln2005.projectdependencies(prj2)
end
--
-- Tests
--
function suite.On2005_Cpp()
prepare("C++")
test.capture [[
ProjectSection(ProjectDependencies) = postProject
{AE61726D-187C-E440-BD07-2556188A6565} = {AE61726D-187C-E440-BD07-2556188A6565}
EndProjectSection
]]
end
function suite.On2005_Cs()
prepare("C#")
test.capture [[
ProjectSection(ProjectDependencies) = postProject
{AE61726D-187C-E440-BD07-2556188A6565} = {AE61726D-187C-E440-BD07-2556188A6565}
EndProjectSection
]]
end
@@ -0,0 +1,79 @@
--
-- tests/actions/vstudio/sln2005/header.lua
-- Validate generation of Visual Studio 2005+ solution header.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.vstudio_sln2005_header = { }
local suite = T.vstudio_sln2005_header
local sln2005 = premake.vstudio.sln2005
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
sln2005.header()
end
--
-- Tests
--
function suite.On2005()
_ACTION = "vs2005"
prepare()
test.capture [[
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
]]
end
function suite.On2008()
_ACTION = "vs2008"
prepare()
test.capture [[
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
]]
end
function suite.On2010()
_ACTION = "vs2010"
prepare()
test.capture [[
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
]]
end
function suite.On2012()
_ACTION = "vs2012"
prepare()
test.capture [[
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
]]
end
function suite.On2013()
_ACTION = "vs2013"
prepare()
test.capture [[
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
]]
end
@@ -0,0 +1,51 @@
--
-- tests/actions/vstudio/sln2005/layout.lua
-- Validate the overall layout of VS 2005-2010 solutions.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.vstudio_sln2005_layout = { }
local suite = T.vstudio_sln2005_layout
local sln2005 = premake.vstudio.sln2005
local sln
function suite.setup()
_ACTION = "vs2005"
sln = test.createsolution()
uuid "AE61726D-187C-E440-BD07-2556188A6565"
end
local function prepare()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
sln2005.generate(sln)
end
function suite.BasicLayout()
prepare()
test.capture ('\239\187\191' .. [[
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MyProject", "MyProject.vcproj", "{AE61726D-187C-E440-BD07-2556188A6565}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
]])
end
@@ -0,0 +1,135 @@
--
-- tests/actions/vstudio/sln2005/platforms.lua
-- Validate generation of Visual Studio 2005+ SolutionConfigurationPlatforms block.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.vstudio_sln2005_platforms = { }
local suite = T.vstudio_sln2005_platforms
local sln2005 = premake.vstudio.sln2005
--
-- Setup
--
local sln, prj
function suite.setup()
sln, prj = test.createsolution()
end
local function prepare(language)
prj.language = language
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
sln2005.platforms(sln)
end
--
-- C/C++ Tests
--
function suite.On2005_Cpp()
_ACTION = "vs2005"
prepare("C++")
test.capture [[
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
]]
end
--
-- C# Tests
--
function suite.On2005_Cs()
_ACTION = "vs2005"
prepare("C#")
test.capture [[
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Win32 = Debug|Win32
Release|Any CPU = Release|Any CPU
Release|Win32 = Release|Win32
EndGlobalSection
]]
end
function suite.On2010_Cs()
_ACTION = "vs2010"
prepare("C#")
test.capture [[
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|x86 = Release|x86
EndGlobalSection
]]
end
--
-- Mixed language tests
--
function suite.On2005_MixedLanguages()
_ACTION = "vs2005"
test.createproject(sln)
prepare("C#")
test.capture [[
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
EndGlobalSection
]]
end
function suite.On2010_MixedLanguages()
_ACTION = "vs2010"
test.createproject(sln)
prepare("C#")
test.capture [[
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Debug|x86 = Debug|x86
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
Release|x86 = Release|x86
EndGlobalSection
]]
end
--
-- Test multiple platforms
--
function suite.On2005_MixedPlatforms()
_ACTION = "vs2005"
platforms { "x32", "x64" }
prepare("C++")
test.capture [[
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
]]
end
@@ -0,0 +1,99 @@
--
-- tests/actions/vstudio/sln2005/projectplatforms.lua
-- Validate generation of Visual Studio 2005+ ProjectConfigurationPlatforms block.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.vstudio_sln2005_projectplatforms = { }
local suite = T.vstudio_sln2005_projectplatforms
local sln2005 = premake.vstudio.sln2005
--
-- Setup
--
local sln, prj
function suite.setup()
sln, prj = test.createsolution()
uuid "C9135098-6047-8142-B10E-D27E7F73FCB3"
end
local function prepare(language)
prj.language = language
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
sln2005.project_platforms(sln)
end
function suite.ProjectPlatforms_OnMixedLanguages()
_ACTION = "vs2005"
test.createproject(sln)
uuid "AE61726D-187C-E440-BD07-2556188A6565"
prepare("C#")
test.capture [[
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Win32.ActiveCfg = Debug|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.Build.0 = Release|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.ActiveCfg = Release|Any CPU
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Any CPU.ActiveCfg = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Any CPU.ActiveCfg = Release|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.Build.0 = Release|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
]]
end
function suite.ProjectPlatforms_OnMultiplePlatformsAndMixedModes()
_ACTION = "vs2005"
platforms { "x32", "x64" }
test.createproject(sln)
uuid "AE61726D-187C-E440-BD07-2556188A6565"
prepare("C#")
test.capture [[
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Win32.ActiveCfg = Debug|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x64.ActiveCfg = Debug|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.Build.0 = Release|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.ActiveCfg = Release|Any CPU
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.ActiveCfg = Release|Any CPU
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Any CPU.ActiveCfg = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|x64.ActiveCfg = Debug|x64
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|x64.Build.0 = Debug|x64
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Any CPU.ActiveCfg = Release|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.Build.0 = Release|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32
{AE61726D-187C-E440-BD07-2556188A6565}.Release|x64.ActiveCfg = Release|x64
{AE61726D-187C-E440-BD07-2556188A6565}.Release|x64.Build.0 = Release|x64
EndGlobalSection
]]
end
@@ -0,0 +1,67 @@
--
-- tests/actions/vstudio/sln2005/projects.lua
-- Validate generation of Visual Studio 2005+ solution project entries.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.vstudio_sln2005_projects = { }
local suite = T.vstudio_sln2005_projects
local sln2005 = premake.vstudio.sln2005
--
-- Setup
--
local sln, prj
function suite.setup()
_ACTION = "vs2005"
sln = test.createsolution()
uuid "AE61726D-187C-E440-BD07-2556188A6565"
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln2005.project(prj)
end
--
-- C/C++ project reference tests
--
function suite.On2005_CppProject()
_ACTION = "vs2005"
prepare()
test.capture [[
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MyProject", "MyProject.vcproj", "{AE61726D-187C-E440-BD07-2556188A6565}"
EndProject
]]
end
function suite.On2010_CppProject()
_ACTION = "vs2010"
prepare()
test.capture [[
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MyProject", "MyProject.vcxproj", "{AE61726D-187C-E440-BD07-2556188A6565}"
EndProject
]]
end
--
-- C# project reference tests
--
function suite.On2005_CsProject()
_ACTION = "vs2005"
language "C#"
prepare()
test.capture [[
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyProject", "MyProject.csproj", "{AE61726D-187C-E440-BD07-2556188A6565}"
EndProject
]]
end
@@ -0,0 +1,687 @@
--
-- tests/test_vs200x_vcproj.lua
-- Automated test suite for Visual Studio 2002-2008 C/C++ project generation.
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
--
T.vs200x_vcproj = { }
local suite = T.vs200x_vcproj
local vc200x = premake.vstudio.vc200x
--
-- Configure a solution for testing
--
local sln, prj
function suite.setup()
_ACTION = "vs2005"
sln = solution "MySolution"
configurations { "Debug", "Release" }
platforms {}
project "DotNetProject" -- to test handling of .NET platform in solution
language "C#"
kind "ConsoleApp"
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
uuid "AE61726D-187C-E440-BD07-2556188A6565"
end
local function prepare()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
local cfg = premake.getconfig(sln.projects[2])
cfg.name = prj.name
cfg.blocks = prj.blocks
prj = cfg
end
--
-- Make sure I've got the basic layout correct
--
function suite.BasicLayout()
prepare()
vc200x.generate(prj)
test.capture [[
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="MyProject"
ProjectGUID="{AE61726D-187C-E440-BD07-2556188A6565}"
RootNamespace="MyProject"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="."
IntermediateDirectory="obj\Debug\MyProject"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
DebugInformationFormat="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)\MyProject.exe"
LinkIncremental="2"
AdditionalLibraryDirectories=""
GenerateDebugInformation="false"
SubSystem="1"
EntryPointSymbol="mainCRTStartup"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="."
IntermediateDirectory="obj\Release\MyProject"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
DebugInformationFormat="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)\MyProject.exe"
LinkIncremental="2"
AdditionalLibraryDirectories=""
GenerateDebugInformation="false"
SubSystem="1"
EntryPointSymbol="mainCRTStartup"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
]]
end
--
-- Test multiple platforms
--
function suite.Platforms_OnMultiplePlatforms()
platforms { "x32", "x64" }
prepare()
vc200x.generate(prj)
local result = io.endcapture()
test.istrue(result:find '<Configuration\r\n\t\t\tName="Debug|Win32"\r\n')
test.istrue(result:find '<Configuration\r\n\t\t\tName="Release|Win32"\r\n')
test.istrue(result:find '<Configuration\r\n\t\t\tName="Debug|x64"\r\n')
test.istrue(result:find '<Configuration\r\n\t\t\tName="Release|x64"\r\n')
end
--
-- Test x64 handling
--
function suite.PlatformsList_OnX64()
platforms { "Native", "x64" }
prepare()
vc200x.Platforms(prj)
test.capture [[
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
]]
end
--
-- Test Xbox360 handling
--
function suite.PlatformsList_OnXbox360()
platforms { "Native", "Xbox360" }
prepare()
vc200x.Platforms(prj)
test.capture [[
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="Xbox 360"
/>
</Platforms>
]]
end
function suite.CompilerBlock_OnXbox360()
platforms { "Xbox360" }
prepare()
vc200x.VCCLCompilerTool(premake.getconfig(prj, "Debug", "Xbox360"))
test.capture [[
<Tool
Name="VCCLX360CompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
DebugInformationFormat="0"
/>
]]
end
--
-- Test PS3 handling
--
function suite.PlatformsList_OnPS3()
platforms { "Native", "PS3" }
prepare()
vc200x.Platforms(prj)
test.capture [[
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
]]
end
function suite.CompilerBlock_OnPS3()
platforms { "PS3" }
flags { "Symbols" }
includedirs { "include/pkg1", "include/pkg2" }
defines { "DEFINE1", "DEFINE2" }
prepare()
vc200x.VCCLCompilerTool_PS3(premake.getconfig(prj, "Debug", "PS3"))
test.capture [[
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
AdditionalOptions=""
AdditionalIncludeDirectories="include\pkg1;include\pkg2"
PreprocessorDefinitions="DEFINE1;DEFINE2"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
DebugInformationFormat="0"
CompileAs="0"
/>
]]
end
function suite.LinkerBlock_OnPS3ConsoleApp()
platforms { "PS3" }
prepare()
vc200x.VCLinkerTool_PS3(premake.getconfig(prj, "Debug", "PS3"))
test.capture [[
<Tool
Name="VCLinkerTool"
AdditionalOptions="-s"
OutputFile="$(OutDir)\MyProject.elf"
LinkIncremental="0"
AdditionalLibraryDirectories=""
GenerateManifest="false"
ProgramDatabaseFile=""
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
/>
]]
end
function suite.LinkerBlock_OnPS3StaticLib()
platforms { "PS3" }
kind "StaticLib"
prepare()
vc200x.VCLinkerTool_PS3(premake.getconfig(prj, "Debug", "PS3"))
test.capture [[
<Tool
Name="VCLibrarianTool"
AdditionalOptions="-s"
OutputFile="$(OutDir)\libMyProject.a"
/>
]]
end
function suite.LinkerBlock_OnPS3SharedLink()
platforms { "PS3" }
links { "MyLibrary" }
project "MyLibrary"
language "C++"
kind "SharedLib"
prepare()
vc200x.VCLinkerTool_PS3(premake.getconfig(prj, "Debug", "PS3"))
test.capture [[
<Tool
Name="VCLinkerTool"
AdditionalOptions="-s"
AdditionalDependencies="libMyLibrary.a"
OutputFile="$(OutDir)\MyProject.elf"
LinkIncremental="0"
AdditionalLibraryDirectories=""
GenerateManifest="false"
ProgramDatabaseFile=""
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
/>
]]
end
--
-- Test manifest file handling.
--
function suite.VCManifestTool_OnNoManifests()
files { "hello.c", "goodbye.c" }
prepare()
vc200x.VCManifestTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCManifestTool"
/>
]]
end
function suite.VCManifestTool_OnNoManifests()
files { "hello.c", "project1.manifest", "goodbye.c", "project2.manifest" }
prepare()
vc200x.VCManifestTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCManifestTool"
AdditionalManifestFiles="project1.manifest;project2.manifest"
/>
]]
end
--
-- Test precompiled header handling; the header should be treated as
-- a plain string value, with no path manipulation applied, since it
-- needs to match the value of the #include statement used in the
-- project code.
--
function suite.CompilerBlock_OnPCH()
location "build/MyProject"
pchheader "include/common.h"
pchsource "source/common.cpp"
prepare()
vc200x.VCCLCompilerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCCLCompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="include/common.h"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
DebugInformationFormat="0"
/>
]]
end
--
-- Floating point flag tests
--
function suite.CompilerBlock_OnFpFast()
flags { "FloatFast" }
prepare()
vc200x.VCCLCompilerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCCLCompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
FloatingPointModel="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
DebugInformationFormat="0"
/>
]]
end
function suite.CompilerBlock_OnFpStrict()
flags { "FloatStrict" }
prepare()
vc200x.VCCLCompilerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCCLCompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
FloatingPointModel="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
DebugInformationFormat="0"
/>
]]
end
--
-- PDB file naming tests
--
function suite.CompilerBlock_OnTargetName()
targetname "foob"
prepare()
vc200x.VCCLCompilerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCCLCompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\foob.pdb"
DebugInformationFormat="0"
/>
]]
end
--
-- Compilation option tests
--
function suite.CompilerBlock_OnMinimalRebuild()
flags { "Symbols", "EnableMinimalRebuild" }
prepare()
vc200x.VCCLCompilerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCCLCompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
DebugInformationFormat="4"
/>
]]
end
--
-- RuntimeLibrary tests
--
function suite.CompilerBlock_RuntimeLibrary_IsDebug_OnSymbolsNoOptimize()
flags { "Symbols" }
prepare()
vc200x.VCCLCompilerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCCLCompilerTool"
Optimization="0"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
DebugInformationFormat="4"
/>
]]
end
function suite.CompilerBlock_RuntimeLibrary_IsRelease_OnOptimize()
flags { "Symbols", "Optimize" }
prepare()
vc200x.VCCLCompilerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCCLCompilerTool"
Optimization="3"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
DebugInformationFormat="3"
/>
]]
end
--
-- C language support
--
function suite.CompilerBlock_RuntimeLibrary_IsDebug_OnSymbolsNoOptimize()
language "C"
flags { "Symbols" }
prepare()
vc200x.VCCLCompilerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCCLCompilerTool"
Optimization="0"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
DebugInformationFormat="4"
CompileAs="1"
/>
]]
end
function suite.noLinkIncrementalFlag_valueEqualsOne()
flags { "NoIncrementalLink" }
prepare()
vc200x.VCLinkerTool(premake.getconfig(prj, "Debug"))
local result = io.endcapture()
test.string_contains(result,'LinkIncremental="1"')
end
function suite.staticLib_platformX64_MachineX64SetInAdditionalOptions()
local sln1 = solution "sol"
configurations { "foo" }
platforms {'x64'}
local prj1 = project "prj"
language 'C++'
kind 'StaticLib'
premake.bake.buildconfigs()
sln1.vstudio_configs = premake.vstudio.buildconfigs(sln1)
prj1= premake.getconfig(sln1.projects[1])
vc200x.generate(prj1)
local result = io.endcapture()
test.string_contains(result,'AdditionalOptions="/MACHINE:X64"')
end
function suite.staticLib_platformX32_MachineX86SetInAdditionalOptions()
local sln1 = solution "sol"
configurations { "foo" }
platforms {'x32'}
local prj1 = project "prj"
language 'C++'
kind 'StaticLib'
premake.bake.buildconfigs()
sln1.vstudio_configs = premake.vstudio.buildconfigs(sln1)
prj1= premake.getconfig(sln1.projects[1])
vc200x.generate(prj1)
local result = io.endcapture()
test.string_contains(result,'AdditionalOptions="/MACHINE:X86"')
end
@@ -0,0 +1,116 @@
--
-- tests/actions/vstudio/test_vs200x_vcproj_linker.lua
-- Automated tests for Visual Studio 2002-2008 C/C++ linker block.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.vs200x_vcproj_linker = { }
local suite = T.vs200x_vcproj_linker
local vc200x = premake.vstudio.vc200x
--
-- Setup/Teardown
--
local sln, prj
function suite.setup()
_ACTION = "vs2005"
sln, prj = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
end
--
-- Test default linker blocks for each target kind
-- (ConsoleApp, StaticLib, etc.)
--
function suite.DefaultLinkerBlock_OnConsoleApp()
kind "ConsoleApp"
prepare()
vc200x.VCLinkerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)\MyProject.exe"
LinkIncremental="2"
AdditionalLibraryDirectories=""
GenerateDebugInformation="false"
SubSystem="1"
EntryPointSymbol="mainCRTStartup"
TargetMachine="1"
/>
]]
end
function suite.DefaultLinkerBlock_OnWindowedApp()
kind "WindowedApp"
prepare()
vc200x.VCLinkerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)\MyProject.exe"
LinkIncremental="2"
AdditionalLibraryDirectories=""
GenerateDebugInformation="false"
SubSystem="2"
EntryPointSymbol="mainCRTStartup"
TargetMachine="1"
/>
]]
end
function suite.DefaultLinkerBlock_OnSharedLib()
kind "SharedLib"
prepare()
vc200x.VCLinkerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)\MyProject.dll"
LinkIncremental="2"
AdditionalLibraryDirectories=""
GenerateDebugInformation="false"
SubSystem="2"
ImportLibrary="MyProject.lib"
TargetMachine="1"
/>
]]
end
function suite.DefaultLinkerBlock_OnStaticLib()
kind "StaticLib"
prepare()
vc200x.VCLinkerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)\MyProject.lib"
/>
]]
end
--
-- linkoptions tests
--
function suite.AdditionalOptions_OnStaticLib()
kind "StaticLib"
linkoptions { "/ltcg", "/lZ" }
prepare()
vc200x.VCLinkerTool(premake.getconfig(prj, "Debug"))
test.capture [[
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)\MyProject.lib"
AdditionalOptions="/ltcg /lZ"
/>
]]
end
@@ -0,0 +1,363 @@
T.vs2010_flags = { }
local vs10_flags = T.vs2010_flags
local sln, prj
function vs10_flags.setup()
_ACTION = "vs2010"
sln = solution "MySolution"
configurations { "Debug" }
platforms {}
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
uuid "AE61726D-187C-E440-BD07-2556188A6565"
includedirs{"foo/bar"}
end
function vs10_flags.teardown()
sln = nil
prj = nil
end
local function get_buffer()
io.capture()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
prj = premake.solution.getproject(sln, 1)
premake.vs2010_vcxproj(prj)
local buffer = io.endcapture()
return buffer
end
function vs10_flags.sseSet()
flags {"EnableSSE"}
local buffer = get_buffer()
test.string_contains(buffer,'<EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet>')
end
function vs10_flags.sse2Set()
flags {"EnableSSE2"}
local buffer = get_buffer()
test.string_contains(buffer,'<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>')
end
function vs10_flags.extraWarningNotSet_warningLevelIsThree()
local buffer = get_buffer()
test.string_contains(buffer,'<WarningLevel>Level3</WarningLevel>')
end
function vs10_flags.extraWarning_warningLevelIsFour()
flags {"ExtraWarnings"}
local buffer = get_buffer()
test.string_contains(buffer,'<WarningLevel>Level4</WarningLevel>')
end
function vs10_flags.extraWarning_treatWarningsAsError_setToTrue()
flags {"FatalWarnings"}
local buffer = get_buffer()
test.string_contains(buffer,'<TreatWarningAsError>true</TreatWarningAsError>')
end
function vs10_flags.floatFast_floatingPointModel_setToFast()
flags {"FloatFast"}
local buffer = get_buffer()
test.string_contains(buffer,'<FloatingPointModel>Fast</FloatingPointModel>')
end
function vs10_flags.floatStrict_floatingPointModel_setToStrict()
flags {"FloatStrict"}
local buffer = get_buffer()
test.string_contains(buffer,'<FloatingPointModel>Strict</FloatingPointModel>')
end
function vs10_flags.nativeWideChar_TreatWChar_tAsBuiltInType_setToTrue()
flags {"NativeWChar"}
local buffer = get_buffer()
test.string_contains(buffer,'<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>')
end
function vs10_flags.nativeWideChar_TreatWChar_tAsBuiltInType_setToFalse()
flags {"NoNativeWChar"}
local buffer = get_buffer()
test.string_contains(buffer,'<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>')
end
function vs10_flags.noExceptions_exceptionHandling_setToFalse()
flags {"NoExceptions"}
local buffer = get_buffer()
test.string_contains(buffer,'<ExceptionHandling>false</ExceptionHandling>')
end
function vs10_flags.structuredExceptions_exceptionHandling_setToAsync()
flags {"SEH"}
local buffer = get_buffer()
test.string_contains(buffer,'<ExceptionHandling>Async</ExceptionHandling>')
end
function vs10_flags.noFramePointer_omitFramePointers_setToTrue()
flags {"NoFramePointer"}
local buffer = get_buffer()
test.string_contains(buffer,'<OmitFramePointers>true</OmitFramePointers>')
end
function vs10_flags.noRTTI_runtimeTypeInfo_setToFalse()
flags {"NoRTTI"}
local buffer = get_buffer()
test.string_contains(buffer,'<RuntimeTypeInfo>false</RuntimeTypeInfo>')
end
function vs10_flags.callingconvention_fastcall()
flags {"FastCall"}
local buffer = get_buffer()
test.string_contains(buffer,'<CallingConvention>FastCall</CallingConvention>')
end
function vs10_flags.callingconvention_stdcall()
flags {"StdCall"}
local buffer = get_buffer()
test.string_contains(buffer,'<CallingConvention>StdCall</CallingConvention>')
end
function vs10_flags.optimizeSize_optimization_setToMinSpace()
flags {"OptimizeSize"}
local buffer = get_buffer()
test.string_contains(buffer,'<Optimization>MinSpace</Optimization>')
end
function vs10_flags.optimizeSpeed_optimization_setToMaxSpeed()
flags {"OptimizeSpeed"}
local buffer = get_buffer()
test.string_contains(buffer,'<Optimization>MaxSpeed</Optimization>')
end
function vs10_flags.optimizeSpeed_optimization_setToMaxSpeed()
flags {"Optimize"}
local buffer = get_buffer()
test.string_contains(buffer,'<Optimization>Full</Optimization>')
end
local debug_string = "Symbols"
local release_string = "Optimize"
function vs10_flags.debugHasNoStaticRuntime_runtimeLibrary_setToMultiThreadedDebugDLL()
flags {debug_string}
local buffer = get_buffer()
test.string_contains(buffer,'<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>')
end
function vs10_flags.debugAndStaticRuntime_runtimeLibrary_setToMultiThreadedDebug()
flags {debug_string,"StaticRuntime"}
local buffer = get_buffer()
test.string_contains(buffer,'<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>')
end
function vs10_flags.releaseHasNoStaticRuntime_runtimeLibrary_setToMultiThreadedDLL()
flags {release_string}
local buffer = get_buffer()
test.string_contains(buffer,'<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>')
end
function vs10_flags.releaseAndStaticRuntime_runtimeLibrary_setToMultiThreaded()
flags {release_string,"StaticRuntime"}
local buffer = get_buffer()
test.string_contains(buffer,'<RuntimeLibrary>MultiThreaded</RuntimeLibrary>')
end
function vs10_flags.debugAndMinimalRebuildAndSymbols_minimalRebuild_setToFalse()
flags {debug_string,"EnableMinimalRebuild"}
local buffer = get_buffer()
test.string_contains(buffer,'<MinimalRebuild>true</MinimalRebuild>')
end
function vs10_flags.debugYetNotMinimalRebuild_minimalRebuild_setToTrue()
flags {debug_string}
local buffer = get_buffer()
test.string_contains(buffer,'<MinimalRebuild>true</MinimalRebuild>')
end
function vs10_flags.release_minimalRebuild_setToFalse()
flags {release_string}
local buffer = get_buffer()
test.string_contains(buffer,'<MinimalRebuild>false</MinimalRebuild>')
end
--there is not an option for /Z7 OldStyle
--/ZI is not compatible with /clr or x64_64
--minimal Rebuild requires /Zi in x86_64
function vs10_flags.symbols_32BitBuild_DebugInformationFormat_setToEditAndContinue()
flags{"Symbols"}
platforms{'x32'}
local buffer = get_buffer()
test.string_contains(buffer,'<DebugInformationFormat>EditAndContinue</DebugInformationFormat>')
end
function vs10_flags.symbols_64BitBuild_DebugInformationFormat_setToProgramDatabase()
flags{"Symbols"}
platforms{"x64"}
local buffer = get_buffer()
test.string_contains(buffer,'<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>')
end
function vs10_flags.symbolsAndNoEditAndContinue_DebugInformationFormat_setToProgramDatabase()
flags{"Symbols","NoEditAndContinue"}
local buffer = get_buffer()
test.string_contains(buffer,'<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>')
end
function vs10_flags.symbolsAndRelease_DebugInformationFormat_setToProgramDatabase()
flags{"Symbols",release_string}
local buffer = get_buffer()
test.string_contains(buffer,'<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>')
end
function vs10_flags.symbolsManaged_DebugInformationFormat_setToProgramDatabase()
flags{"Symbols","Managed"}
local buffer = get_buffer()
test.string_contains(buffer,'<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>')
end
function vs10_flags.noSymbols_DebugInformationFormat_blockIsEmpty()
local buffer = get_buffer()
test.string_contains(buffer,'<DebugInformationFormat></DebugInformationFormat>')
end
function vs10_flags.noSymbols_bufferDoesNotContainprogramDataBaseFile()
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<Link>.*<ProgramDataBaseFileName>.*</Link>')
end
function vs10_flags.symbols_bufferContainsprogramDataBaseFile()
flags{"Symbols"}
local buffer = get_buffer()
test.string_contains(buffer,'<ClCompile>.*<ProgramDataBaseFileName>%$%(OutDir%)MyProject%.pdb</ProgramDataBaseFileName>.*</ClCompile>')
end
function vs10_flags.WithOutManaged_bufferContainsKeywordWin32Proj()
local buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup Label="Globals">.*<Keyword>Win32Proj</Keyword>.*</PropertyGroup>')
end
function vs10_flags.WithOutManaged_bufferDoesNotContainKeywordManagedCProj()
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<PropertyGroup Label="Globals">.*<Keyword>ManagedCProj</Keyword>.*</PropertyGroup>')
end
T.vs2010_managedFlag = { }
local vs10_managedFlag = T.vs2010_managedFlag
local function vs10_managedFlag_setOnProject()
local sln = solution "Sol"
configurations { "Debug" }
language "C++"
kind "ConsoleApp"
local prj = project "Prj"
flags {"Managed"}
return sln,prj
end
local function get_managed_buffer(sln,prj)
io.capture()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
prj = premake.solution.getproject(sln, 1)
premake.vs2010_vcxproj(prj)
local buffer = io.endcapture()
return buffer
end
function vs10_managedFlag.setup()
end
function vs10_managedFlag.managedSetOnProject_CLRSupport_setToTrue()
local sln, prj = vs10_managedFlag_setOnProject()
local buffer = get_managed_buffer(sln,prj)
test.string_contains(buffer,
'<PropertyGroup Condition=".*" Label="Configuration">'
..'.*<CLRSupport>true</CLRSupport>'
..'.*</PropertyGroup>')
end
function vs10_managedFlag.globals_bufferContainsKeywordManagedCProj()
local sln, prj = vs10_managedFlag_setOnProject()
local buffer = get_managed_buffer(sln,prj)
test.string_contains(buffer,'<PropertyGroup Label="Globals">.*<Keyword>ManagedCProj</Keyword>.*</PropertyGroup>')
end
function vs10_managedFlag.globals_bufferDoesNotContainKeywordWin32Proj()
local sln, prj = vs10_managedFlag_setOnProject()
local buffer = get_managed_buffer(sln,prj)
test.string_does_not_contain(buffer,'<PropertyGroup Label="Globals">.*<Keyword>Win32Proj</Keyword>.*</PropertyGroup>')
end
function vs10_managedFlag.globals_FrameworkVersion_setToV4()
local sln, prj = vs10_managedFlag_setOnProject()
local buffer = get_managed_buffer(sln,prj)
test.string_contains(buffer,'<PropertyGroup Label="Globals">.*<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>.*</PropertyGroup>')
end
function vs10_managedFlag.withFloatFast_FloatingPointModelNotFoundInBuffer()
local sln, prj = vs10_managedFlag_setOnProject()
flags {"FloatStrict"}
local buffer = get_managed_buffer(sln,prj)
test.string_does_not_contain(buffer,'<FloatingPointModel>.*</FloatingPointModel>')
end
function vs10_managedFlag.debugWithStaticRuntime_flagIgnoredAndRuntimeSetToMDd()
local sln, prj = vs10_managedFlag_setOnProject()
flags {"Symbols","StaticRuntime"}
local buffer = get_managed_buffer(sln,prj)
test.string_contains(buffer,'<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>')
end
function vs10_managedFlag.notDebugWithStaticRuntime_flagIgnoredAndRuntimeSetToMD()
local sln, prj = vs10_managedFlag_setOnProject()
flags {"StaticRuntime"}
local buffer = get_managed_buffer(sln,prj)
test.string_contains(buffer,'<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>')
end
function vs10_managedFlag.noOptimisationFlag_basicRuntimeChecksNotFoundInBuffer()
local sln, prj = vs10_managedFlag_setOnProject()
local buffer = get_managed_buffer(sln,prj)
test.string_does_not_contain(buffer,'<BasicRuntimeChecks>.*</BasicRuntimeChecks>')
end
function vs10_managedFlag.applictionWithOutWinMain_EntryPointSymbolNotFoundInBuffer()
local sln, prj = vs10_managedFlag_setOnProject()
local buffer = get_managed_buffer(sln,prj)
test.string_does_not_contain(buffer,'<EntryPointSymbol>.*</EntryPointSymbol>')
end
@@ -0,0 +1,166 @@
T.vs2010_project_kinds= { }
local vs10_project_kinds = T.vs2010_project_kinds
local sln, prj
function vs10_project_kinds.setup()
_ACTION = "vs2010"
sln = solution "MySolution"
configurations { "Debug" }
platforms {}
prj = project "MyProject"
language "C++"
end
local function get_buffer(platform)
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
prj = premake.solution.getproject(sln, 1)
premake.vs2010_vcxproj(prj)
buffer = io.endcapture()
return buffer
end
function vs10_project_kinds.staticLib_containsLibSection()
kind "StaticLib"
local buffer = get_buffer()
test.string_contains(buffer,'<ItemDefinitionGroup.*<Lib>.*</Lib>.*</ItemDefinitionGroup>')
end
function vs10_project_kinds.staticLib_libSection_containsProjectNameDotLib()
kind "StaticLib"
local buffer = get_buffer()
test.string_contains(buffer,'<Lib>.*<OutputFile>.*MyProject.lib.*</OutputFile>.*</Lib>')
end
function vs10_project_kinds.staticLib_valueInMinimalRebuildIsTrue()
kind "StaticLib"
flags {"Symbols"}
local buffer = get_buffer()
test.string_contains(buffer,'<ClCompile>.*<MinimalRebuild>true</MinimalRebuild>.*</ClCompile>')
end
function vs10_project_kinds.sharedLib_valueInMinimalRebuildIsTrue()
kind "SharedLib"
flags {"Symbols"}
local buffer = get_buffer()
test.string_contains(buffer,'<ClCompile>.*<MinimalRebuild>true</MinimalRebuild>.*</ClCompile>')
end
function vs10_project_kinds.sharedLib_valueDebugInformationFormatIsEditAndContinue()
kind "SharedLib"
flags {"Symbols"}
local buffer = get_buffer()
test.string_contains(buffer,'<ClCompile>.*<DebugInformationFormat>EditAndContinue</DebugInformationFormat>.*</ClCompile>')
end
function vs10_project_kinds.sharedLib_valueGenerateDebugInformationIsTrue()
kind "SharedLib"
flags {"Symbols"}
local buffer = get_buffer()
test.string_contains(buffer,'<Link>.*<GenerateDebugInformation>true</GenerateDebugInformation>.*</Link>')
end
function vs10_project_kinds.sharedLib_linkSectionContainsImportLibrary()
kind "SharedLib"
local buffer = get_buffer()
test.string_contains(buffer,'<Link>.*<ImportLibrary>.*</ImportLibrary>.*</Link>')
end
function vs10_project_kinds.sharedLib_withoutOptimisation_linkIncrementalValueIsTrue()
kind "SharedLib"
local buffer = get_buffer()
test.string_contains(buffer,'<LinkIncremental.*true</LinkIncremental>')
end
function vs10_project_kinds.sharedLib_withOptimisation_linkIncrementalValueIsFalse()
kind "SharedLib"
flags{"Optimize"}
local buffer = get_buffer()
test.string_contains(buffer,'<LinkIncremental.*false</LinkIncremental>')
end
function vs10_project_kinds.kindDoesNotMatter_noAdditionalDirectoriesSpecified_bufferDoesNotContainAdditionalIncludeDirectories()
kind "SharedLib"
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<ClCompile>.*<AdditionalIncludeDirectories>.*</ClCompile>')
end
function vs10_project_kinds.configType_configIsWindowedApp_resultComparesEqualToApplication()
local t = { kind = "WindowedApp"}
local result = premake.vstudio.vc2010.config_type(t)
test.isequal('Application',result)
end
function vs10_project_kinds.linkOptions_staticLib_bufferContainsAdditionalOptionsInSideLibTag()
kind "StaticLib"
linkoptions{'/dummyOption'}
test.string_contains(get_buffer(),
'<AdditionalOptions>.*%%%(AdditionalOptions%)</AdditionalOptions>.*</Lib>')
end
function vs10_project_kinds.noLinkOptions_staticLib_bufferDoesNotContainAdditionalOptionsInSideLibTag()
kind "StaticLib"
test.string_does_not_contain(get_buffer(),
'<AdditionalOptions>.*%%%(AdditionalOptions%)</AdditionalOptions>.*</Lib>')
end
function vs10_project_kinds.linkOptions_staticLib_bufferContainsPassedOption()
kind "StaticLib"
linkoptions{'/dummyOption'}
test.string_contains(get_buffer(),
'<AdditionalOptions>/dummyOption %%%(AdditionalOptions%)</AdditionalOptions>.*</Lib>')
end
function vs10_project_kinds.linkOptions_windowedApp_bufferContainsAdditionalOptionsInSideLinkTag()
kind "WindowedApp"
linkoptions{'/dummyOption'}
test.string_contains(get_buffer(),
'<AdditionalOptions>.* %%%(AdditionalOptions%)</AdditionalOptions>.*</Link>')
end
function vs10_project_kinds.linkOptions_consoleApp_bufferContainsAdditionalOptionsInSideLinkTag()
kind "ConsoleApp"
linkoptions{'/dummyOption'}
test.string_contains(get_buffer(),
'<AdditionalOptions>.* %%%(AdditionalOptions%)</AdditionalOptions>.*</Link>')
end
function vs10_project_kinds.linkOptions_sharedLib_bufferContainsAdditionalOptionsInSideLinkTag()
kind "SharedLib"
linkoptions{'/dummyOption'}
test.string_contains(get_buffer(),
'<AdditionalOptions>.* %%%(AdditionalOptions%)</AdditionalOptions>.*</Link>')
end
function vs10_project_kinds.staticLibX64_TargetMachineSetInLib()
kind "StaticLib"
platforms{'x64'}
local buffer = get_buffer()
test.string_contains(buffer,'<Lib>.*<TargetMachine>.*</TargetMachine>.*</Lib>')
end
function vs10_project_kinds.staticLibX64_TargetMachineInLibSetToMachineX64()
kind "StaticLib"
platforms{'x64'}
local buffer = get_buffer()
test.string_contains(buffer,'<Lib>.*<TargetMachine>MachineX64</TargetMachine>.*</Lib>')
end
function vs10_project_kinds.staticLibX32_TargetMachineSetInLib()
kind "StaticLib"
platforms{'x32'}
local buffer = get_buffer()
test.string_contains(buffer,'<Lib>.*<TargetMachine>.*</TargetMachine>.*</Lib>')
end
function vs10_project_kinds.staticLibX32_TargetMachineInLibSetToMachineX86()
kind "StaticLib"
platforms{'x32'}
local buffer = get_buffer()
test.string_contains(buffer,'<Lib>.*<TargetMachine>MachineX86</TargetMachine>.*</Lib>')
end
@@ -0,0 +1,289 @@
T.vs2010_vcxproj = { }
local vs10_vcxproj = T.vs2010_vcxproj
local include_directory = "bar/foo"
local include_directory2 = "baz/foo"
local debug_define = "I_AM_ALIVE_NUMBER_FIVE"
local vc2010 = premake.vstudio.vc2010
local sln, prj
function vs10_vcxproj.teardown()
sln = nil
prj = nil
end
function vs10_vcxproj.setup()
_ACTION = "vs2010"
sln = solution "MySolution"
configurations { "Debug", "Release" }
platforms {}
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
uuid "AE61726D-187C-E440-BD07-2556188A6565"
includedirs
{
include_directory,
include_directory2
}
files
{
"foo/dummyHeader.h",
"foo/dummySource.cpp",
"../src/host/*h",
"../src/host/*.c",
"dummyResourceScript.rc"
}
configuration("Release")
flags {"Optimize"}
links{"foo","bar"}
configuration("Debug")
defines {debug_define}
links{"foo_d"}
end
local function get_buffer()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
prj = premake.solution.getproject(sln, 1)
premake.vs2010_vcxproj(prj)
local buffer = io.endcapture()
return buffer
end
--
-- Tests
--
function vs10_vcxproj.xmlDeclarationPresent()
local buffer = get_buffer()
test.istrue(string.startswith(buffer, '<?xml version=\"1.0\" encoding=\"utf-8\"?>'))
end
function vs10_vcxproj.projectBlocksArePresent()
local buffer = get_buffer()
test.string_contains(buffer,'<Project.*</Project>')
end
function vs10_vcxproj.projectOpenTagIsCorrect()
local buffer = get_buffer()
test.string_contains(buffer,'<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">.*</Project>')
end
function vs10_vcxproj.configItemGroupPresent()
local buffer = get_buffer()
test.string_contains(buffer,'<ItemGroup Label="ProjectConfigurations">.*</ItemGroup>')
end
function vs10_vcxproj.configBlocksArePresent()
local buffer = get_buffer()
test.string_contains(buffer,'<ProjectConfiguration.*</ProjectConfiguration>')
end
function vs10_vcxproj.configTypeBlockPresent()
local buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'.*\'" Label="Configuration">.*</PropertyGroup>')
end
function vs10_vcxproj.twoConfigTypeBlocksPresent()
local buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup Condition.*</PropertyGroup>.*<PropertyGroup Condition=.*</PropertyGroup>')
end
function vs10_vcxproj.propsDefaultForCppProjArePresent()
local buffer = get_buffer()
test.string_contains(buffer,'<Import Project="$%(VCTargetsPath%)\\Microsoft.Cpp.Default.props" />')
end
function vs10_vcxproj.propsForCppProjArePresent()
local buffer = get_buffer()
test.string_contains(buffer,'<Import Project="%$%(VCTargetsPath%)\\Microsoft.Cpp.props" />')
end
function vs10_vcxproj.extensionSettingArePresent()
local buffer = get_buffer()
test.string_contains(buffer,'<ImportGroup Label="ExtensionSettings">.*</ImportGroup>')
end
function vs10_vcxproj.userMacrosPresent()
local buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup Label="UserMacros" />')
end
function vs10_vcxproj.projectWithDebugAndReleaseConfig_twoOutDirsAndTwoIntDirs()
local buffer = get_buffer()
test.string_contains(buffer,'<OutDir.*</OutDir>.*<IntDir.*</IntDir>.*<OutDir.*</OutDir>.*<IntDir.*</IntDir>')
end
function vs10_vcxproj.containsItemDefinition()
local buffer = get_buffer()
test.string_contains(buffer,'<ItemDefinitionGroup Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'.*\'">.*</ItemDefinitionGroup>')
end
function vs10_vcxproj.containsClCompileBlock()
local buffer = get_buffer()
test.string_contains(buffer,'<ClCompile>.*</ClCompile>')
end
function vs10_vcxproj.containsAdditionalOptions()
buildoptions {"/Gm"}
local buffer = get_buffer()
test.string_contains(buffer,'<AdditionalOptions>/Gm %%%(AdditionalOptions%)</AdditionalOptions>')
end
local function cl_compile_string(version)
return '<ItemDefinitionGroup Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\''..version..'|Win32\'">.*<ClCompile>'
end
function vs10_vcxproj.debugHasNoOptimisation()
local buffer = get_buffer()
test.string_contains(buffer, cl_compile_string('Debug').. '.*<Optimization>Disabled</Optimization>.*</ItemDefinitionGroup>')
end
function vs10_vcxproj.releaseHasFullOptimisation()
local buffer = get_buffer()
test.string_contains(buffer, cl_compile_string('Release').. '.*<Optimization>Full</Optimization>.*</ItemDefinitionGroup>')
end
function vs10_vcxproj.includeDirectories_debugEntryContains_include_directory()
local buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Debug').. '.*<AdditionalIncludeDirectories>'.. path.translate(include_directory, '\\') ..'.*</AdditionalIncludeDirectories>')
end
function vs10_vcxproj.includeDirectories_debugEntryContains_include_directory2PrefixWithSemiColon()
local buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Debug').. '.*<AdditionalIncludeDirectories>.*;'.. path.translate(include_directory2, '\\') ..'.*</AdditionalIncludeDirectories>')
end
function vs10_vcxproj.includeDirectories_debugEntryContains_include_directory2PostfixWithSemiColon()
local buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Debug').. '.*<AdditionalIncludeDirectories>.*'.. path.translate(include_directory2, '\\') ..';.*</AdditionalIncludeDirectories>')
end
function vs10_vcxproj.debugContainsPreprossorBlock()
local buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Debug').. '.*<PreprocessorDefinitions>.*</PreprocessorDefinitions>')
end
function vs10_vcxproj.debugHasDebugDefine()
local buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Debug')..'.*<PreprocessorDefinitions>.*'..debug_define..'.*</PreprocessorDefinitions>')
end
function vs10_vcxproj.releaseHasStringPoolingOn()
local buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Release')..'.*<StringPooling>true</StringPooling>')
end
function vs10_vcxproj.hasItemGroupSection()
local buffer = get_buffer()
test.string_contains(buffer,'<ItemGroup>.*</ItemGroup>')
end
function vs10_vcxproj.itemGroupSection_hasResourceCompileSection()
--for some reason this does not work here and it needs to be in
--the project setting at the top ?
--files{"dummyResourceScript.rc"}
local buffer = get_buffer()
test.string_contains(buffer,'<ItemGroup>.*<ResourceCompile.*</ItemGroup>')
end
function vs10_vcxproj.checkProjectConfigurationOpeningTag_hasACloseingAngleBracket()
local buffer = get_buffer()
test.string_contains(buffer,'<ProjectConfiguration Include="Debug|Win32">')
end
function vs10_vcxproj.postBuildEvent_isPresent()
postbuildcommands { "doSomeThing" }
local buffer = get_buffer()
test.string_contains(buffer,'<PostBuildEvent>.*<Command>.*</Command>.*</PostBuildEvent>')
end
function vs10_vcxproj.postBuildEvent_containsCorrectInformationBetweenCommandTag()
postbuildcommands { "doSomeThing" }
local buffer = get_buffer()
test.string_contains(buffer,'<PostBuildEvent>.*<Command>doSomeThing</Command>.*</PostBuildEvent>')
end
function vs10_vcxproj.postBuildEvent_eventEncloseByQuotes_containsCorrectInformationBetweenCommandTag()
postbuildcommands { "\"doSomeThing\"" }
local buffer = get_buffer()
test.string_contains(buffer,'<PostBuildEvent>.*<Command>&quot;doSomeThing&quot;</Command>.*</PostBuildEvent>')
end
function vs10_vcxproj.noExtraWarnings_bufferDoesNotContainSmallerTypeCheck()
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<SmallerTypeCheck>')
end
function vs10_vcxproj.debugAndExtraWarnings_bufferContainsSmallerTypeCheck()
configuration("Debug")
flags {"ExtraWarnings"}
local buffer = get_buffer()
test.string_contains(buffer,'<SmallerTypeCheck>true</SmallerTypeCheck>')
end
function vs10_vcxproj.releaseAndExtraWarnings_bufferDoesNotContainSmallerTypeCheck()
configuration("Release")
flags {"ExtraWarnings"}
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<SmallerTypeCheck>')
end
function vs10_vcxproj.onlyOneProjectConfigurationBlockWhenMultipleConfigs()
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<ItemGroup Label="ProjectConfigurations">.*<ItemGroup Label="ProjectConfigurations">')
end
function vs10_vcxproj.languageC_bufferContainsCompileAsC()
language "C"
local buffer = get_buffer()
test.string_contains(buffer,'<CompileAs>CompileAsC</CompileAs>')
end
local debug_config_pch_string = '<PrecompiledHeader Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'Debug|Win32\'">Create</PrecompiledHeader>'
local release_config_pch_string = debug_config_pch_string:gsub('Debug','Release')
function vs10_vcxproj.noPchFlagSet_bufferDoesNotContainPchCreate()
configuration("Debug")
flags{"NoPCH"}
local buffer = get_buffer()
test.string_does_not_contain(buffer,debug_config_pch_string)
end
function vs10_vcxproj.pchHeaderSetYetPchSourceIsNot_bufferDoesNotContainPchCreate()
configuration("Debug")
pchheader "foo/dummyHeader.h"
local buffer = get_buffer()
test.string_does_not_contain(buffer,debug_config_pch_string)
end
function vs10_vcxproj.pchHeaderAndSourceSet_yetAlsoNoPch_bufferDoesNotContainpchCreate()
configuration('Debug')
pchheader "foo/dummyHeader.h"
pchsource "foo/dummySource.cpp"
flags{"NoPCH"}
local buffer = get_buffer()
test.string_does_not_contain(buffer,debug_config_pch_string)
end
function vs10_vcxproj.pchHeaderAndPchSourceSet_bufferContainPchCreate()
configuration("Debug")
pchheader "foo/dummyHeader.h"
pchsource "foo/dummySource.cpp"
local buffer = get_buffer()
test.string_contains(buffer,debug_config_pch_string)
end
function vs10_vcxproj.wholeProgramOptimizationIsNotSetByDefault_bufferDoesNotContainWholeProgramOptimization()
local buffer = get_buffer()
test.string_does_not_contain(buffer,"WholeProgramOptimization")
end
@@ -0,0 +1,88 @@
--
-- tests/actions/vstudio/vc200x/debugdir.lua
-- Validate handling of the working directory for debugging.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs200x_debugdir = { }
local suite = T.vstudio_vs200x_debugdir
local vc200x = premake.vstudio.vc200x
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
vc200x.debugdir(prj)
end
--
-- Tests
--
function suite.EmptyBlock_OnNoDebugSettings()
prepare()
test.capture [[
<DebugSettings
/>
]]
end
function suite.WorkingDirectory_OnRelativePath()
debugdir "bin/debug"
prepare()
test.capture [[
<DebugSettings
WorkingDirectory="bin\debug"
/>
]]
end
function suite.Arguments()
debugargs { "arg1", "arg2" }
prepare()
test.capture [[
<DebugSettings
CommandArguments="arg1 arg2"
/>
]]
end
T.vc200x_env_args = { }
local vs200x_env_args = T.vc200x_env_args
function vs200x_env_args.environmentArgs_notSet_bufferDoesNotContainEnvironment()
vc200x.environmentargs( {flags={}} )
test.string_does_not_contain(io.endcapture(),'Environment=')
end
function vs200x_env_args.environmentArgs_set_bufferContainsEnvironment()
vc200x.environmentargs( {flags={},environmentargs={'key=value'}} )
test.string_contains(io.endcapture(),'Environment=')
end
function vs200x_env_args.environmentArgs_valueUsesQuotes_quotesMarksReplaced()
vc200x.environmentargs( {flags={},environmentargs={'key="value"'}} )
test.string_contains(io.endcapture(),'Environment="key=&quot;value&quot;"')
end
function vs200x_env_args.environmentArgs_multipleArgs_seperatedUsingCorrectEscape()
vc200x.environmentargs( {flags={},environmentargs={'key=value','foo=bar'}} )
test.string_contains(io.endcapture(),'Environment="key=value&#x0A;foo=bar"')
end
function vs200x_env_args.environmentArgs_withDontMergeFlag_EnvironmentArgsDontMergeEqualsFalse()
vc200x.environmentargs( {flags={EnvironmentArgsDontMerge=1},environmentargs={'key=value'}} )
test.string_contains(io.endcapture(),'EnvironmentMerge="false"')
end
@@ -0,0 +1,43 @@
--
-- tests/actions/vstudio/vc200x/header.lua
-- Validate generation of the project file header block.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs200x_header = { }
local suite = T.vstudio_vs200x_header
local vc200x = premake.vstudio.vc200x
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
vc200x.header('VisualStudioProject')
end
--
-- Tests
--
function suite.On2008()
_ACTION = 'vs2008'
prepare()
test.capture [[
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
]]
end
@@ -0,0 +1,222 @@
--
-- tests/actions/vstudio/vc200x/test_files.lua
-- Validate generation of <files/> block in Visual Studio 200x projects.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.vstudio_vs200x_files = { }
local suite = T.vstudio_vs200x_files
local vc200x = premake.vstudio.vc200x
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
vc200x.Files(prj)
end
--
-- Test grouping and nesting
--
function suite.SimpleSourceFile()
files { "hello.cpp" }
prepare()
test.capture [[
<File
RelativePath="hello.cpp"
>
</File>
]]
end
function suite.SingleFolderLevel()
files { "src/hello.cpp" }
prepare()
test.capture [[
<Filter
Name="src"
Filter=""
>
<File
RelativePath="src\hello.cpp"
>
</File>
</Filter>
]]
end
function suite.MultipleFolderLevels()
files { "src/greetings/hello.cpp" }
prepare()
test.capture [[
<Filter
Name="src"
Filter=""
>
<Filter
Name="greetings"
Filter=""
>
<File
RelativePath="src\greetings\hello.cpp"
>
</File>
</Filter>
</Filter>
]]
end
--
-- Non-source code files, such as header files and documentation, should
-- be marked as such, so the compiler won't attempt to build them.
--
function suite.file_markedAsNonBuildable_onSupportFiles()
language "c"
files { "hello.lua" }
prepare()
test.capture [[
<File
RelativePath="hello.lua"
>
</File>
]]
end
--
-- Mixed language support
--
function suite.CompileAsC_InCppProject()
language "c++"
files { "hello.c" }
prepare()
test.capture [[
<File
RelativePath="hello.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="1"
/>
</FileConfiguration>
</File>
]]
end
function suite.CompileAsCpp_InCProject()
language "c"
files { "hello.cpp" }
prepare()
test.capture [[
<File
RelativePath="hello.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
]]
end
--
-- PCH support
--
function suite.OnPCH_OnWindows()
files { "afxwin.cpp" }
pchsource "afxwin.cpp"
prepare()
test.capture [[
<File
RelativePath="afxwin.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
]]
end
function suite.Files_OnPCH_OnXbox360()
files { "afxwin.cpp" }
pchsource "afxwin.cpp"
platforms { "Xbox360" }
prepare()
test.capture [[
<File
RelativePath="afxwin.cpp"
>
<FileConfiguration
Name="Debug|Xbox 360"
>
<Tool
Name="VCCLX360CompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Xbox 360"
>
<Tool
Name="VCCLX360CompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
]]
end
@@ -0,0 +1,58 @@
--
-- tests/actions/vstudio/vc200x/test_filters.lua
-- Validate generation of filter blocks in Visual Studio 200x C/C++ projects.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vs200x_filters = { }
local suite = T.vs200x_filters
local vc200x = premake.vstudio.vc200x
--
-- Setup/teardown
--
local sln, prj
local os_uuid
function suite.setup()
os_uuid = os.uuid
os.uuid = function() return "00112233-4455-6677-8888-99AABBCCDDEE" end
_ACTION = "vs2008"
sln, prj = test.createsolution()
end
function suite.teardown()
os.uuid = os_uuid
end
local function prepare()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
prj = premake.solution.getproject(sln,1)
end
--
-- File/filter assignment tests
--
function suite.Filter_UsesVirtualForm_OnVpath()
files { "src/hello.cpp" }
vpaths { ["Source Files"] = "**.cpp" }
prepare()
vc200x.Files(prj)
test.capture [[
<Filter
Name="Source Files"
Filter=""
>
<File
RelativePath="src\hello.cpp"
>
</File>
</Filter>
]]
end
@@ -0,0 +1,78 @@
--
-- tests/actions/vstudio/vc2010/test_config_props.lua
-- Validate generation of the configuration property group.
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
--
T.vstudio_vs2010_config_props = { }
local suite = T.vstudio_vs2010_config_props
local vc2010 = premake.vstudio.vc2010
local project = premake.project
--
-- Setup
--
local sln, prj
function suite.setup()
sln, prj = test.createsolution()
end
local function prepare(platform)
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
local cfginfo = sln.vstudio_configs[1]
local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
vc2010.configurationPropertyGroup(cfg, cfginfo)
end
--
-- Check the structure with the default project values.
--
function suite.structureIsCorrect_onDefaultValues()
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
]]
end
--
-- Visual Studio 2012 adds a platform toolset.
--
function suite.structureIsCorrect_onDefaultValues()
_ACTION = "vs2012"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
]]
end
function suite.structureIsCorrect_onDefaultValues_on2013()
_ACTION = "vs2013"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
]]
end
@@ -0,0 +1,96 @@
--
-- tests/actions/vstudio/vc2010/test_debugdir.lua
-- Validate handling of the working directory for debugging.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs2010_debugdir = { }
local suite = T.vstudio_vs2010_debugdir
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
vc2010.debugdir(prj)
end
--
-- Tests
--
function suite.PrintsNothing_OnDebugDirSet()
prepare()
test.capture [[
]]
end
function suite.IsFormattedCorrectly_OnRelativePath()
debugdir "bin/debug"
prepare()
test.capture [[
<LocalDebuggerWorkingDirectory>bin\debug</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
]]
end
function suite.Arguments()
debugargs { "arg1", "arg2" }
prepare()
test.capture [[
<LocalDebuggerCommandArguments>arg1 arg2</LocalDebuggerCommandArguments>
]]
end
T.vs2010_debug_environment = { }
local vs10_debug_environment = T.vs2010_debug_environment
local vs2010 = premake.vstudio.vc2010
function vs10_debug_environment.config_noDebugEnvsTable_bufferDoesNotContainLocalDebuggerEnvironment()
vs2010.debugenvs( {flags={}} )
test.string_does_not_contain(io.endcapture(),'<LocalDebuggerEnvironment>')
end
function vs10_debug_environment.config_NoneEmtpyDebugEnvTable_bufferContainsLocalDebuggerEnvironment()
vs2010.debugenvs({flags={},debugenvs ={'key=value'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerEnvironment>')
end
function vs10_debug_environment.format_listContainsOneEntry_openTagKeyValuePairCloseTag()
vs2010.debugenvs({flags={},debugenvs ={'key=value'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerEnvironment>key=value</LocalDebuggerEnvironment>')
end
function vs10_debug_environment.format_listContainsTwoEntries_openTagFirstPairNewLineSecondPairCloseTag()
vs2010.debugenvs({flags={},debugenvs ={'key=value','foo=bar'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerEnvironment>key=value\nfoo=bar</LocalDebuggerEnvironment>')
end
function vs10_debug_environment.flags_withOutEnvironmentArgsInherit_doesNotContainLocalDebuggerEnvironmentArg()
vs2010.debugenvs({flags={},environmentargs ={'key=value'}} )
test.string_does_not_contain(io.endcapture(),'%$%(LocalDebuggerEnvironment%)')
end
function vs10_debug_environment.flags_withDebugEnvsInherit_endsWithNewLineLocalDebuggerEnvironmentFollowedByClosedTag()
vs2010.debugenvs({flags={DebugEnvsInherit=1},debugenvs ={'key=value'}} )
test.string_contains(io.endcapture(),'\n%$%(LocalDebuggerEnvironment%)</LocalDebuggerEnvironment>')
end
function vs10_debug_environment.flags_withDebugEnvsDontMerge_localDebuggerMergeEnvironmentSetToFalse()
vs2010.debugenvs({flags={DebugEnvsDontMerge=1},debugenvs ={'key=value'}} )
test.string_contains(io.endcapture(),'<LocalDebuggerMergeEnvironment>false</LocalDebuggerMergeEnvironment>')
end
@@ -0,0 +1,103 @@
--
-- tests/actions/vstudio/vc2010/test_files.lua
-- Validate generation of files block in Visual Studio 2010 C/C++ projects.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs2010_files = { }
local suite = T.vstudio_vs2010_files
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
vc2010.files(prj)
end
--
-- Test file groups
--
function suite.SimpleHeaderFile()
files { "include/hello.h" }
prepare()
test.capture [[
<ItemGroup>
<ClInclude Include="include\hello.h" />
</ItemGroup>
]]
end
function suite.SimpleSourceFile()
files { "hello.c" }
prepare()
test.capture [[
<ItemGroup>
<ClCompile Include="hello.c">
</ClCompile>
</ItemGroup>
]]
end
function suite.SimpleObjectFile()
files { "hello.obj" }
prepare()
test.capture [[
<ItemGroup>
<Object Include="hello.obj" />
</ItemGroup>
]]
end
function suite.SimpleNoneFile()
files { "docs/hello.txt" }
prepare()
test.capture [[
<ItemGroup>
<None Include="docs\hello.txt" />
</ItemGroup>
]]
end
function suite.SimpleResourceFile()
files { "resources/hello.rc" }
prepare()
test.capture [[
<ItemGroup>
<ResourceCompile Include="resources\hello.rc" />
</ItemGroup>
]]
end
--
-- Test path handling
--
function suite.MultipleFolderLevels()
files { "src/greetings/hello.c" }
prepare()
test.capture [[
<ItemGroup>
<ClCompile Include="src\greetings\hello.c">
</ClCompile>
</ItemGroup>
]]
end
@@ -0,0 +1,193 @@
--
-- tests/actions/vstudio/vc2010/test_filters.lua
-- Validate generation of filter blocks in Visual Studio 2010 C/C++ projects.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vs2010_filters = { }
local suite = T.vs2010_filters
local vc2010 = premake.vstudio.vc2010
--
-- Setup/teardown
--
local sln, prj
local os_uuid
function suite.setup()
os_uuid = os.uuid
os.uuid = function() return "00112233-4455-6677-8888-99AABBCCDDEE" end
_ACTION = "vs2010"
sln, prj = test.createsolution()
end
function suite.teardown()
os.uuid = os_uuid
end
local function prepare()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
end
--
-- Filter identifiers sections
--
function suite.UniqueIdentifiers_IsEmpty_OnRootFilesOnly()
files { "hello.c", "goodbye.c" }
prepare()
vc2010.filteridgroup(prj)
test.isemptycapture()
end
function suite.UniqueIdentifiers_MergeCommonSubfolders()
files { "src/hello.c", "src/goodbye.c" }
prepare()
vc2010.filteridgroup(prj)
test.capture [[
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
end
function suite.UniqueIdentifiers_ListAllSubfolders()
files { "src/hello.c", "src/departures/goodbye.c" }
prepare()
vc2010.filteridgroup(prj)
test.capture [[
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
<Filter Include="src\departures">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
end
function suite.UniqueIdentifiers_ListVpaths()
files { "hello.c", "goodbye.c" }
vpaths { ["Source Files"] = "**.c" }
prepare()
vc2010.filteridgroup(prj)
test.capture [[
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
end
function suite.UniqueIdentifiers_ListRealAndVpaths()
files { "hello.h", "goodbye.c" }
vpaths { ["Source Files"] = "*.c", ["Header Files"] = "*.h" }
prepare()
vc2010.filteridgroup(prj)
test.capture [[
<ItemGroup>
<Filter Include="Header Files">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files">
<UniqueIdentifier>{00112233-4455-6677-8888-99AABBCCDDEE}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
end
--
-- File/filter assignment tests
--
function suite.FileFilters_NoFilter_OnRootFile()
files { "hello.c", "goodbye.c" }
prepare()
vc2010.filefiltergroup(prj, "ClCompile")
test.capture [[
<ItemGroup>
<ClCompile Include="hello.c" />
<ClCompile Include="goodbye.c" />
</ItemGroup>
]]
end
function suite.FileFilters_NoFilter_OnRealPath()
files { "src/hello.c" }
prepare()
vc2010.filefiltergroup(prj, "ClCompile")
test.capture [[
<ItemGroup>
<ClCompile Include="src\hello.c">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
]]
end
function suite.FileFilters_HasFilter_OnVpath()
files { "src/hello.c" }
vpaths { ["Source Files"] = "**.c" }
prepare()
vc2010.filefiltergroup(prj, "ClCompile")
test.capture [[
<ItemGroup>
<ClCompile Include="src\hello.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
]]
end
function suite.FileFilters_OnIncludeSection()
files { "hello.c", "hello.h", "hello.rc", "hello.txt" }
prepare()
vc2010.filefiltergroup(prj, "ClInclude")
test.capture [[
<ItemGroup>
<ClInclude Include="hello.h" />
</ItemGroup>
]]
end
function suite.FileFilters_OnResourceSection()
files { "hello.c", "hello.h", "hello.rc", "hello.txt" }
prepare()
vc2010.filefiltergroup(prj, "ResourceCompile")
test.capture [[
<ItemGroup>
<ResourceCompile Include="hello.rc" />
</ItemGroup>
]]
end
function suite.FileFilters_OnNoneSection()
files { "hello.c", "hello.h", "hello.rc", "hello.txt" }
prepare()
vc2010.filefiltergroup(prj, "None")
test.capture [[
<ItemGroup>
<None Include="hello.txt" />
</ItemGroup>
]]
end
@@ -0,0 +1,45 @@
--
-- tests/actions/vstudio/vc2010/test_header.lua
-- Validate generation of the project file header block.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs2010_header = { }
local suite = T.vstudio_vs2010_header
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj
function suite.setup()
_ACTION = 'vs2010'
sln = test.createsolution()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
end
--
-- Tests
--
function suite.On2010_WithNoTarget()
vc2010.header()
test.capture [[
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
]]
end
function suite.On2010_WithTarget()
vc2010.header("Build")
test.capture [[
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
]]
end
@@ -0,0 +1,229 @@
--
-- tests/actions/vstudio/vc2010/test_link_settings.lua
-- Validate linker settings in Visual Studio 2010 C/C++ projects.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs2010_link_settings = { }
local suite = T.vstudio_vs2010_link_settings
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj, cfg
function suite.setup()
_ACTION = "vs2010"
sln, prj = test.createsolution()
end
local function prepare(platform)
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
cfg = premake.getconfig(prj, "Debug", platform)
vc2010.link(cfg)
end
--
-- Check the basic element structure for a console application.
--
function suite.writesCorrectSubsystem_onConsoleApp()
kind "ConsoleApp"
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
]]
end
--
-- Check the basic element structure for a windowed application.
--
function suite.writesCorrectSubsystem_onWindowedApp()
kind "WindowedApp"
prepare()
test.capture [[
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
]]
end
--
-- Check the basic element structure for a shared library.
--
function suite.writesCorrectSubsystem_onSharedLib()
kind "SharedLib"
prepare()
test.capture [[
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.dll</OutputFile>
<ImportLibrary>MyProject.lib</ImportLibrary>
</Link>
]]
end
--
-- Check the basic element structure for a static library.
--
function suite.writesCorrectSubsystem_onStaticLib()
kind "StaticLib"
prepare()
test.capture [[
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
]]
end
--
-- Check the structure of the additional library directories element.
--
function suite.additionalLibraryDirectories()
libdirs { "include/GL", "include/lua" }
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<AdditionalLibraryDirectories>include\GL;include\lua;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
]]
end
--
-- Enable debug information if the Symbols flag is specified.
--
function suite.generateDebugInformation_onSymbolsFlag()
flags { "Symbols" }
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
]]
end
--
-- Enable reference optimizing if Optimize flag is specified.
--
function suite.optimizeReferences_onOptimizeFlag()
flags { "Optimize" }
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
]]
end
--
-- Skip the entry point override if the WinMain flag is specified.
--
function suite.noEntryPointElement_onWinMainFlag()
flags { "WinMain" }
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
</Link>
]]
end
--
-- Use the x86 target for Premake's x32 platform.
--
function suite.writesCorrectTarget_onX32Platform()
platforms "x32"
prepare("x32")
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
<TargetMachine>MachineX86</TargetMachine>
</Link>
]]
end
--
-- Use the x64 target for Premake's x64 platform.
--
function suite.writesCorrectTarget_onX64Platform()
platforms { "x64" }
prepare("x64")
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
<TargetMachine>MachineX64</TargetMachine>
</Link>
]]
end
--
-- Correctly handle module definition (.def) files.
--
function suite.recognizesModuleDefinitionFile()
files { "hello.cpp", "hello.def" }
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
<ModuleDefinitionFile>hello.def</ModuleDefinitionFile>
</Link>
]]
end
@@ -0,0 +1,93 @@
--
-- tests/actions/vstudio/vc2010/test_links.lua
-- Validate linking and project references in Visual Studio 2010 C/C++ projects.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs2010_links = { }
local suite = T.vstudio_vs2010_links
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj, prj2
function suite.setup()
os_uuid = os.uuid
os.uuid = function() return "00112233-4455-6677-8888-99AABBCCDDEE" end
sln = test.createsolution()
test.createproject(sln)
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
prj2 = premake.solution.getproject(sln, 2)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
end
--
-- If there are no sibling projects listed in links(), then the
-- entire project references item group should be skipped.
--
function suite.noProjectReferencesGroup_onNoSiblingReferences()
prepare()
vc2010.projectReferences(prj2)
test.isemptycapture()
end
--
-- If a sibling project is listed in links(), an item group should
-- be written with a reference to that sibling project.
--
function suite.projectReferenceAdded_onSiblingProjectLink()
links { "MyProject" }
prepare()
vc2010.projectReferences(prj2)
test.capture [[
<ItemGroup>
<ProjectReference Include="MyProject.vcproj">
<Project>{00112233-4455-6677-8888-99AABBCCDDEE}</Project>
</ProjectReference>
</ItemGroup>
]]
end
--
-- If a sibling library is listed in links(), it should NOT appear in
-- the additional dependencies element. Visual Studio will figure that
-- out from the project reference item group.
--
function suite.noDependencies_onOnlySiblingProjectLinks()
links { "MyProject" }
prepare()
vc2010.additionalDependencies(prj2)
test.isemptycapture()
end
--
-- If a mix of sibling and system links are listed, only the system
-- libraries should appear in the additional dependencies element.
--
function suite.onlySystemDependencies_OnSiblingProjectLink()
links { "MyProject", "kernel32" }
prepare()
vc2010.additionalDependencies(prj2)
test.capture [[
<AdditionalDependencies>kernel32;%(AdditionalDependencies)</AdditionalDependencies>
]]
end
@@ -0,0 +1,179 @@
--
-- tests/actions/vstudio/vc2010/test_output_props.lua
-- Validate generation of the output property groups.
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
--
T.vstudio_vs2010_output_props = {}
local suite = T.vstudio_vs2010_output_props
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln
function suite.setup()
_ACTION = "vs2010"
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
local prj = premake.solution.getproject(sln, 1)
vc2010.outputProperties(prj)
end
--
-- Check the structure with the default project values.
--
function suite.structureIsCorrect_onDefaultValues()
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\</OutDir>
<IntDir>obj\Debug\</IntDir>
<TargetName>MyProject</TargetName>
<TargetExt>.exe</TargetExt>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
]]
end
--
-- Static libraries should omit the link incremental element entirely.
--
function suite.omitLinkIncremental_onStaticLib()
kind "StaticLib"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\</OutDir>
<IntDir>obj\Debug\</IntDir>
<TargetName>MyProject</TargetName>
<TargetExt>.lib</TargetExt>
</PropertyGroup>
]]
end
--
-- Optimized builds should not link incrementally.
--
function suite.noIncrementalLink_onOptimizedBuild()
flags "Optimize"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\</OutDir>
<IntDir>obj\Debug\</IntDir>
<TargetName>MyProject</TargetName>
<TargetExt>.exe</TargetExt>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
]]
end
--
-- The target directory is applied, if specified.
--
function suite.outDir_onTargetDir()
targetdir "../bin"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>..\bin\</OutDir>
]]
end
--
-- The objeccts directory is applied, if specified.
--
function suite.intDir_onTargetDir()
objdir "../tmp"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\</OutDir>
<IntDir>..\tmp\Debug\</IntDir>
]]
end
--
-- The target name is applied, if specified.
--
function suite.targetName_onTargetName()
targetname "MyTarget"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\</OutDir>
<IntDir>obj\Debug\</IntDir>
<TargetName>MyTarget</TargetName>
]]
end
--
-- A target extension should be used if specified.
--
function suite.targetExt_onTargetExtension()
targetextension ".delta"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\</OutDir>
<IntDir>obj\Debug\</IntDir>
<TargetName>MyProject</TargetName>
<TargetExt>.delta</TargetExt>
]]
end
--
-- If the NoImportLib flag is set, add the IgnoreImportLibrary element.
--
function suite.ignoreImportLib_onNoImportLib()
kind "SharedLib"
flags "NoImportLib"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\</OutDir>
<IntDir>obj\Debug\</IntDir>
<TargetName>MyProject</TargetName>
<TargetExt>.dll</TargetExt>
<IgnoreImportLibrary>true</IgnoreImportLibrary>
]]
end
--
-- If the NoManifest flag is set, add the GenerateManifest element.
--
function suite.generateManifest_onNoManifest()
flags "NoManifest"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\</OutDir>
<IntDir>obj\Debug\</IntDir>
<TargetName>MyProject</TargetName>
<TargetExt>.exe</TargetExt>
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
]]
end
@@ -0,0 +1,63 @@
--
-- tests/actions/vstudio/vc2010/test_pch.lua
-- Validate generation of files block in Visual Studio 2010 C/C++ projects.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs2010_pch = { }
local suite = T.vstudio_vs2010_pch
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
vc2010.files(prj)
end
--
-- Tests
--
function suite.pch_OnProject()
files { "afxwin.cpp" }
pchheader "afxwin.h"
pchsource "afxwin.cpp"
prepare()
test.capture [[
<ItemGroup>
<ClCompile Include="afxwin.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
]]
end
function suite.pch_OnSingleConfig()
files { "afxwin.cpp" }
configuration "Debug"
pchheader "afxwin.h"
pchsource "afxwin.cpp"
prepare()
test.capture [[
<ItemGroup>
<ClCompile Include="afxwin.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
]]
end
@@ -0,0 +1,78 @@
--
-- tests/actions/vstudio/vc2010/test_project_refs.lua
-- Validate project references in Visual Studio 2010 C/C++ projects.
-- Copyright (c) 2011-2012 Jason Perkins and the Premake project
--
T.vstudio_vs2010_project_refs = { }
local suite = T.vstudio_vs2010_project_refs
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj
function suite.setup()
_ACTION = "vs2010"
sln = test.createsolution()
uuid "00112233-4455-6677-8888-99AABBCCDDEE"
test.createproject(sln)
end
local function prepare(platform)
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 2)
vc2010.projectReferences(prj)
end
--
-- If there are no sibling projects listed in links(), then the
-- entire project references item group should be skipped.
--
function suite.noProjectReferencesGroup_onNoSiblingReferences()
prepare()
test.isemptycapture()
end
--
-- If a sibling project is listed in links(), an item group should
-- be written with a reference to that sibling project.
--
function suite.projectReferenceAdded_onSiblingProjectLink()
links { "MyProject" }
prepare()
test.capture [[
<ItemGroup>
<ProjectReference Include="MyProject.vcxproj">
<Project>{00112233-4455-6677-8888-99AABBCCDDEE}</Project>
</ProjectReference>
</ItemGroup>
]]
end
--
-- Project references should always be specified relative to the
-- project doing the referencing.
--
function suite.referencesAreRelative_onDifferentProjectLocation()
links { "MyProject" }
location "build/MyProject2"
project("MyProject")
location "build/MyProject"
prepare()
test.capture [[
<ItemGroup>
<ProjectReference Include="..\MyProject\MyProject.vcxproj">
<Project>{00112233-4455-6677-8888-99AABBCCDDEE}</Project>
</ProjectReference>
</ItemGroup>
]]
end
@@ -0,0 +1,99 @@
--
-- tests/baking/test_merging.lua
-- Verifies different field types are merged properly during baking.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.baking_merging = { }
local suite = T.baking_merging
--
-- Setup code
--
local sln, prj, cfg
function suite.setup()
sln = solution "MySolution"
configurations { "Debug", "Release" }
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
end
--
-- String value tests
--
function suite.Strings_AreReplaced()
kind "SharedLib"
project "MyProject"
kind "StaticLib"
prepare()
test.isequal("StaticLib", prj.kind)
end
function suite.Strings_KeepPreviousValue()
kind "SharedLib"
project "MyProject"
prepare()
test.isequal("SharedLib", prj.kind)
end
--
-- List tests
--
function suite.Lists_KeepPreviousValue()
project "MyProject"
prepare()
test.isequal("Debug:Release", table.concat(prj.configurations, ":"))
end
function suite.Lists_AreJoined()
defines { "SOLUTION" }
project "MyProject"
defines { "PROJECT" }
prepare()
test.isequal("SOLUTION:PROJECT", table.concat(prj.defines, ":"))
end
function suite.Lists_RemoveDuplicates()
defines { "SOLUTION", "DUPLICATE" }
project "MyProject"
defines { "PROJECT", "DUPLICATE" }
prepare()
test.isequal("SOLUTION:DUPLICATE:PROJECT", table.concat(prj.defines, ":"))
end
function suite.Lists_FlattensNestedTables()
defines { "ROOT", { "NESTED" } }
project "MyProject"
prepare()
test.isequal("ROOT:NESTED", table.concat(prj.defines, ":"))
end
--
-- Key/value tests
--
function suite.KeyValue_AreMerged()
vpaths { ["Solution"] = "*.sln" }
project "MyProject"
vpaths { ["Project"] = "*.prj" }
prepare()
test.isequal({"*.sln"}, prj.vpaths["Solution"])
test.isequal({"*.prj"}, prj.vpaths["Project"])
end
function suite.KeyValue_MergesValues()
vpaths { ["Solution"] = "*.sln", ["Project"] = "*.prj" }
project "MyProject"
vpaths { ["Project"] = "*.prjx" }
prepare()
test.isequal({"*.prj","*.prjx"}, prj.vpaths["Project"])
end
@@ -0,0 +1,73 @@
--
-- tests/base/test_action.lua
-- Automated test suite for the action list.
-- Copyright (c) 2009 Jason Perkins and the Premake project
--
T.action = { }
--
-- Setup/teardown
--
local fake = {
trigger = "fake",
description = "Fake action used for testing",
}
function T.action.setup()
premake.action.list["fake"] = fake
solution "MySolution"
configurations "Debug"
project "MyProject"
premake.bake.buildconfigs()
end
function T.action.teardown()
premake.action.list["fake"] = nil
end
--
-- Tests for call()
--
function T.action.CallCallsExecuteIfPresent()
local called = false
fake.execute = function () called = true end
premake.action.call("fake")
test.istrue(called)
end
function T.action.CallCallsOnSolutionIfPresent()
local called = false
fake.onsolution = function () called = true end
premake.action.call("fake")
test.istrue(called)
end
function T.action.CallCallsOnProjectIfPresent()
local called = false
fake.onproject = function () called = true end
premake.action.call("fake")
test.istrue(called)
end
function T.action.CallSkipsCallbacksIfNotPresent()
test.success(premake.action.call, "fake")
end
--
-- Tests for set()
--
function T.action.set_SetsActionOS()
local oldos = _OS
_OS = "linux"
premake.action.set("vs2008")
test.isequal(_OS, "windows")
_OS = oldos
end
@@ -0,0 +1,404 @@
--
-- tests/base/test_api.lua
-- Automated test suite for the project API support functions.
-- Copyright (c) 2008-2011 Jason Perkins and the Premake project
--
T.api = { }
local suite = T.api
local sln
function suite.setup()
sln = solution "MySolution"
end
--
-- premake.getobject() tests
--
function suite.getobject_RaisesError_OnNoContainer()
premake.CurrentContainer = nil
c, err = premake.getobject("container")
test.istrue(c == nil)
test.isequal("no active solution or project", err)
end
function suite.getobject_RaisesError_OnNoActiveSolution()
premake.CurrentContainer = { }
c, err = premake.getobject("solution")
test.istrue(c == nil)
test.isequal("no active solution", err)
end
function suite.getobject_RaisesError_OnNoActiveConfig()
premake.CurrentConfiguration = nil
c, err = premake.getobject("config")
test.istrue(c == nil)
test.isequal("no active solution, project, or configuration", err)
end
--
-- premake.setarray() tests
--
function suite.setarray_Inserts_OnStringValue()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { }
premake.setarray("config", "myfield", "hello")
test.isequal("hello", premake.CurrentConfiguration.myfield[1])
end
function suite.setarray_Inserts_OnTableValue()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { }
premake.setarray("config", "myfield", { "hello", "goodbye" })
test.isequal("hello", premake.CurrentConfiguration.myfield[1])
test.isequal("goodbye", premake.CurrentConfiguration.myfield[2])
end
function suite.setarray_Appends_OnNewValues()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { "hello" }
premake.setarray("config", "myfield", "goodbye")
test.isequal("hello", premake.CurrentConfiguration.myfield[1])
test.isequal("goodbye", premake.CurrentConfiguration.myfield[2])
end
function suite.setarray_FlattensTables()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { }
premake.setarray("config", "myfield", { {"hello"}, {"goodbye"} })
test.isequal("hello", premake.CurrentConfiguration.myfield[1])
test.isequal("goodbye", premake.CurrentConfiguration.myfield[2])
end
function suite.setarray_RaisesError_OnInvalidValue()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { }
ok, err = pcall(function () premake.setarray("config", "myfield", "bad", { "Good", "Better", "Best" }) end)
test.isfalse(ok)
end
function suite.setarray_CorrectsCase_OnConstrainedValue()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = { }
premake.setarray("config", "myfield", "better", { "Good", "Better", "Best" })
test.isequal("Better", premake.CurrentConfiguration.myfield[1])
end
--
-- premake.setstring() tests
--
function suite.setstring_Sets_OnNewProperty()
premake.CurrentConfiguration = { }
premake.setstring("config", "myfield", "hello")
test.isequal("hello", premake.CurrentConfiguration.myfield)
end
function suite.setstring_Overwrites_OnExistingProperty()
premake.CurrentConfiguration = { }
premake.CurrentConfiguration.myfield = "hello"
premake.setstring("config", "myfield", "goodbye")
test.isequal("goodbye", premake.CurrentConfiguration.myfield)
end
function suite.setstring_RaisesError_OnInvalidValue()
premake.CurrentConfiguration = { }
ok, err = pcall(function () premake.setstring("config", "myfield", "bad", { "Good", "Better", "Best" }) end)
test.isfalse(ok)
end
function suite.setstring_CorrectsCase_OnConstrainedValue()
premake.CurrentConfiguration = { }
premake.setstring("config", "myfield", "better", { "Good", "Better", "Best" })
test.isequal("Better", premake.CurrentConfiguration.myfield)
end
--
-- premake.setkeyvalue() tests
--
function suite.setkeyvalue_Inserts_OnStringValue()
premake.CurrentConfiguration = { }
premake.setkeyvalue("config", "vpaths", { ["Headers"] = "*.h" })
test.isequal({"*.h"}, premake.CurrentConfiguration.vpaths["Headers"])
end
function suite.setkeyvalue_Inserts_OnTableValue()
premake.CurrentConfiguration = { }
premake.setkeyvalue("config", "vpaths", { ["Headers"] = {"*.h","*.hpp"} })
test.isequal({"*.h","*.hpp"}, premake.CurrentConfiguration.vpaths["Headers"])
end
function suite.setkeyvalue_Inserts_OnEmptyStringKey()
premake.CurrentConfiguration = { }
premake.setkeyvalue("config", "vpaths", { [""] = "src" })
test.isequal({"src"}, premake.CurrentConfiguration.vpaths[""])
end
function suite.setkeyvalue_RaisesError_OnString()
premake.CurrentConfiguration = { }
ok, err = pcall(function () premake.setkeyvalue("config", "vpaths", "Headers") end)
test.isfalse(ok)
end
function suite.setkeyvalue_InsertsString_IntoExistingKey()
premake.CurrentConfiguration = { }
premake.setkeyvalue("config", "vpaths", { ["Headers"] = "*.h" })
premake.setkeyvalue("config", "vpaths", { ["Headers"] = "*.hpp" })
test.isequal({"*.h","*.hpp"}, premake.CurrentConfiguration.vpaths["Headers"])
end
function suite.setkeyvalue_InsertsTable_IntoExistingKey()
premake.CurrentConfiguration = { }
premake.setkeyvalue("config", "vpaths", { ["Headers"] = {"*.h"} })
premake.setkeyvalue("config", "vpaths", { ["Headers"] = {"*.hpp"} })
test.isequal({"*.h","*.hpp"}, premake.CurrentConfiguration.vpaths["Headers"])
end
--
-- accessor tests
--
function suite.accessor_CanRetrieveString()
sln.blocks[1].kind = "ConsoleApp"
test.isequal("ConsoleApp", kind())
end
--
-- solution() tests
--
function suite.solution_SetsCurrentContainer_OnName()
test.istrue(sln == premake.CurrentContainer)
end
function suite.solution_CreatesNewObject_OnNewName()
solution "MySolution2"
test.isfalse(sln == premake.CurrentContainer)
end
function suite.solution_ReturnsPrevious_OnExistingName()
solution "MySolution2"
local sln2 = solution "MySolution"
test.istrue(sln == sln2)
end
function suite.solution_SetsCurrentContainer_OnExistingName()
solution "MySolution2"
solution "MySolution"
test.istrue(sln == premake.CurrentContainer)
end
function suite.solution_ReturnsNil_OnNoActiveSolutionAndNoName()
premake.CurrentContainer = nil
test.isnil(solution())
end
function suite.solution_ReturnsCurrentSolution_OnActiveSolutionAndNoName()
test.istrue(sln == solution())
end
function suite.solution_ReturnsCurrentSolution_OnActiveProjectAndNoName()
project "MyProject"
test.istrue(sln == solution())
end
function suite.solution_LeavesProjectActive_OnActiveProjectAndNoName()
local prj = project "MyProject"
solution()
test.istrue(prj == premake.CurrentContainer)
end
function suite.solution_LeavesConfigActive_OnActiveSolutionAndNoName()
local cfg = configuration "windows"
solution()
test.istrue(cfg == premake.CurrentConfiguration)
end
function suite.solution_LeavesConfigActive_OnActiveProjectAndNoName()
project "MyProject"
local cfg = configuration "windows"
solution()
test.istrue(cfg == premake.CurrentConfiguration)
end
function suite.solution_SetsName_OnNewName()
test.isequal("MySolution", sln.name)
end
function suite.solution_AddsNewConfig_OnNewName()
test.istrue(#sln.blocks == 1)
end
function suite.solution_AddsNewConfig_OnName()
local num = #sln.blocks
solution "MySolution"
test.istrue(#sln.blocks == num + 1)
end
--
-- configuration() tests
--
function suite.configuration_RaisesError_OnNoContainer()
premake.CurrentContainer = nil
local fn = function() configuration{"Debug"} end
ok, err = pcall(fn)
test.isfalse(ok)
end
function suite.configuration_SetsCurrentConfiguration_OnKeywords()
local cfg = configuration {"Debug"}
test.istrue(premake.CurrentConfiguration == cfg)
end
function suite.configuration_AddsToContainer_OnKeywords()
local cfg = configuration {"Debug"}
test.istrue(cfg == sln.blocks[#sln.blocks])
end
function suite.configuration_ReturnsCurrent_OnNoKeywords()
local cfg = configuration()
test.istrue(cfg == sln.blocks[1])
end
function suite.configuration_SetsTerms()
local cfg = configuration {"aa", "bb"}
test.isequal({"aa", "bb"}, cfg.terms)
end
function suite.configuration_SetsTermsWithNestedTables()
local cfg = configuration { {"aa", "bb"}, "cc" }
test.isequal({"aa", "bb", "cc"}, cfg.terms)
end
function suite.configuration_CanReuseTerms()
local cfg = configuration { "aa", "bb" }
local cfg2 = configuration { cfg.terms, "cc" }
test.isequal({"aa", "bb", "cc"}, cfg2.terms)
end
--
-- project() tests
--
function suite.project_RaisesError_OnNoSolution()
premake.CurrentContainer = nil
local fn = function() project("MyProject") end
ok, err = pcall(fn)
test.isfalse(ok)
end
function suite.project_SetsCurrentContainer_OnName()
local prj = project "MyProject"
test.istrue(prj == premake.CurrentContainer)
end
function suite.project_CreatesNewObject_OnNewName()
local prj = project "MyProject"
local pr2 = project "MyProject2"
test.isfalse(prj == premake.CurrentContainer)
end
function suite.project_AddsToSolution_OnNewName()
local prj = project "MyProject"
test.istrue(prj == sln.projects[1])
end
function suite.project_ReturnsPrevious_OnExistingName()
local prj = project "MyProject"
local pr2 = project "MyProject2"
local pr3 = project "MyProject"
test.istrue(prj == pr3)
end
function suite.project_SetsCurrentContainer_OnExistingName()
local prj = project "MyProject"
local pr2 = project "MyProject2"
local pr3 = project "MyProject"
test.istrue(prj == premake.CurrentContainer)
end
function suite.project_ReturnsNil_OnNoActiveProjectAndNoName()
test.isnil(project())
end
function suite.project_ReturnsCurrentProject_OnActiveProjectAndNoName()
local prj = project "MyProject"
test.istrue(prj == project())
end
function suite.project_LeavesProjectActive_OnActiveProjectAndNoName()
local prj = project "MyProject"
project()
test.istrue(prj == premake.CurrentContainer)
end
function suite.project_LeavesConfigActive_OnActiveProjectAndNoName()
local prj = project "MyProject"
local cfg = configuration "Windows"
project()
test.istrue(cfg == premake.CurrentConfiguration)
end
function suite.project_SetsName_OnNewName()
prj = project("MyProject")
test.isequal("MyProject", prj.name)
end
function suite.project_SetsSolution_OnNewName()
prj = project("MyProject")
test.istrue(sln == prj.solution)
end
function suite.project_SetsConfiguration()
prj = project("MyProject")
test.istrue(premake.CurrentConfiguration == prj.blocks[1])
end
function suite.project_SetsUUID()
local prj = project "MyProject"
test.istrue(prj.uuid)
end
--
-- uuid() tests
--
function suite.uuid_makes_uppercase()
premake.CurrentContainer = {}
uuid "7CBB5FC2-7449-497f-947F-129C5129B1FB"
test.isequal(premake.CurrentContainer.uuid, "7CBB5FC2-7449-497F-947F-129C5129B1FB")
end
--
-- Fields with allowed value lists should be case-insensitive.
--
function suite.flags_onCaseMismatch()
premake.CurrentConfiguration = {}
flags "symbols"
test.isequal(premake.CurrentConfiguration.flags[1], "Symbols")
end
function suite.flags_onCaseMismatchAndAlias()
premake.CurrentConfiguration = {}
flags "optimisespeed"
test.isequal(premake.CurrentConfiguration.flags[1], "OptimizeSpeed")
end
@@ -0,0 +1,174 @@
--
-- tests/test_baking.lua
-- Automated test suite for the configuration baking functions.
-- Copyright (c) 2009, 2010 Jason Perkins and the Premake project
--
T.baking = { }
local suite = T.baking
--
-- Setup code
--
local prj, cfg
function suite.setup()
_ACTION = "gmake"
solution "MySolution"
configurations { "Debug", "Release" }
platforms { "x32", "ps3" }
defines "SOLUTION"
configuration "Debug"
defines "SOLUTION_DEBUG"
prj = project "MyProject"
language "C"
kind "SharedLib"
targetdir "../bin"
defines "PROJECT"
configuration "Debug"
defines "DEBUG"
configuration "Release"
defines "RELEASE"
configuration "native"
defines "NATIVE"
configuration "x32"
defines "X86_32"
configuration "x64"
defines "X86_64"
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.getconfig(prj)
cfg = premake.getconfig(prj, "Debug")
end
--
-- Tests
--
function suite.ProjectWideSettings()
prepare()
test.isequal("SOLUTION:PROJECT:NATIVE", table.concat(prj.defines,":"))
end
function suite.BuildCfgSettings()
prepare()
test.isequal("SOLUTION:SOLUTION_DEBUG:PROJECT:DEBUG:NATIVE", table.concat(cfg.defines,":"))
end
function suite.PlatformSettings()
prepare()
local cfg = premake.getconfig(prj, "Debug", "x32")
test.isequal("SOLUTION:SOLUTION_DEBUG:PROJECT:DEBUG:X86_32", table.concat(cfg.defines,":"))
end
function suite.SetsConfigName()
prepare()
local cfg = premake.getconfig(prj, "Debug", "x32")
test.isequal("Debug", cfg.name)
end
function suite.SetsPlatformName()
prepare()
local cfg = premake.getconfig(prj, "Debug", "x32")
test.isequal("x32", cfg.platform)
end
function suite.SetsPlatformNativeName()
test.isequal("Native", cfg.platform)
end
function suite.SetsShortName()
prepare()
local cfg = premake.getconfig(prj, "Debug", "x32")
test.isequal("debug32", cfg.shortname)
end
function suite.SetsNativeShortName()
prepare()
test.isequal("debug", cfg.shortname)
end
function suite.SetsLongName()
prepare()
local cfg = premake.getconfig(prj, "Debug", "x32")
test.isequal("Debug|x32", cfg.longname)
end
function suite.SetsNativeLongName()
prepare()
test.isequal("Debug", cfg.longname)
end
function suite.SetsProject()
prepare()
local cfg = premake.getconfig(prj, "Debug", "x32")
test.istrue(prj.project == cfg.project)
end
--
-- Target system testing
--
function suite.SetsTargetSystem_OnNative()
prepare()
test.isequal(os.get(), cfg.system)
end
function suite.SetTargetSystem_OnCrossCompiler()
prepare()
local cfg = premake.getconfig(prj, "Debug", "PS3")
test.isequal("PS3", cfg.system)
end
--
-- Configuration-specific kinds
--
function suite.SetsConfigSpecificKind()
configuration "Debug"
kind "ConsoleApp"
prepare()
test.isequal("ConsoleApp", cfg.kind)
end
--
-- Platform kind translation
--
function suite.SetsTargetKind_OnSupportedKind()
prepare()
test.isequal("SharedLib", cfg.kind)
end
function suite.SetsTargetKind_OnUnsupportedKind()
prepare()
local cfg = premake.getconfig(prj, "Debug", "PS3")
test.isequal("StaticLib", cfg.kind)
end
@@ -0,0 +1,98 @@
--
-- tests/test_config.lua
-- Automated test suite for the configuration handling functions.
-- Copyright (c) 2010 Jason Perkins and the Premake project
--
T.config = { }
local suite = T.config
--
-- Setup/Teardown
--
function suite.setup()
sln = test.createsolution()
end
local cfg
local function prepare()
premake.bake.buildconfigs()
cfg = premake.solution.getproject(sln, 1)
end
--
-- Debug/Release build testing
--
function suite.IsDebug_ReturnsFalse_EnglishSpellingOfOptimiseFlag()
flags { "Optimise" }
prepare()
return test.isfalse(premake.config.isdebugbuild(cfg))
end
function suite.IsDebug_ReturnsFalse_EnglishSpellingOfOptimiseSizeFlag()
flags { "OptimiseSize" }
prepare()
return test.isfalse(premake.config.isdebugbuild(cfg))
end
function suite.IsDebug_ReturnsFalse_EnglishSpellingOfOptimiseSpeedFlag()
flags { "OptimiseSpeed" }
prepare()
return test.isfalse(premake.config.isdebugbuild(cfg))
end
function suite.IsDebug_ReturnsFalse_OnOptimizeFlag()
flags { "Optimize" }
prepare()
return test.isfalse(premake.config.isdebugbuild(cfg))
end
function suite.IsDebug_ReturnsFalse_OnOptimizeSizeFlag()
flags { "OptimizeSize" }
prepare()
return test.isfalse(premake.config.isdebugbuild(cfg))
end
function suite.IsDebug_ReturnsFalse_OnOptimizeSpeedFlag()
flags { "OptimizeSpeed" }
prepare()
return test.isfalse(premake.config.isdebugbuild(cfg))
end
function suite.IsDebug_ReturnsFalse_OnNoSymbolsFlag()
prepare()
return test.isfalse(premake.config.isdebugbuild(cfg))
end
function suite.IsDebug_ReturnsTrue_OnSymbolsFlag()
flags { "Symbols" }
prepare()
return test.istrue(premake.config.isdebugbuild(cfg))
end
function suite.shouldIncrementallyLink_staticLib_returnsFalse()
kind "StaticLib"
prepare()
return test.isfalse(premake.config.isincrementallink(cfg))
end
function suite.shouldIncrementallyLink_optimizeFlagSet_returnsFalse()
flags { "Optimize" }
prepare()
return test.isfalse(premake.config.isincrementallink(cfg))
end
function suite.shouldIncrementallyLink_NoIncrementalLinkFlag_returnsFalse()
flags { "NoIncrementalLink" }
prepare()
return test.isfalse(premake.config.isincrementallink(cfg))
end
function suite.shouldIncrementallyLink_notStaticLib_NoIncrementalLinkFlag_noOptimiseFlag_returnsTrue()
prepare()
return test.istrue(premake.config.isincrementallink(cfg))
end
@@ -0,0 +1,192 @@
T.config_bug_report = { }
local config_bug = T.config_bug_report
local vs10_helpers = premake.vstudio.vs10_helpers
local sln, prjA,prjB,prjC,prjD,prjE
function config_bug.teardown()
sln = nil
prjA = nil
prjB = nil
prjC = nil
prjD = nil
prjE = nil
end
function config_bug.setup()
end
local config_bug_updated = function ()
local setCommonLibraryConfig = function()
configuration "Debug or Release"
kind "StaticLib"
configuration "DebugDLL or ReleaseDLL"
kind "SharedLib"
end
sln = solution "Test"
configurations { "Debug", "Release", "DebugDLL", "ReleaseDLL" }
language "C++"
prjA = project "A"
files { "a.cpp" }
setCommonLibraryConfig()
prjB = project "B"
files { "b.cpp" }
setCommonLibraryConfig()
configuration "SharedLib"
links { "A" }
prjC = project "C"
files { "c.cpp" }
setCommonLibraryConfig()
configuration "SharedLib"
links { "A", "B" }
prjD = project "D"
files { "d.cpp" }
setCommonLibraryConfig()
configuration "SharedLib"
links { "A", "B", "C" }
prjE = project "Executable"
kind "WindowedApp"
links { "A", "B", "C", "D" }
end
local kindSetOnConfiguration_and_linkSetOnSharedLibProjB = function (config_kind)
sln = solution "DontCare"
configurations { "DebugDLL"}
configuration "DebugDLL"
kind(config_kind)
prjA = project "A"
prjB = project "B"
configuration { config_kind }
links { "A" }
end
local sharedLibKindSetOnProject_and_linkSetOnSharedLibProjB = function ()
sln = solution "DontCare"
configurations { "DebugDLL" }
project "A"
prjB = project "B"
configuration "DebugDLL"
kind "SharedLib"
configuration "SharedLib"
links { "A" }
defines {"defineSet"}
end
local kindSetOnConfiguration_and_linkSetOnBundleProjB = function (config_kind)
sln = solution "DontCare"
configurations { "DebugDLL"}
configuration "DebugDLL"
kind(config_kind)
prjA = project "A"
prjB = project "B"
configuration { config_kind }
links { "A" }
end
local sharedLibKindSetOnProject_and_linkSetOnBundleProjB = function ()
sln = solution "DontCare"
configurations { "DebugDLL" }
project "A"
prjB = project "B"
configuration "DebugDLL"
kind "Bundle"
configuration "Bundle"
links { "A" }
defines {"defineSet"}
end
function kind_set_on_project_config_block()
sln = solution "DontCare"
configurations { "DebugDLL" }
local A = project "A"
configuration "DebugDLL"
kind "SharedLib"
defines {"defineSet"}
return A
end
function config_bug.bugUpdated_prjBLinksContainsA()
config_bug_updated()
premake.bake.buildconfigs()
local conf = premake.getconfig(prjB,"DebugDLL","Native")
test.isnotnil(conf.links.A)
end
function config_bug.kindSetOnProjectConfigBlock_projKindEqualsSharedLib()
local proj = kind_set_on_project_config_block()
premake.bake.buildconfigs()
local conf = premake.getconfig(proj,"DebugDLL","Native")
test.isequal("SharedLib",conf.kind)
end
function config_bug.kindSetOnProjectConfigBlock_projKindEqualsBundle()
local proj = kind_set_on_project_config_block()
premake.bake.buildconfigs()
local conf = premake.getconfig(proj,"DebugDLL","Native")
test.isequal("Bundle",conf.kind)
end
function config_bug.defineSetOnProjectConfigBlock_projDefineSetIsNotNil()
local proj = kind_set_on_project_config_block()
premake.bake.buildconfigs()
local conf = premake.getconfig(proj,"DebugDLL","Native")
test.isnotnil(conf.defines.defineSet)
end
function config_bug.defineSetInBlockInsideProject ()
sharedLibKindSetOnProject_and_linkSetOnSharedLibProjB()
premake.bake.buildconfigs()
local conf = premake.getconfig(prjB,"DebugDLL","Native")
test.isnotnil(conf.defines.defineSet)
end
function config_bug.whenKindSetOnProject_PrjBLinksContainsA()
sharedLibKindSetOnProject_and_linkSetOnSharedLibProjB()
premake.bake.buildconfigs()
local conf = premake.getconfig(prjB,"DebugDLL","Native")
test.isnotnil(conf.links.A)
end
function config_bug.whenKindSetOnConfiguration_prjBLinksContainsA_StaticLib()
-- sharedLibKindSetOnConfiguration_and_linkSetOnSharedLibProjB()
kindSetOnConfiguration_and_linkSetOnSharedLibProjB("StaticLib")
premake.bake.buildconfigs()
local config = premake.getconfig(prjB,"DebugDLL","Native")
test.isnotnil(config.links.A)
end
function config_bug.whenKindSetOnConfiguration_prjBLinksContainsA()
-- sharedLibKindSetOnConfiguration_and_linkSetOnSharedLibProjB()
kindSetOnConfiguration_and_linkSetOnSharedLibProjB("SharedLib")
premake.bake.buildconfigs()
local config = premake.getconfig(prjB,"DebugDLL","Native")
test.isnotnil(config.links.A)
end
function config_bug.whenKindSetOnConfiguration_prjBLinksContainsA_bundle()
-- sharedLibKindSetOnConfiguration_and_linkSetOnBundleProjB()
kindSetOnConfiguration_and_linkSetOnBundleProjB("Bundle")
premake.bake.buildconfigs()
local config = premake.getconfig(prjB,"DebugDLL","Native")
test.isnotnil(config.links.A)
end
@@ -0,0 +1,100 @@
--
-- tests/base/test_location.lua
-- Automated tests for the location() function.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.base_location = { }
local suite = T.base_location
--
-- Setup/Teardown
--
function suite.setup()
sln = solution "MySolution"
configurations { "Debug", "Release" }
language "C"
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
end
--
-- Test no location set
--
function suite.solutionUsesCwd_OnNoLocationSet()
project "MyProject"
prepare()
test.isequal(os.getcwd(), sln.location)
end
function suite.projectUsesCwd_OnNoLocationSet()
project "MyProject"
prepare()
test.isequal(os.getcwd(), prj.location)
end
--
-- Test with location set on solution only
--
function suite.solutionUsesLocation_OnSolutionOnly()
location "build"
project "MyProject"
prepare()
test.isequal(path.join(os.getcwd(), "build"), sln.location)
end
function suite.projectUsesLocation_OnSolutionOnly()
location "build"
project "MyProject"
prepare()
test.isequal(path.join(os.getcwd(), "build"), prj.location)
end
--
-- Test with location set on project only
--
function suite.solutionUsesCwd_OnProjectOnly()
project "MyProject"
location "build"
prepare()
test.isequal(os.getcwd(), sln.location)
end
function suite.projectUsesLocation_OnProjectOnly()
project "MyProject"
location "build"
prepare()
test.isequal(path.join(os.getcwd(), "build"), prj.location)
end
--
-- Test with location set on both solution and project only
--
function suite.solutionUsesCwd_OnProjectOnly()
location "build/solution"
project "MyProject"
location "build/project"
prepare()
test.isequal(path.join(os.getcwd(), "build/solution"), sln.location)
end
function suite.projectUsesLocation_OnProjectOnly()
location "build/solution"
project "MyProject"
location "build/project"
prepare()
test.isequal(path.join(os.getcwd(), "build/project"), prj.location)
end
@@ -0,0 +1,124 @@
--
-- tests/base/test_os.lua
-- Automated test suite for the new OS functions.
-- Copyright (c) 2008-2011 Jason Perkins and the Premake project
--
T.os = { }
local suite = T.os
--
-- os.findlib() tests
--
function suite.findlib_FindSystemLib()
if os.is("windows") then
test.istrue(os.findlib("user32"))
else
test.istrue(os.findlib("m"))
end
end
function suite.findlib_FailsOnBadLibName()
test.isfalse(os.findlib("NoSuchLibraryAsThisOneHere"))
end
--
-- os.isfile() tests
--
function suite.isfile_ReturnsTrue_OnExistingFile()
test.istrue(os.isfile("premake4.lua"))
end
function suite.isfile_ReturnsFalse_OnNonexistantFile()
test.isfalse(os.isfile("no_such_file.lua"))
end
--
-- os.matchfiles() tests
--
function suite.matchfiles_OnNonRecursive()
local result = os.matchfiles("*.lua")
test.istrue(table.contains(result, "testfx.lua"))
test.isfalse(table.contains(result, "folder/ok.lua"))
end
function suite.matchfiles_Recursive()
local result = os.matchfiles("**.lua")
test.istrue(table.contains(result, "folder/ok.lua"))
end
function suite.matchfiles_SkipsDotDirs_OnRecursive()
local result = os.matchfiles("**.lua")
test.isfalse(table.contains(result, ".svn/text-base/testfx.lua.svn-base"))
end
function suite.matchfiles_OnSubfolderMatch()
local result = os.matchfiles("**/xcode/*")
test.istrue(table.contains(result, "actions/xcode/test_xcode_project.lua"))
test.isfalse(table.contains(result, "premake4.lua"))
end
function suite.matchfiles_OnDotSlashPrefix()
local result = os.matchfiles("./**.lua")
test.istrue(table.contains(result, "folder/ok.lua"))
end
function suite.matchfiles_OnImplicitEndOfString()
local result = os.matchfiles("folder/*.lua")
test.istrue(table.contains(result, "folder/ok.lua"))
test.isfalse(table.contains(result, "folder/ok.lua.2"))
end
function suite.matchfiles_OnLeadingDotSlashWithPath()
local result = os.matchfiles("./folder/*.lua")
test.istrue(table.contains(result, "folder/ok.lua"))
end
--
-- os.pathsearch() tests
--
function suite.pathsearch_ReturnsNil_OnNotFound()
test.istrue( os.pathsearch("nosuchfile", "aaa;bbb;ccc") == nil )
end
function suite.pathsearch_ReturnsPath_OnFound()
test.isequal(os.getcwd(), os.pathsearch("premake4.lua", os.getcwd()))
end
function suite.pathsearch_FindsFile_OnComplexPath()
test.isequal(os.getcwd(), os.pathsearch("premake4.lua", "aaa;"..os.getcwd()..";bbb"))
end
function suite.pathsearch_NilPathsAllowed()
test.isequal(os.getcwd(), os.pathsearch("premake4.lua", nil, os.getcwd(), nil))
end
--
-- os.uuid() tests
--
function suite.guid_ReturnsValidUUID()
local g = os.uuid()
test.istrue(#g == 36)
for i=1,36 do
local ch = g:sub(i,i)
test.istrue(ch:find("[ABCDEF0123456789-]"))
end
test.isequal("-", g:sub(9,9))
test.isequal("-", g:sub(14,14))
test.isequal("-", g:sub(19,19))
test.isequal("-", g:sub(24,24))
end
@@ -0,0 +1,266 @@
--
-- tests/base/test_path.lua
-- Automated test suite for the action list.
-- Copyright (c) 2008-2010 Jason Perkins and the Premake project
--
T.path = { }
local suite = T.path
--
-- path.getabsolute() tests
--
function suite.getabsolute_ReturnsCorrectPath_OnMissingSubdir()
local expected = path.translate(os.getcwd(), "/") .. "/a/b/c"
test.isequal(expected, path.getabsolute("a/b/c"))
end
function suite.getabsolute_RemovesDotDots_OnWindowsAbsolute()
test.isequal("c:/ProjectB/bin", path.getabsolute("c:/ProjectA/../ProjectB/bin"))
end
function suite.getabsolute_RemovesDotDots_OnPosixAbsolute()
test.isequal("/ProjectB/bin", path.getabsolute("/ProjectA/../ProjectB/bin"))
end
function suite.getabsolute_OnTrailingSlash()
local expected = path.translate(os.getcwd(), "/") .. "/a/b/c"
test.isequal(expected, path.getabsolute("a/b/c/"))
end
function suite.getabsolute_OnLeadingEnvVar()
test.isequal("$(HOME)/user", path.getabsolute("$(HOME)/user"))
end
function suite.getabsolute_OnMultipleEnvVar()
test.isequal("$(HOME)/$(USER)", path.getabsolute("$(HOME)/$(USER)"))
end
function suite.getabsolute_OnTrailingEnvVar()
local expected = path.translate(os.getcwd(), "/") .. "/home/$(USER)"
test.isequal(expected, path.getabsolute("home/$(USER)"))
end
--
-- path.getbasename() tests
--
function suite.getbasename_ReturnsCorrectName_OnDirAndExtension()
test.isequal("filename", path.getbasename("folder/filename.ext"))
end
--
-- path.getdirectory() tests
--
function suite.getdirectory_ReturnsEmptyString_OnNoDirectory()
test.isequal(".", path.getdirectory("filename.ext"))
end
function suite.getdirectory_ReturnsDirectory_OnSingleLevelPath()
test.isequal("dir0", path.getdirectory("dir0/filename.ext"))
end
function suite.getdirectory_ReturnsDirectory_OnMultiLeveLPath()
test.isequal("dir0/dir1/dir2", path.getdirectory("dir0/dir1/dir2/filename.ext"))
end
function suite.getdirectory_ReturnsRootPath_OnRootPathOnly()
test.isequal("/", path.getdirectory("/filename.ext"))
end
--
-- path.getdrive() tests
--
function suite.getdrive_ReturnsNil_OnNotWindows()
test.isnil(path.getdrive("/hello"))
end
function suite.getdrive_ReturnsLetter_OnWindowsAbsolute()
test.isequal("x", path.getdrive("x:/hello"))
end
--
-- path.getextension() tests
--
function suite.getextension_ReturnsEmptyString_OnNoExtension()
test.isequal("", path.getextension("filename"))
end
function suite.getextension_ReturnsExtension()
test.isequal(".txt", path.getextension("filename.txt"))
end
function suite.getextension_OnMultipleDots()
test.isequal(".txt", path.getextension("filename.mod.txt"))
end
function suite.getextension_OnLeadingNumeric()
test.isequal(".7z", path.getextension("filename.7z"))
end
function suite.getextension_OnUnderscore()
test.isequal(".a_c", path.getextension("filename.a_c"))
end
function suite.getextension_OnHyphen()
test.isequal(".a-c", path.getextension("filename.a-c"))
end
--
-- path.getrelative() tests
--
function suite.getrelative_ReturnsDot_OnMatchingPaths()
test.isequal(".", path.getrelative("/a/b/c", "/a/b/c"))
end
function suite.getrelative_ReturnsDoubleDot_OnChildToParent()
test.isequal("..", path.getrelative("/a/b/c", "/a/b"))
end
function suite.getrelative_ReturnsDoubleDot_OnSiblingToSibling()
test.isequal("../d", path.getrelative("/a/b/c", "/a/b/d"))
end
function suite.getrelative_ReturnsChildPath_OnParentToChild()
test.isequal("d", path.getrelative("/a/b/c", "/a/b/c/d"))
end
function suite.getrelative_ReturnsChildPath_OnWindowsAbsolute()
test.isequal("obj/debug", path.getrelative("C:/Code/Premake4", "C:/Code/Premake4/obj/debug"))
end
function suite.getrelative_ReturnsAbsPath_OnDifferentDriveLetters()
test.isequal("D:/Files", path.getrelative("C:/Code/Premake4", "D:/Files"))
end
function suite.getrelative_ReturnsAbsPath_OnDollarMacro()
test.isequal("$(SDK_HOME)/include", path.getrelative("C:/Code/Premake4", "$(SDK_HOME)/include"))
end
function suite.getrelative_ReturnsAbsPath_OnRootedPath()
test.isequal("/opt/include", path.getrelative("/home/me/src/project", "/opt/include"))
end
--
-- path.isabsolute() tests
--
function suite.isabsolute_ReturnsTrue_OnAbsolutePosixPath()
test.istrue(path.isabsolute("/a/b/c"))
end
function suite.isabsolute_ReturnsTrue_OnAbsoluteWindowsPathWithDrive()
test.istrue(path.isabsolute("C:/a/b/c"))
end
function suite.isabsolute_ReturnsFalse_OnRelativePath()
test.isfalse(path.isabsolute("a/b/c"))
end
function suite.isabsolute_ReturnsTrue_OnDollarSign()
test.istrue(path.isabsolute("$(SDK_HOME)/include"))
end
--
-- path.join() tests
--
function suite.join_OnValidParts()
test.isequal("p1/p2", path.join("p1", "p2"))
end
function suite.join_OnAbsoluteUnixPath()
test.isequal("/p2", path.join("p1", "/p2"))
end
function suite.join_OnAbsoluteWindowsPath()
test.isequal("C:/p2", path.join("p1", "C:/p2"))
end
function suite.join_OnCurrentDirectory()
test.isequal("p2", path.join(".", "p2"))
end
function suite.join_OnNilSecondPart()
test.isequal("p1", path.join("p1", nil))
end
function suite.join_onMoreThanTwoParts()
test.isequal("p1/p2/p3", path.join("p1", "p2", "p3"))
end
function suite.join_removesExtraInternalSlashes()
test.isequal("p1/p2", path.join("p1/", "p2"))
end
function suite.join_removesTrailingSlash()
test.isequal("p1/p2", path.join("p1", "p2/"))
end
function suite.join_ignoresNilParts()
test.isequal("p2", path.join(nil, "p2", nil))
end
function suite.join_ignoresEmptyParts()
test.isequal("p2", path.join("", "p2", ""))
end
--
-- path.rebase() tests
--
function suite.rebase_WithEndingSlashOnPath()
local cwd = os.getcwd()
test.isequal("src", path.rebase("../src/", cwd, path.getdirectory(cwd)))
end
--
-- path.translate() tests
--
function suite.translate_ReturnsTranslatedPath_OnValidPath()
test.isequal("dir/dir/file", path.translate("dir\\dir\\file", "/"))
end
function suite.translate_ReturnsCorrectSeparator_OnMixedPath()
local actual = path.translate("dir\\dir/file")
if (os.is("windows")) then
test.isequal("dir\\dir\\file", actual)
else
test.isequal("dir/dir/file", actual)
end
end
--
-- path.wildcards tests
--
function suite.wildcards_MatchesTrailingStar()
local p = path.wildcards("**/xcode/*")
test.isequal(".*/xcode/[^/]*", p)
end
function suite.wildcards_MatchPlusSign()
local patt = path.wildcards("file+name.*")
local name = "file+name.c"
test.isequal(name, name:match(patt))
end
@@ -0,0 +1,14 @@
--
-- tests/base/test_premake_command.lua
-- Test the initialization of the _PREMAKE_COMMAND global.
-- Copyright (c) 2012 Jason Perkins and the Premake project
--
T.premake_command = { }
local suite = T.premake_command
function suite.valueIsSet()
local filename = iif(os.is("windows"), "premake4.exe", "premake4")
test.isequal(path.getabsolute("../bin/debug/" .. filename), _PREMAKE_COMMAND)
end
@@ -0,0 +1,65 @@
--
-- tests/base/test_table.lua
-- Automated test suite for the new table functions.
-- Copyright (c) 2008-2010 Jason Perkins and the Premake project
--
T.table = { }
local suite = T.table
--
-- table.contains() tests
--
function suite.contains_OnContained()
t = { "one", "two", "three" }
test.istrue( table.contains(t, "two") )
end
function suite.contains_OnNotContained()
t = { "one", "two", "three" }
test.isfalse( table.contains(t, "four") )
end
--
-- table.flatten() tests
--
function suite.flatten_OnMixedValues()
t = { "a", { "b", "c" }, "d" }
test.isequal({ "a", "b", "c", "d" }, table.flatten(t))
end
--
-- table.implode() tests
--
function suite.implode()
t = { "one", "two", "three", "four" }
test.isequal("[one], [two], [three], [four]", table.implode(t, "[", "]", ", "))
end
--
-- table.isempty() tests
--
function suite.isempty_ReturnsTrueOnEmpty()
test.istrue(table.isempty({}))
end
function suite.isempty_ReturnsFalseOnNotEmpty()
test.isfalse(table.isempty({ 1 }))
end
function suite.isempty_ReturnsFalseOnNotEmptyMap()
test.isfalse(table.isempty({ name = 'premake' }))
end
function suite.isempty_ReturnsFalseOnNotEmptyMapWithFalseKey()
test.isfalse(table.isempty({ [false] = 0 }))
end
@@ -0,0 +1,143 @@
--
-- tests/base/test_tree.lua
-- Automated test suite source code tree handling.
-- Copyright (c) 2009 Jason Perkins and the Premake project
--
T.tree = { }
local suite = T.tree
local tree = premake.tree
--
-- Setup/teardown
--
local tr, nodes
function suite.setup()
tr = tree.new()
nodes = { }
end
local function getresult()
tree.traverse(tr, {
onnode = function(node, depth)
table.insert(nodes, string.rep(">", depth) .. node.name)
end
})
return table.concat(nodes)
end
--
-- Tests for tree.new()
--
function suite.NewReturnsObject()
test.isnotnil(tr)
end
--
-- Tests for tree.add()
--
function suite.CanAddAtRoot()
tree.add(tr, "Root")
test.isequal("Root", getresult())
end
function suite.CanAddAtChild()
tree.add(tr, "Root/Child")
test.isequal("Root>Child", getresult())
end
function suite.CanAddAtGrandchild()
tree.add(tr, "Root/Child/Grandchild")
test.isequal("Root>Child>>Grandchild", getresult())
end
function suite.SkipsLeadingDotDots()
tree.add(tr, "../MyProject/hello")
test.isequal("MyProject>hello", getresult())
end
function suite.SkipsInlineDotDots()
tree.add(tr, "MyProject/../hello")
test.isequal("MyProject>hello", getresult())
end
function suite.AddsNodes_OnDifferentParentLevel()
tree.add(tr, "../Common")
tree.add(tr, "../../Common")
test.isequal(2, #tr.children)
test.isequal("Common", tr.children[1].name)
test.isequal("Common", tr.children[2].name)
test.isequal("../Common", tr.children[1].path)
test.isequal("../../Common", tr.children[2].path)
end
--
-- Tests for tree.getlocalpath()
--
function suite.GetLocalPath_ReturnsPath_OnNoParentPath()
local c = tree.add(tr, "Root/Child")
c.parent.path = nil
test.isequal("Root/Child", tree.getlocalpath(c))
end
function suite.GetLocalPath_ReturnsName_OnParentPathSet()
local c = tree.add(tr, "Root/Child")
test.isequal("Child", tree.getlocalpath(c))
end
--
-- Tests for tree.remove()
--
function suite.Remove_RemovesNodes()
local n1 = tree.add(tr, "1")
local n2 = tree.add(tr, "2")
local n3 = tree.add(tr, "3")
tree.remove(n2)
local r = ""
for _, n in ipairs(tr.children) do r = r .. n.name end
test.isequal("13", r)
end
function suite.Remove_WorksInTraversal()
tree.add(tr, "Root/1")
tree.add(tr, "Root/2")
tree.add(tr, "Root/3")
local r = ""
tree.traverse(tr, {
onleaf = function(node)
r = r .. node.name
tree.remove(node)
end
})
test.isequal("123", r)
test.isequal(0, #tr.children[1])
end
--
-- Tests for tree.sort()
--
function suite.Sort_SortsAllLevels()
tree.add(tr, "B/3")
tree.add(tr, "B/1")
tree.add(tr, "A/2")
tree.add(tr, "A/1")
tree.add(tr, "B/2")
tree.sort(tr)
test.isequal("A>1>2B>1>2>3", getresult(tr))
end
@@ -0,0 +1 @@
return "ok"
@@ -0,0 +1 @@
return "ok"
@@ -0,0 +1,616 @@
--[[
== Introduction ==
Note that this requires os.clock(), debug.sethook(),
and debug.getinfo() or your equivalent replacements to
be available if this is an embedded application.
Example usage:
profiler = newProfiler()
profiler:start()
< call some functions that take time >
profiler:stop()
local outfile = io.open( "profile.txt", "w+" )
profiler:report( outfile )
outfile:close()
== Optionally choosing profiling method ==
The rest of this comment can be ignored if you merely want a good profiler.
newProfiler(method, sampledelay):
If method is omitted or "time", will profile based on real performance.
optionally, frequency can be provided to control the number of opcodes
per profiling tick. By default this is 100000, which (on my system) provides
one tick approximately every 2ms and reduces system performance by about 10%.
This can be reduced to increase accuracy at the cost of performance, or
increased for the opposite effect.
If method is "call", will profile based on function calls. Frequency is
ignored.
"time" may bias profiling somewhat towards large areas with "simple opcodes",
as the profiling function (which introduces a certain amount of unavoidable
overhead) will be called more often. This can be minimized by using a larger
sample delay - the default should leave any error largely overshadowed by
statistical noise. With a delay of 1000 I was able to achieve inaccuray of
approximately 25%. Increasing the delay to 100000 left inaccuracy below my
testing error.
"call" may bias profiling heavily towards areas with many function calls.
Testing found a degenerate case giving a figure inaccurate by approximately
20,000%. (Yes, a multiple of 200.) This is, however, more directly comparable
to common profilers (such as gprof) and also gives accurate function call
counts, which cannot be retrieved from "time".
I strongly recommend "time" mode, and it is now the default.
== History ==
2008-09-16 - Time-based profiling and conversion to Lua 5.1
by Ben Wilhelm ( zorba-pepperfish@pavlovian.net ).
Added the ability to optionally choose profiling methods, along with a new
profiling method.
Converted to Lua 5, a few improvements, and
additional documentation by Tom Spilman ( tom@sickheadgames.com )
Additional corrections and tidying by original author
Daniel Silverstone ( dsilvers@pepperfish.net )
== Status ==
Daniel Silverstone is no longer using this code, and judging by how long it's
been waiting for Lua 5.1 support, I don't think Tom Spilman is either. I'm
perfectly willing to take on maintenance, so if you have problems or
questions, go ahead and email me :)
-- Ben Wilhelm ( zorba-pepperfish@pavlovian.net ) '
== Copyright ==
Lua profiler - Copyright Pepperfish 2002,2003,2004
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to
do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
--]]
--
-- All profiler related stuff is stored in the top level table '_profiler'
--
_profiler = {}
--
-- newProfiler() creates a new profiler object for managing
-- the profiler and storing state. Note that only one profiler
-- object can be executing at one time.
--
function newProfiler(variant, sampledelay)
if _profiler.running then
print("Profiler already running.")
return
end
variant = variant or "time"
if variant ~= "time" and variant ~= "call" then
print("Profiler method must be 'time' or 'call'.")
return
end
local newprof = {}
for k,v in pairs(_profiler) do
newprof[k] = v
end
newprof.variant = variant
newprof.sampledelay = sampledelay or 100000
return newprof
end
--
-- This function starts the profiler. It will do nothing
-- if this (or any other) profiler is already running.
--
function _profiler.start(self)
if _profiler.running then
return
end
-- Start the profiler. This begins by setting up internal profiler state
_profiler.running = self
self.rawstats = {}
self.callstack = {}
if self.variant == "time" then
self.lastclock = os.clock()
debug.sethook( _profiler_hook_wrapper_by_time, "", self.sampledelay )
elseif self.variant == "call" then
debug.sethook( _profiler_hook_wrapper_by_call, "cr" )
else
print("Profiler method must be 'time' or 'call'.")
sys.exit(1)
end
end
--
-- This function stops the profiler. It will do nothing
-- if a profiler is not running, and nothing if it isn't
-- the currently running profiler.
--
function _profiler.stop(self)
if _profiler.running ~= self then
return
end
-- Stop the profiler.
debug.sethook( nil )
_profiler.running = nil
end
--
-- Simple wrapper to handle the hook. You should not
-- be calling this directly. Duplicated to reduce overhead.
--
function _profiler_hook_wrapper_by_call(action)
if _profiler.running == nil then
debug.sethook( nil )
end
_profiler.running:_internal_profile_by_call(action)
end
function _profiler_hook_wrapper_by_time(action)
if _profiler.running == nil then
debug.sethook( nil )
end
_profiler.running:_internal_profile_by_time(action)
end
--
-- This is the main by-function-call function of the profiler and should not
-- be called except by the hook wrapper
--
function _profiler._internal_profile_by_call(self,action)
-- Since we can obtain the 'function' for the item we've had call us, we
-- can use that...
local caller_info = debug.getinfo( 3 )
if caller_info == nil then
print "No caller_info"
return
end
--SHG_LOG("[_profiler._internal_profile] "..(caller_info.name or "<nil>"))
-- Retrieve the most recent activation record...
local latest_ar = nil
if table.getn(self.callstack) > 0 then
latest_ar = self.callstack[table.getn(self.callstack)]
end
-- Are we allowed to profile this function?
local should_not_profile = 0
for k,v in pairs(self.prevented_functions) do
if k == caller_info.func then
should_not_profile = v
end
end
-- Also check the top activation record...
if latest_ar then
if latest_ar.should_not_profile == 2 then
should_not_profile = 2
end
end
-- Now then, are we in 'call' or 'return' ?
-- print("Profile:", caller_info.name, "SNP:", should_not_profile,
-- "Action:", action )
if action == "call" then
-- Making a call...
local this_ar = {}
this_ar.should_not_profile = should_not_profile
this_ar.parent_ar = latest_ar
this_ar.anon_child = 0
this_ar.name_child = 0
this_ar.children = {}
this_ar.children_time = {}
this_ar.clock_start = os.clock()
-- Last thing to do on a call is to insert this onto the ar stack...
table.insert( self.callstack, this_ar )
else
local this_ar = latest_ar
if this_ar == nil then
return -- No point in doing anything if no upper activation record
end
-- Right, calculate the time in this function...
this_ar.clock_end = os.clock()
this_ar.this_time = this_ar.clock_end - this_ar.clock_start
-- Now, if we have a parent, update its call info...
if this_ar.parent_ar then
this_ar.parent_ar.children[caller_info.func] =
(this_ar.parent_ar.children[caller_info.func] or 0) + 1
this_ar.parent_ar.children_time[caller_info.func] =
(this_ar.parent_ar.children_time[caller_info.func] or 0 ) +
this_ar.this_time
if caller_info.name == nil then
this_ar.parent_ar.anon_child =
this_ar.parent_ar.anon_child + this_ar.this_time
else
this_ar.parent_ar.name_child =
this_ar.parent_ar.name_child + this_ar.this_time
end
end
-- Now if we're meant to record information about ourselves, do so...
if this_ar.should_not_profile == 0 then
local inforec = self:_get_func_rec(caller_info.func,1)
inforec.count = inforec.count + 1
inforec.time = inforec.time + this_ar.this_time
inforec.anon_child_time = inforec.anon_child_time + this_ar.anon_child
inforec.name_child_time = inforec.name_child_time + this_ar.name_child
inforec.func_info = caller_info
for k,v in pairs(this_ar.children) do
inforec.children[k] = (inforec.children[k] or 0) + v
inforec.children_time[k] =
(inforec.children_time[k] or 0) + this_ar.children_time[k]
end
end
-- Last thing to do on return is to drop the last activation record...
table.remove( self.callstack, table.getn( self.callstack ) )
end
end
--
-- This is the main by-time internal function of the profiler and should not
-- be called except by the hook wrapper
--
function _profiler._internal_profile_by_time(self,action)
-- we do this first so we add the minimum amount of extra time to this call
local timetaken = os.clock() - self.lastclock
local depth = 3
local at_top = true
local last_caller
local caller = debug.getinfo(depth)
while caller do
if not caller.func then caller.func = "(tail call)" end
if self.prevented_functions[caller.func] == nil then
local info = self:_get_func_rec(caller.func, 1, caller)
info.count = info.count + 1
info.time = info.time + timetaken
if last_caller then
-- we're not the head, so update the "children" times also
if last_caller.name then
info.name_child_time = info.name_child_time + timetaken
else
info.anon_child_time = info.anon_child_time + timetaken
end
info.children[last_caller.func] =
(info.children[last_caller.func] or 0) + 1
info.children_time[last_caller.func] =
(info.children_time[last_caller.func] or 0) + timetaken
end
end
depth = depth + 1
last_caller = caller
caller = debug.getinfo(depth)
end
self.lastclock = os.clock()
end
--
-- This returns a (possibly empty) function record for
-- the specified function. It is for internal profiler use.
--
function _profiler._get_func_rec(self,func,force,info)
-- Find the function ref for 'func' (if force and not present, create one)
local ret = self.rawstats[func]
if ret == nil and force ~= 1 then
return nil
end
if ret == nil then
-- Build a new function statistics table
ret = {}
ret.func = func
ret.count = 0
ret.time = 0
ret.anon_child_time = 0
ret.name_child_time = 0
ret.children = {}
ret.children_time = {}
ret.func_info = info
self.rawstats[func] = ret
end
return ret
end
--
-- This writes a profile report to the output file object. If
-- sort_by_total_time is nil or false the output is sorted by
-- the function time minus the time in it's children.
--
function _profiler.report( self, outfile, sort_by_total_time )
outfile:write
[[Lua Profile output created by profiler.lua. Copyright Pepperfish 2002+
]]
-- This is pretty awful.
local terms = {}
if self.variant == "time" then
terms.capitalized = "Sample"
terms.single = "sample"
terms.pastverb = "sampled"
elseif self.variant == "call" then
terms.capitalized = "Call"
terms.single = "call"
terms.pastverb = "called"
else
assert(false)
end
local total_time = 0
local ordering = {}
for func,record in pairs(self.rawstats) do
table.insert(ordering, func)
end
if sort_by_total_time then
table.sort( ordering,
function(a,b) return self.rawstats[a].time > self.rawstats[b].time end
)
else
table.sort( ordering,
function(a,b)
local arec = self.rawstats[a]
local brec = self.rawstats[b]
local atime = arec.time - (arec.anon_child_time + arec.name_child_time)
local btime = brec.time - (brec.anon_child_time + brec.name_child_time)
return atime > btime
end
)
end
for i=1,table.getn(ordering) do
local func = ordering[i]
local record = self.rawstats[func]
local thisfuncname = " " .. self:_pretty_name(func) .. " "
if string.len( thisfuncname ) < 42 then
thisfuncname =
string.rep( "-", (42 - string.len(thisfuncname))/2 ) .. thisfuncname
thisfuncname =
thisfuncname .. string.rep( "-", 42 - string.len(thisfuncname) )
end
total_time = total_time + ( record.time - ( record.anon_child_time +
record.name_child_time ) )
outfile:write( string.rep( "-", 19 ) .. thisfuncname ..
string.rep( "-", 19 ) .. "\n" )
outfile:write( terms.capitalized.." count: " ..
string.format( "%4d", record.count ) .. "\n" )
outfile:write( "Time spend total: " ..
string.format( "%4.3f", record.time ) .. "s\n" )
outfile:write( "Time spent in children: " ..
string.format("%4.3f",record.anon_child_time+record.name_child_time) ..
"s\n" )
local timeinself =
record.time - (record.anon_child_time + record.name_child_time)
outfile:write( "Time spent in self: " ..
string.format("%4.3f", timeinself) .. "s\n" )
outfile:write( "Time spent per " .. terms.single .. ": " ..
string.format("%4.5f", record.time/record.count) ..
"s/" .. terms.single .. "\n" )
outfile:write( "Time spent in self per "..terms.single..": " ..
string.format( "%4.5f", timeinself/record.count ) .. "s/" ..
terms.single.."\n" )
-- Report on each child in the form
-- Child <funcname> called n times and took a.bs
local added_blank = 0
for k,v in pairs(record.children) do
if self.prevented_functions[k] == nil or
self.prevented_functions[k] == 0
then
if added_blank == 0 then
outfile:write( "\n" ) -- extra separation line
added_blank = 1
end
outfile:write( "Child " .. self:_pretty_name(k) ..
string.rep( " ", 41-string.len(self:_pretty_name(k)) ) .. " " ..
terms.pastverb.." " .. string.format("%6d", v) )
outfile:write( " times. Took " ..
string.format("%4.2f", record.children_time[k] ) .. "s\n" )
end
end
outfile:write( "\n" ) -- extra separation line
outfile:flush()
end
outfile:write( "\n\n" )
outfile:write( "Total time spent in profiled functions: " ..
string.format("%5.3g",total_time) .. "s\n" )
outfile:write( [[
END
]] )
outfile:flush()
end
--
-- This writes the profile to the output file object as
-- loadable Lua source.
--
function _profiler.lua_report(self,outfile)
-- Purpose: Write out the entire raw state in a cross-referenceable form.
local ordering = {}
local functonum = {}
for func,record in pairs(self.rawstats) do
table.insert(ordering, func)
functonum[func] = table.getn(ordering)
end
outfile:write(
"-- Profile generated by profiler.lua Copyright Pepperfish 2002+\n\n" )
outfile:write( "-- Function names\nfuncnames = {}\n" )
for i=1,table.getn(ordering) do
local thisfunc = ordering[i]
outfile:write( "funcnames[" .. i .. "] = " ..
string.format("%q", self:_pretty_name(thisfunc)) .. "\n" )
end
outfile:write( "\n" )
outfile:write( "-- Function times\nfunctimes = {}\n" )
for i=1,table.getn(ordering) do
local thisfunc = ordering[i]
local record = self.rawstats[thisfunc]
outfile:write( "functimes[" .. i .. "] = { " )
outfile:write( "tot=" .. record.time .. ", " )
outfile:write( "achild=" .. record.anon_child_time .. ", " )
outfile:write( "nchild=" .. record.name_child_time .. ", " )
outfile:write( "count=" .. record.count .. " }\n" )
end
outfile:write( "\n" )
outfile:write( "-- Child links\nchildren = {}\n" )
for i=1,table.getn(ordering) do
local thisfunc = ordering[i]
local record = self.rawstats[thisfunc]
outfile:write( "children[" .. i .. "] = { " )
for k,v in pairs(record.children) do
if functonum[k] then -- non-recorded functions will be ignored now
outfile:write( functonum[k] .. ", " )
end
end
outfile:write( "}\n" )
end
outfile:write( "\n" )
outfile:write( "-- Child call counts\nchildcounts = {}\n" )
for i=1,table.getn(ordering) do
local thisfunc = ordering[i]
local record = self.rawstats[thisfunc]
outfile:write( "children[" .. i .. "] = { " )
for k,v in record.children do
if functonum[k] then -- non-recorded functions will be ignored now
outfile:write( v .. ", " )
end
end
outfile:write( "}\n" )
end
outfile:write( "\n" )
outfile:write( "-- Child call time\nchildtimes = {}\n" )
for i=1,table.getn(ordering) do
local thisfunc = ordering[i]
local record = self.rawstats[thisfunc];
outfile:write( "children[" .. i .. "] = { " )
for k,v in pairs(record.children) do
if functonum[k] then -- non-recorded functions will be ignored now
outfile:write( record.children_time[k] .. ", " )
end
end
outfile:write( "}\n" )
end
outfile:write( "\n\n-- That is all.\n\n" )
outfile:flush()
end
-- Internal function to calculate a pretty name for the profile output
function _profiler._pretty_name(self,func)
-- Only the data collected during the actual
-- run seems to be correct.... why?
local info = self.rawstats[ func ].func_info
-- local info = debug.getinfo( func )
local name = ""
if info.what == "Lua" then
name = "L:"
end
if info.what == "C" then
name = "C:"
end
if info.what == "main" then
name = " :"
end
if info.name == nil then
name = name .. "<"..tostring(func) .. ">"
else
name = name .. info.name
end
if info.source then
name = name .. "@" .. info.source
else
if info.what == "C" then
name = name .. "@?"
else
name = name .. "@<string>"
end
end
name = name .. ":"
if info.what == "C" then
name = name .. "?"
else
name = name .. info.linedefined
end
return name
end
--
-- This allows you to specify functions which you do
-- not want profiled. Setting level to 1 keeps the
-- function from being profiled. Setting level to 2
-- keeps both the function and its children from
-- being profiled.
--
-- BUG: 2 will probably act exactly like 1 in "time" mode.
-- If anyone cares, let me (zorba) know and it can be fixed.
--
function _profiler.prevent(self, func, level)
self.prevented_functions[func] = (level or 1)
end
_profiler.prevented_functions = {
[_profiler.start] = 2,
[_profiler.stop] = 2,
[_profiler._internal_profile_by_time] = 2,
[_profiler._internal_profile_by_call] = 2,
[_profiler_hook_wrapper_by_time] = 2,
[_profiler_hook_wrapper_by_call] = 2,
[_profiler.prevent] = 2,
[_profiler._get_func_rec] = 2,
[_profiler.report] = 2,
[_profiler.lua_report] = 2,
[_profiler._pretty_name] = 2
}
@@ -0,0 +1,150 @@
--
-- tests/premake4.lua
-- Automated test suite for Premake 4.x
-- Copyright (c) 2008-2011 Jason Perkins and the Premake project
--
dofile("testfx.lua")
--
-- Some helper functions
--
test.createsolution = function()
local sln = solution "MySolution"
configurations { "Debug", "Release" }
local prj = project "MyProject"
language "C++"
kind "ConsoleApp"
return sln, prj
end
test.createproject = function(sln)
local n = #sln.projects + 1
if n == 1 then n = "" end
local prj = project ("MyProject" .. n)
language "C++"
kind "ConsoleApp"
return prj
end
--
-- The test suites
--
dofile("test_dofile.lua")
dofile("test_string.lua")
dofile("test_premake.lua")
dofile("test_platforms.lua")
dofile("test_targets.lua")
dofile("test_keywords.lua")
dofile("test_gmake_cpp.lua")
dofile("test_gmake_cs.lua")
dofile("base/test_api.lua")
dofile("base/test_action.lua")
dofile("base/test_config.lua")
dofile("base/test_location.lua")
dofile("base/test_os.lua")
dofile("base/test_path.lua")
dofile("base/test_premake_command.lua")
dofile("base/test_table.lua")
dofile("base/test_tree.lua")
dofile("tools/test_gcc.lua")
dofile("base/test_config_bug.lua")
-- Project API tests
dofile("test_project.lua")
dofile("project/test_eachfile.lua")
dofile("project/test_vpaths.lua")
-- Baking tests
dofile("base/test_baking.lua")
dofile("baking/test_merging.lua")
-- Clean tests
dofile("actions/test_clean.lua")
-- Visual Studio tests
dofile("actions/vstudio/test_vs200x_vcproj.lua")
dofile("actions/vstudio/test_vs200x_vcproj_linker.lua")
dofile("actions/vstudio/test_vs2010_vcxproj.lua")
dofile("actions/vstudio/test_vs2010_flags.lua")
dofile("actions/vstudio/test_vs2010_project_kinds.lua")
-- Visual Studio 2002-2003 C# projects
dofile("actions/vstudio/cs2002/test_files.lua")
-- Visual Studio 2005-2010 C# projects
dofile("actions/vstudio/cs2005/test_files.lua")
dofile("actions/vstudio/cs2005/projectelement.lua")
dofile("actions/vstudio/cs2005/projectsettings.lua")
dofile("actions/vstudio/cs2005/propertygroup.lua")
-- Visual Studio 2005-2010 solutions
dofile("actions/vstudio/sln2005/dependencies.lua")
dofile("actions/vstudio/sln2005/header.lua")
dofile("actions/vstudio/sln2005/layout.lua")
dofile("actions/vstudio/sln2005/platforms.lua")
dofile("actions/vstudio/sln2005/projectplatforms.lua")
dofile("actions/vstudio/sln2005/projects.lua")
-- Visual Studio 2002-2008 C/C++ projects
dofile("actions/vstudio/vc200x/debugdir.lua")
dofile("actions/vstudio/vc200x/header.lua")
dofile("actions/vstudio/vc200x/test_files.lua")
dofile("actions/vstudio/vc200x/test_filters.lua")
-- Visual Studio 2010 C/C++ projects
dofile("actions/vstudio/vc2010/test_config_props.lua")
dofile("actions/vstudio/vc2010/test_debugdir.lua")
dofile("actions/vstudio/vc2010/test_header.lua")
dofile("actions/vstudio/vc2010/test_files.lua")
dofile("actions/vstudio/vc2010/test_filters.lua")
dofile("actions/vstudio/vc2010/test_link_settings.lua")
dofile("actions/vstudio/vc2010/test_links.lua")
dofile("actions/vstudio/vc2010/test_output_props.lua")
dofile("actions/vstudio/vc2010/test_pch.lua")
dofile("actions/vstudio/vc2010/test_project_refs.lua")
-- Makefile tests
dofile("actions/make/test_make_escaping.lua")
dofile("actions/make/test_make_pch.lua")
dofile("actions/make/test_make_linking.lua")
-- dofile("actions/make/test_makesettings.lua")
dofile("actions/make/test_wiidev.lua")
--
-- Register a test action
--
newoption {
trigger = "test",
description = "A suite or test to run"
}
newaction {
trigger = "test",
description = "Run the automated test suite",
execute = function ()
if _OPTIONS["test"] then
local t = string.explode(_OPTIONS["test"] or "", ".", true)
passed, failed = test.runall(t[1], t[2])
else
passed, failed = test.runall()
end
msg = string.format("%d tests passed, %d failed", passed, failed)
if (failed > 0) then
-- should probably return an error code here somehow
print(msg)
else
print(msg)
end
end
}
@@ -0,0 +1,46 @@
--
-- tests/project/test_eachfile.lua
-- Automated test suite for the file iteration function.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.project_eachfile = { }
local suite = T.project_eachfile
local project = premake.project
--
-- Setup and teardown
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
premake.bake.buildconfigs()
prj = premake.solution.getproject(sln, 1)
end
--
-- Tests
--
function suite.ReturnsAllFiles()
files { "hello.h", "hello.c" }
prepare()
local iter = project.eachfile(prj)
test.isequal("hello.h", iter().name)
test.isequal("hello.c", iter().name)
test.isnil(iter())
end
function suite.ReturnedObjectIncludesVpath()
files { "hello.h", "hello.c" }
prepare()
local iter = project.eachfile(prj)
test.isequal("hello.h", iter().vpath)
end
@@ -0,0 +1,160 @@
--
-- tests/project/test_vpaths.lua
-- Automated test suite for the project support functions.
-- Copyright (c) 2011-2012 Jason Perkins and the Premake project
--
T.project_vpaths = { }
local suite = T.project_vpaths
local project = premake.project
--
-- Setup and teardown
--
local sln
function suite.setup()
sln = test.createsolution()
end
local function run()
premake.bake.buildconfigs()
local prj = premake.solution.getproject(sln, 1)
local cfg = premake.getconfig(prj, "Debug")
return project.getvpath(prj, cfg.files[1])
end
--
-- Test simple replacements
--
function suite.ReturnsOriginalPath_OnNoVpaths()
files { "hello.c" }
test.isequal("hello.c", run())
end
function suite.ReturnsOriginalPath_OnNoMatches()
files { "hello.c" }
vpaths { ["Headers"] = "**.h" }
test.isequal("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_ToNestedGroup_Flat()
files { "src/myproject/hello.h" }
vpaths { ["Group/Headers"] = "**.h" }
test.isequal("Group/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
@@ -0,0 +1,2 @@
#!/bin/sh
../bin/debug/premake4 /scripts=../src /file=test_stress.lua vs2008
@@ -0,0 +1,2 @@
#!/bin/sh
cd `dirname $0` && ../bin/debug/premake4 /scripts=../src $1 $2 $3 test
@@ -0,0 +1,3 @@
CALL ..\\bin\\debug\\premake4 /scripts=..\\src test
::CALL ..\\bin\\release\\premake4 /scripts=..\\src test
@@ -0,0 +1,36 @@
--
-- tests/test_dofile.lua
-- Automated test suite for the extended dofile() functions.
-- Copyright (c) 2008 Jason Perkins and the Premake project
--
T.dofile = { }
local os_getenv
function T.dofile.setup()
os_getenv = os.getenv
end
function T.dofile.teardown()
os.getenv = os_getenv
end
--
-- dofile() tests
--
function T.dofile.SearchesPath()
os.getenv = function() return os.getcwd().."/folder" end
result = dofile("ok.lua")
test.isequal("ok", result)
end
function T.dofile.SearchesScriptsOption()
_OPTIONS["scripts"] = os.getcwd().."/folder"
result = dofile("ok.lua")
test.isequal("ok", result)
end
@@ -0,0 +1,194 @@
--
-- tests/test_gmake_cpp.lua
-- Automated test suite for GNU Make C/C++ project generation.
-- Copyright (c) 2009 Jason Perkins and the Premake project
--
T.gmake_cpp = { }
--
-- Configure a solution for testing
--
local sln, prj
function T.gmake_cpp.setup()
_ACTION = "gmake"
_OPTIONS.os = "linux"
sln = solution "MySolution"
configurations { "Debug", "Release" }
platforms { "native" }
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
end
local function prepare()
premake.bake.buildconfigs()
end
--
-- Test the header
--
function T.gmake_cpp.BasicHeader()
prepare()
premake.gmake_cpp_header(prj, premake.gcc, sln.platforms)
test.capture [[
# GNU Make project makefile autogenerated by Premake
ifndef config
config=debug
endif
ifndef verbose
SILENT = @
endif
CC = gcc
CXX = g++
AR = ar
ifndef RESCOMP
ifdef WINDRES
RESCOMP = $(WINDRES)
else
RESCOMP = windres
endif
endif
]]
end
--
-- Test configuration blocks
--
function T.gmake_cpp.BasicCfgBlock()
prepare()
local cfg = premake.getconfig(prj, "Debug")
premake.gmake_cpp_config(cfg, premake.gcc)
test.capture [[
ifeq ($(config),debug)
OBJDIR = obj/Debug
TARGETDIR = .
TARGET = $(TARGETDIR)/MyProject
DEFINES +=
INCLUDES +=
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
ALL_LDFLAGS += $(LDFLAGS) -s
LDDEPS +=
LIBS += $(LDDEPS)
LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
define PREBUILDCMDS
endef
define PRELINKCMDS
endef
define POSTBUILDCMDS
endef
endif
]]
end
function T.gmake_cpp.BasicCfgBlockWithPlatformCc()
platforms { "ps3" }
prepare()
local cfg = premake.getconfig(prj, "Debug", "PS3")
premake.gmake_cpp_config(cfg, premake.gcc)
test.capture [[
ifeq ($(config),debugps3)
CC = ppu-lv2-g++
CXX = ppu-lv2-g++
AR = ppu-lv2-ar
OBJDIR = obj/PS3/Debug
TARGETDIR = .
TARGET = $(TARGETDIR)/MyProject.elf
DEFINES +=
INCLUDES +=
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
ALL_LDFLAGS += $(LDFLAGS) -s
LDDEPS +=
LIBS += $(LDDEPS)
LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
define PREBUILDCMDS
endef
define PRELINKCMDS
endef
define POSTBUILDCMDS
endef
endif
]]
end
function T.gmake_cpp.PlatformSpecificBlock()
platforms { "x64" }
prepare()
local cfg = premake.getconfig(prj, "Debug", "x64")
premake.gmake_cpp_config(cfg, premake.gcc)
test.capture [[
ifeq ($(config),debug64)
OBJDIR = obj/x64/Debug
TARGETDIR = .
TARGET = $(TARGETDIR)/MyProject
DEFINES +=
INCLUDES +=
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -m64
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
ALL_LDFLAGS += $(LDFLAGS) -s -m64 -L/usr/lib64
LDDEPS +=
LIBS += $(LDDEPS)
LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
define PREBUILDCMDS
endef
define PRELINKCMDS
endef
define POSTBUILDCMDS
endef
endif
]]
end
function T.gmake_cpp.UniversalStaticLibBlock()
kind "StaticLib"
platforms { "universal32" }
prepare()
local cfg = premake.getconfig(prj, "Debug", "Universal32")
premake.gmake_cpp_config(cfg, premake.gcc)
test.capture [[
ifeq ($(config),debuguniv32)
OBJDIR = obj/Universal32/Debug
TARGETDIR = .
TARGET = $(TARGETDIR)/libMyProject.a
DEFINES +=
INCLUDES +=
ALL_CPPFLAGS += $(CPPFLAGS) $(DEFINES) $(INCLUDES)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -arch i386 -arch ppc
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
ALL_LDFLAGS += $(LDFLAGS) -s -arch i386 -arch ppc
LDDEPS +=
LIBS += $(LDDEPS)
LINKCMD = libtool -o $(TARGET) $(OBJECTS)
define PREBUILDCMDS
endef
define PRELINKCMDS
endef
define POSTBUILDCMDS
endef
endif
]]
end
@@ -0,0 +1,79 @@
--
-- tests/test_gmake_cs.lua
-- Automated test suite for GNU Make C/C++ project generation.
-- Copyright (c) 2009 Jason Perkins and the Premake project
--
T.gmake_cs = { }
--
-- Configure a solution for testing
--
local sln, prj
function T.gmake_cs.setup()
_ACTION = "gmake"
_OPTIONS.os = "linux"
sln = solution "MySolution"
configurations { "Debug", "Release" }
platforms { "native" }
prj = project "MyProject"
language "C#"
kind "ConsoleApp"
end
local function prepare()
premake.bake.buildconfigs()
end
--
-- Test configuration blocks
--
function T.gmake_cs.BasicCfgBlock()
prepare()
local cfg = premake.getconfig(prj, "Debug")
premake.gmake_cs_config(cfg, premake.dotnet, {[cfg]={}})
test.capture [[
ifneq (,$(findstring debug,$(config)))
TARGETDIR := .
OBJDIR := obj/Debug
DEPENDS :=
REFERENCES :=
FLAGS +=
define PREBUILDCMDS
endef
define PRELINKCMDS
endef
define POSTBUILDCMDS
endef
endif
]]
end
function T.gmake_cs.OnBuildOptions()
buildoptions { "/define:SYMBOL" }
prepare()
local cfg = premake.getconfig(prj, "Debug")
premake.gmake_cs_config(cfg, premake.dotnet, {[cfg]={}})
test.capture [[
ifneq (,$(findstring debug,$(config)))
TARGETDIR := .
OBJDIR := obj/Debug
DEPENDS :=
REFERENCES :=
FLAGS += /define:SYMBOL
define PREBUILDCMDS
endef
define PRELINKCMDS
endef
define POSTBUILDCMDS
endef
endif
]]
end
@@ -0,0 +1,87 @@
--
-- tests/test_keywords.lua
-- Automated test suite for configuration block keyword filtering.
-- Copyright (c) 2008, 2009 Jason Perkins and the Premake project
--
T.keywords = { }
local suite = T.keywords
--
-- Keyword escaping tests
--
function suite.escapes_special_chars()
test.isequal("%.%-", path.wildcards(".-"))
end
function suite.escapes_star()
test.isequal("vs[^/]*", path.wildcards("vs*"))
end
function suite.escapes_star_star()
test.isequal("Images/.*%.bmp", path.wildcards("Images/**.bmp"))
end
--
-- Keyword matching tests
--
function T.keywords.matches_simple_strings()
test.istrue(premake.iskeywordmatch("debug", { "debug", "windows", "vs2005" }))
end
function T.keywords.match_files_with_simple_strings()
test.isfalse(premake.iskeywordmatch("release", { "debug", "windows", "vs2005" }))
end
function T.keywords.matches_with_patterns()
test.istrue(premake.iskeywordmatch("vs20.*", { "debug", "windows", "vs2005" }))
end
function T.keywords.match_fails_with_not_term()
test.isfalse(premake.iskeywordmatch("not windows", { "debug", "windows", "vs2005" }))
end
function T.keywords.match_ok_with_not_term()
test.istrue(premake.iskeywordmatch("not linux", { "debug", "windows", "vs2005" }))
end
function T.keywords.match_ok_with_first_or()
test.istrue(premake.iskeywordmatch("windows or linux", { "debug", "windows", "vs2005" }))
end
function T.keywords.match_ok_with_first_or()
test.istrue(premake.iskeywordmatch("windows or linux", { "debug", "linux", "vs2005" }))
end
function T.keywords.match_ok_with_not_and_or()
test.istrue(premake.iskeywordmatch("not macosx or linux", { "debug", "windows", "vs2005" }))
end
function T.keywords.match_fail_with_not_and_or()
test.isfalse(premake.iskeywordmatch("not macosx or windows", { "debug", "windows", "vs2005" }))
end
function T.keywords.match_ok_required_term()
test.istrue(premake.iskeywordsmatch({ "debug", "hello.c" }, { "debug", "windows", "vs2005", required="hello.c" }))
end
function T.keywords.match_fail_required_term()
test.isfalse(premake.iskeywordsmatch({ "debug" }, { "debug", "windows", "vs2005", required="hello.c" }))
end
@@ -0,0 +1,58 @@
--
-- tests/test_platforms.lua
-- Automated test suite for platform handling functions.
-- Copyright (c) 2009 Jason Perkins and the Premake project
--
T.platforms = { }
local testmap = { Native="Win32", x32="Win32", x64="x64" }
local sln, r
function T.platforms.setup()
sln = solution "MySolution"
configurations { "Debug", "Release" }
end
function T.platforms.filter_OnNoSolutionPlatforms()
premake.bake.buildconfigs()
r = premake.filterplatforms(sln, testmap)
test.isequal("", table.concat(r, ":"))
end
function T.platforms.filter_OnNoSolutionPlatformsAndDefault()
premake.bake.buildconfigs()
r = premake.filterplatforms(sln, testmap, "x32")
test.isequal("x32", table.concat(r, ":"))
end
function T.platforms.filter_OnIntersection()
platforms { "x32", "x64", "Xbox360" }
premake.bake.buildconfigs()
r = premake.filterplatforms(sln, testmap, "x32")
test.isequal("x32:x64", table.concat(r, ":"))
end
function T.platforms.filter_OnNoIntersection()
platforms { "Universal", "Xbox360" }
premake.bake.buildconfigs()
r = premake.filterplatforms(sln, testmap)
test.isequal("", table.concat(r, ":"))
end
function T.platforms.filter_OnNoIntersectionAndDefault()
platforms { "Universal", "Xbox360" }
premake.bake.buildconfigs()
r = premake.filterplatforms(sln, testmap, "x32")
test.isequal("x32", table.concat(r, ":"))
end
function T.platforms.filter_OnDuplicateKeys()
platforms { "Native", "x32" }
premake.bake.buildconfigs()
r = premake.filterplatforms(sln, testmap, "x32")
test.isequal("Native", table.concat(r, ":"))
end
@@ -0,0 +1,47 @@
--
-- tests/test_premake.lua
-- Automated test suite for the Premake support functions.
-- Copyright (c) 2008-2009 Jason Perkins and the Premake project
--
T.premake = { }
--
-- premake.checktools() tests
--
function T.premake.checktools_SetsDefaultTools()
_ACTION = "gmake"
premake.checktools()
test.isequal("gcc", _OPTIONS.cc)
test.isequal("mono", _OPTIONS.dotnet)
end
function T.premake.checktools_Fails_OnToolMismatch()
_ACTION = "gmake"
_OPTIONS["cc"] = "xyz"
ok, err = premake.checktools()
test.isfalse( ok )
test.isequal("the GNU Make action does not support /cc=xyz (yet)", err)
end
--
-- generate() tests
--
function T.premake.generate_OpensCorrectFile()
prj = { name = "MyProject", location = "MyLocation" }
premake.generate(prj, "%%.prj", function () end)
test.openedfile("MyLocation/MyProject.prj")
end
function T.premake.generate_ClosesFile()
prj = { name = "MyProject", location = "MyLocation" }
premake.generate(prj, "%%.prj", function () end)
test.closedfile(true)
end
@@ -0,0 +1,64 @@
--
-- tests/test_project.lua
-- Automated test suite for the project support functions.
-- Copyright (c) 2008-2010 Jason Perkins and the Premake project
--
local _project = premake.project
T.project = { }
local cfg, result
function T.project.setup()
_ACTION = "gmake"
cfg = {}
cfg.project = {}
cfg.language = "C++"
cfg.files = {}
cfg.trimpaths = {}
cfg.platform = "Native"
result = "\n"
end
--
-- findproject() tests
--
function T.project.findproject_IsCaseSensitive()
local sln = test.createsolution()
local prj = test.createproject(sln)
premake.bake.buildconfigs()
test.isnil(premake.findproject("myproject"))
end
--
-- getfilename() tests
--
function T.project.getfilename_ReturnsRelativePath()
local prj = { name = "project", location = "location" }
local r = _project.getfilename(prj, path.join(os.getcwd(), "../filename"))
test.isequal("../filename", r)
end
function T.project.getfilename_PerformsSubstitutions()
local prj = { name = "project", location = "location" }
local r = _project.getfilename(prj, "%%.prj")
test.isequal("location/project.prj", r)
end
--
-- premake.getlinks() tests
--
function T.project.getlinks_OnMscSystemLibs()
_OPTIONS.cc = "msc"
cfg.links = { "user32", "gdi32" }
result = premake.getlinks(cfg, "all", "fullpath")
test.isequal("user32.lib gdi32.lib", table.concat(result, " "))
end
@@ -0,0 +1,44 @@
--
-- tests/tests_stress.lua
-- Stress test for Premake.
-- Copyright (c) 2009 Jason Perkins and the Premake project
--
local numprojects = 100
local numfiles = 100
dofile("pepperfish_profiler.lua")
profiler = newProfiler()
function dumpresults(sorttotal)
local outfile = io.open("build/profile.txt", "w+" )
profiler:report(outfile, sorttotal)
outfile:close()
end
solution "MySolution"
configurations { "Debug", "Release", "DebugDLL", "ReleaseDLL" }
platforms { "Native", "x32", "x64" }
location "build"
configuration "Debug"
defines { "_DEBUG" }
flags { "Symbols" }
configuration "Release"
defines { "NDEBUG" }
flags { "Optimize" }
for pi = 1, numprojects do
project ("Project" .. pi)
location "build"
kind "ConsoleApp"
language "C++"
for fi = 1, numfiles do
files { "file" .. fi .. ".cpp" }
end
end
@@ -0,0 +1,73 @@
--
-- tests/test_string.lua
-- Automated test suite for the new string functions.
-- Copyright (c) 2008 Jason Perkins and the Premake project
--
T.string = { }
--
-- string.endswith() tests
--
function T.string.endswith_ReturnsTrue_OnMatch()
test.istrue(string.endswith("Abcdef", "def"))
end
function T.string.endswith_ReturnsFalse_OnMismatch()
test.isfalse(string.endswith("Abcedf", "efg"))
end
function T.string.endswith_ReturnsFalse_OnLongerNeedle()
test.isfalse(string.endswith("Abc", "Abcdef"))
end
function T.string.endswith_ReturnsFalse_OnNilHaystack()
test.isfalse(string.endswith(nil, "ghi"))
end
function T.string.endswith_ReturnsFalse_OnNilNeedle()
test.isfalse(string.endswith("Abc", nil))
end
function T.string.endswith_ReturnsTrue_OnExactMatch()
test.istrue(string.endswith("/", "/"))
end
--
-- string.explode() tests
--
function T.string.explode_ReturnsParts_OnValidCall()
test.isequal({"aaa","bbb","ccc"}, string.explode("aaa/bbb/ccc", "/", true))
end
--
-- string.startswith() tests
--
function T.string.startswith_OnMatch()
test.istrue(string.startswith("Abcdef", "Abc"))
end
function T.string.startswith_OnMismatch()
test.isfalse(string.startswith("Abcdef", "ghi"))
end
function T.string.startswith_OnLongerNeedle()
test.isfalse(string.startswith("Abc", "Abcdef"))
end
function T.string.startswith_OnEmptyHaystack()
test.isfalse(string.startswith("", "Abc"))
end
function T.string.startswith_OnEmptyNeedle()
test.istrue(string.startswith("Abcdef", ""))
end
@@ -0,0 +1,294 @@
--
-- tests/test_targets.lua
-- Automated test suite for premake.gettarget()
-- Copyright (c) 2008, 2009 Jason Perkins and the Premake project
--
T.targets = { }
local cfg
function T.targets.setup()
cfg = { }
cfg.basedir = "."
cfg.location = "."
cfg.targetdir = "../bin"
cfg.language = "C++"
cfg.project = { name = "MyProject" }
cfg.flags = { }
cfg.objectsdir = "obj"
cfg.platform = "Native"
end
--
-- Path Style Name Style Example Environment
-- ---------- ---------- -------------------
-- windows windows VStudio with MSC
-- posix posix GMake with GCC
-- windows posix VStudio for PS3
-- posix windows GMake for .NET
--
--
-- ConsoleApp tests
--
function T.targets.ConsoleApp_Build_WindowsNames()
cfg.kind = "ConsoleApp"
result = premake.gettarget(cfg, "build", "posix", "windows", "macosx")
test.isequal([[../bin/MyProject.exe]], result.fullpath)
end
function T.targets.ConsoleApp_Build_PosixNames_OnWindows()
cfg.kind = "ConsoleApp"
result = premake.gettarget(cfg, "build", "posix", "posix", "windows")
test.isequal([[../bin/MyProject.exe]], result.fullpath)
end
function T.targets.ConsoleApp_Build_PosixNames_OnLinux()
cfg.kind = "ConsoleApp"
result = premake.gettarget(cfg, "build", "posix", "posix", "linux")
test.isequal([[../bin/MyProject]], result.fullpath)
end
function T.targets.ConsoleApp_Build_PosixNames_OnMacOSX()
cfg.kind = "ConsoleApp"
result = premake.gettarget(cfg, "build", "posix", "posix", "macosx")
test.isequal([[../bin/MyProject]], result.fullpath)
end
function T.targets.ConsoleApp_Build_PS3Names()
cfg.kind = "ConsoleApp"
result = premake.gettarget(cfg, "build", "posix", "PS3", "macosx")
test.isequal([[../bin/MyProject.elf]], result.fullpath)
end
--
-- WindowedApp tests
--
function T.targets.WindowedApp_Build_WindowsNames()
cfg.kind = "WindowedApp"
result = premake.gettarget(cfg, "build", "posix", "windows", "macosx")
test.isequal([[../bin/MyProject.exe]], result.fullpath)
end
function T.targets.WindowedApp_Build_PosixNames_OnWindows()
cfg.kind = "WindowedApp"
result = premake.gettarget(cfg, "build", "posix", "posix", "windows")
test.isequal([[../bin/MyProject.exe]], result.fullpath)
end
function T.targets.WindowedApp_Build_PosixNames_OnLinux()
cfg.kind = "WindowedApp"
result = premake.gettarget(cfg, "build", "posix", "posix", "linux")
test.isequal([[../bin/MyProject]], result.fullpath)
end
function T.targets.WindowedApp_Build_PosixNames_OnMacOSX()
cfg.kind = "WindowedApp"
result = premake.gettarget(cfg, "build", "posix", "posix", "macosx")
test.isequal([[../bin/MyProject.app/Contents/MacOS/MyProject]], result.fullpath)
end
function T.targets.WindowedApp_Build_PS3Names()
cfg.kind = "WindowedApp"
result = premake.gettarget(cfg, "build", "posix", "PS3", "macosx")
test.isequal([[../bin/MyProject.elf]], result.fullpath)
end
--
-- SharedLib tests
--
function T.targets.SharedLib_Build_WindowsNames()
cfg.kind = "SharedLib"
result = premake.gettarget(cfg, "build", "posix", "windows", "macosx")
test.isequal([[../bin/MyProject.dll]], result.fullpath)
end
function T.targets.SharedLib_Link_WindowsNames()
cfg.kind = "SharedLib"
result = premake.gettarget(cfg, "link", "posix", "windows", "macosx")
test.isequal([[../bin/MyProject.lib]], result.fullpath)
end
function T.targets.SharedLib_Build_PosixNames_OnWindows()
cfg.kind = "SharedLib"
result = premake.gettarget(cfg, "build", "posix", "posix", "windows")
test.isequal([[../bin/MyProject.dll]], result.fullpath)
end
function T.targets.SharedLib_Link_PosixNames_OnWindows()
cfg.kind = "SharedLib"
result = premake.gettarget(cfg, "link", "posix", "posix", "windows")
test.isequal([[../bin/libMyProject.a]], result.fullpath)
end
function T.targets.SharedLib_Build_PosixNames_OnLinux()
cfg.kind = "SharedLib"
result = premake.gettarget(cfg, "build", "posix", "posix", "linux")
test.isequal([[../bin/libMyProject.so]], result.fullpath)
end
function T.targets.SharedLib_Link_PosixNames_OnLinux()
cfg.kind = "SharedLib"
result = premake.gettarget(cfg, "link", "posix", "posix", "linux")
test.isequal([[../bin/libMyProject.so]], result.fullpath)
end
function T.targets.SharedLib_Build_PosixNames_OnMacOSX()
cfg.kind = "SharedLib"
result = premake.gettarget(cfg, "build", "posix", "posix", "macosx")
test.isequal([[../bin/libMyProject.dylib]], result.fullpath)
end
function T.targets.SharedLib_Link_PosixNames_OnMacOSX()
cfg.kind = "SharedLib"
result = premake.gettarget(cfg, "link", "posix", "posix", "macosx")
test.isequal([[../bin/libMyProject.dylib]], result.fullpath)
end
--
-- Bundle tests
--
function T.targets.Bundle_Build_WindowsNames()
cfg.kind = "Bundle"
result = premake.gettarget(cfg, "build", "posix", "windows", "macosx")
test.isequal([[../bin/MyProject.dll]], result.fullpath)
end
function T.targets.Bundle_Link_WindowsNames()
cfg.kind = "Bundle"
result = premake.gettarget(cfg, "link", "posix", "windows", "macosx")
test.isequal([[../bin/MyProject.lib]], result.fullpath)
end
function T.targets.Bundle_Build_PosixNames_OnWindows()
cfg.kind = "Bundle"
result = premake.gettarget(cfg, "build", "posix", "posix", "windows")
test.isequal([[../bin/MyProject.dll]], result.fullpath)
end
function T.targets.Bundle_Link_PosixNames_OnWindows()
cfg.kind = "Bundle"
result = premake.gettarget(cfg, "link", "posix", "posix", "windows")
test.isequal([[../bin/libMyProject.a]], result.fullpath)
end
function T.targets.Bundle_Build_PosixNames_OnLinux()
cfg.kind = "Bundle"
result = premake.gettarget(cfg, "build", "posix", "posix", "linux")
test.isequal([[../bin/libMyProject.so]], result.fullpath)
end
function T.targets.Bundle_Link_PosixNames_OnLinux()
cfg.kind = "Bundle"
result = premake.gettarget(cfg, "link", "posix", "posix", "linux")
test.isequal([[../bin/libMyProject.so]], result.fullpath)
end
function T.targets.Bundle_Build_PosixNames_OnMacOSX()
cfg.kind = "Bundle"
result = premake.gettarget(cfg, "build", "posix", "posix", "macosx")
test.isequal([[../bin/MyProject.bundle]], result.fullpath)
end
function T.targets.Bundle_Link_PosixNames_OnMacOSX()
cfg.kind = "Bundle"
result = premake.gettarget(cfg, "link", "posix", "posix", "macosx")
test.isequal([[../bin/MyProject.bundle]], result.fullpath)
end
--
-- StaticLib tests
--
function T.targets.StaticLib_Build_WindowsNames()
cfg.kind = "StaticLib"
result = premake.gettarget(cfg, "build", "posix", "windows", "macosx")
test.isequal([[../bin/MyProject.lib]], result.fullpath)
end
function T.targets.StaticLib_Link_WindowsNames()
cfg.kind = "StaticLib"
result = premake.gettarget(cfg, "link", "posix", "windows", "macosx")
test.isequal([[../bin/MyProject.lib]], result.fullpath)
end
function T.targets.StaticLib_Build_PosixNames_OnWindows()
cfg.kind = "StaticLib"
result = premake.gettarget(cfg, "build", "posix", "posix", "windows")
test.isequal([[../bin/libMyProject.a]], result.fullpath)
end
function T.targets.StaticLib_Link_PosixNames_OnWindows()
cfg.kind = "StaticLib"
result = premake.gettarget(cfg, "link", "posix", "posix", "windows")
test.isequal([[../bin/libMyProject.a]], result.fullpath)
end
function T.targets.StaticLib_Build_PosixNames_OnLinux()
cfg.kind = "StaticLib"
result = premake.gettarget(cfg, "build", "posix", "posix", "linux")
test.isequal([[../bin/libMyProject.a]], result.fullpath)
end
function T.targets.StaticLib_Link_PosixNames_OnLinux()
cfg.kind = "StaticLib"
result = premake.gettarget(cfg, "link", "posix", "posix", "linux")
test.isequal([[../bin/libMyProject.a]], result.fullpath)
end
function T.targets.StaticLib_Build_PosixNames_OnMacOSX()
cfg.kind = "StaticLib"
result = premake.gettarget(cfg, "build", "posix", "posix", "macosx")
test.isequal([[../bin/libMyProject.a]], result.fullpath)
end
function T.targets.StaticLib_Link_PosixNames_OnMacOSX()
cfg.kind = "StaticLib"
result = premake.gettarget(cfg, "link", "posix", "posix", "macosx")
test.isequal([[../bin/libMyProject.a]], result.fullpath)
end
function T.targets.StaticLib_Build_PosixNames_OnPS3()
cfg.kind = "StaticLib"
result = premake.gettarget(cfg, "build", "posix", "PS3", "macosx")
test.isequal([[../bin/libMyProject.a]], result.fullpath)
end
function T.targets.StaticLib_Link_PosixNames_OnPS3()
cfg.kind = "StaticLib"
result = premake.gettarget(cfg, "link", "posix", "PS3", "macosx")
test.isequal([[../bin/libMyProject.a]], result.fullpath)
end
function T.targets.StaticLib_Link_IgnoresImpLib()
cfg.kind = "StaticLib"
cfg.implibdir = "../lib"
result = premake.gettarget(cfg, "link", "posix", "posix", "macosx")
test.isequal([[../bin/libMyProject.a]], result.fullpath)
end
--
-- Windows path tests
--
function T.targets.WindowsPaths()
cfg.kind = "ConsoleApp"
result = premake.gettarget(cfg, "build", "windows", "windows", "linux")
test.isequal([[..\bin]], result.directory)
test.isequal([[..\bin\MyProject.exe]], result.fullpath)
end
@@ -0,0 +1,287 @@
--
-- tests/testfx.lua
-- Automated test framework for Premake.
-- Copyright (c) 2008-2009 Jason Perkins and the Premake project
--
--
-- Define a namespace for the testing functions
--
test = { }
--
-- Assertion functions
--
function test.string_contains(buffer, expected)
if not string.find(buffer,expected) then
test.fail("\n==Fail==: Expected to find :\n%s\nyet it was not found in buffer:\n%s\n", expected,buffer)
end
end
function test.string_does_not_contain(buffer, expected)
if string.find(buffer,expected) then
test.fail("\n==Fail==: Did not expected to find :\n%s\nyet it was found in buffer:\n%s\n", expected,buffer)
end
end
function test.capture(expected)
local actual = io.endcapture()
local ait = actual:gfind("(.-)" .. io.eol)
local eit = expected:gfind("(.-)\n")
local linenum = 1
local atxt = ait()
local etxt = eit()
while etxt do
if (etxt ~= atxt) then
test.fail("(%d) expected:\n%s\n...but was:\n%s", linenum, etxt, atxt)
end
linenum = linenum + 1
atxt = ait()
etxt = eit()
end
end
function test.closedfile(expected)
if expected and not test.value_closedfile then
test.fail("expected file to be closed")
elseif not expected and test.value_closedfile then
test.fail("expected file to remain open")
end
end
function test.contains(value, expected)
if not table.contains(value, expected) then
test.fail("expected value %s not found", expected)
end
end
function test.fail(format, ...)
-- convert nils into something more usefuls
for i = 1, arg.n do
if (arg[i] == nil) then
arg[i] = "(nil)"
elseif (type(arg[i]) == "table") then
arg[i] = "{" .. table.concat(arg[i], ", ") .. "}"
end
end
error(string.format(format, unpack(arg)), 3)
end
function test.filecontains(expected, fn)
local f = io.open(fn)
local actual = f:read("*a")
f:close()
if (expected ~= actual) then
test.fail("expected %s but was %s", expected, actual)
end
end
function test.isemptycapture()
local actual = io.endcapture()
if actual ~= "" then
test.fail("expected empty capture, but was %s", actual);
end
end
function test.isequal(expected, actual)
if (type(expected) == "table") then
for k,v in pairs(expected) do
if not (test.isequal(expected[k], actual[k])) then
test.fail("expected %s but was %s", expected, actual)
end
end
else
if (expected ~= actual) then
test.fail("expected %s but was %s", expected, actual)
end
end
return true
end
function test.isfalse(value)
if (value) then
test.fail("expected false but was true")
end
end
function test.isnil(value)
if (value ~= nil) then
test.fail("expected nil but was " .. tostring(value))
end
end
function test.isnotnil(value)
if (value == nil) then
test.fail("expected not nil")
end
end
function test.istrue(value)
if (not value) then
test.fail("expected true but was false")
end
end
function test.openedfile(fname)
if fname ~= test.value_openedfilename then
local msg = "expected to open file '" .. fname .. "'"
if test.value_openedfilename then
msg = msg .. ", got '" .. test.value_openedfilename .. "'"
end
test.fail(msg)
end
end
function test.success(fn, ...)
local ok, err = pcall(fn, unpack(arg))
if not ok then
test.fail("call failed: " .. err)
end
end
--
-- Test stubs
--
local function stub_io_open(fname, mode)
test.value_openedfilename = fname
test.value_openedfilemode = mode
return {
close = function()
test.value_closedfile = true
end
}
end
local function stub_io_output(f)
end
local function stub_print(s)
end
--
-- Define a collection for the test suites
--
T = { }
--
-- Test execution function
--
local _OS_host = _OS
local function test_setup(suite, fn)
-- clear out some important globals
_ACTION = "test"
_ARGS = { }
_OPTIONS = { }
_OS = _OS_host
premake.solution.list = { }
io.indent = nil
io.eol = "\n"
-- reset captured I/O values
test.value_openedfilename = nil
test.value_openedfilemode = nil
test.value_closedfile = false
if suite.setup then
return pcall(suite.setup)
else
return true
end
end
local function test_run(suite, fn)
io.capture()
return pcall(fn)
end
local function test_teardown(suite, fn)
if suite.teardown then
return pcall(suite.teardown)
else
return true
end
end
function test.runall(suitename, testname)
test.print = print
print = stub_print
io.open = stub_io_open
io.output = stub_io_output
local numpassed = 0
local numfailed = 0
local start_time = os.clock()
function runtest(suitename, suitetests, testname, testfunc)
if suitetests.setup ~= testfunc and suitetests.teardown ~= testfunc then
local ok, err = test_setup(suitetests, testfunc)
if ok then
ok, err = test_run(suitetests, testfunc)
end
local tok, terr = test_teardown(suitetests, testfunc)
ok = ok and tok
err = err or terr
if (not ok) then
test.print(string.format("%s.%s: %s", suitename, testname, err))
numfailed = numfailed + 1
else
numpassed = numpassed + 1
end
end
end
function runsuite(suitename, suitetests, testname)
if testname then
runtest(suitename, suitetests, testname, suitetests[testname])
else
for testname, testfunc in pairs(suitetests) do
runtest(suitename, suitetests, testname, testfunc)
end
end
end
if suitename then
runsuite(suitename, T[suitename], testname)
else
for suitename, suitetests in pairs(T) do
runsuite(suitename, suitetests, testname)
end
end
io.write('running time : ', os.clock() - start_time,'\n')
print = test.print
return numpassed, numfailed
end
@@ -0,0 +1,78 @@
--
-- tests/test_gcc.lua
-- Automated test suite for the GCC toolset interface.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
--
T.gcc = { }
local suite = T.gcc
local cfg
function suite.setup()
cfg = { }
cfg.basedir = "."
cfg.location = "."
cfg.language = "C++"
cfg.project = { name = "MyProject" }
cfg.flags = { }
cfg.objectsdir = "obj"
cfg.platform = "Native"
cfg.links = { }
cfg.libdirs = { }
cfg.linktarget = { fullpath="libMyProject.a" }
end
--
-- CPPFLAGS tests
--
function suite.cppflags_OnWindows()
cfg.system = "windows"
local r = premake.gcc.getcppflags(cfg)
test.isequal("-MMD -MP", table.concat(r, " "))
end
--
-- CFLAGS tests
--
function suite.cflags_SharedLib_Windows()
cfg.kind = "SharedLib"
cfg.system = "windows"
local r = premake.gcc.getcflags(cfg)
test.isequal('', table.concat(r,"|"))
end
function suite.cflags_OnFpFast()
cfg.flags = { "FloatFast" }
local r = premake.gcc.getcflags(cfg)
test.isequal('-ffast-math', table.concat(r,"|"))
end
function suite.cflags_OnFpStrict()
cfg.flags = { "FloatStrict" }
local r = premake.gcc.getcflags(cfg)
test.isequal('-ffloat-store', table.concat(r,"|"))
end
--
-- LDFLAGS tests
--
function suite.ldflags_SharedLib_Windows()
cfg.kind = "SharedLib"
cfg.system = "windows"
local r = premake.gcc.getldflags(cfg)
test.isequal('-s|-shared|-Wl,--out-implib="libMyProject.a"', table.concat(r,"|"))
end
function suite.linkflags_OnFrameworks()
cfg.links = { "Cocoa.framework" }
local r = premake.gcc.getlinkflags(cfg)
test.isequal('-framework Cocoa', table.concat(r,"|"))
end