test_msc.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. --
  2. -- tests/test_msc.lua
  3. -- Automated test suite for the Microsoft C toolset interface.
  4. -- Copyright (c) 2012-2013 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. local suite = test.declare("tools_msc")
  8. local msc = p.tools.msc
  9. --
  10. -- Setup/teardown
  11. --
  12. local wks, prj, cfg
  13. function suite.setup()
  14. wks, prj = test.createWorkspace()
  15. kind "SharedLib"
  16. end
  17. local function prepare()
  18. cfg = test.getconfig(prj, "Debug")
  19. end
  20. --
  21. -- Check the optimization flags.
  22. --
  23. function suite.cflags_onNoOptimize()
  24. optimize "Off"
  25. prepare()
  26. test.contains("/Od", msc.getcflags(cfg))
  27. end
  28. function suite.cflags_onOptimize()
  29. optimize "On"
  30. prepare()
  31. test.contains("/Ot", msc.getcflags(cfg))
  32. end
  33. function suite.cflags_onOptimizeSize()
  34. optimize "Size"
  35. prepare()
  36. test.contains("/O1", msc.getcflags(cfg))
  37. end
  38. function suite.cflags_onOptimizeSpeed()
  39. optimize "Speed"
  40. prepare()
  41. test.contains("/O2", msc.getcflags(cfg))
  42. end
  43. function suite.cflags_onOptimizeFull()
  44. optimize "Full"
  45. prepare()
  46. test.contains("/Ox", msc.getcflags(cfg))
  47. end
  48. function suite.cflags_onOptimizeDebug()
  49. optimize "Debug"
  50. prepare()
  51. test.contains("/Od", msc.getcflags(cfg))
  52. end
  53. function suite.cflags_onNoFramePointers()
  54. flags "NoFramePointer"
  55. prepare()
  56. test.contains("/Oy", msc.getcflags(cfg))
  57. end
  58. function suite.cflags_onOmitFramePointer()
  59. omitframepointer "On"
  60. prepare()
  61. test.contains("/Oy", msc.getcflags(cfg))
  62. end
  63. function suite.cflags_onNoOmitFramePointers()
  64. omitframepointer "Off"
  65. prepare()
  66. test.excludes("/Oy", msc.getcflags(cfg))
  67. end
  68. function suite.cflags_onLinkTimeOptimizations()
  69. flags "LinkTimeOptimization"
  70. prepare()
  71. test.contains("/GL", msc.getcflags(cfg))
  72. end
  73. function suite.ldflags_onLinkTimeOptimizations()
  74. flags "LinkTimeOptimization"
  75. prepare()
  76. test.contains("/LTCG", msc.getldflags(cfg))
  77. end
  78. function suite.cflags_onStringPoolingOn()
  79. stringpooling "On"
  80. prepare()
  81. test.contains("/GF", msc.getcflags(cfg))
  82. end
  83. function suite.cflags_onStringPoolingOff()
  84. stringpooling "Off"
  85. prepare()
  86. test.contains("/GF-", msc.getcflags(cfg))
  87. end
  88. function suite.cflags_onStringPoolingNotSpecified()
  89. prepare()
  90. test.excludes("/GF", msc.getcflags(cfg))
  91. test.excludes("/GF-", msc.getcflags(cfg))
  92. end
  93. function suite.cflags_onFloatingPointExceptionsOn()
  94. floatingpointexceptions "On"
  95. prepare()
  96. test.contains("/fp:except", msc.getcflags(cfg))
  97. end
  98. function suite.cflags_onFloatingPointExceptionsOff()
  99. floatingpointexceptions "Off"
  100. prepare()
  101. test.contains("/fp:except-", msc.getcflags(cfg))
  102. end
  103. function suite.cflags_onFloatingPointExceptionsNotSpecified()
  104. prepare()
  105. test.excludes("/fp:except", msc.getcflags(cfg))
  106. test.excludes("/fp:except-", msc.getcflags(cfg))
  107. end
  108. function suite.cflags_onFunctionLevelLinkingOn()
  109. functionlevellinking "On"
  110. prepare()
  111. test.contains("/Gy", msc.getcflags(cfg))
  112. end
  113. function suite.cflags_onFunctionLevelLinkingOff()
  114. functionlevellinking "Off"
  115. prepare()
  116. test.contains("/Gy-", msc.getcflags(cfg))
  117. end
  118. function suite.cflags_onFunctionLevelLinkingNotSpecified()
  119. prepare()
  120. test.excludes("/Gy", msc.getcflags(cfg))
  121. test.excludes("/Gy-", msc.getcflags(cfg))
  122. end
  123. function suite.cflags_onIntrinsicsOn()
  124. intrinsics "On"
  125. prepare()
  126. test.contains("/Oi", msc.getcflags(cfg))
  127. end
  128. --
  129. -- Check the translation of symbols.
  130. --
  131. function suite.cflags_onDefaultSymbols()
  132. prepare()
  133. test.excludes({ "/Z7" }, msc.getcflags(cfg))
  134. end
  135. function suite.cflags_onNoSymbols()
  136. symbols "Off"
  137. prepare()
  138. test.excludes({ "/Z7" }, msc.getcflags(cfg))
  139. end
  140. function suite.cflags_onSymbols()
  141. symbols "On"
  142. prepare()
  143. test.contains({ "/Z7" }, msc.getcflags(cfg))
  144. end
  145. --
  146. -- Check the translation of unsignedchar.
  147. --
  148. function suite.sharedflags_onUnsignedCharOn()
  149. unsignedchar "On"
  150. prepare()
  151. test.contains({ "/J" }, msc.getcflags(cfg))
  152. test.contains({ "/J" }, msc.getcxxflags(cfg))
  153. end
  154. function suite.sharedflags_onUnsignedCharOff()
  155. unsignedchar "Off"
  156. prepare()
  157. test.excludes({ "/J" }, msc.getcflags(cfg))
  158. test.excludes({ "/J" }, msc.getcxxflags(cfg))
  159. end
  160. --
  161. -- Check handling of debugging support.
  162. --
  163. function suite.ldflags_onSymbols()
  164. symbols "On"
  165. prepare()
  166. test.contains("/DEBUG", msc.getldflags(cfg))
  167. end
  168. --
  169. -- Check handling warnings and errors.
  170. --
  171. function suite.cflags_OnNoWarnings()
  172. warnings "Off"
  173. prepare()
  174. test.contains("/W0", msc.getcflags(cfg))
  175. end
  176. function suite.cflags_OnHighWarnings()
  177. warnings "High"
  178. prepare()
  179. test.contains("/W4", msc.getcflags(cfg))
  180. end
  181. function suite.cflags_OnExtraWarnings()
  182. warnings "Extra"
  183. prepare()
  184. test.contains("/W4", msc.getcflags(cfg))
  185. end
  186. function suite.cflags_OnEverythingWarnings()
  187. warnings "Everything"
  188. prepare()
  189. test.contains("/Wall", msc.getcflags(cfg))
  190. end
  191. function suite.cflags_OnFatalWarnings()
  192. flags "FatalWarnings"
  193. prepare()
  194. test.contains("/WX", msc.getcflags(cfg))
  195. end
  196. function suite.cflags_onSpecificWarnings()
  197. enablewarnings { "enable" }
  198. disablewarnings { "disable" }
  199. fatalwarnings { "fatal" }
  200. prepare()
  201. test.contains({ '/w1"enable"', '/wd"disable"', '/we"fatal"' }, msc.getcflags(cfg))
  202. end
  203. function suite.ldflags_OnFatalWarnings()
  204. flags "FatalWarnings"
  205. prepare()
  206. test.contains("/WX", msc.getldflags(cfg))
  207. end
  208. --
  209. -- Check handling of library search paths.
  210. --
  211. function suite.libdirs_onLibdirs()
  212. libdirs { "../libs" }
  213. prepare()
  214. test.contains('/LIBPATH:"../libs"', msc.getLibraryDirectories(cfg))
  215. end
  216. --
  217. -- Check handling of forced includes.
  218. --
  219. function suite.forcedIncludeFiles()
  220. forceincludes { "include/sys.h" }
  221. prepare()
  222. test.contains('/FIinclude/sys.h', msc.getforceincludes(cfg))
  223. end
  224. --
  225. -- Check handling of floating point modifiers.
  226. --
  227. function suite.cflags_onFloatingPointFast()
  228. floatingpoint "Fast"
  229. prepare()
  230. test.contains("/fp:fast", msc.getcflags(cfg))
  231. end
  232. function suite.cflags_onFloatingPointStrict()
  233. floatingpoint "Strict"
  234. prepare()
  235. test.contains("/fp:strict", msc.getcflags(cfg))
  236. end
  237. function suite.cflags_onSSE()
  238. vectorextensions "SSE"
  239. prepare()
  240. test.contains("/arch:SSE", msc.getcflags(cfg))
  241. end
  242. function suite.cflags_onSSE2()
  243. vectorextensions "SSE2"
  244. prepare()
  245. test.contains("/arch:SSE2", msc.getcflags(cfg))
  246. end
  247. function suite.cflags_onSSE4_2()
  248. vectorextensions "SSE4.2"
  249. prepare()
  250. test.contains("/arch:SSE2", msc.getcflags(cfg))
  251. end
  252. function suite.cflags_onAVX()
  253. vectorextensions "AVX"
  254. prepare()
  255. test.contains("/arch:AVX", msc.getcflags(cfg))
  256. end
  257. function suite.cflags_onAVX2()
  258. vectorextensions "AVX2"
  259. prepare()
  260. test.contains("/arch:AVX2", msc.getcflags(cfg))
  261. end
  262. --
  263. -- Check the defines and undefines.
  264. --
  265. function suite.defines()
  266. defines "DEF"
  267. prepare()
  268. test.contains({ '/D"DEF"' }, msc.getdefines(cfg.defines, cfg))
  269. end
  270. function suite.undefines()
  271. undefines "UNDEF"
  272. prepare()
  273. test.contains({ '/U"UNDEF"' }, msc.getundefines(cfg.undefines))
  274. end
  275. --
  276. -- Check compilation options.
  277. --
  278. function suite.cflags_onNoMinimalRebuild()
  279. flags "NoMinimalRebuild"
  280. prepare()
  281. test.contains("/Gm-", msc.getcflags(cfg))
  282. end
  283. function suite.cflags_onMultiProcessorCompile()
  284. flags "MultiProcessorCompile"
  285. prepare()
  286. test.contains("/MP", msc.getcflags(cfg))
  287. end
  288. --
  289. -- Check handling of C++ language features.
  290. --
  291. function suite.cxxflags_onExceptions()
  292. exceptionhandling "on"
  293. prepare()
  294. test.contains("/EHsc", msc.getcxxflags(cfg))
  295. end
  296. function suite.cxxflags_onSEH()
  297. exceptionhandling "SEH"
  298. prepare()
  299. test.contains("/EHa", msc.getcxxflags(cfg))
  300. end
  301. function suite.cxxflags_onNoExceptions()
  302. exceptionhandling "Off"
  303. prepare()
  304. test.missing("/EHsc", msc.getcxxflags(cfg))
  305. end
  306. function suite.cxxflags_onNoRTTI()
  307. rtti "Off"
  308. prepare()
  309. test.contains("/GR-", msc.getcxxflags(cfg))
  310. end
  311. --
  312. -- Check handling of additional linker options.
  313. --
  314. function suite.ldflags_onOmitDefaultLibrary()
  315. flags "OmitDefaultLibrary"
  316. prepare()
  317. test.contains("/NODEFAULTLIB", msc.getldflags(cfg))
  318. end
  319. function suite.ldflags_onNoIncrementalLink()
  320. flags "NoIncrementalLink"
  321. prepare()
  322. test.contains("/INCREMENTAL:NO", msc.getldflags(cfg))
  323. end
  324. function suite.ldflags_onNoManifest()
  325. flags "NoManifest"
  326. prepare()
  327. test.contains("/MANIFEST:NO", msc.getldflags(cfg))
  328. end
  329. function suite.ldflags_onDLL()
  330. kind "SharedLib"
  331. prepare()
  332. test.contains("/DLL", msc.getldflags(cfg))
  333. end
  334. --
  335. -- Check handling of CLR settings.
  336. --
  337. function suite.cflags_onClrOn()
  338. clr "On"
  339. prepare()
  340. test.contains("/clr", msc.getcflags(cfg))
  341. end
  342. function suite.cflags_onClrUnsafe()
  343. clr "Unsafe"
  344. prepare()
  345. test.contains("/clr", msc.getcflags(cfg))
  346. end
  347. function suite.cflags_onClrSafe()
  348. clr "Safe"
  349. prepare()
  350. test.contains("/clr:safe", msc.getcflags(cfg))
  351. end
  352. function suite.cflags_onClrPure()
  353. clr "Pure"
  354. prepare()
  355. test.contains("/clr:pure", msc.getcflags(cfg))
  356. end
  357. --
  358. -- Check handling of character set switches
  359. --
  360. function suite.cflags_onCharSetDefault()
  361. prepare()
  362. test.contains('/D"_UNICODE"', msc.getdefines(cfg.defines, cfg))
  363. end
  364. function suite.cflags_onCharSetUnicode()
  365. characterset "Unicode"
  366. prepare()
  367. test.contains('/D"_UNICODE"', msc.getdefines(cfg.defines, cfg))
  368. end
  369. function suite.cflags_onCharSetMBCS()
  370. characterset "MBCS"
  371. prepare()
  372. test.contains('/D"_MBCS"', msc.getdefines(cfg.defines, cfg))
  373. end
  374. function suite.cflags_onCharSetASCII()
  375. characterset "ASCII"
  376. prepare()
  377. test.excludes({'/D"_MBCS"', '/D"_UNICODE"'}, msc.getdefines(cfg.defines, cfg))
  378. end
  379. --
  380. -- Check handling of system search paths.
  381. --
  382. function suite.includeDirs_onSysIncludeDirs()
  383. sysincludedirs { "/usr/local/include" }
  384. prepare()
  385. test.contains("-I/usr/local/include", msc.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs))
  386. end
  387. function suite.libDirs_onSysLibDirs()
  388. syslibdirs { "/usr/local/lib" }
  389. prepare()
  390. test.contains('/LIBPATH:"/usr/local/lib"', msc.getLibraryDirectories(cfg))
  391. end
  392. --
  393. -- Check handling of ignore default libraries
  394. --
  395. function suite.ignoreDefaultLibraries_WithExtensions()
  396. ignoredefaultlibraries { "lib1.lib" }
  397. prepare()
  398. test.contains('/NODEFAULTLIB:lib1.lib', msc.getldflags(cfg))
  399. end
  400. function suite.ignoreDefaultLibraries_WithoutExtensions()
  401. ignoredefaultlibraries { "lib1" }
  402. prepare()
  403. test.contains('/NODEFAULTLIB:lib1.lib', msc.getldflags(cfg))
  404. end
  405. --
  406. -- Check handling of shared C/C++ flags.
  407. --
  408. function suite.mixedToolFlags_onCFlags()
  409. flags { "FatalCompileWarnings" }
  410. prepare()
  411. test.isequal({ "/WX", "/MD" }, msc.getcflags(cfg))
  412. end
  413. function suite.mixedToolFlags_onCxxFlags()
  414. flags { "FatalCompileWarnings" }
  415. prepare()
  416. test.isequal({ "/WX", "/MD", "/EHsc" }, msc.getcxxflags(cfg))
  417. end
  418. --
  419. -- Check handling of Run-Time Library flags.
  420. --
  421. function suite.cflags_onStaticRuntime()
  422. staticruntime "On"
  423. prepare()
  424. test.isequal({ "/MT" }, msc.getcflags(cfg))
  425. end
  426. function suite.cflags_onDynamicRuntime()
  427. staticruntime "Off"
  428. prepare()
  429. test.isequal({ "/MD" }, msc.getcflags(cfg))
  430. end
  431. function suite.cflags_onStaticRuntimeAndDebug()
  432. staticruntime "On"
  433. runtime "Debug"
  434. prepare()
  435. test.isequal({ "/MTd" }, msc.getcflags(cfg))
  436. end
  437. function suite.cflags_onDynamicRuntimeAndDebug()
  438. staticruntime "Off"
  439. runtime "Debug"
  440. prepare()
  441. test.isequal({ "/MDd" }, msc.getcflags(cfg))
  442. end
  443. function suite.cflags_onStaticRuntimeAndSymbols()
  444. staticruntime "On"
  445. symbols "On"
  446. prepare()
  447. test.isequal({ "/MTd", "/Z7" }, msc.getcflags(cfg))
  448. end
  449. function suite.cflags_onDynamicRuntimeAndSymbols()
  450. staticruntime "Off"
  451. symbols "On"
  452. prepare()
  453. test.isequal({ "/MDd", "/Z7" }, msc.getcflags(cfg))
  454. end
  455. function suite.cflags_onDynamicRuntimeAndReleaseAndSymbols()
  456. staticruntime "Off"
  457. runtime "Release"
  458. symbols "On"
  459. prepare()
  460. test.isequal({ "/MD", "/Z7" }, msc.getcflags(cfg))
  461. end