diff --git a/src/actions/vstudio/vs2005_csproj.lua b/src/actions/vstudio/vs2005_csproj.lua index e63d89b9..e59f3b30 100644 --- a/src/actions/vstudio/vs2005_csproj.lua +++ b/src/actions/vstudio/vs2005_csproj.lua @@ -17,18 +17,6 @@ cs2005.elements = {} --- --- XML escaping for C# projects is a little different than for C++. --- - - function cs2005.esc(value) - value = value:gsub('&', "&") - value = value:gsub('<', "<") - value = value:gsub('>', ">") - return value - end - - -- -- Generate a Visual Studio 200x C# project, with support for the new platforms API. -- @@ -45,7 +33,6 @@ function cs2005.generate(prj) io.indent = " " io.eol = "\r\n" - io.esc = cs2005.esc io.utf8() premake.callarray(cs2005, cs2005.elements.project, prj) diff --git a/src/actions/vstudio/vs2010.lua b/src/actions/vstudio/vs2010.lua index 3961724c..3df7a7fc 100644 --- a/src/actions/vstudio/vs2010.lua +++ b/src/actions/vstudio/vs2010.lua @@ -36,6 +36,19 @@ +-- +-- The VS 2010 standard for XML escaping in generated project files. +-- + + function vs2010.esc(value) + value = value:gsub('&', "&") + value = value:gsub('<', "<") + value = value:gsub('>', ">") + return value + end + + + --- -- Define the Visual Studio 2010 export action. --- diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index 1f6bb126..013b743a 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -27,7 +27,6 @@ function vc2010.generate(prj) io.indent = " " - io.esc = vc2010.esc io.utf8() vc2010.xmlDeclaration() @@ -71,22 +70,6 @@ ---- --- Apply XML escaping on a value to be included in an --- exported project file. ---- - - function vc2010.esc(value) - value = string.gsub(value, '&', "&") - value = value:gsub('<', "<") - value = value:gsub('>', ">") - value = value:gsub('\r', " ") - value = value:gsub('\n', " ") - return value - end - - - -- -- Output the XML declaration and opening tag. -- diff --git a/tests/actions/vstudio/cs2005/test_build_events.lua b/tests/actions/vstudio/cs2005/test_build_events.lua index 6ddf76d7..1c9bd7aa 100644 --- a/tests/actions/vstudio/cs2005/test_build_events.lua +++ b/tests/actions/vstudio/cs2005/test_build_events.lua @@ -15,7 +15,7 @@ local sln, prj, cfg function suite.setup() - io.esc = cs2005.esc + io.esc = premake.vstudio.vs2010.esc sln = test.createsolution() end diff --git a/tests/actions/vstudio/vc2010/test_build_events.lua b/tests/actions/vstudio/vc2010/test_build_events.lua new file mode 100644 index 00000000..3fbd2d34 --- /dev/null +++ b/tests/actions/vstudio/vc2010/test_build_events.lua @@ -0,0 +1,101 @@ +-- +-- tests/actions/vstudio/vc2010/test_build_events.lua +-- Check generation of pre- and post-build commands for C++ projects. +-- Copyright (c) 2012-2013 Jason Perkins and the Premake project +-- + + local suite = test.declare("vstudio_vc2010_build_events") + local vc2010 = premake.vstudio.vc2010 + + +-- +-- Setup +-- + + local sln, prj, cfg + + function suite.setup() + io.esc = premake.vstudio.vs2010.esc + sln = test.createsolution() + end + + local function prepare(platform) + prj = premake.solution.getproject(sln, 1) + vc2010.buildEvents(prj) + end + + +-- +-- If no build steps are specified, nothing should be written. +-- + + function suite.noOutput_onNoEvents() + prepare() + test.isemptycapture() + end + + +-- +-- If one command set is used and not the other, only the one should be written. +-- + + function suite.onlyOne_onPreBuildOnly() + prebuildcommands { "command1" } + prepare() + test.capture [[ + + command1 + + ]] + end + + function suite.onlyOne_onPostBuildOnly() + postbuildcommands { "command1" } + prepare() + test.capture [[ + + command1 + + ]] + end + + function suite.both_onBoth() + prebuildcommands { "command1" } + postbuildcommands { "command2" } + prepare() + test.capture [[ + + command1 + + + command2 + + ]] + end + + +-- +-- Multiple commands should be separated with un-escaped EOLs. +-- + + function suite.splits_onMultipleCommands() + postbuildcommands { "command1", "command2" } + prepare() + test.capture ("\t\t\n\t\t\tcommand1\r\ncommand2\n\t\t\n") + end + + + +-- +-- Quotes should not be escaped, other special characters should. +-- + + function suite.onSpecialChars() + postbuildcommands { '\' " < > &' } + prepare() + test.capture [[ + + ' " < > & + + ]] + end diff --git a/tests/actions/vstudio/vc2010/test_resource_compile.lua b/tests/actions/vstudio/vc2010/test_resource_compile.lua index 05e2accd..519fa02d 100755 --- a/tests/actions/vstudio/vc2010/test_resource_compile.lua +++ b/tests/actions/vstudio/vc2010/test_resource_compile.lua @@ -16,7 +16,7 @@ local sln, prj function suite.setup() - io.esc = vc2010.esc + io.esc = premake.vstudio.vs2010.esc sln, prj = test.createsolution() end diff --git a/tests/premake5.lua b/tests/premake5.lua index de49662c..2447ba8e 100644 --- a/tests/premake5.lua +++ b/tests/premake5.lua @@ -142,6 +142,7 @@ -- Visual Studio 2010 C/C++ projects dofile("actions/vstudio/vc2010/test_assembly_refs.lua") + dofile("actions/vstudio/vc2010/test_build_events.lua") dofile("actions/vstudio/vc2010/test_compile_settings.lua") dofile("actions/vstudio/vc2010/test_config_props.lua") dofile("actions/vstudio/vc2010/test_debug_settings.lua")