test_containers.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. --
  2. -- tests/api/test_containers.lua
  3. -- Tests the API's workspace() and project() container definitions.
  4. -- Copyright (c) 2013-2014 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. local suite = test.declare("api_containers")
  8. local api = p.api
  9. --
  10. -- Setup and teardown
  11. --
  12. local wks
  13. function suite.setup()
  14. wks = workspace("MyWorkspace")
  15. end
  16. --
  17. -- The first time a name is encountered, a new container should be created.
  18. --
  19. function suite.workspace_createsOnFirstUse()
  20. test.isnotnil(p.global.getWorkspace("MyWorkspace"))
  21. end
  22. function suite.project_createsOnFirstUse()
  23. project("MyProject")
  24. test.isnotnil(test.getproject(wks, "MyProject"))
  25. end
  26. --
  27. -- When a container is created, it should become the active scope.
  28. --
  29. function suite.workspace_setsActiveScope()
  30. test.issame(api.scope.workspace, wks)
  31. end
  32. function suite.project_setsActiveScope()
  33. local prj = project("MyProject")
  34. test.issame(api.scope.project, prj)
  35. end
  36. --
  37. -- When container function is called with no arguments, that should
  38. -- become the current scope.
  39. --
  40. function suite.workspace_setsActiveScope_onNoArgs()
  41. project("MyProject")
  42. group("MyGroup")
  43. workspace()
  44. test.issame(wks, api.scope.workspace)
  45. test.isnil(api.scope.project)
  46. test.isnil(api.scope.group)
  47. end
  48. function suite.project_setsActiveScope_onNoArgs()
  49. local prj = project("MyProject")
  50. group("MyGroup")
  51. project()
  52. test.issame(prj, api.scope.project)
  53. end
  54. --
  55. -- The "*" name should activate the parent scope.
  56. --
  57. function suite.workspace_onStar()
  58. project("MyProject")
  59. group("MyGroup")
  60. filter("Debug")
  61. workspace("*")
  62. test.isnil(api.scope.workspace)
  63. test.isnil(api.scope.project)
  64. test.isnil(api.scope.group)
  65. end
  66. function suite.project_onStar()
  67. project("MyProject")
  68. group("MyGroup")
  69. filter("Debug")
  70. project "*"
  71. test.issame(wks, api.scope.workspace)
  72. test.isnil(api.scope.project)
  73. end