test_aliasing.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. --
  2. -- tests/base/test_aliasing.lua
  3. -- Verify handling of function aliases.
  4. -- Copyright (c) 2015 Jason Perkins and the Premake project
  5. --
  6. local suite = test.declare("premake_alias")
  7. local m = {}
  8. local p = premake
  9. function suite.setup()
  10. m.testfunc = function()
  11. return 48
  12. end
  13. m.aliased = nil
  14. m.aliased2 = nil
  15. end
  16. function suite.returnsOriginalFunction_onNoAlias()
  17. local scope, f = p.resolveAlias(m, "testfunc")
  18. test.isequal("testfunc", f)
  19. end
  20. function suite.pointsAliasToOriginalFunction()
  21. p.alias(m, "testfunc", "aliased")
  22. test.isequal(48, m.aliased())
  23. end
  24. function suite.returnsOriginalFunction_onAlias()
  25. p.alias(m, "testfunc", "aliased")
  26. local scope, f = p.resolveAlias(m, "aliased")
  27. test.isequal("testfunc", f)
  28. end
  29. function suite.returnsOriginalFunction_onChainedAliases()
  30. p.alias(m, "testfunc", "aliased")
  31. p.alias(m, "aliased", "aliased2")
  32. local scope, f = p.resolveAlias(m, "aliased2")
  33. test.isequal("testfunc", f)
  34. end
  35. function suite.overrideResolvesAliases()
  36. p.alias(m, "testfunc", "aliased")
  37. p.override(m, "aliased", function(base)
  38. return base() + 1
  39. end)
  40. test.isequal(49, m.testfunc())
  41. end
  42. function suite.aliasTracksOverrides()
  43. p.alias(m, "testfunc", "aliased")
  44. p.override(m, "testfunc", function(base)
  45. return base() + 1
  46. end)
  47. test.isequal(49, m.aliased())
  48. end