2015-07-28 20:50:42 +00:00
|
|
|
--
|
|
|
|
-- tests/base/test_aliasing.lua
|
|
|
|
-- Verify handling of function aliases.
|
|
|
|
-- Copyright (c) 2015 Jason Perkins and the Premake project
|
|
|
|
--
|
|
|
|
|
|
|
|
local suite = test.declare("premake_alias")
|
2018-04-30 14:14:24 +00:00
|
|
|
local m = {}
|
2015-07-28 20:50:42 +00:00
|
|
|
|
|
|
|
local p = premake
|
|
|
|
|
|
|
|
|
|
|
|
function suite.setup()
|
2018-04-30 14:14:24 +00:00
|
|
|
m.testfunc = function()
|
2015-07-28 20:50:42 +00:00
|
|
|
return 48
|
|
|
|
end
|
2018-04-30 14:14:24 +00:00
|
|
|
m.aliased = nil
|
|
|
|
m.aliased2 = nil
|
2015-07-28 20:50:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function suite.returnsOriginalFunction_onNoAlias()
|
2018-04-30 14:14:24 +00:00
|
|
|
local scope, f = p.resolveAlias(m, "testfunc")
|
2015-07-28 20:50:42 +00:00
|
|
|
test.isequal("testfunc", f)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function suite.pointsAliasToOriginalFunction()
|
2018-04-30 14:14:24 +00:00
|
|
|
p.alias(m, "testfunc", "aliased")
|
|
|
|
test.isequal(48, m.aliased())
|
2015-07-28 20:50:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function suite.returnsOriginalFunction_onAlias()
|
2018-04-30 14:14:24 +00:00
|
|
|
p.alias(m, "testfunc", "aliased")
|
|
|
|
local scope, f = p.resolveAlias(m, "aliased")
|
2015-07-28 20:50:42 +00:00
|
|
|
test.isequal("testfunc", f)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function suite.returnsOriginalFunction_onChainedAliases()
|
2018-04-30 14:14:24 +00:00
|
|
|
p.alias(m, "testfunc", "aliased")
|
|
|
|
p.alias(m, "aliased", "aliased2")
|
|
|
|
local scope, f = p.resolveAlias(m, "aliased2")
|
2015-07-28 20:50:42 +00:00
|
|
|
test.isequal("testfunc", f)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function suite.overrideResolvesAliases()
|
2018-04-30 14:14:24 +00:00
|
|
|
p.alias(m, "testfunc", "aliased")
|
|
|
|
p.override(m, "aliased", function(base)
|
2015-07-28 20:50:42 +00:00
|
|
|
return base() + 1
|
|
|
|
end)
|
2018-04-30 14:14:24 +00:00
|
|
|
test.isequal(49, m.testfunc())
|
2015-07-28 20:50:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function suite.aliasTracksOverrides()
|
2018-04-30 14:14:24 +00:00
|
|
|
p.alias(m, "testfunc", "aliased")
|
|
|
|
p.override(m, "testfunc", function(base)
|
2015-07-28 20:50:42 +00:00
|
|
|
return base() + 1
|
|
|
|
end)
|
2018-04-30 14:14:24 +00:00
|
|
|
test.isequal(49, m.aliased())
|
2015-07-28 20:50:42 +00:00
|
|
|
end
|
|
|
|
|