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