This repository has been archived on 2022-12-23. You can view files and clone it, but cannot push or open issues or pull requests.
fuck-premake-old2/tests/base/test_override.lua

76 lines
1.4 KiB
Lua
Raw Normal View History

--
-- 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