test_links.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. --
  2. -- tests/config/test_links.lua
  3. -- Test the list of linked objects retrieval function.
  4. -- Copyright (c) 2012-2013 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. local suite = test.declare("config_links")
  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. _TARGET_OS = "windows"
  16. wks, prj = test.createWorkspace()
  17. end
  18. local function prepare(kind, part, linkage)
  19. cfg = test.getconfig(prj, "Debug")
  20. return config.getlinks(cfg, kind, part, linkage)
  21. end
  22. --
  23. -- If no links are present, should return an empty table.
  24. --
  25. function suite.emptyResult_onNoLinks()
  26. local r = prepare("all", "object")
  27. test.isequal(0, #r)
  28. end
  29. --
  30. -- System libraries which include path information are made project relative.
  31. --
  32. function suite.pathMadeRelative_onSystemLibWithPath()
  33. location "build"
  34. links { "../libs/z" }
  35. local r = prepare("all", "fullpath")
  36. test.isequal({ "../../libs/z" }, r)
  37. end
  38. --
  39. -- Handle the case where the library extension has been explicitly
  40. -- included in the link statement.
  41. --
  42. function suite.skipsExtension_onExplicitExtension()
  43. system "windows"
  44. links { "user32.lib" }
  45. local r = prepare("all", "fullpath")
  46. test.isequal({ "user32.lib" }, r)
  47. end
  48. --
  49. -- Check handling of shell variables in library paths.
  50. --
  51. function suite.variableMaintained_onLeadingVariable()
  52. system "windows"
  53. location "build"
  54. links { "$(LOCAL_DEV_PATH)/sdk/lib/DEVMAPI" }
  55. local r = prepare("all", "fullpath")
  56. test.isequal({ "$(LOCAL_DEV_PATH)/sdk/lib/DEVMAPI" }, r)
  57. end
  58. function suite.variableMaintained_onQuotedVariable()
  59. system "windows"
  60. location "build"
  61. links { '"$(LOCAL_DEV_PATH)/sdk/lib/DEVMAPI.lib"' }
  62. local r = prepare("all", "fullpath")
  63. test.isequal({ '"$(LOCAL_DEV_PATH)/sdk/lib/DEVMAPI.lib"' }, r)
  64. end
  65. --
  66. -- If fetching directories, the libdirs should be included in the result.
  67. --
  68. function suite.includesLibDirs_onDirectories()
  69. libdirs { "../libs" }
  70. local r = prepare("all", "directory")
  71. test.isequal({ "../libs" }, r)
  72. end
  73. --
  74. -- Managed C++ projects should ignore links to managed assemblies, which
  75. -- are designated with an explicit ".dll" extension.
  76. --
  77. function suite.skipsAssemblies_onManagedCpp()
  78. system "windows"
  79. clr "On"
  80. links { "user32", "System.dll" }
  81. local r = prepare("all", "fullpath")
  82. test.isequal({ "user32" }, r)
  83. end
  84. --
  85. -- When explicitly requesting managed links, any unmanaged items in the
  86. -- list should be ignored.
  87. --
  88. function suite.skipsUnmanagedLibs_onManagedLinkage()
  89. system "windows"
  90. clr "On"
  91. links { "user32", "System.dll" }
  92. local r = prepare("all", "fullpath", "managed")
  93. test.isequal({ "System.dll" }, r)
  94. end
  95. --
  96. -- Managed projects can link to other managed projects, and unmanaged
  97. -- projects can link to unmanaged projects.
  98. --
  99. function suite.canLink_CppAndCpp()
  100. links { "MyProject2" }
  101. project "MyProject2"
  102. kind "StaticLib"
  103. language "C++"
  104. local r = prepare("all", "fullpath")
  105. test.isequal({ "bin/Debug/MyProject2.lib" }, r)
  106. end
  107. function suite.canLink_CsAndCs()
  108. language "C#"
  109. links { "MyProject2" }
  110. project "MyProject2"
  111. kind "SharedLib"
  112. language "C#"
  113. local r = prepare("all", "fullpath")
  114. test.isequal({ "bin/Debug/MyProject2.dll" }, r)
  115. end
  116. function suite.canLink_ManagedCppAndManagedCpp()
  117. clr "On"
  118. links { "MyProject2" }
  119. project "MyProject2"
  120. kind "StaticLib"
  121. language "C++"
  122. clr "On"
  123. local r = prepare("all", "fullpath")
  124. test.isequal({ "bin/Debug/MyProject2.lib" }, r)
  125. end
  126. function suite.canLink_ManagedCppAndCs()
  127. clr "On"
  128. links { "MyProject2" }
  129. project "MyProject2"
  130. kind "SharedLib"
  131. language "C#"
  132. local r = prepare("all", "fullpath")
  133. test.isequal({ "bin/Debug/MyProject2.dll" }, r)
  134. end
  135. --
  136. -- Managed and unmanaged projects can not link to each other.
  137. --
  138. function suite.ignoreLink_CppAndCs()
  139. links { "MyProject2" }
  140. project "MyProject2"
  141. kind "SharedLib"
  142. language "C#"
  143. local r = prepare("all", "fullpath")
  144. test.isequal({}, r)
  145. end
  146. --
  147. -- Mixed and unmanaged projects can link to each other.
  148. --
  149. function suite.canLink_MixedAndNativeCpp()
  150. clr "On"
  151. links { "MyProject2" }
  152. project "MyProject2"
  153. kind "SharedLib"
  154. language "C++"
  155. local r = prepare("all", "fullpath")
  156. test.isequal({ "bin/Debug/MyProject2.lib" }, r)
  157. end
  158. function suite.canLink_NativeAndMixedCpp()
  159. links { "MyProject2" }
  160. project "MyProject2"
  161. kind "SharedLib"
  162. language "C++"
  163. clr "On"
  164. local r = prepare("all", "fullpath")
  165. test.isequal({ "bin/Debug/MyProject2.lib" }, r)
  166. end