-- -- 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 p = premake local suite = test.declare("vstudio_vs2010_files") local vc2010 = p.vstudio.vc2010 -- -- Setup -- local wks, prj function suite.setup() p.action.set("vs2010") rule "Animation" fileextension ".dae" propertydefinition { name = "AdditionalOptions", kind = "list", separator = ";" } wks = test.createWorkspace() end local function prepare() prj = test.getproject(wks, 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.midlCompile_onIDLFile() files { "idl/interfaces.idl" } prepare() test.capture [[ ]] end function suite.none_onTxtFile() files { "docs/hello.txt" } prepare() test.capture [[ ]] end -- -- Check handling of buildaction. -- function suite.customBuildTool_onBuildAction() files { "test.x", "test2.cpp", "test3.cpp" } filter "files:**.x" buildaction "FxCompile" filter "files:test2.cpp" buildaction "None" 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 ]] 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 ]] 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) ]] 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 ]] 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 ]] 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 ]] 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 ]] end function suite.excludedFromBuild_onResourceFile_excludeFlag_nonWindows() files { "hello.rc" } system "Linux" filter "files:hello.rc" flags { "ExcludeFromBuild" } prepare() test.capture [[ true ]] end function suite.includedFromBuild_onResourceFile_nonWindows() files { "hello.rc" } system "Linux" 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 ]] 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 a custom rule outputs an object file, it's automatically linked, unless -- we explicitly specify that it isn't with linkbuildoutputs. -- function suite.linkBuildOutputs_onNotSpecified() files { "hello.x" } filter "files:**.x" buildcommands { "echo $(InputFile)" } buildoutputs { "$(InputName).obj" } prepare() test.capture [[ Document echo $(InputFile) $(InputName).obj ]] end function suite.linkBuildOutputs_onOff() files { "hello.x" } filter "files:**.x" buildcommands { "echo $(InputFile)" } buildoutputs { "$(InputName).obj" } linkbuildoutputs "Off" prepare() test.capture [[ Document echo $(InputFile) $(InputName).obj false ]] end function suite.linkBuildOutputs_onOn() files { "hello.x" } filter "files:**.x" buildcommands { "echo $(InputFile)" } buildoutputs { "$(InputName).obj" } linkbuildoutputs "On" prepare() test.capture [[ Document echo $(InputFile) $(InputName).obj true ]] 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 ]] end function suite.uniqueObjectNames_onBaseNameCollision1() files { "a/hello.cpp", "b/hello.cpp", "c/hello1.cpp" } prepare() test.capture [[ $(IntDir)\hello1.obj $(IntDir)\hello11.obj ]] end function suite.uniqueObjectNames_onBaseNameCollision2() files { "a/hello1.cpp", "b/hello.cpp", "c/hello.cpp" } prepare() test.capture [[ $(IntDir)\hello2.obj ]] end function suite.uniqueObjectNames_onBaseNameCollision_Release() files { "a/hello.cpp", "b/hello.cpp", "c/hello1.cpp", "d/hello11.cpp" } filter "configurations:Debug" excludes {"b/hello.cpp"} filter "configurations:Release" excludes {"d/hello11.cpp"} prepare() test.capture [[ true $(IntDir)\hello1.obj $(IntDir)\hello11.obj true ]] end -- -- Test that changes in case are treated as if multiple files of the same name are being built -- function suite.uniqueObjectNames_onSourceNameCollision_ignoreCase() files { "hello.cpp", "greetings/Hello.cpp" } prepare() test.capture [[ $(IntDir)\hello1.obj ]] end function suite.uniqueObjectNames_onBaseNameCollision_ignoreCase1() files { "a/hello.cpp", "b/Hello.cpp", "c/hello1.cpp" } prepare() test.capture [[ $(IntDir)\Hello1.obj $(IntDir)\hello11.obj ]] end function suite.uniqueObjectNames_onBaseNameCollision_ignoreCase2() files { "a/hello1.cpp", "b/Hello.cpp", "c/hello.cpp" } prepare() test.capture [[ $(IntDir)\hello2.obj ]] end function suite.uniqueObjectNames_onBaseNameCollision_Release_ignoreCase() files { "a/Hello.cpp", "b/hello.cpp", "c/hello1.cpp", "d/hello11.cpp" } filter "configurations:Debug" excludes {"b/hello.cpp"} filter "configurations:Release" excludes {"d/hello11.cpp"} prepare() test.capture [[ true $(IntDir)\hello1.obj $(IntDir)\hello11.obj true ]] 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 ]] 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) ]] end -- -- Check handling of per-file compileas options. -- function suite.onCompileAs() files { "hello.c" } filter "files:hello.c" compileas "C++" prepare() test.capture [[ CompileAsCpp ]] end function suite.onCompileAsDebug() files { "hello.c" } filter { "configurations:Debug", "files:hello.c" } compileas "C++" prepare() test.capture [[ CompileAsCpp ]] 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 optimization levels. -- function suite.onPerFileRttiOn() files { "hello.cpp" } filter "files:hello.cpp" rtti "On" prepare() test.capture [[ true ]] end function suite.onPerFileRttiOff() files { "hello.cpp" } filter "files:hello.cpp" rtti "Off" prepare() test.capture [[ false ]] 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 ]] 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) ]] end -- -- Check handling of per-file command line build options. -- function suite.perFileSEH() files { "hello.asm", "hello.cpp" } filter "files:**.asm" exceptionhandling 'SEH' prepare() test.capture [[ true ]] 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 ]] 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 -- -- test warning level set for a single file -- function suite.warningLevelPerFile() warnings 'Off' files { "hello.cpp", "hello2.cpp" } filter { "files:hello.cpp" } warnings 'Extra' prepare() test.capture [[ Level4 ]] end