test_register.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. --
  2. -- tests/api/test_register.lua
  3. -- Tests the new API registration function.
  4. -- Copyright (c) 2012 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. local suite = test.declare("api_register")
  8. local api = p.api
  9. --
  10. -- Setup and teardown
  11. --
  12. function suite.teardown()
  13. testapi = nil
  14. end
  15. --
  16. -- Verify that the function exists.
  17. --
  18. function suite.registerFunctionExists()
  19. test.isequal("function", type(p.api.register))
  20. end
  21. --
  22. -- When called, a new function with with provided name should
  23. -- added to the global namespace.
  24. --
  25. function suite.createsNewGlobalFunction()
  26. api.register { name = "testapi", kind = "string", scope = "project" }
  27. test.isequal("function", type(testapi));
  28. end
  29. --
  30. -- Verify that an error is raised if no name is provided.
  31. --
  32. function suite.raisesError_onMissingName()
  33. ok, err = pcall(function ()
  34. api.register { kind = "string", scope = "project" }
  35. end)
  36. test.isfalse(ok)
  37. end
  38. --
  39. -- Verify that an error is raised if the name is already in use.
  40. --
  41. function suite.raisesError_onExistingGlobalName()
  42. testapi = "testapi"
  43. ok, err = pcall(function ()
  44. api.register { name = "testapi", kind = "string", scope = "project" }
  45. end)
  46. test.isfalse(ok)
  47. end
  48. --
  49. -- Verify that an error is raised if an invalid kind is used.
  50. --
  51. function suite.raisesError_onInvalidKind()
  52. ok, err = pcall(function ()
  53. api.register { name = "testapi", kind = "bogus", scope = "project" }
  54. end)
  55. test.isfalse(ok)
  56. end
  57. --
  58. -- Verify that key-value forms are accepted.
  59. --
  60. function suite.succeeds_onKeyValueForm()
  61. ok, err = pcall(function ()
  62. api.register { name = "testapi", kind = "string", keyed = true, scope = "project" }
  63. end)
  64. test.istrue(ok)
  65. end