123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- --
- -- tests/base/test_override.lua
- -- Verify function override support.
- -- Copyright (c) 2012 Jason Perkins and the Premake project
- --
- local p = premake
- local suite = test.declare("base_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()
- p.override(X, "testfunc", function()
- return "canOverride"
- end)
- test.isequal("canOverride", X.testfunc())
- end
- --
- -- Should be able to reference the original implementation.
- --
- function suite.canCallOriginal()
- p.override(X, "testfunc", function(base)
- return "canOverride > " .. base()
- end)
- test.isequal("canOverride > testfunc", X.testfunc())
- end
- --
- -- Arguments should pass through.
- --
- function suite.canPassThroughArguments()
- p.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()
- p.override(X, "testfunc", function(base, value)
- return string.format("[%s > %s]", value, base("base1"))
- end)
- p.override(X, "testfunc", function(base, value)
- return string.format("{%s > %s}", value, base("base2"))
- end)
- test.isequal("{base3 > [base2 > base1]}", X.testfunc("base3"))
- end
|