Commits

Jason Perkins committed edb558d

Make VC2010 C++ .user file more extensible; add premake.override() convenience function.

  • Participants
  • Parent commits 8be1050

Comments (0)

Files changed (5)

File src/actions/vstudio/vs2010_vcxproj_user.lua

 	end
 
 	function vc2010.debugsettings(cfg)
+		vc2010.LocalDebuggerCommand(cfg)
+		vc2010.LocalDebuggerWorkingDirectory(cfg)
+		vc2010.DebuggerFlavor(cfg)
+		vc2010.LocalDebuggerCommandArguments(cfg)
+		vc2010.LocalDebuggerEnvironment(cfg)
+	end
+
+	function vc2010.DebuggerFlavor(cfg)
+		if cfg.debugdir or cfg.debugcommand then
+			_p(2,'<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>')	
+		end
+	end
+
+	function vc2010.LocalDebuggerCommand(cfg)
 		if cfg.debugcommand then
 			local dir = project.getrelative(cfg.project, cfg.debugcommand)
 			_p(2,'<LocalDebuggerCommand>%s</LocalDebuggerCommand>', path.translate(dir))
 		end
+	end
 
+	function vc2010.LocalDebuggerCommandArguments(cfg)
+		if #cfg.debugargs > 0 then
+			_x(2,'<LocalDebuggerCommandArguments>%s</LocalDebuggerCommandArguments>', table.concat(cfg.debugargs, " "))
+		end
+	end
+
+	function vc2010.LocalDebuggerWorkingDirectory(cfg)
 		if cfg.debugdir then
 			local dir = project.getrelative(cfg.project, cfg.debugdir)
 			_x(2,'<LocalDebuggerWorkingDirectory>%s</LocalDebuggerWorkingDirectory>', path.translate(dir))
+		end
+	end
 
-		end
-
-		if cfg.debugdir or cfg.debugcommand then
-			_p(2,'<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>')	
-		end
-
-		if #cfg.debugargs > 0 then
-			_x(2,'<LocalDebuggerCommandArguments>%s</LocalDebuggerCommandArguments>', table.concat(cfg.debugargs, " "))
-		end
+	function vc2010.LocalDebuggerEnvironment(cfg)
 		if #cfg.debugenvs > 0 then
 			local envs = table.concat(cfg.debugenvs, "\n")
 			if cfg.flags.DebugEnvsInherit then

File src/base/premake.lua

 		callback(obj)
 		f:close()
 	end
+
+
+--
+-- Override an existing function with a new one; the original function
+-- is passed as the first argument to the replacement when called.
+--
+-- @param scope
+--    The table containing the function to be overridden. Use _G for
+--    global functions.
+-- @param name
+--    The name of the function to override.
+-- @param repl
+--    The replacement function. The first argument to the function
+--    will be the original implementation.
+--
+
+	function premake.override(scope, name, repl)
+		local original = scope[name]
+		scope[name] = function(...)
+			return repl(original, ...)
+		end
+	end

File tests/base/test_override.lua

+--
+-- tests/base/test_override.lua
+-- Verify function override support.
+-- Copyright (c) 2012 Jason Perkins and the Premake project
+--
+
+
+	T.premake_override = {}
+	local suite = T.premake_override
+
+
+--
+-- Setup
+--
+
+	local X = {}
+
+	function suite.setup()
+		X.testfunc = function(value)
+			return value or "testfunc"
+		end
+	end
+
+
+--
+-- Should be able to completely replace the function with one of my own.
+--
+
+	function suite.canOverride()
+		premake.override(X, "testfunc", function()
+			return "canOverride"
+		end)
+		test.isequal("canOverride", X.testfunc())
+	end
+
+
+--
+-- Should be able to reference the original implementation.
+--
+
+	function suite.canCallOriginal()
+		premake.override(X, "testfunc", function(base)
+			return "canOverride > " .. base()
+		end)
+		test.isequal("canOverride > testfunc", X.testfunc())
+	end
+
+
+--
+-- Arguments should pass through.
+--
+
+	function suite.canPassThroughArguments()
+		premake.override(X, "testfunc", function(base, value)
+			return value .. " > " .. base()
+		end)
+		test.isequal("testval > testfunc", X.testfunc("testval"))
+	end
+
+
+--
+-- Can override the same function multiple times.
+--
+
+	function suite.canOverrideMultipleTimes()
+		premake.override(X, "testfunc", function(base, value)
+			return string.format("[%s > %s]", value, base("base1"))
+		end)
+
+		premake.override(X, "testfunc", function(base, value)
+			return string.format("{%s > %s}", value, base("base2"))
+		end)
+
+		test.isequal("{base3 > [base2 > base1]}", X.testfunc("base3"))
+	end

File tests/premake4.lua

 	dofile("base/test_detoken.lua")
 	dofile("base/test_include.lua")
 	dofile("base/test_os.lua")
+	dofile("base/test_override.lua")
 	dofile("base/test_path.lua")
 	dofile("base/test_premake_command.lua")
 	dofile("base/test_table.lua")

File tests/testfx.lua

 --
 -- tests/testfx.lua
 -- Automated test framework for Premake.
--- Copyright (c) 2008-2009 Jason Perkins and the Premake project
+-- Copyright (c) 2008-2012 Jason Perkins and the Premake project
 --
 
 
 -- Define a namespace for the testing functions
 --
 
-	test = { }
+	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()
 		
 -- Define a collection for the test suites
 --
 
-	T = { }
+	T = {}