@@ -100,9 +100,10 @@ def generate(input_file, output_file, tests, used_mocks, testfile_includes)
100100 create_suite_setup ( output )
101101 create_suite_teardown ( output )
102102 create_reset ( output )
103- create_run_test ( output ) unless tests . empty?
103+ create_run_test ( output )
104104 create_args_wrappers ( output , tests )
105105 create_shuffle_tests ( output ) if @options [ :shuffle_tests ]
106+ tests = create_warning_test ( output , input_file , tests )
106107 create_main ( output , input_file , tests , used_mocks )
107108 end
108109
@@ -406,10 +407,43 @@ def create_reset(output)
406407 end
407408
408409 def create_run_test ( output )
409- require 'erb'
410- file = File . read ( File . join ( __dir__ , 'run_test.erb' ) )
411- template = ERB . new ( file , trim_mode : '<>' )
412- output . puts ( "\n #{ template . result ( binding ) } " )
410+ output . puts ( "/*=======Test Runner Used To Run Each Test=====*/" )
411+ output . puts ( "static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num)" )
412+ output . puts ( "{" )
413+ output . puts ( " Unity.CurrentTestName = name;" )
414+ output . puts ( " Unity.CurrentTestLineNumber = (UNITY_UINT) line_num;" )
415+ output . puts ( "#ifdef UNITY_USE_COMMAND_LINE_ARGS" )
416+ output . puts ( " if (!UnityTestMatches())" )
417+ output . puts ( " return;" )
418+ output . puts ( "#endif" )
419+ output . puts ( " Unity.NumberOfTests++;" )
420+ output . puts ( " UNITY_CLR_DETAILS();" )
421+ output . puts ( " UNITY_EXEC_TIME_START();" )
422+ output . puts ( " CMock_Init();" )
423+ output . puts ( " if (TEST_PROTECT())" )
424+ output . puts ( " {" )
425+ if @options [ :plugins ] . include? ( :cexception )
426+ output . puts ( " volatile CEXCEPTION_T e;" )
427+ output . puts ( " Try {" )
428+ output . puts ( " #{ @options [ :setup_name ] } ();" )
429+ output . puts ( " func();" )
430+ output . puts ( " } Catch(e) {" )
431+ output . puts ( " TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, \" Unhandled Exception!\" );" )
432+ output . puts ( " }" )
433+ else
434+ output . puts ( " #{ @options [ :setup_name ] } ();" )
435+ output . puts ( " func();" )
436+ end
437+ output . puts ( " }" )
438+ output . puts ( " if (TEST_PROTECT())" )
439+ output . puts ( " {" )
440+ output . puts ( " #{ @options [ :teardown_name ] } ();" )
441+ output . puts ( " CMock_Verify();" )
442+ output . puts ( " }" )
443+ output . puts ( " CMock_Destroy();" )
444+ output . puts ( " UNITY_EXEC_TIME_STOP();" )
445+ output . puts ( " UnityConcludeTest();" )
446+ output . puts ( "}" )
413447 end
414448
415449 def create_args_wrappers ( output , tests )
@@ -428,6 +462,22 @@ def create_args_wrappers(output, tests)
428462 end
429463 end
430464
465+ def create_warning_test ( output , filename , tests )
466+ if count_tests ( tests ) == 0
467+ warning_test = {
468+ :test => "test_empty_warning" ,
469+ :line_number => 0
470+ }
471+ output . puts ( "\n /*=======Warning Test=====*/" )
472+ output . puts ( "static void #{ warning_test [ :test ] } (void)" )
473+ output . puts ( '{' )
474+ output . puts ( " TEST_IGNORE_MESSAGE(\" Test file '#{ filename . gsub ( /\\ / , '\\\\\\' ) } ' contains no tests.\" );" )
475+ output . puts ( "}\n " )
476+ tests = [ warning_test ]
477+ end
478+ return tests
479+ end
480+
431481 def create_shuffle_tests ( output )
432482 output . puts ( "\n /*=======Shuffle Test Order=====*/" )
433483 output . puts ( 'static void shuffleTests(struct UnityRunTestParameters run_test_params_arr[], int num_of_tests)' )
0 commit comments