--
-- tests/actions/vstudio/vc2010/test_files.lua
-- Validate generation of files block in Visual Studio 2010 C/C++ projects.
-- Copyright (c) 2011-2014 Jason Perkins and the Premake project
--
local suite = test.declare("vstudio_vs2010_files")
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj
function suite.setup()
_ACTION = "vs2010"
rule "Animation"
fileextension ".dae"
propertydefinition {
name = "AdditionalOptions",
kind = "list",
separator = ";"
}
sln = test.createsolution()
end
local function prepare()
prj = premake.solution.getproject(sln, 1)
vc2010.files(prj)
end
--
-- Test filtering of source files into the correct categories.
--
function suite.clInclude_onHFile()
files { "include/hello.h" }
prepare()
test.capture [[
]]
end
function suite.clCompile_onCFile()
files { "hello.c" }
prepare()
test.capture [[
]]
end
function suite.resourceCompile_onRCFile()
files { "resources/hello.rc" }
prepare()
test.capture [[
]]
end
function suite.none_onTxtFile()
files { "docs/hello.txt" }
prepare()
test.capture [[
]]
end
--
-- Check handling of files with custom build rules.
--
function suite.customBuild_onBuildRule()
files { "hello.cg" }
filter "files:**.cg"
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
prepare()
test.capture [[
Document
cgc $(InputFile)
$(InputName).obj
cgc $(InputFile)
$(InputName).obj
]]
end
function suite.customBuild_onBuildRuleMultipleBuildOutputs()
files { "hello.cg" }
filter "files:**.cg"
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).a", "$(InputName).b" }
prepare()
test.capture [[
Document
cgc $(InputFile)
$(InputName).a;$(InputName).b
cgc $(InputFile)
$(InputName).a;$(InputName).b
]]
end
function suite.customBuild_onBuildRuleWithMessage()
files { "hello.cg" }
filter "files:**.cg"
buildmessage "Compiling shader $(InputFile)"
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
prepare()
test.capture [[
Document
cgc $(InputFile)
$(InputName).obj
Compiling shader $(InputFile)
cgc $(InputFile)
$(InputName).obj
Compiling shader $(InputFile)
]]
end
function suite.customBuild_onBuildRuleWithAdditionalInputs()
files { "hello.cg" }
filter "files:**.cg"
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
buildinputs { "common.cg.inc", "common.cg.inc2" }
prepare()
test.capture [[
Document
cgc $(InputFile)
$(InputName).obj
common.cg.inc;common.cg.inc2
cgc $(InputFile)
$(InputName).obj
common.cg.inc;common.cg.inc2
]]
end
--
-- If a PCH source is specified, ensure it is included in the file configuration.
--
function suite.precompiledHeader_onPchSource()
files { "afxwin.cpp" }
pchheader "afxwin.h"
pchsource "afxwin.cpp"
prepare()
test.capture [[
Create
Create
]]
end
--
-- If a file is excluded from a configuration, make sure it is marked as such.
--
function suite.excludedFromBuild_onExcludedFile()
files { "hello.cpp" }
filter "Debug"
removefiles { "hello.cpp" }
prepare()
test.capture [[
true
]]
end
function suite.excludedFromBuild_onExcludeFlag()
files { "hello.cpp" }
filter "files:hello.cpp"
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
true
true
]]
end
function suite.excludedFromBuild_onResourceFile_excludedFile()
files { "hello.rc" }
filter "Debug"
removefiles { "hello.rc" }
prepare()
test.capture [[
true
]]
end
function suite.excludedFromBuild_onResourceFile_excludeFlag()
files { "hello.rc" }
filter "files:hello.rc"
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
true
true
]]
end
function suite.excludedFromBuild_onResourceFile_excludeFlag_nonWindows()
files { "hello.rc" }
system "Linux"
filter "files:hello.rc"
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
]]
end
function suite.excludedFromBuild_onCustomBuildRule_excludedFile()
files { "hello.cg" }
filter "files:**.cg"
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
filter "Debug"
removefiles { "hello.cg" }
prepare()
test.capture [[
Document
cgc $(InputFile)
$(InputName).obj
]]
end
function suite.excludedFromBuild_onCustomBuildRule_excludeFlag()
files { "hello.cg" }
filter "files:**.cg"
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
Document
true
cgc $(InputFile)
$(InputName).obj
true
cgc $(InputFile)
$(InputName).obj
]]
end
function suite.excludedFromBuild_onCustomBuildRule_withNoCommands()
files { "hello.cg" }
filter { "files:**.cg", "Debug" }
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
filter { "files:**.cg" }
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
Document
true
cgc $(InputFile)
$(InputName).obj
]]
end
--
-- If two files at different folder levels have the same name, a different
-- object file name should be used for each.
--
function suite.uniqueObjectNames_onSourceNameCollision()
files { "hello.cpp", "greetings/hello.cpp" }
prepare()
test.capture [[
$(IntDir)\hello1.obj
$(IntDir)\hello1.obj
]]
end
--
-- Check handling of per-file forced includes.
--
function suite.forcedIncludeFiles()
files { "hello.cpp" }
filter "files:**.cpp"
forceincludes { "../include/force1.h", "../include/force2.h" }
prepare()
test.capture [[
..\include\force1.h;..\include\force2.h
..\include\force1.h;..\include\force2.h
]]
end
--
-- Check handling of per-file command line build options.
--
function suite.additionalOptions()
files { "hello.cpp" }
filter "files:**.cpp"
buildoptions { "/Xc" }
prepare()
test.capture [[
/Xc %(AdditionalOptions)
/Xc %(AdditionalOptions)
]]
end
--
-- Check handling of per-file optimization levels.
--
function suite.onOptimize()
files { "hello.cpp" }
filter "files:hello.cpp"
optimize "On"
prepare()
test.capture [[
Full
]]
end
function suite.onOptimizeSize()
files { "hello.cpp" }
filter "files:hello.cpp"
optimize "Size"
prepare()
test.capture [[
MinSpace
]]
end
function suite.onOptimizeSpeed()
files { "hello.cpp" }
filter "files:hello.cpp"
optimize "Speed"
prepare()
test.capture [[
MaxSpeed
]]
end
function suite.onOptimizeFull()
files { "hello.cpp" }
filter "files:hello.cpp"
optimize "Full"
prepare()
test.capture [[
Full
]]
end
function suite.onOptimizeOff()
files { "hello.cpp" }
filter "files:hello.cpp"
optimize "Off"
prepare()
test.capture [[
Disabled
]]
end
function suite.onOptimizeDebug()
files { "hello.cpp" }
filter "files:hello.cpp"
optimize "Debug"
prepare()
test.capture [[
Disabled
]]
end
--
-- Check handling of per-file no PCH build options.
--
function suite.excludedFromPCH()
files { "hello.cpp" }
filter "files:**.cpp"
flags { "NoPCH" }
prepare()
test.capture [[
NotUsing
NotUsing
]]
end
--
-- Check handling of per-file command line build options.
--
function suite.perFileDefines()
files { "hello.cpp" }
filter "files:**.cpp"
defines { "IS_CPP" }
prepare()
test.capture [[
IS_CPP;%(PreprocessorDefinitions)
IS_CPP;%(PreprocessorDefinitions)
]]
end
--
-- Make sure that the sort order of the source files is maintained even
-- when virtual paths are used to organize them.
--
function suite.maintainsSortOrder_onVirtualPaths()
files { "SystemTray.h", "PrefsWriter.h", "SystemTray.cpp", "PrefsWriter.cpp" }
vpaths {
["source/mfc"] = { "PrefsWriter.*" },
["source/core"] = { "SystemTray.*" },
}
prepare()
test.capture [[
]]
end
--
-- Check handling of per-file vector extensions.
--
function suite.perFileVectorExtensions()
files { "hello.cpp" }
filter "files:**.cpp"
vectorextensions "sse2"
prepare()
test.capture [[
StreamingSIMDExtensions2
StreamingSIMDExtensions2
]]
end
--
-- Check handling of files using custom rule definitions.
--
function suite.isCategorizedByRule()
rules "Animation"
files { "hello.dae" }
prepare()
test.capture [[
]]
end
function suite.listsPerConfigRuleVars()
rules "Animation"
files { "hello.dae" }
filter { "files:hello.*", "configurations:Debug" }
animationVars { AdditionalOptions = { "File1", "File2" }}
filter { "files:hello.*", "configurations:Release" }
animationVars { AdditionalOptions = { "File3" }}
prepare()
test.capture [[
File1;File2
File3
]]
end