test_generate_test_runner.rb 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. # ==========================================
  2. # CMock Project - Automatic Mock Generation for C
  3. # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
  4. # [Released under MIT License. Please refer to license.txt for details]
  5. # ==========================================
  6. require '../auto/generate_test_runner.rb'
  7. $generate_test_runner_tests = 0
  8. $generate_test_runner_failures = 0
  9. OUT_FILE = 'build/testsample_'
  10. RUNNER_TESTS = [
  11. { :name => 'DefaultsThroughOptions',
  12. :testfile => 'testdata/testRunnerGenerator.c',
  13. :testdefines => ['TEST'],
  14. :options => nil, #defaults
  15. :expected => {
  16. :to_pass => [ 'test_ThisTestAlwaysPasses',
  17. 'spec_ThisTestPassesWhenNormalSetupRan',
  18. 'spec_ThisTestPassesWhenNormalTeardownRan',
  19. 'test_NotBeConfusedByLongComplicatedStrings',
  20. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  21. 'test_StillNotBeConfusedByLongComplicatedStrings',
  22. 'should_RunTestsStartingWithShouldByDefault',
  23. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  24. ],
  25. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  26. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  27. }
  28. },
  29. { :name => 'DefaultsThroughCommandLine',
  30. :testfile => 'testdata/testRunnerGenerator.c',
  31. :testdefines => ['TEST'],
  32. :cmdline => "", #defaults
  33. :expected => {
  34. :to_pass => [ 'test_ThisTestAlwaysPasses',
  35. 'spec_ThisTestPassesWhenNormalSetupRan',
  36. 'spec_ThisTestPassesWhenNormalTeardownRan',
  37. 'test_NotBeConfusedByLongComplicatedStrings',
  38. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  39. 'test_StillNotBeConfusedByLongComplicatedStrings',
  40. 'should_RunTestsStartingWithShouldByDefault',
  41. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  42. ],
  43. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  44. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  45. }
  46. },
  47. { :name => 'DefaultsThroughYAMLFile',
  48. :testfile => 'testdata/testRunnerGenerator.c',
  49. :testdefines => ['TEST'],
  50. :cmdline => "", #defaults
  51. :yaml => {}, #defaults
  52. :expected => {
  53. :to_pass => [ 'test_ThisTestAlwaysPasses',
  54. 'spec_ThisTestPassesWhenNormalSetupRan',
  55. 'spec_ThisTestPassesWhenNormalTeardownRan',
  56. 'test_NotBeConfusedByLongComplicatedStrings',
  57. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  58. 'test_StillNotBeConfusedByLongComplicatedStrings',
  59. 'should_RunTestsStartingWithShouldByDefault',
  60. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  61. ],
  62. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  63. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  64. }
  65. },
  66. { :name => 'ShorterFilterOfJustTest',
  67. :testfile => 'testdata/testRunnerGenerator.c',
  68. :testdefines => ['TEST'],
  69. :options => {
  70. :test_prefix => "test",
  71. },
  72. :expected => {
  73. :to_pass => [ 'test_ThisTestAlwaysPasses',
  74. 'test_NotBeConfusedByLongComplicatedStrings',
  75. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  76. 'test_StillNotBeConfusedByLongComplicatedStrings',
  77. ],
  78. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  79. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  80. }
  81. },
  82. { :name => 'ShorterFilterOfJustShould',
  83. :testfile => 'testdata/testRunnerGenerator.c',
  84. :testdefines => ['TEST'],
  85. :options => {
  86. :test_prefix => "should",
  87. },
  88. :expected => {
  89. :to_pass => [ 'should_RunTestsStartingWithShouldByDefault' ],
  90. :to_fail => [ ],
  91. :to_ignore => [ ],
  92. }
  93. },
  94. { :name => 'ShorterFilterOfJustSpec',
  95. :testfile => 'testdata/testRunnerGenerator.c',
  96. :testdefines => ['TEST'],
  97. :options => {
  98. :test_prefix => "spec",
  99. },
  100. :expected => {
  101. :to_pass => [ 'spec_ThisTestPassesWhenNormalSetupRan',
  102. 'spec_ThisTestPassesWhenNormalTeardownRan',
  103. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  104. ],
  105. :to_fail => [ ],
  106. :to_ignore => [ ],
  107. }
  108. },
  109. { :name => 'InjectIncludes',
  110. :testfile => 'testdata/testRunnerGenerator.c',
  111. :testdefines => ['TEST'],
  112. :options => {
  113. :includes => ['Defs.h'],
  114. },
  115. :expected => {
  116. :to_pass => [ 'test_ThisTestAlwaysPasses',
  117. 'spec_ThisTestPassesWhenNormalSetupRan',
  118. 'spec_ThisTestPassesWhenNormalTeardownRan',
  119. 'test_NotBeConfusedByLongComplicatedStrings',
  120. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  121. 'test_StillNotBeConfusedByLongComplicatedStrings',
  122. 'should_RunTestsStartingWithShouldByDefault',
  123. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  124. ],
  125. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  126. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  127. }
  128. },
  129. { :name => 'ParameterizedThroughOptions',
  130. :testfile => 'testdata/testRunnerGenerator.c',
  131. :testdefines => ['TEST'],
  132. :options => {
  133. :test_prefix => "paratest",
  134. :use_param_tests => true,
  135. },
  136. :expected => {
  137. :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
  138. 'paratest_ShouldHandleParameterizedTests\(125\)',
  139. 'paratest_ShouldHandleParameterizedTests\(5\)',
  140. 'paratest_ShouldHandleParameterizedTests2\(7\)',
  141. 'paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid\(RUN_TEST_NO_ARGS\)',
  142. ],
  143. :to_fail => [ 'paratest_ShouldHandleParameterizedTestsThatFail\(17\)' ],
  144. :to_ignore => [ ],
  145. }
  146. },
  147. { :name => 'ParameterizedThroughCommandLine',
  148. :testfile => 'testdata/testRunnerGenerator.c',
  149. :testdefines => ['TEST'],
  150. :cmdline => " --test_prefix=\"paratest\" --use_param_tests=1",
  151. :expected => {
  152. :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
  153. 'paratest_ShouldHandleParameterizedTests\(125\)',
  154. 'paratest_ShouldHandleParameterizedTests\(5\)',
  155. 'paratest_ShouldHandleParameterizedTests2\(7\)',
  156. 'paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid\(RUN_TEST_NO_ARGS\)',
  157. ],
  158. :to_fail => [ 'paratest_ShouldHandleParameterizedTestsThatFail\(17\)' ],
  159. :to_ignore => [ ],
  160. }
  161. },
  162. { :name => 'ParameterizedThroughCommandLineAndYaml',
  163. :testfile => 'testdata/testRunnerGenerator.c',
  164. :testdefines => ['TEST'],
  165. :cmdline => "--use_param_tests=1",
  166. :yaml => {
  167. :test_prefix => "paratest"
  168. },
  169. :expected => {
  170. :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
  171. 'paratest_ShouldHandleParameterizedTests\(125\)',
  172. 'paratest_ShouldHandleParameterizedTests\(5\)',
  173. 'paratest_ShouldHandleParameterizedTests2\(7\)',
  174. 'paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid\(RUN_TEST_NO_ARGS\)',
  175. ],
  176. :to_fail => [ 'paratest_ShouldHandleParameterizedTestsThatFail\(17\)' ],
  177. :to_ignore => [ ],
  178. }
  179. },
  180. { :name => 'CException',
  181. :testfile => 'testdata/testRunnerGenerator.c',
  182. :testdefines => ['TEST', 'USE_CEXCEPTION'],
  183. :options => {
  184. :test_prefix => "extest",
  185. :plugins => [ :cexception ],
  186. },
  187. :expected => {
  188. :to_pass => [ 'extest_ShouldHandleCExceptionInTest' ],
  189. :to_fail => [ ],
  190. :to_ignore => [ ],
  191. }
  192. },
  193. { :name => 'CustomSetupAndTeardownThroughOptions',
  194. :testfile => 'testdata/testRunnerGenerator.c',
  195. :testdefines => ['TEST'],
  196. :options => {
  197. :test_prefix => "custtest|test",
  198. :setup_name => "custom_setup",
  199. :teardown_name => "custom_teardown",
  200. },
  201. :expected => {
  202. :to_pass => [ 'test_ThisTestAlwaysPasses',
  203. 'test_NotBeConfusedByLongComplicatedStrings',
  204. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  205. 'test_StillNotBeConfusedByLongComplicatedStrings',
  206. 'custtest_ThisTestPassesWhenCustomSetupRan',
  207. 'custtest_ThisTestPassesWhenCustomTeardownRan',
  208. ],
  209. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  210. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  211. }
  212. },
  213. { :name => 'CustomSetupAndTeardownThroughCommandLine',
  214. :testfile => 'testdata/testRunnerGenerator.c',
  215. :testdefines => ['TEST'],
  216. :cmdline => " --test_prefix=\"custtest|test\" --setup_name=\"custom_setup\" --teardown_name=\"custom_teardown\"",
  217. :expected => {
  218. :to_pass => [ 'test_ThisTestAlwaysPasses',
  219. 'test_NotBeConfusedByLongComplicatedStrings',
  220. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  221. 'test_StillNotBeConfusedByLongComplicatedStrings',
  222. 'custtest_ThisTestPassesWhenCustomSetupRan',
  223. 'custtest_ThisTestPassesWhenCustomTeardownRan',
  224. ],
  225. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  226. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  227. }
  228. },
  229. { :name => 'CustomSetupAndTeardownThroughYaml',
  230. :testfile => 'testdata/testRunnerGenerator.c',
  231. :testdefines => ['TEST'],
  232. :cmdline => " --test_prefix=\"custtest|test\"",
  233. :yaml => {
  234. :setup_name => "custom_setup",
  235. :teardown_name => "custom_teardown",
  236. },
  237. :expected => {
  238. :to_pass => [ 'test_ThisTestAlwaysPasses',
  239. 'test_NotBeConfusedByLongComplicatedStrings',
  240. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  241. 'test_StillNotBeConfusedByLongComplicatedStrings',
  242. 'custtest_ThisTestPassesWhenCustomSetupRan',
  243. 'custtest_ThisTestPassesWhenCustomTeardownRan',
  244. ],
  245. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  246. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  247. }
  248. },
  249. { :name => 'CustomMain',
  250. :testfile => 'testdata/testRunnerGenerator.c',
  251. :testdefines => ['TEST', "USE_ANOTHER_MAIN"],
  252. :options => {
  253. :main_name => "custom_main",
  254. },
  255. :expected => {
  256. :to_pass => [ 'test_ThisTestAlwaysPasses',
  257. 'spec_ThisTestPassesWhenNormalSetupRan',
  258. 'spec_ThisTestPassesWhenNormalTeardownRan',
  259. 'test_NotBeConfusedByLongComplicatedStrings',
  260. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  261. 'test_StillNotBeConfusedByLongComplicatedStrings',
  262. 'should_RunTestsStartingWithShouldByDefault',
  263. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  264. ],
  265. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  266. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  267. }
  268. },
  269. { :name => 'CustomSuiteSetupAndTeardown',
  270. :testfile => 'testdata/testRunnerGenerator.c',
  271. :testdefines => ['TEST'],
  272. :includes => ['Defs.h'],
  273. :options => {
  274. :test_prefix => "suitetest|test",
  275. :suite_setup => " CounterSuiteSetup = 1;",
  276. :suite_teardown => " return num_failures;",
  277. },
  278. :expected => {
  279. :to_pass => [ 'test_ThisTestAlwaysPasses',
  280. 'test_NotBeConfusedByLongComplicatedStrings',
  281. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  282. 'test_StillNotBeConfusedByLongComplicatedStrings',
  283. 'suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan',
  284. ],
  285. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  286. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  287. }
  288. },
  289. { :name => 'MainExternDeclaration',
  290. :testfile => 'testdata/testRunnerGenerator.c',
  291. :testdefines => ['TEST'],
  292. :includes => ['Defs.h'],
  293. :options => {
  294. :main_export_decl => "EXTERN_DECL",
  295. },
  296. :expected => {
  297. :to_pass => [ 'test_ThisTestAlwaysPasses',
  298. 'spec_ThisTestPassesWhenNormalSetupRan',
  299. 'spec_ThisTestPassesWhenNormalTeardownRan',
  300. 'test_NotBeConfusedByLongComplicatedStrings',
  301. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  302. 'test_StillNotBeConfusedByLongComplicatedStrings',
  303. 'should_RunTestsStartingWithShouldByDefault',
  304. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  305. ],
  306. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  307. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  308. }
  309. },
  310. #### WITH MOCKS ##########################################
  311. { :name => 'DefaultsThroughOptions',
  312. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  313. :testdefines => ['TEST'],
  314. :options => nil, #defaults
  315. :expected => {
  316. :to_pass => [ 'test_ThisTestAlwaysPasses',
  317. 'spec_ThisTestPassesWhenNormalSetupRan',
  318. 'spec_ThisTestPassesWhenNormalTeardownRan',
  319. 'test_NotBeConfusedByLongComplicatedStrings',
  320. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  321. 'test_StillNotBeConfusedByLongComplicatedStrings',
  322. 'should_RunTestsStartingWithShouldByDefault',
  323. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  324. 'test_ShouldCallMockInitAndVerifyFunctionsForEachTest',
  325. ],
  326. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  327. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  328. }
  329. },
  330. { :name => 'DefaultsThroughCommandLine',
  331. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  332. :testdefines => ['TEST'],
  333. :cmdline => "", #defaults
  334. :expected => {
  335. :to_pass => [ 'test_ThisTestAlwaysPasses',
  336. 'spec_ThisTestPassesWhenNormalSetupRan',
  337. 'spec_ThisTestPassesWhenNormalTeardownRan',
  338. 'test_NotBeConfusedByLongComplicatedStrings',
  339. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  340. 'test_StillNotBeConfusedByLongComplicatedStrings',
  341. 'should_RunTestsStartingWithShouldByDefault',
  342. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  343. 'test_ShouldCallMockInitAndVerifyFunctionsForEachTest',
  344. ],
  345. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  346. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  347. }
  348. },
  349. { :name => 'DefaultsThroughYAMLFile',
  350. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  351. :testdefines => ['TEST'],
  352. :cmdline => "", #defaults
  353. :yaml => {}, #defaults
  354. :expected => {
  355. :to_pass => [ 'test_ThisTestAlwaysPasses',
  356. 'spec_ThisTestPassesWhenNormalSetupRan',
  357. 'spec_ThisTestPassesWhenNormalTeardownRan',
  358. 'test_NotBeConfusedByLongComplicatedStrings',
  359. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  360. 'test_StillNotBeConfusedByLongComplicatedStrings',
  361. 'should_RunTestsStartingWithShouldByDefault',
  362. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  363. 'test_ShouldCallMockInitAndVerifyFunctionsForEachTest',
  364. ],
  365. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  366. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  367. }
  368. },
  369. { :name => 'ShorterFilterOfJustTest',
  370. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  371. :testdefines => ['TEST'],
  372. :options => {
  373. :test_prefix => "test",
  374. },
  375. :expected => {
  376. :to_pass => [ 'test_ThisTestAlwaysPasses',
  377. 'test_NotBeConfusedByLongComplicatedStrings',
  378. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  379. 'test_StillNotBeConfusedByLongComplicatedStrings',
  380. 'test_ShouldCallMockInitAndVerifyFunctionsForEachTest',
  381. ],
  382. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  383. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  384. }
  385. },
  386. { :name => 'ShorterFilterOfJustShould',
  387. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  388. :testdefines => ['TEST'],
  389. :options => {
  390. :test_prefix => "should",
  391. },
  392. :expected => {
  393. :to_pass => [ 'should_RunTestsStartingWithShouldByDefault' ],
  394. :to_fail => [ ],
  395. :to_ignore => [ ],
  396. }
  397. },
  398. { :name => 'ShorterFilterOfJustSpec',
  399. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  400. :testdefines => ['TEST'],
  401. :options => {
  402. :test_prefix => "spec",
  403. },
  404. :expected => {
  405. :to_pass => [ 'spec_ThisTestPassesWhenNormalSetupRan',
  406. 'spec_ThisTestPassesWhenNormalTeardownRan',
  407. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  408. ],
  409. :to_fail => [ ],
  410. :to_ignore => [ ],
  411. }
  412. },
  413. { :name => 'InjectIncludes',
  414. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  415. :testdefines => ['TEST'],
  416. :options => {
  417. :includes => ['Defs.h'],
  418. },
  419. :expected => {
  420. :to_pass => [ 'test_ThisTestAlwaysPasses',
  421. 'spec_ThisTestPassesWhenNormalSetupRan',
  422. 'spec_ThisTestPassesWhenNormalTeardownRan',
  423. 'test_NotBeConfusedByLongComplicatedStrings',
  424. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  425. 'test_StillNotBeConfusedByLongComplicatedStrings',
  426. 'should_RunTestsStartingWithShouldByDefault',
  427. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  428. 'test_ShouldCallMockInitAndVerifyFunctionsForEachTest',
  429. ],
  430. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  431. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  432. }
  433. },
  434. { :name => 'ParameterizedThroughOptions',
  435. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  436. :testdefines => ['TEST'],
  437. :options => {
  438. :test_prefix => "paratest",
  439. :use_param_tests => true,
  440. },
  441. :expected => {
  442. :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
  443. 'paratest_ShouldHandleParameterizedTests\(125\)',
  444. 'paratest_ShouldHandleParameterizedTests\(5\)',
  445. 'paratest_ShouldHandleParameterizedTests2\(7\)',
  446. 'paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid\(RUN_TEST_NO_ARGS\)',
  447. ],
  448. :to_fail => [ 'paratest_ShouldHandleParameterizedTestsThatFail\(17\)' ],
  449. :to_ignore => [ ],
  450. }
  451. },
  452. { :name => 'ParameterizedThroughCommandLine',
  453. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  454. :testdefines => ['TEST'],
  455. :cmdline => " --test_prefix=\"paratest\" --use_param_tests=1",
  456. :expected => {
  457. :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
  458. 'paratest_ShouldHandleParameterizedTests\(125\)',
  459. 'paratest_ShouldHandleParameterizedTests\(5\)',
  460. 'paratest_ShouldHandleParameterizedTests2\(7\)',
  461. 'paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid\(RUN_TEST_NO_ARGS\)',
  462. ],
  463. :to_fail => [ 'paratest_ShouldHandleParameterizedTestsThatFail\(17\)' ],
  464. :to_ignore => [ ],
  465. }
  466. },
  467. { :name => 'ParameterizedThroughCommandLineAndYaml',
  468. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  469. :testdefines => ['TEST'],
  470. :cmdline => "--use_param_tests=1",
  471. :yaml => {
  472. :test_prefix => "paratest"
  473. },
  474. :expected => {
  475. :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
  476. 'paratest_ShouldHandleParameterizedTests\(125\)',
  477. 'paratest_ShouldHandleParameterizedTests\(5\)',
  478. 'paratest_ShouldHandleParameterizedTests2\(7\)',
  479. 'paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid\(RUN_TEST_NO_ARGS\)',
  480. ],
  481. :to_fail => [ 'paratest_ShouldHandleParameterizedTestsThatFail\(17\)' ],
  482. :to_ignore => [ ],
  483. }
  484. },
  485. { :name => 'CException',
  486. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  487. :testdefines => ['TEST', 'USE_CEXCEPTION'],
  488. :options => {
  489. :test_prefix => "extest",
  490. :plugins => [ :cexception ],
  491. },
  492. :expected => {
  493. :to_pass => [ 'extest_ShouldHandleCExceptionInTest' ],
  494. :to_fail => [ ],
  495. :to_ignore => [ ],
  496. }
  497. },
  498. { :name => 'CustomSetupAndTeardownThroughOptions',
  499. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  500. :testdefines => ['TEST'],
  501. :options => {
  502. :test_prefix => "custtest|test",
  503. :setup_name => "custom_setup",
  504. :teardown_name => "custom_teardown",
  505. },
  506. :expected => {
  507. :to_pass => [ 'test_ThisTestAlwaysPasses',
  508. 'test_NotBeConfusedByLongComplicatedStrings',
  509. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  510. 'test_StillNotBeConfusedByLongComplicatedStrings',
  511. 'custtest_ThisTestPassesWhenCustomSetupRan',
  512. 'custtest_ThisTestPassesWhenCustomTeardownRan',
  513. 'test_ShouldCallMockInitAndVerifyFunctionsForEachTest',
  514. ],
  515. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  516. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  517. }
  518. },
  519. { :name => 'CustomSetupAndTeardownThroughCommandLine',
  520. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  521. :testdefines => ['TEST'],
  522. :cmdline => " --test_prefix=\"custtest|test\" --setup_name=\"custom_setup\" --teardown_name=\"custom_teardown\"",
  523. :expected => {
  524. :to_pass => [ 'test_ThisTestAlwaysPasses',
  525. 'test_NotBeConfusedByLongComplicatedStrings',
  526. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  527. 'test_StillNotBeConfusedByLongComplicatedStrings',
  528. 'custtest_ThisTestPassesWhenCustomSetupRan',
  529. 'custtest_ThisTestPassesWhenCustomTeardownRan',
  530. 'test_ShouldCallMockInitAndVerifyFunctionsForEachTest',
  531. ],
  532. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  533. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  534. }
  535. },
  536. { :name => 'CustomSetupAndTeardownThroughYaml',
  537. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  538. :testdefines => ['TEST'],
  539. :cmdline => " --test_prefix=\"custtest|test\"",
  540. :yaml => {
  541. :setup_name => "custom_setup",
  542. :teardown_name => "custom_teardown",
  543. },
  544. :expected => {
  545. :to_pass => [ 'test_ThisTestAlwaysPasses',
  546. 'test_NotBeConfusedByLongComplicatedStrings',
  547. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  548. 'test_StillNotBeConfusedByLongComplicatedStrings',
  549. 'custtest_ThisTestPassesWhenCustomSetupRan',
  550. 'custtest_ThisTestPassesWhenCustomTeardownRan',
  551. 'test_ShouldCallMockInitAndVerifyFunctionsForEachTest',
  552. ],
  553. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  554. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  555. }
  556. },
  557. { :name => 'CustomMain',
  558. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  559. :testdefines => ['TEST', "USE_ANOTHER_MAIN"],
  560. :options => {
  561. :main_name => "custom_main",
  562. },
  563. :expected => {
  564. :to_pass => [ 'test_ThisTestAlwaysPasses',
  565. 'spec_ThisTestPassesWhenNormalSetupRan',
  566. 'spec_ThisTestPassesWhenNormalTeardownRan',
  567. 'test_NotBeConfusedByLongComplicatedStrings',
  568. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  569. 'test_StillNotBeConfusedByLongComplicatedStrings',
  570. 'should_RunTestsStartingWithShouldByDefault',
  571. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  572. 'test_ShouldCallMockInitAndVerifyFunctionsForEachTest',
  573. ],
  574. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  575. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  576. }
  577. },
  578. { :name => 'CustomSuiteSetupAndTeardown',
  579. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  580. :testdefines => ['TEST'],
  581. :includes => ['Defs.h'],
  582. :options => {
  583. :test_prefix => "suitetest|test",
  584. :suite_setup => " CounterSuiteSetup = 1;",
  585. :suite_teardown => " return num_failures;",
  586. },
  587. :expected => {
  588. :to_pass => [ 'test_ThisTestAlwaysPasses',
  589. 'test_NotBeConfusedByLongComplicatedStrings',
  590. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  591. 'test_StillNotBeConfusedByLongComplicatedStrings',
  592. 'suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan',
  593. 'test_ShouldCallMockInitAndVerifyFunctionsForEachTest',
  594. ],
  595. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  596. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  597. }
  598. },
  599. { :name => 'MainExternDeclaration',
  600. :testfile => 'testdata/testRunnerGeneratorWithMocks.c',
  601. :testdefines => ['TEST'],
  602. :includes => ['Defs.h'],
  603. :options => {
  604. :main_export_decl => "EXTERN_DECL",
  605. },
  606. :expected => {
  607. :to_pass => [ 'test_ThisTestAlwaysPasses',
  608. 'spec_ThisTestPassesWhenNormalSetupRan',
  609. 'spec_ThisTestPassesWhenNormalTeardownRan',
  610. 'test_NotBeConfusedByLongComplicatedStrings',
  611. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  612. 'test_StillNotBeConfusedByLongComplicatedStrings',
  613. 'should_RunTestsStartingWithShouldByDefault',
  614. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  615. 'test_ShouldCallMockInitAndVerifyFunctionsForEachTest',
  616. ],
  617. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  618. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  619. }
  620. },
  621. #### WITH ARGS ##########################################
  622. { :name => 'ArgsThroughOptions',
  623. :testfile => 'testdata/testRunnerGenerator.c',
  624. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  625. :options => {
  626. :cmdline_args => true,
  627. },
  628. :expected => {
  629. :to_pass => [ 'test_ThisTestAlwaysPasses',
  630. 'spec_ThisTestPassesWhenNormalSetupRan',
  631. 'spec_ThisTestPassesWhenNormalTeardownRan',
  632. 'test_NotBeConfusedByLongComplicatedStrings',
  633. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  634. 'test_StillNotBeConfusedByLongComplicatedStrings',
  635. 'should_RunTestsStartingWithShouldByDefault',
  636. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  637. ],
  638. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  639. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  640. }
  641. },
  642. { :name => 'ArgsThroughCommandLine',
  643. :testfile => 'testdata/testRunnerGenerator.c',
  644. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  645. :cmdline => "--cmdline_args=1",
  646. :expected => {
  647. :to_pass => [ 'test_ThisTestAlwaysPasses',
  648. 'spec_ThisTestPassesWhenNormalSetupRan',
  649. 'spec_ThisTestPassesWhenNormalTeardownRan',
  650. 'test_NotBeConfusedByLongComplicatedStrings',
  651. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  652. 'test_StillNotBeConfusedByLongComplicatedStrings',
  653. 'should_RunTestsStartingWithShouldByDefault',
  654. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  655. ],
  656. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  657. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  658. }
  659. },
  660. { :name => 'ArgsThroughYAMLFile',
  661. :testfile => 'testdata/testRunnerGenerator.c',
  662. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  663. :cmdline => "",
  664. :yaml => {
  665. :cmdline_args => true,
  666. },
  667. :expected => {
  668. :to_pass => [ 'test_ThisTestAlwaysPasses',
  669. 'spec_ThisTestPassesWhenNormalSetupRan',
  670. 'spec_ThisTestPassesWhenNormalTeardownRan',
  671. 'test_NotBeConfusedByLongComplicatedStrings',
  672. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  673. 'test_StillNotBeConfusedByLongComplicatedStrings',
  674. 'should_RunTestsStartingWithShouldByDefault',
  675. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  676. ],
  677. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  678. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  679. }
  680. },
  681. { :name => 'ArgsNameFilterJustTest',
  682. :testfile => 'testdata/testRunnerGenerator.c',
  683. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  684. :options => {
  685. :cmdline_args => true,
  686. },
  687. :cmdline_args => "-n test_",
  688. :expected => {
  689. :to_pass => [ 'test_ThisTestAlwaysPasses',
  690. 'test_NotBeConfusedByLongComplicatedStrings',
  691. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  692. 'test_StillNotBeConfusedByLongComplicatedStrings',
  693. ],
  694. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  695. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  696. }
  697. },
  698. { :name => 'ArgsNameFilterJustShould',
  699. :testfile => 'testdata/testRunnerGenerator.c',
  700. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  701. :options => {
  702. :cmdline_args => true,
  703. },
  704. :cmdline_args => "-n should_",
  705. :expected => {
  706. :to_pass => [ 'should_RunTestsStartingWithShouldByDefault' ],
  707. :to_fail => [ ],
  708. :to_ignore => [ ],
  709. }
  710. },
  711. { :name => 'ArgsNameFilterTestAndShould',
  712. :testfile => 'testdata/testRunnerGenerator.c',
  713. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  714. :options => {
  715. :cmdline_args => true,
  716. },
  717. :cmdline_args => "-n should_,test_",
  718. :expected => {
  719. :to_pass => [ 'test_ThisTestAlwaysPasses',
  720. 'test_NotBeConfusedByLongComplicatedStrings',
  721. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  722. 'test_StillNotBeConfusedByLongComplicatedStrings',
  723. 'should_RunTestsStartingWithShouldByDefault' ],
  724. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  725. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  726. }
  727. },
  728. { :name => 'ArgsNameFilterWithWildcardOnFile',
  729. :testfile => 'testdata/testRunnerGeneratorSmall.c',
  730. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  731. :options => {
  732. :cmdline_args => true,
  733. },
  734. :cmdline_args => "-n testRunnerGeneratorSma*",
  735. :expected => {
  736. :to_pass => [ 'test_ThisTestAlwaysPasses',
  737. 'spec_ThisTestPassesWhenNormalSetupRan',
  738. 'spec_ThisTestPassesWhenNormalTeardownRan' ],
  739. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  740. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  741. }
  742. },
  743. { :name => 'ArgsNameFilterWithWildcardAsName',
  744. :testfile => 'testdata/testRunnerGeneratorSmall.c',
  745. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  746. :options => {
  747. :cmdline_args => true,
  748. },
  749. :cmdline_args => "-n testRunnerGeneratorSmall:*",
  750. :expected => {
  751. :to_pass => [ 'test_ThisTestAlwaysPasses',
  752. 'spec_ThisTestPassesWhenNormalSetupRan',
  753. 'spec_ThisTestPassesWhenNormalTeardownRan' ],
  754. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  755. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  756. }
  757. },
  758. { :name => 'ArgsNameFilterWithWildcardOnName',
  759. :testfile => 'testdata/testRunnerGeneratorSmall.c',
  760. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  761. :options => {
  762. :cmdline_args => true,
  763. },
  764. :cmdline_args => "-n testRunnerGeneratorSmall:test_*",
  765. :expected => {
  766. :to_pass => [ 'test_ThisTestAlwaysPasses' ],
  767. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  768. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  769. }
  770. },
  771. { :name => 'ArgsNameFilterWithWildcardAndShortName',
  772. :testfile => 'testdata/testRunnerGeneratorSmall.c',
  773. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  774. :options => {
  775. :cmdline_args => true,
  776. },
  777. :cmdline_args => "-n testRunnerGeneratorSmall:te*",
  778. :expected => {
  779. :to_pass => [ 'test_ThisTestAlwaysPasses' ],
  780. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  781. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  782. }
  783. },
  784. { :name => 'ArgsNameFilterWithWildcardOnBoth',
  785. :testfile => 'testdata/testRunnerGeneratorSmall.c',
  786. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  787. :options => {
  788. :cmdline_args => true,
  789. },
  790. :cmdline_args => "-n testRunnerGeneratorSm*:*",
  791. :expected => {
  792. :to_pass => [ 'test_ThisTestAlwaysPasses',
  793. 'spec_ThisTestPassesWhenNormalSetupRan',
  794. 'spec_ThisTestPassesWhenNormalTeardownRan' ],
  795. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  796. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  797. }
  798. },
  799. { :name => 'ArgsExcludeFilterJustTest',
  800. :testfile => 'testdata/testRunnerGenerator.c',
  801. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  802. :options => {
  803. :cmdline_args => true,
  804. },
  805. :cmdline_args => "-x test_",
  806. :expected => {
  807. :to_pass => [ 'spec_ThisTestPassesWhenNormalSetupRan',
  808. 'spec_ThisTestPassesWhenNormalTeardownRan',
  809. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  810. 'should_RunTestsStartingWithShouldByDefault',
  811. ],
  812. :to_fail => [ ],
  813. :to_ignore => [ ],
  814. }
  815. },
  816. { :name => 'ArgsIncludeAndExcludeFilter',
  817. :testfile => 'testdata/testRunnerGenerator.c',
  818. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  819. :options => {
  820. :cmdline_args => true,
  821. :includes => ['Defs.h'],
  822. },
  823. :cmdline_args => "-n test_ -x Ignored",
  824. :expected => {
  825. :to_pass => [ 'test_ThisTestAlwaysPasses',
  826. 'test_NotBeConfusedByLongComplicatedStrings',
  827. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  828. 'test_StillNotBeConfusedByLongComplicatedStrings',
  829. ],
  830. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  831. :to_ignore => [ ],
  832. }
  833. },
  834. { :name => 'ArgsIncludeSingleTest',
  835. :testfile => 'testdata/testRunnerGenerator.c',
  836. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  837. :options => {
  838. :cmdline_args => true,
  839. },
  840. :cmdline_args => "-n ThisTestAlwaysPasses",
  841. :expected => {
  842. :to_pass => [ 'test_ThisTestAlwaysPasses' ],
  843. :to_fail => [ ],
  844. :to_ignore => [ ],
  845. }
  846. },
  847. { :name => 'ArgsIncludeSingleTestInSpecificFile',
  848. :testfile => 'testdata/testRunnerGenerator.c',
  849. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  850. :options => {
  851. :cmdline_args => true,
  852. },
  853. :cmdline_args => "-n testRunnerGenerator:ThisTestAlwaysPasses",
  854. :expected => {
  855. :to_pass => [ 'test_ThisTestAlwaysPasses' ],
  856. :to_fail => [ ],
  857. :to_ignore => [ ],
  858. }
  859. },
  860. { :name => 'ArgsIncludeTestFileWithExtension',
  861. :testfile => 'testdata/testRunnerGenerator.c',
  862. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  863. :options => {
  864. :cmdline_args => true,
  865. },
  866. :cmdline_args => "-n testRunnerGenerator.c:ThisTestAlwaysPasses",
  867. :expected => {
  868. :to_pass => [ 'test_ThisTestAlwaysPasses' ],
  869. :to_fail => [ ],
  870. :to_ignore => [ ],
  871. }
  872. },
  873. { :name => 'ArgsIncludeDoubleQuotes',
  874. :testfile => 'testdata/testRunnerGenerator.c',
  875. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  876. :options => {
  877. :cmdline_args => true,
  878. },
  879. :cmdline_args => "-n \"testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails\"",
  880. :expected => {
  881. :to_pass => [ 'test_ThisTestAlwaysPasses' ],
  882. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  883. :to_ignore => [ ],
  884. }
  885. },
  886. { :name => 'ArgsIncludeSingleQuotes',
  887. :testfile => 'testdata/testRunnerGenerator.c',
  888. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  889. :options => {
  890. :cmdline_args => true,
  891. },
  892. :cmdline_args => "-n 'testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails'",
  893. :expected => {
  894. :to_pass => [ 'test_ThisTestAlwaysPasses' ],
  895. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  896. :to_ignore => [ ],
  897. }
  898. },
  899. { :name => 'ArgsIncludeAValidTestForADifferentFile',
  900. :testfile => 'testdata/testRunnerGenerator.c',
  901. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  902. :options => {
  903. :cmdline_args => true,
  904. },
  905. :cmdline_args => "-n AnotherFile:ThisTestDoesNotExist",
  906. :expected => {
  907. :to_pass => [ ],
  908. :to_fail => [ ],
  909. :to_ignore => [ ],
  910. }
  911. },
  912. { :name => 'ArgsIncludeNoTests',
  913. :testfile => 'testdata/testRunnerGenerator.c',
  914. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  915. :options => {
  916. :cmdline_args => true,
  917. },
  918. :cmdline_args => "-n ThisTestDoesNotExist",
  919. :expected => {
  920. :to_pass => [ ],
  921. :to_fail => [ ],
  922. :to_ignore => [ ],
  923. }
  924. },
  925. { :name => 'ArgsExcludeAllTests',
  926. :testfile => 'testdata/testRunnerGenerator.c',
  927. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  928. :options => {
  929. :cmdline_args => true,
  930. },
  931. :cmdline_args => "-x _",
  932. :expected => {
  933. :to_pass => [ ],
  934. :to_fail => [ ],
  935. :to_ignore => [ ],
  936. }
  937. },
  938. { :name => 'ArgsIncludeFullFile',
  939. :testfile => 'testdata/testRunnerGenerator.c',
  940. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  941. :options => {
  942. :cmdline_args => true,
  943. },
  944. :cmdline_args => "-n testRunnerGenerator",
  945. :expected => {
  946. :to_pass => [ 'test_ThisTestAlwaysPasses',
  947. 'spec_ThisTestPassesWhenNormalSetupRan',
  948. 'spec_ThisTestPassesWhenNormalTeardownRan',
  949. 'test_NotBeConfusedByLongComplicatedStrings',
  950. 'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
  951. 'test_StillNotBeConfusedByLongComplicatedStrings',
  952. 'should_RunTestsStartingWithShouldByDefault',
  953. 'spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan',
  954. ],
  955. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  956. :to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
  957. }
  958. },
  959. { :name => 'ArgsIncludeWithAlternateFlag',
  960. :testfile => 'testdata/testRunnerGenerator.c',
  961. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  962. :options => {
  963. :cmdline_args => true,
  964. },
  965. :cmdline_args => "-f=\"testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails\"",
  966. :expected => {
  967. :to_pass => [ 'test_ThisTestAlwaysPasses' ],
  968. :to_fail => [ 'test_ThisTestAlwaysFails' ],
  969. :to_ignore => [ ],
  970. }
  971. },
  972. { :name => 'ArgsIncludeWithParameterized',
  973. :testfile => 'testdata/testRunnerGenerator.c',
  974. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  975. :cmdline => "--use_param_tests=1",
  976. :yaml => {
  977. :cmdline_args => true,
  978. :test_prefix => "paratest"
  979. },
  980. :cmdline_args => "-n ShouldHandleParameterizedTests",
  981. :expected => {
  982. :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
  983. 'paratest_ShouldHandleParameterizedTests\(125\)',
  984. 'paratest_ShouldHandleParameterizedTests\(5\)',
  985. 'paratest_ShouldHandleParameterizedTests2\(7\)',
  986. ],
  987. :to_fail => [ 'paratest_ShouldHandleParameterizedTestsThatFail\(17\)' ],
  988. :to_ignore => [ ],
  989. }
  990. },
  991. { :name => 'ArgsList',
  992. :testfile => 'testdata/testRunnerGenerator.c',
  993. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  994. :options => {
  995. :cmdline_args => true,
  996. },
  997. :cmdline_args => "-l",
  998. :expected => {
  999. :to_pass => [ ],
  1000. :to_fail => [ ],
  1001. :to_ignore => [ ],
  1002. :text => [ "testRunnerGenerator",
  1003. "test_ThisTestAlwaysPasses",
  1004. "test_ThisTestAlwaysFails",
  1005. "test_ThisTestAlwaysIgnored",
  1006. "spec_ThisTestPassesWhenNormalSuiteSetupAndTeardownRan",
  1007. "spec_ThisTestPassesWhenNormalSetupRan",
  1008. "spec_ThisTestPassesWhenNormalTeardownRan",
  1009. "test_NotBeConfusedByLongComplicatedStrings",
  1010. "test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings",
  1011. "test_StillNotBeConfusedByLongComplicatedStrings",
  1012. "should_RunTestsStartingWithShouldByDefault"
  1013. ]
  1014. }
  1015. },
  1016. { :name => 'ArgsListParameterized',
  1017. :testfile => 'testdata/testRunnerGenerator.c',
  1018. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  1019. :options => {
  1020. :test_prefix => "paratest",
  1021. :use_param_tests => true,
  1022. :cmdline_args => true,
  1023. },
  1024. :cmdline_args => "-l",
  1025. :expected => {
  1026. :to_pass => [ ],
  1027. :to_fail => [ ],
  1028. :to_ignore => [ ],
  1029. :text => [ "testRunnerGenerator",
  1030. 'paratest_ShouldHandleParameterizedTests\(25\)',
  1031. 'paratest_ShouldHandleParameterizedTests\(125\)',
  1032. 'paratest_ShouldHandleParameterizedTests\(5\)',
  1033. 'paratest_ShouldHandleParameterizedTests2\(7\)',
  1034. 'paratest_ShouldHandleNonParameterizedTestsWhenParameterizationValid\(RUN_TEST_NO_ARGS\)',
  1035. 'paratest_ShouldHandleParameterizedTestsThatFail\(17\)'
  1036. ],
  1037. }
  1038. },
  1039. { :name => 'ArgsIncompleteIncludeFlags',
  1040. :testfile => 'testdata/testRunnerGenerator.c',
  1041. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  1042. :options => {
  1043. :cmdline_args => true,
  1044. },
  1045. :cmdline_args => "-n",
  1046. :expected => {
  1047. :to_pass => [ ],
  1048. :to_fail => [ ],
  1049. :to_ignore => [ ],
  1050. :text => [ "ERROR: No Test String to Include Matches For" ],
  1051. }
  1052. },
  1053. { :name => 'ArgsIncompleteExcludeFlags',
  1054. :testfile => 'testdata/testRunnerGenerator.c',
  1055. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  1056. :options => {
  1057. :cmdline_args => true,
  1058. },
  1059. :cmdline_args => "-x",
  1060. :expected => {
  1061. :to_pass => [ ],
  1062. :to_fail => [ ],
  1063. :to_ignore => [ ],
  1064. :text => [ "ERROR: No Test String to Exclude Matches For" ],
  1065. }
  1066. },
  1067. { :name => 'ArgsIllegalFlags',
  1068. :testfile => 'testdata/testRunnerGenerator.c',
  1069. :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
  1070. :options => {
  1071. :cmdline_args => true,
  1072. },
  1073. :cmdline_args => "-z",
  1074. :expected => {
  1075. :to_pass => [ ],
  1076. :to_fail => [ ],
  1077. :to_ignore => [ ],
  1078. :text => [ "ERROR: Unknown Option z" ],
  1079. }
  1080. },
  1081. ]
  1082. def runner_test(test, runner, expected, test_defines, cmdline_args)
  1083. # Tack on TEST define for compiling unit tests
  1084. load_configuration($cfg_file)
  1085. #compile objects
  1086. obj_list = [
  1087. compile(runner, test_defines),
  1088. compile(test, test_defines),
  1089. compile('../src/unity.c', test_defines),
  1090. ]
  1091. # Link the test executable
  1092. test_base = File.basename(test, C_EXTENSION)
  1093. link_it(test_base, obj_list)
  1094. # Execute unit test and generate results file
  1095. simulator = build_simulator_fields
  1096. cmdline_args ||= ""
  1097. executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension'] + " #{cmdline_args}"
  1098. cmd_str = if simulator.nil?
  1099. executable
  1100. else
  1101. "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
  1102. end
  1103. output = execute(cmd_str, true)
  1104. #compare to the expected pass/fail
  1105. allgood = expected[:to_pass].inject(true) {|s,v| s && verify_match(/#{v}:PASS/, output) }
  1106. allgood = expected[:to_fail].inject(allgood) {|s,v| s && verify_match(/#{v}:FAIL/, output) }
  1107. allgood = expected[:to_ignore].inject(allgood) {|s,v| s && verify_match(/#{v}:IGNORE/, output) }
  1108. #verify there weren't more pass/fail/etc than expected
  1109. allgood &&= verify_number( expected[:to_pass], /(:PASS)/, output)
  1110. allgood &&= verify_number( expected[:to_fail], /(:FAIL)/, output)
  1111. allgood &&= verify_number( expected[:to_ignore], /(:IGNORE)/, output)
  1112. #if we care about any other text, check that too
  1113. if (expected[:text])
  1114. allgood = expected[:text].inject(allgood) {|s,v| s && verify_match(/#{v}/, output) }
  1115. allgood &&= verify_number( expected[:text], /.+/, output )
  1116. end
  1117. report output if (!allgood && !$verbose) #report failures if not already reporting everything
  1118. return allgood
  1119. end
  1120. def verify_match(expression, output)
  1121. if (expression =~ output)
  1122. return true
  1123. else
  1124. report " FAIL: No Match For /#{expression.to_s}/"
  1125. return false
  1126. end
  1127. end
  1128. def verify_number(expected, expression, output)
  1129. exp = expected.length
  1130. act = output.scan(expression).length
  1131. if (exp == act)
  1132. return true
  1133. else
  1134. report " FAIL: Expected #{exp} Matches For /#{expression.to_s}/. Was #{act}"
  1135. return false
  1136. end
  1137. end
  1138. RUNNER_TESTS.each do |testset|
  1139. basename = File.basename(testset[:testfile], C_EXTENSION)
  1140. testset_name = "Runner_#{basename}_#{testset[:name]}"
  1141. should testset_name do
  1142. runner_name = OUT_FILE + testset[:name] + '_runner.c'
  1143. #create a yaml file first if required
  1144. yaml_option = ""
  1145. if (testset[:yaml])
  1146. File.open("build/runner_options.yml",'w') {|f| f << { :unity => testset[:yaml] }.to_yaml }
  1147. yaml_option = "build/runner_options.yml"
  1148. end
  1149. #run script via command line or through hash function call, as requested
  1150. if (testset[:cmdline])
  1151. cmdstr = "ruby ../auto/generate_test_runner.rb #{yaml_option} #{testset[:cmdline]} \"#{testset[:testfile]}\" \"#{runner_name}\""
  1152. `#{cmdstr}`
  1153. else
  1154. UnityTestRunnerGenerator.new(testset[:options]).run(testset[:testfile], runner_name)
  1155. end
  1156. #test the script against the specified test file and check results
  1157. if (runner_test(testset[:testfile], runner_name, testset[:expected], testset[:testdefines], testset[:cmdline_args]))
  1158. report "#{testset_name}:PASS"
  1159. else
  1160. report "#{testset_name}:FAIL"
  1161. $generate_test_runner_failures += 1
  1162. end
  1163. $generate_test_runner_tests += 1
  1164. end
  1165. end
  1166. raise "There were #{$generate_test_runner_failures.to_s} failures while testing generate_test_runner.rb" if ($generate_test_runner_failures > 0)