generate_test_runner.rb 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. #!/usr/bin/ruby
  2. # ==========================================
  3. # Unity Project - A Test Framework for C
  4. # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
  5. # [Released under MIT License. Please refer to license.txt for details]
  6. # ==========================================
  7. class UnityTestRunnerGenerator
  8. def initialize(options = nil)
  9. @options = UnityTestRunnerGenerator.default_options
  10. case options
  11. when NilClass
  12. @options
  13. when String
  14. @options.merge!(UnityTestRunnerGenerator.grab_config(options))
  15. when Hash
  16. # Check if some of these have been specified
  17. @options[:has_setup] = !options[:setup_name].nil?
  18. @options[:has_teardown] = !options[:teardown_name].nil?
  19. @options[:has_suite_setup] = !options[:suite_setup].nil?
  20. @options[:has_suite_teardown] = !options[:suite_teardown].nil?
  21. @options.merge!(options)
  22. else
  23. raise 'If you specify arguments, it should be a filename or a hash of options'
  24. end
  25. require_relative 'type_sanitizer'
  26. end
  27. def self.default_options
  28. {
  29. includes: [],
  30. defines: [],
  31. plugins: [],
  32. framework: :unity,
  33. test_prefix: 'test|spec|should',
  34. mock_prefix: 'Mock',
  35. mock_suffix: '',
  36. setup_name: 'setUp',
  37. teardown_name: 'tearDown',
  38. test_reset_name: 'resetTest',
  39. test_verify_name: 'verifyTest',
  40. main_name: 'main', # set to :auto to automatically generate each time
  41. main_export_decl: '',
  42. cmdline_args: false,
  43. omit_begin_end: false,
  44. use_param_tests: false,
  45. use_system_files: true,
  46. include_extensions: '(?:hpp|hh|H|h)',
  47. source_extensions: '(?:cpp|cc|ino|C|c)'
  48. }
  49. end
  50. def self.grab_config(config_file)
  51. options = default_options
  52. unless config_file.nil? || config_file.empty?
  53. require_relative 'yaml_helper'
  54. yaml_guts = YamlHelper.load_file(config_file)
  55. options.merge!(yaml_guts[:unity] || yaml_guts[:cmock])
  56. raise "No :unity or :cmock section found in #{config_file}" unless options
  57. end
  58. options
  59. end
  60. def run(input_file, output_file, options = nil)
  61. @options.merge!(options) unless options.nil?
  62. # pull required data from source file
  63. source = File.read(input_file)
  64. source = source.force_encoding('ISO-8859-1').encode('utf-8', replace: nil)
  65. tests = find_tests(source)
  66. headers = find_includes(source)
  67. testfile_includes = @options[:use_system_files] ? (headers[:local] + headers[:system]) : (headers[:local])
  68. used_mocks = find_mocks(testfile_includes)
  69. testfile_includes = (testfile_includes - used_mocks)
  70. testfile_includes.delete_if { |inc| inc =~ /(unity|cmock)/ }
  71. find_setup_and_teardown(source)
  72. # build runner file
  73. generate(input_file, output_file, tests, used_mocks, testfile_includes)
  74. # determine which files were used to return them
  75. all_files_used = [input_file, output_file]
  76. all_files_used += testfile_includes.map { |filename| "#{filename}.c" } unless testfile_includes.empty?
  77. all_files_used += @options[:includes] unless @options[:includes].empty?
  78. all_files_used += headers[:linkonly] unless headers[:linkonly].empty?
  79. all_files_used.uniq
  80. end
  81. def generate(input_file, output_file, tests, used_mocks, testfile_includes)
  82. File.open(output_file, 'w') do |output|
  83. create_header(output, used_mocks, testfile_includes)
  84. create_externs(output, tests, used_mocks)
  85. create_mock_management(output, used_mocks)
  86. create_setup(output)
  87. create_teardown(output)
  88. create_suite_setup(output)
  89. create_suite_teardown(output)
  90. create_reset(output)
  91. create_run_test(output) unless tests.empty?
  92. create_args_wrappers(output, tests)
  93. create_main(output, input_file, tests, used_mocks)
  94. end
  95. return unless @options[:header_file] && !@options[:header_file].empty?
  96. File.open(@options[:header_file], 'w') do |output|
  97. create_h_file(output, @options[:header_file], tests, testfile_includes, used_mocks)
  98. end
  99. end
  100. def find_tests(source)
  101. tests_and_line_numbers = []
  102. # contains characters which will be substituted from within strings, doing
  103. # this prevents these characters from interfering with scrubbers
  104. # @ is not a valid C character, so there should be no clashes with files genuinely containing these markers
  105. substring_subs = { '{' => '@co@', '}' => '@cc@', ';' => '@ss@', '/' => '@fs@' }
  106. substring_re = Regexp.union(substring_subs.keys)
  107. substring_unsubs = substring_subs.invert # the inverse map will be used to fix the strings afterwords
  108. substring_unsubs['@quote@'] = '\\"'
  109. substring_unsubs['@apos@'] = '\\\''
  110. substring_unre = Regexp.union(substring_unsubs.keys)
  111. source_scrubbed = source.clone
  112. source_scrubbed = source_scrubbed.gsub(/\\"/, '@quote@') # hide escaped quotes to allow capture of the full string/char
  113. source_scrubbed = source_scrubbed.gsub(/\\'/, '@apos@') # hide escaped apostrophes to allow capture of the full string/char
  114. source_scrubbed = source_scrubbed.gsub(/("[^"\n]*")|('[^'\n]*')/) { |s| s.gsub(substring_re, substring_subs) } # temporarily hide problematic characters within strings
  115. source_scrubbed = source_scrubbed.gsub(/\/\/(?:.+\/\*|\*(?:$|[^\/])).*$/, '') # remove line comments that comment out the start of blocks
  116. source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments
  117. source_scrubbed = source_scrubbed.gsub(/\/\/.*$/, '') # remove line comments (all that remain)
  118. lines = source_scrubbed.split(/(^\s*\#.*$) | (;|\{|\}) /x) # Treat preprocessor directives as a logical line. Match ;, {, and } as end of lines
  119. .map { |line| line.gsub(substring_unre, substring_unsubs) } # unhide the problematic characters previously removed
  120. lines.each_with_index do |line, _index|
  121. # find tests
  122. next unless line =~ /^((?:\s*(?:TEST_(?:CASE|RANGE|MATRIX))\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]}).*)\s*\(\s*(.*)\s*\)/m
  123. next unless line =~ /^((?:\s*(?:TEST_(?:CASE|RANGE|MATRIX))\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]})\w*)\s*\(\s*(.*)\s*\)/m
  124. arguments = Regexp.last_match(1)
  125. name = Regexp.last_match(2)
  126. call = Regexp.last_match(3)
  127. params = Regexp.last_match(4)
  128. args = nil
  129. if @options[:use_param_tests] && !arguments.empty?
  130. args = []
  131. type_and_args = arguments.split(/TEST_(CASE|RANGE|MATRIX)/)
  132. (1...type_and_args.length).step(2).each do |i|
  133. case type_and_args[i]
  134. when 'CASE'
  135. args << type_and_args[i + 1].sub(/^\s*\(\s*(.*?)\s*\)\s*$/m, '\1')
  136. when 'RANGE'
  137. args += type_and_args[i + 1].scan(/(\[|<)\s*(-?\d+.?\d*)\s*,\s*(-?\d+.?\d*)\s*,\s*(-?\d+.?\d*)\s*(\]|>)/m).map do |arg_values_str|
  138. exclude_end = arg_values_str[0] == '<' && arg_values_str[-1] == '>'
  139. arg_values_str[1...-1].map do |arg_value_str|
  140. arg_value_str.include?('.') ? arg_value_str.to_f : arg_value_str.to_i
  141. end.push(exclude_end)
  142. end.map do |arg_values|
  143. Range.new(arg_values[0], arg_values[1], arg_values[3]).step(arg_values[2]).to_a
  144. end.reduce(nil) do |result, arg_range_expanded|
  145. result.nil? ? arg_range_expanded.map { |a| [a] } : result.product(arg_range_expanded)
  146. end.map do |arg_combinations|
  147. arg_combinations.flatten.join(', ')
  148. end
  149. when 'MATRIX'
  150. single_arg_regex_string = /(?:(?:"(?:\\"|[^\\])*?")+|(?:'\\?.')+|(?:[^\s\]\["',]|\[[\d\S_-]+\])+)/.source
  151. args_regex = /\[((?:\s*#{single_arg_regex_string}\s*,?)*(?:\s*#{single_arg_regex_string})?\s*)\]/m
  152. arg_elements_regex = /\s*(#{single_arg_regex_string})\s*,\s*/m
  153. args += type_and_args[i + 1].scan(args_regex).flatten.map do |arg_values_str|
  154. ("#{arg_values_str},").scan(arg_elements_regex)
  155. end.reduce do |result, arg_range_expanded|
  156. result.product(arg_range_expanded)
  157. end.map do |arg_combinations|
  158. arg_combinations.flatten.join(', ')
  159. end
  160. end
  161. end
  162. end
  163. tests_and_line_numbers << { test: name, args: args, call: call, params: params, line_number: 0 }
  164. end
  165. tests_and_line_numbers.uniq! { |v| v[:test] }
  166. # determine line numbers and create tests to run
  167. source_lines = source.split("\n")
  168. source_index = 0
  169. tests_and_line_numbers.size.times do |i|
  170. source_lines[source_index..].each_with_index do |line, index|
  171. next unless line =~ /\s+#{tests_and_line_numbers[i][:test]}(?:\s|\()/
  172. source_index += index
  173. tests_and_line_numbers[i][:line_number] = source_index + 1
  174. break
  175. end
  176. end
  177. tests_and_line_numbers
  178. end
  179. def find_includes(source)
  180. # remove comments (block and line, in three steps to ensure correct precedence)
  181. source.gsub!(/\/\/(?:.+\/\*|\*(?:$|[^\/])).*$/, '') # remove line comments that comment out the start of blocks
  182. source.gsub!(/\/\*.*?\*\//m, '') # remove block comments
  183. source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain)
  184. # parse out includes
  185. {
  186. local: source.scan(/^\s*#include\s+"\s*(.+\.#{@options[:include_extensions]})\s*"/).flatten,
  187. system: source.scan(/^\s*#include\s+<\s*(.+)\s*>/).flatten.map { |inc| "<#{inc}>" },
  188. linkonly: source.scan(/^TEST_SOURCE_FILE\(\s*"\s*(.+\.#{@options[:source_extensions]})\s*"/).flatten
  189. }
  190. end
  191. def find_mocks(includes)
  192. mock_headers = []
  193. includes.each do |include_path|
  194. include_file = File.basename(include_path)
  195. mock_headers << include_path if include_file =~ /^#{@options[:mock_prefix]}.*#{@options[:mock_suffix]}\.h$/i
  196. end
  197. mock_headers
  198. end
  199. def find_setup_and_teardown(source)
  200. @options[:has_setup] = source =~ /void\s+#{@options[:setup_name]}\s*\(/
  201. @options[:has_teardown] = source =~ /void\s+#{@options[:teardown_name]}\s*\(/
  202. @options[:has_suite_setup] ||= (source =~ /void\s+suiteSetUp\s*\(/)
  203. @options[:has_suite_teardown] ||= (source =~ /int\s+suiteTearDown\s*\(int\s+([a-zA-Z0-9_])+\s*\)/)
  204. end
  205. def create_header(output, mocks, testfile_includes = [])
  206. output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
  207. output.puts("\n/*=======Automagically Detected Files To Include=====*/")
  208. output.puts('extern "C" {') if @options[:externcincludes]
  209. output.puts("#include \"#{@options[:framework]}.h\"")
  210. output.puts('#include "cmock.h"') unless mocks.empty?
  211. output.puts('}') if @options[:externcincludes]
  212. if @options[:defines] && !@options[:defines].empty?
  213. output.puts("/* injected defines for unity settings, etc */")
  214. @options[:defines].each do |d|
  215. def_only = d.match(/(\w+).*/)[1]
  216. output.puts("#ifndef #{def_only}\n#define #{d}\n#endif /* #{def_only} */")
  217. end
  218. end
  219. if @options[:header_file] && !@options[:header_file].empty?
  220. output.puts("#include \"#{File.basename(@options[:header_file])}\"")
  221. else
  222. @options[:includes].flatten.uniq.compact.each do |inc|
  223. output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}")
  224. end
  225. testfile_includes.each do |inc|
  226. output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}")
  227. end
  228. end
  229. output.puts('extern "C" {') if @options[:externcincludes]
  230. mocks.each do |mock|
  231. output.puts("#include \"#{mock}\"")
  232. end
  233. output.puts('}') if @options[:externcincludes]
  234. output.puts('#include "CException.h"') if @options[:plugins].include?(:cexception)
  235. return unless @options[:enforce_strict_ordering]
  236. output.puts('')
  237. output.puts('int GlobalExpectCount;')
  238. output.puts('int GlobalVerifyOrder;')
  239. output.puts('char* GlobalOrderError;')
  240. end
  241. def create_externs(output, tests, _mocks)
  242. output.puts("\n/*=======External Functions This Runner Calls=====*/")
  243. output.puts("extern void #{@options[:setup_name]}(void);")
  244. output.puts("extern void #{@options[:teardown_name]}(void);")
  245. output.puts("\n#ifdef __cplusplus\nextern \"C\"\n{\n#endif") if @options[:externc]
  246. tests.each do |test|
  247. output.puts("extern void #{test[:test]}(#{test[:call] || 'void'});")
  248. end
  249. output.puts("#ifdef __cplusplus\n}\n#endif") if @options[:externc]
  250. output.puts('')
  251. end
  252. def create_mock_management(output, mock_headers)
  253. output.puts("\n/*=======Mock Management=====*/")
  254. output.puts('static void CMock_Init(void)')
  255. output.puts('{')
  256. if @options[:enforce_strict_ordering]
  257. output.puts(' GlobalExpectCount = 0;')
  258. output.puts(' GlobalVerifyOrder = 0;')
  259. output.puts(' GlobalOrderError = NULL;')
  260. end
  261. mocks = mock_headers.map { |mock| File.basename(mock, '.*') }
  262. mocks.each do |mock|
  263. mock_clean = TypeSanitizer.sanitize_c_identifier(mock)
  264. output.puts(" #{mock_clean}_Init();")
  265. end
  266. output.puts("}\n")
  267. output.puts('static void CMock_Verify(void)')
  268. output.puts('{')
  269. mocks.each do |mock|
  270. mock_clean = TypeSanitizer.sanitize_c_identifier(mock)
  271. output.puts(" #{mock_clean}_Verify();")
  272. end
  273. output.puts("}\n")
  274. output.puts('static void CMock_Destroy(void)')
  275. output.puts('{')
  276. mocks.each do |mock|
  277. mock_clean = TypeSanitizer.sanitize_c_identifier(mock)
  278. output.puts(" #{mock_clean}_Destroy();")
  279. end
  280. output.puts("}\n")
  281. end
  282. def create_setup(output)
  283. return if @options[:has_setup]
  284. output.puts("\n/*=======Setup (stub)=====*/")
  285. output.puts("void #{@options[:setup_name]}(void) {}")
  286. end
  287. def create_teardown(output)
  288. return if @options[:has_teardown]
  289. output.puts("\n/*=======Teardown (stub)=====*/")
  290. output.puts("void #{@options[:teardown_name]}(void) {}")
  291. end
  292. def create_suite_setup(output)
  293. return if @options[:suite_setup].nil?
  294. output.puts("\n/*=======Suite Setup=====*/")
  295. output.puts('void suiteSetUp(void)')
  296. output.puts('{')
  297. output.puts(@options[:suite_setup])
  298. output.puts('}')
  299. end
  300. def create_suite_teardown(output)
  301. return if @options[:suite_teardown].nil?
  302. output.puts("\n/*=======Suite Teardown=====*/")
  303. output.puts('int suiteTearDown(int num_failures)')
  304. output.puts('{')
  305. output.puts(@options[:suite_teardown])
  306. output.puts('}')
  307. end
  308. def create_reset(output)
  309. output.puts("\n/*=======Test Reset Options=====*/")
  310. output.puts("void #{@options[:test_reset_name]}(void);")
  311. output.puts("void #{@options[:test_reset_name]}(void)")
  312. output.puts('{')
  313. output.puts(" #{@options[:teardown_name]}();")
  314. output.puts(' CMock_Verify();')
  315. output.puts(' CMock_Destroy();')
  316. output.puts(' CMock_Init();')
  317. output.puts(" #{@options[:setup_name]}();")
  318. output.puts('}')
  319. output.puts("void #{@options[:test_verify_name]}(void);")
  320. output.puts("void #{@options[:test_verify_name]}(void)")
  321. output.puts('{')
  322. output.puts(' CMock_Verify();')
  323. output.puts('}')
  324. end
  325. def create_run_test(output)
  326. require 'erb'
  327. file = File.read(File.join(__dir__, 'run_test.erb'))
  328. template = ERB.new(file, trim_mode: '<>')
  329. output.puts("\n#{template.result(binding)}")
  330. end
  331. def create_args_wrappers(output, tests)
  332. return unless @options[:use_param_tests]
  333. output.puts("\n/*=======Parameterized Test Wrappers=====*/")
  334. tests.each do |test|
  335. next if test[:args].nil? || test[:args].empty?
  336. test[:args].each.with_index(1) do |args, idx|
  337. output.puts("static void runner_args#{idx}_#{test[:test]}(void)")
  338. output.puts('{')
  339. output.puts(" #{test[:test]}(#{args});")
  340. output.puts("}\n")
  341. end
  342. end
  343. end
  344. def create_main(output, filename, tests, used_mocks)
  345. output.puts("\n/*=======MAIN=====*/")
  346. main_name = @options[:main_name].to_sym == :auto ? "main_#{filename.gsub('.c', '')}" : (@options[:main_name]).to_s
  347. if @options[:cmdline_args]
  348. if main_name != 'main'
  349. output.puts("#{@options[:main_export_decl]} int #{main_name}(int argc, char** argv);")
  350. end
  351. output.puts("#{@options[:main_export_decl]} int #{main_name}(int argc, char** argv)")
  352. output.puts('{')
  353. output.puts(' int parse_status = UnityParseOptions(argc, argv);')
  354. output.puts(' if (parse_status != 0)')
  355. output.puts(' {')
  356. output.puts(' if (parse_status < 0)')
  357. output.puts(' {')
  358. output.puts(" UnityPrint(\"#{filename.gsub('.c', '').gsub(/\\/, '\\\\\\')}.\");")
  359. output.puts(' UNITY_PRINT_EOL();')
  360. tests.each do |test|
  361. if (!@options[:use_param_tests]) || test[:args].nil? || test[:args].empty?
  362. output.puts(" UnityPrint(\" #{test[:test]}\");")
  363. output.puts(' UNITY_PRINT_EOL();')
  364. else
  365. test[:args].each do |args|
  366. output.puts(" UnityPrint(\" #{test[:test]}(#{args})\");")
  367. output.puts(' UNITY_PRINT_EOL();')
  368. end
  369. end
  370. end
  371. output.puts(' return 0;')
  372. output.puts(' }')
  373. output.puts(' return parse_status;')
  374. output.puts(' }')
  375. else
  376. main_return = @options[:omit_begin_end] ? 'void' : 'int'
  377. if main_name != 'main'
  378. output.puts("#{@options[:main_export_decl]} #{main_return} #{main_name}(void);")
  379. end
  380. output.puts("#{main_return} #{main_name}(void)")
  381. output.puts('{')
  382. end
  383. output.puts(' suiteSetUp();') if @options[:has_suite_setup]
  384. if @options[:omit_begin_end]
  385. output.puts(" UnitySetTestFile(\"#{filename.gsub(/\\/, '\\\\\\')}\");")
  386. else
  387. output.puts(" UnityBegin(\"#{filename.gsub(/\\/, '\\\\\\')}\");")
  388. end
  389. tests.each do |test|
  390. if (!@options[:use_param_tests]) || test[:args].nil? || test[:args].empty?
  391. output.puts(" run_test(#{test[:test]}, \"#{test[:test]}\", #{test[:line_number]});")
  392. else
  393. test[:args].each.with_index(1) do |args, idx|
  394. wrapper = "runner_args#{idx}_#{test[:test]}"
  395. testname = "#{test[:test]}(#{args})".dump
  396. output.puts(" run_test(#{wrapper}, #{testname}, #{test[:line_number]});")
  397. end
  398. end
  399. end
  400. output.puts
  401. output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty?
  402. if @options[:has_suite_teardown]
  403. if @options[:omit_begin_end]
  404. output.puts(' (void) suite_teardown(0);')
  405. else
  406. output.puts(' return suiteTearDown(UnityEnd());')
  407. end
  408. else
  409. output.puts(' return UnityEnd();') unless @options[:omit_begin_end]
  410. end
  411. output.puts('}')
  412. end
  413. def create_h_file(output, filename, tests, testfile_includes, used_mocks)
  414. filename = File.basename(filename).gsub(/[-\/\\.,\s]/, '_').upcase
  415. output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
  416. output.puts("#ifndef _#{filename}")
  417. output.puts("#define _#{filename}\n\n")
  418. output.puts("#include \"#{@options[:framework]}.h\"")
  419. output.puts('#include "cmock.h"') unless used_mocks.empty?
  420. @options[:includes].flatten.uniq.compact.each do |inc|
  421. output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}")
  422. end
  423. testfile_includes.each do |inc|
  424. output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}")
  425. end
  426. output.puts "\n"
  427. tests.each do |test|
  428. if test[:params].nil? || test[:params].empty?
  429. output.puts("void #{test[:test]}(void);")
  430. else
  431. output.puts("void #{test[:test]}(#{test[:params]});")
  432. end
  433. end
  434. output.puts("#endif\n\n")
  435. end
  436. end
  437. if $0 == __FILE__
  438. options = { includes: [] }
  439. # parse out all the options first (these will all be removed as we go)
  440. ARGV.reject! do |arg|
  441. case arg
  442. when '-cexception'
  443. options[:plugins] = [:cexception]
  444. true
  445. when '-externcincludes'
  446. options[:externcincludes] = true
  447. true
  448. when /\.*\.ya?ml$/
  449. options = UnityTestRunnerGenerator.grab_config(arg)
  450. true
  451. when /--(\w+)="?(.*)"?/
  452. options[Regexp.last_match(1).to_sym] = Regexp.last_match(2)
  453. true
  454. when /\.*\.(?:hpp|hh|H|h)$/
  455. options[:includes] << arg
  456. true
  457. else false
  458. end
  459. end
  460. # make sure there is at least one parameter left (the input file)
  461. unless ARGV[0]
  462. puts ["\nusage: ruby #{__FILE__} (files) (options) input_test_file (output)",
  463. "\n input_test_file - this is the C file you want to create a runner for",
  464. ' output - this is the name of the runner file to generate',
  465. ' defaults to (input_test_file)_Runner',
  466. ' files:',
  467. ' *.yml / *.yaml - loads configuration from here in :unity or :cmock',
  468. ' *.h - header files are added as #includes in runner',
  469. ' options:',
  470. ' -cexception - include cexception support',
  471. ' -externc - add extern "C" for cpp support',
  472. ' --setup_name="" - redefine setUp func name to something else',
  473. ' --teardown_name="" - redefine tearDown func name to something else',
  474. ' --main_name="" - redefine main func name to something else',
  475. ' --test_prefix="" - redefine test prefix from default test|spec|should',
  476. ' --test_reset_name="" - redefine resetTest func name to something else',
  477. ' --test_verify_name="" - redefine verifyTest func name to something else',
  478. ' --suite_setup="" - code to execute for setup of entire suite',
  479. ' --suite_teardown="" - code to execute for teardown of entire suite',
  480. ' --use_param_tests=1 - enable parameterized tests (disabled by default)',
  481. ' --omit_begin_end=1 - omit calls to UnityBegin and UnityEnd (disabled by default)',
  482. ' --header_file="" - path/name of test header file to generate too'].join("\n")
  483. exit 1
  484. end
  485. # create the default test runner name if not specified
  486. ARGV[1] = ARGV[0].gsub('.c', '_Runner.c') unless ARGV[1]
  487. UnityTestRunnerGenerator.new(options).run(ARGV[0], ARGV[1])
  488. end