test_targetinfo.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. --
  2. -- tests/config/test_targetinfo.lua
  3. -- Test the config object's build target accessor.
  4. -- Copyright (c) 2011-2013 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. local suite = test.declare("config_targetinfo")
  8. local config = p.config
  9. --
  10. -- Setup and teardown
  11. --
  12. local wks, prj
  13. function suite.setup()
  14. p.action.set("test")
  15. wks, prj = test.createWorkspace()
  16. system "macosx"
  17. end
  18. local function prepare()
  19. local cfg = test.getconfig(prj, "Debug")
  20. return config.gettargetinfo(cfg)
  21. end
  22. --
  23. -- Directory uses targetdir() value if present.
  24. --
  25. function suite.directoryIsTargetDir_onTargetDir()
  26. targetdir "../bin"
  27. i = prepare()
  28. test.isequal("../bin", path.getrelative(os.getcwd(), i.directory))
  29. end
  30. --
  31. -- Base name should use the project name by default.
  32. --
  33. function suite.basenameIsProjectName_onNoTargetName()
  34. i = prepare()
  35. test.isequal("MyProject", i.basename)
  36. end
  37. --
  38. -- Base name should use targetname() if present.
  39. --
  40. function suite.basenameIsTargetName_onTargetName()
  41. targetname "MyTarget"
  42. i = prepare()
  43. test.isequal("MyTarget", i.basename)
  44. end
  45. --
  46. -- Base name should use suffix if present.
  47. --
  48. function suite.basenameUsesSuffix_onTargetSuffix()
  49. targetsuffix "-d"
  50. i = prepare()
  51. test.isequal("MyProject-d", i.basename)
  52. end
  53. --
  54. -- Name should not have an extension for Posix executables.
  55. --
  56. function suite.nameHasNoExtension_onMacOSXConsoleApp()
  57. system "MacOSX"
  58. i = prepare()
  59. test.isequal("MyProject", i.name)
  60. end
  61. function suite.nameHasNoExtension_onLinuxConsoleApp()
  62. system "Linux"
  63. i = prepare()
  64. test.isequal("MyProject", i.name)
  65. end
  66. function suite.nameHasNoExtension_onBSDConsoleApp()
  67. system "BSD"
  68. i = prepare()
  69. test.isequal("MyProject", i.name)
  70. end
  71. --
  72. -- Name should use ".exe" for Windows executables.
  73. --
  74. function suite.nameUsesExe_onWindowsConsoleApp()
  75. kind "ConsoleApp"
  76. system "Windows"
  77. i = prepare()
  78. test.isequal("MyProject.exe", i.name)
  79. end
  80. function suite.nameUsesExe_onWindowsWindowedApp()
  81. kind "WindowedApp"
  82. system "Windows"
  83. i = prepare()
  84. test.isequal("MyProject.exe", i.name)
  85. end
  86. --
  87. -- Name should use ".dll" for Windows shared libraries.
  88. --
  89. function suite.nameUsesDll_onWindowsSharedLib()
  90. kind "SharedLib"
  91. system "Windows"
  92. i = prepare()
  93. test.isequal("MyProject.dll", i.name)
  94. end
  95. --
  96. -- Name should use ".lib" for Windows static libraries.
  97. --
  98. function suite.nameUsesLib_onWindowsStaticLib()
  99. kind "StaticLib"
  100. system "Windows"
  101. i = prepare()
  102. test.isequal("MyProject.lib", i.name)
  103. end
  104. --
  105. -- Name should use "lib and ".dylib" for Mac shared libraries.
  106. --
  107. function suite.nameUsesLib_onMacSharedLib()
  108. kind "SharedLib"
  109. system "MacOSX"
  110. i = prepare()
  111. test.isequal("libMyProject.dylib", i.name)
  112. end
  113. --
  114. -- Name should use "lib and ".a" for Mac static libraries.
  115. --
  116. function suite.nameUsesLib_onMacStaticLib()
  117. kind "StaticLib"
  118. system "MacOSX"
  119. i = prepare()
  120. test.isequal("libMyProject.a", i.name)
  121. end
  122. --
  123. -- Name should use "lib" and ".so" for Linux shared libraries.
  124. --
  125. function suite.nameUsesLib_onLinuxSharedLib()
  126. kind "SharedLib"
  127. system "Linux"
  128. i = prepare()
  129. test.isequal("libMyProject.so", i.name)
  130. end
  131. --
  132. -- Name should use "lib" and ".a" for Linux shared libraries.
  133. --
  134. function suite.nameUsesLib_onLinuxStaticLib()
  135. kind "StaticLib"
  136. system "Linux"
  137. i = prepare()
  138. test.isequal("libMyProject.a", i.name)
  139. end
  140. --
  141. -- Name should use a prefix if set.
  142. --
  143. function suite.nameUsesPrefix_onTargetPrefix()
  144. targetprefix "sys"
  145. i = prepare()
  146. test.isequal("sysMyProject", i.name)
  147. end
  148. --
  149. -- Bundle name should be set and use ".app" for Mac windowed applications.
  150. --
  151. function suite.bundlenameUsesApp_onMacWindowedApp()
  152. kind "WindowedApp"
  153. system "MacOSX"
  154. i = prepare()
  155. test.isequal("MyProject.app", i.bundlename)
  156. end
  157. --
  158. -- Bundle path should be set for Mac windowed applications.
  159. --
  160. function suite.bundlepathSet_onMacWindowedApp()
  161. kind "WindowedApp"
  162. system "MacOSX"
  163. i = prepare()
  164. test.isequal("bin/Debug/MyProject.app/Contents/MacOS", path.getrelative(os.getcwd(), i.bundlepath))
  165. end
  166. --
  167. -- Bundle path should be set for macOS/iOS cocoa bundle.
  168. --
  169. function suite.bundlepathSet_onMacSharedLibOSXBundle()
  170. kind "SharedLib"
  171. sharedlibtype "OSXBundle"
  172. system "macosx"
  173. i = prepare()
  174. test.isequal("bin/Debug/MyProject.bundle/Contents/MacOS", path.getrelative(os.getcwd(), i.bundlepath))
  175. end
  176. --
  177. -- Bundle path should be set for macOS/iOS cocoa unit test bundle.
  178. --
  179. function suite.bundlepathSet_onMacSharedLibXCTest()
  180. kind "SharedLib"
  181. sharedlibtype "XCTest"
  182. system "macosx"
  183. i = prepare()
  184. test.isequal("bin/Debug/MyProject.xctest/Contents/MacOS", path.getrelative(os.getcwd(), i.bundlepath))
  185. end
  186. --
  187. -- Bundle path should be set for macOS/iOS framework.
  188. --
  189. function suite.bundlepathSet_onMacSharedLibOSXFramework()
  190. kind "SharedLib"
  191. sharedlibtype "OSXFramework"
  192. system "macosx"
  193. i = prepare()
  194. test.isequal("bin/Debug/MyProject.framework/Versions/A", path.getrelative(os.getcwd(), i.bundlepath))
  195. end
  196. --
  197. -- Target extension is used if set.
  198. --
  199. function suite.extensionSet_onTargetExtension()
  200. targetextension ".self"
  201. i = prepare()
  202. test.isequal("MyProject.self", i.name)
  203. end
  204. --
  205. -- .NET executables should always default to ".exe" extensions.
  206. --
  207. function suite.appUsesExe_onDotNet()
  208. _TARGET_OS = "macosx"
  209. language "C#"
  210. i = prepare()
  211. test.isequal("MyProject.exe", i.name)
  212. end
  213. --
  214. -- .NET libraries should always default to ".dll" extensions.
  215. --
  216. function suite.appUsesExe_onDotNetSharedLib()
  217. _TARGET_OS = "macosx"
  218. language "C#"
  219. kind "SharedLib"
  220. i = prepare()
  221. test.isequal("MyProject.dll", i.name)
  222. end