test_eachconfig.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. --
  2. -- tests/project/test_eachconfig.lua
  3. -- Test the project object configuration iterator function.
  4. -- Copyright (c) 2011-2015 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. local suite = test.declare("project_eachconfig")
  8. --
  9. -- Setup and teardown
  10. --
  11. local wks, prj
  12. function suite.setup()
  13. wks = workspace("MyWorkspace")
  14. end
  15. local function prepare(buildcfgs)
  16. project("MyProject")
  17. if buildcfgs then
  18. configurations ( buildcfgs )
  19. end
  20. prj = test.getproject(wks, 1)
  21. for cfg in p.project.eachconfig(prj) do
  22. _p(2,'%s:%s', cfg.buildcfg or "", cfg.platform or "")
  23. end
  24. end
  25. --
  26. -- If no configurations have been defined, the iterator
  27. -- should not return any values.
  28. --
  29. function suite.returnsNoValues_onNoConfigurationsAndNoPlatforms()
  30. prepare()
  31. test.isemptycapture()
  32. end
  33. --
  34. -- If platforms have been defined, but no configurations, the
  35. -- iterator should still not return any values.
  36. --
  37. function suite.returnsNoValues_onNoConfigurationsButPlatforms()
  38. platforms { "x86", "x86_64" }
  39. prepare()
  40. test.isemptycapture()
  41. end
  42. --
  43. -- Configurations should be iterated in the order in which they
  44. -- appear in the script.
  45. --
  46. function suite.iteratesConfigsInOrder()
  47. configurations { "Debug", "Profile", "Release", "Deploy" }
  48. prepare()
  49. test.capture [[
  50. Debug:
  51. Profile:
  52. Release:
  53. Deploy:
  54. ]]
  55. end
  56. --
  57. -- If platforms are supplied, they should be paired with build
  58. -- configurations, with the order of both maintained.
  59. --
  60. function suite.pairsConfigsAndPlatformsInOrder()
  61. configurations { "Debug", "Release" }
  62. platforms { "x86", "x86_64" }
  63. prepare()
  64. test.capture [[
  65. Debug:x86
  66. Debug:x86_64
  67. Release:x86
  68. Release:x86_64
  69. ]]
  70. end
  71. --
  72. -- Test the mapping of a build configuration from workspace to project.
  73. --
  74. function suite.mapsBuildCfg_toBuildCfg()
  75. configurations { "Debug", "Release" }
  76. configmap { ["Debug"] = "ProjectDebug" }
  77. prepare()
  78. test.capture [[
  79. ProjectDebug:
  80. Release:
  81. ]]
  82. end
  83. --
  84. -- Test mapping a platform from workspace to project.
  85. --
  86. function suite.mapsPlatform_toPlatform()
  87. configurations { "Debug", "Release" }
  88. platforms { "Win32" }
  89. configmap { ["Win32"] = "x86_64" }
  90. prepare()
  91. test.capture [[
  92. Debug:x86_64
  93. Release:x86_64
  94. ]]
  95. end
  96. --
  97. -- Test mapping a build configuration to a build config/platform pair.
  98. -- This will cause a second platform to appear in the project, alongside
  99. -- the one defined by the workspace.
  100. --
  101. function suite.mapsBuildCfg_toBuildCfgAndPlatform()
  102. configurations { "Debug", "Release" }
  103. platforms { "Win32" }
  104. configmap { ["Debug"] = { "ProjectDebug", "x86_64" } }
  105. prepare()
  106. test.capture [[
  107. ProjectDebug:x86_64
  108. ProjectDebug:Win32
  109. Release:x86_64
  110. Release:Win32
  111. ]]
  112. end
  113. --
  114. -- Any duplicate configurations created by the mapping should be removed.
  115. --
  116. function suite.removesDups_onConfigMapping()
  117. configurations { "Debug", "Development", "Release" }
  118. configmap { ["Development"] = "Debug" }
  119. prepare()
  120. test.capture [[
  121. Debug:
  122. Release:
  123. ]]
  124. end
  125. --
  126. -- If there is overlap in the workspace and project configuration lists,
  127. -- the ordering at the project level should be maintained to avoid
  128. -- unnecessarily dirtying the project file.
  129. --
  130. function suite.maintainsProjectOrdering_onWorkspaceOverlap()
  131. configurations { "Debug", "Release" }
  132. prepare { "Debug", "Development", "Profile", "Release" }
  133. test.capture [[
  134. Debug:
  135. Development:
  136. Profile:
  137. Release:
  138. ]]
  139. end