Skip to content

Commit 3a6eb6d

Browse files
committed
Add "ignore" test when there are no tests provided in a runner (fixed Ceedling #1181).
Remove erb dependency.
1 parent b6763fb commit 3a6eb6d

5 files changed

Lines changed: 80 additions & 43 deletions

File tree

auto/generate_test_runner.rb

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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)')

auto/run_test.erb

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/unity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#define UNITY_VERSION_MAJOR 2
1313
#define UNITY_VERSION_MINOR 7
14-
#define UNITY_VERSION_BUILD 0
14+
#define UNITY_VERSION_BUILD 1
1515
#define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | (UNITY_VERSION_MINOR << 8) | UNITY_VERSION_BUILD)
1616

1717
#ifdef __cplusplus
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* =========================================================================
2+
Unity - A Test Framework for C
3+
ThrowTheSwitch.org
4+
Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
5+
SPDX-License-Identifier: MIT
6+
========================================================================= */
7+
8+
/* This Test File Is Used To Verify The Warning When No Tests Are Found */
9+
10+
#include "unity.h"
11+
12+
void setUp(void) {}
13+
void tearDown(void) {}

test/tests/test_generate_test_runner.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,17 @@
336336
},
337337

338338

339+
{ :name => 'EmptyFileWarning',
340+
:testfile => 'testdata/testRunnerGeneratorEmpty.c',
341+
:testdefines => ['TEST'],
342+
:options => nil, #defaults
343+
:expected => {
344+
:to_pass => [ ],
345+
:to_fail => [ ],
346+
:to_ignore => [ 'test_empty_warning' ],
347+
}
348+
},
349+
339350
#### WITH MOCKS ##########################################
340351

341352
{ :name => 'DefaultsThroughOptions',

0 commit comments

Comments
 (0)