test_snc.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. --
  2. -- tests/test_snc.lua
  3. -- Automated test suite for the SNC toolset interface.
  4. -- Copyright (c) 2012-2013 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. local suite = test.declare("tools_snc")
  8. local snc = p.tools.snc
  9. --
  10. -- Setup/teardown
  11. --
  12. local wks, prj, cfg
  13. function suite.setup()
  14. wks, prj = test.createWorkspace()
  15. system "PS3"
  16. end
  17. local function prepare()
  18. cfg = test.getconfig(prj, "Debug")
  19. end
  20. --
  21. -- Check the selection of tools based on the target system.
  22. --
  23. function suite.tools_onDefaults()
  24. prepare()
  25. test.isnil(snc.gettoolname(cfg, "cc"))
  26. test.isnil(snc.gettoolname(cfg, "cxx"))
  27. test.isnil(snc.gettoolname(cfg, "ar"))
  28. end
  29. function suite.tools_onPS3()
  30. system "PS3"
  31. prepare()
  32. test.isnil(snc.gettoolname(cfg, "cc"))
  33. test.isnil(snc.gettoolname(cfg, "cxx"))
  34. test.isnil(snc.gettoolname(cfg, "ar"))
  35. end
  36. --
  37. -- By default, the -MMD -MP are used to generate dependencies.
  38. --
  39. function suite.cppflags_defaultWithMMD()
  40. prepare()
  41. test.isequal({ "-MMD", "-MP" }, snc.getcppflags(cfg))
  42. end
  43. --
  44. -- Check the translation of CFLAGS.
  45. --
  46. function suite.cflags_onFatalWarnings()
  47. flags { "FatalWarnings" }
  48. prepare()
  49. test.isequal({ "-Xquit=2" }, snc.getcflags(cfg))
  50. end
  51. --
  52. -- Check the optimization flags.
  53. --
  54. function suite.cflags_onNoOptimize()
  55. optimize "Off"
  56. prepare()
  57. test.isequal({ "-O0" }, snc.getcflags(cfg))
  58. end
  59. function suite.cflags_onOptimize()
  60. optimize "On"
  61. prepare()
  62. test.isequal({ "-O1" }, snc.getcflags(cfg))
  63. end
  64. function suite.cflags_onOptimizeSize()
  65. optimize "Size"
  66. prepare()
  67. test.isequal({ "-Os" }, snc.getcflags(cfg))
  68. end
  69. function suite.cflags_onOptimizeSpeed()
  70. optimize "Speed"
  71. prepare()
  72. test.isequal({ "-O2" }, snc.getcflags(cfg))
  73. end
  74. function suite.cflags_onOptimizeFull()
  75. optimize "Full"
  76. prepare()
  77. test.isequal({ "-O3" }, snc.getcflags(cfg))
  78. end
  79. function suite.cflags_onOptimizeDebug()
  80. optimize "Debug"
  81. prepare()
  82. test.isequal({ "-Od" }, snc.getcflags(cfg))
  83. end
  84. --
  85. -- Turn on exceptions and RTTI by default, to match the other Premake supported toolsets.
  86. --
  87. function suite.cxxflags_onDefault()
  88. prepare()
  89. test.isequal({ "-Xc+=exceptions", "-Xc+=rtti" }, snc.getcxxflags(cfg))
  90. end
  91. --
  92. -- Check the translation of LDFLAGS.
  93. --
  94. function suite.cflags_onDefaults()
  95. prepare()
  96. test.isequal({ "-s" }, snc.getldflags(cfg))
  97. end
  98. --
  99. -- Check the formatting of linked libraries.
  100. --
  101. function suite.links_onSystemLibs()
  102. links { "fs_stub", "net_stub" }
  103. prepare()
  104. test.isequal({ "-lfs_stub", "-lnet_stub" }, snc.getlinks(cfg))
  105. end
  106. --
  107. -- When linking to a static sibling library, the relative path to the library
  108. -- should be used instead of the "-l" flag. This prevents linking against a
  109. -- shared library of the same name, should one be present.
  110. --
  111. function suite.links_onStaticSiblingLibrary()
  112. links { "MyProject2" }
  113. test.createproject(wks)
  114. system "Linux"
  115. kind "StaticLib"
  116. location "MyProject2"
  117. targetdir "lib"
  118. prepare()
  119. test.isequal({ "lib/libMyProject2.a" }, snc.getlinks(cfg))
  120. end
  121. --
  122. -- When linking object files, leave off the "-l".
  123. --
  124. function suite.links_onObjectFile()
  125. links { "generated.o" }
  126. prepare()
  127. test.isequal({ "generated.o" }, snc.getlinks(cfg))
  128. end
  129. --
  130. -- Check handling of forced includes.
  131. --
  132. function suite.forcedIncludeFiles()
  133. forceincludes { "stdafx.h", "include/sys.h" }
  134. prepare()
  135. test.isequal({'-include stdafx.h', '-include include/sys.h'}, snc.getforceincludes(cfg))
  136. end