ceedling 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/GIT_COMMIT_SHA +1 -1
  3. data/assets/tests_with_conditional_includes/src/feature_config.h +13 -0
  4. data/assets/tests_with_conditional_includes/src/feature_extra.h +13 -0
  5. data/assets/tests_with_conditional_includes/src/local_flag_extra.h +13 -0
  6. data/assets/tests_with_conditional_includes/src/nested_extra.h +13 -0
  7. data/assets/tests_with_conditional_includes/src/nested_wrapper.h +16 -0
  8. data/assets/tests_with_conditional_includes/src/project_flag_extra.h +13 -0
  9. data/assets/tests_with_conditional_includes/src/widget.c +48 -0
  10. data/assets/tests_with_conditional_includes/src/widget.h +15 -0
  11. data/assets/tests_with_conditional_includes/src/widget_feature.c +29 -0
  12. data/assets/tests_with_conditional_includes/src/widget_feature.h +13 -0
  13. data/assets/tests_with_conditional_includes/test/test_widget.c +44 -0
  14. data/assets/tests_with_conditional_includes/test/test_widget_feature.c +31 -0
  15. data/docs/Changelog.md +20 -1
  16. data/examples/wondrous_forest/src/SensorHal.h +13 -0
  17. data/examples/wondrous_forest/src/TemperatureSensor.c +12 -5
  18. data/examples/wondrous_forest/src/TemperatureSensor.h +5 -4
  19. data/examples/wondrous_forest/test/TestTemperatureSensor.c +32 -3
  20. data/lib/ceedling/generators/generator_test_runner.rb +25 -1
  21. data/lib/ceedling/partials/partializer.rb +8 -1
  22. data/lib/ceedling/preprocess/preprocessinator.rb +22 -0
  23. data/lib/ceedling/preprocess/preprocessinator_includes_handler.rb +33 -0
  24. data/lib/version.rb +1 -1
  25. data/site-local/sitemap.xml.gz +0 -0
  26. data/spec/support/system/spec_system_helper.rb +11 -0
  27. data/spec/support/system/system_context.rb +18 -9
  28. data/spec/system/conditional_include_macro_visibility_spec.rb +152 -0
  29. data/spec/system/encoding_stress_spec.rb +4 -4
  30. data/spec/system/example_wondrous_forest_spec.rb +2 -2
  31. data/spec/system/support/common_test_cases.rb +5 -1
  32. data/spec/system/test_runner_system_include_spec.rb +90 -0
  33. data/spec/units/generators/generator_test_runner_spec.rb +69 -0
  34. data/spec/units/partials/partializer_spec.rb +69 -0
  35. data/spec/units/preprocess/preprocessinator_includes_handler_spec.rb +61 -0
  36. data/spec/units/preprocess/preprocessinator_spec.rb +136 -0
  37. data/vendor/c_exception/lib/CException.h +1 -1
  38. data/vendor/c_exception/project.yml +2 -2
  39. data/vendor/c_exception/test/TestException.c +1 -1
  40. data/vendor/c_exception/test/support/CExceptionConfig.h +5 -11
  41. data/vendor/cmock/docs/CMockChangeLog.md +23 -22
  42. data/vendor/cmock/scripts/create_makefile.rb +4 -3
  43. data/vendor/cmock/src/cmock.h +1 -1
  44. data/vendor/cmock/vendor/c_exception/lib/CException.h +1 -1
  45. data/vendor/cmock/vendor/c_exception/project.yml +2 -2
  46. data/vendor/cmock/vendor/c_exception/test/TestException.c +1 -1
  47. data/vendor/cmock/vendor/c_exception/test/support/CExceptionConfig.h +5 -11
  48. data/vendor/cmock/vendor/unity/auto/generate_test_runner.rb +85 -29
  49. data/vendor/cmock/vendor/unity/docs/UnityChangeLog.md +1 -0
  50. data/vendor/cmock/vendor/unity/examples/unity_config.h +8 -0
  51. data/vendor/cmock/vendor/unity/src/unity.c +9 -1
  52. data/vendor/cmock/vendor/unity/src/unity.h +1 -1
  53. data/vendor/cmock/vendor/unity/test/rakefile +2 -1
  54. data/vendor/cmock/vendor/unity/test/testdata/testRunnerGeneratorEmpty.c +13 -0
  55. data/vendor/cmock/vendor/unity/test/tests/test_generate_test_runner.rb +31 -0
  56. data/vendor/unity/auto/generate_test_runner.rb +63 -57
  57. data/vendor/unity/docs/UnityChangeLog.md +1 -0
  58. data/vendor/unity/examples/unity_config.h +8 -0
  59. data/vendor/unity/src/unity.c +9 -1
  60. data/vendor/unity/src/unity.h +1 -1
  61. data/vendor/unity/test/rakefile +2 -1
  62. data/vendor/unity/test/tests/test_generate_test_runner.rb +20 -0
  63. metadata +21 -3
  64. data/vendor/cmock/vendor/unity/auto/run_test.erb +0 -37
@@ -0,0 +1,136 @@
1
+ # =========================================================================
2
+ # Ceedling - Test-Centered Build System for C
3
+ # ThrowTheSwitch.org
4
+ # Copyright (c) 2010-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
5
+ # SPDX-License-Identifier: MIT
6
+ # =========================================================================
7
+
8
+ require 'spec_helper'
9
+ require 'ceedling/preprocess/preprocessinator'
10
+ require 'ceedling/includes/includes'
11
+
12
+ RSpec.describe Preprocessinator do
13
+
14
+ before :each do
15
+ @includes_handler = double('preprocessinator_includes_handler')
16
+ @comment_stripper = double('preprocessinator_comment_stripper')
17
+ @file_assembler = double('preprocessinator_file_assembler')
18
+ @reconstructor = double('preprocessinator_reconstructor')
19
+ @file_path_utils = double('file_path_utils')
20
+ @tool_executor = double('tool_executor')
21
+ @file_wrapper = double('file_wrapper')
22
+ @plugin_manager = double('plugin_manager')
23
+ @configurator = double('configurator')
24
+ @loginator = double('loginator')
25
+ @reportinator = double('reportinator')
26
+
27
+ allow(@loginator).to receive(:log)
28
+ allow(@loginator).to receive(:log_list)
29
+ allow(@reportinator).to receive(:generate_module_progress).and_return('')
30
+ allow(@configurator).to receive(:cmock_mock_prefix).and_return('Mock')
31
+ end
32
+
33
+ subject do
34
+ Preprocessinator.new(
35
+ preprocessinator_includes_handler: @includes_handler,
36
+ preprocessinator_comment_stripper: @comment_stripper,
37
+ preprocessinator_file_assembler: @file_assembler,
38
+ preprocessinator_reconstructor: @reconstructor,
39
+ file_path_utils: @file_path_utils,
40
+ tool_executor: @tool_executor,
41
+ file_wrapper: @file_wrapper,
42
+ plugin_manager: @plugin_manager,
43
+ configurator: @configurator,
44
+ loginator: @loginator,
45
+ reportinator: @reportinator
46
+ )
47
+ end
48
+
49
+ # ===========================================================================
50
+ describe '#preprocess_file_includes_common' do
51
+ # ===========================================================================
52
+
53
+ let(:filepath) { '/src/module.c' }
54
+
55
+ def call_it(defines: [])
56
+ subject.send(
57
+ :preprocess_file_includes_common,
58
+ test: 'test',
59
+ filepath: filepath,
60
+ directives_only_filepath: '/build/directives_only/module.c',
61
+ fallback: false,
62
+ flags: [],
63
+ include_paths: [],
64
+ vendor_paths: [],
65
+ defines: defines
66
+ )
67
+ end
68
+
69
+ before do
70
+ # Force the cache-miss path so real extraction runs every time.
71
+ allow(@file_path_utils).to receive(:form_preprocessed_includes_list_filepath).and_return('/build/includes/module.c.yml')
72
+ allow(@file_wrapper).to receive(:newer?).and_return(false)
73
+ allow(@includes_handler).to receive(:write_includes_list)
74
+
75
+ allow(@includes_handler).to receive(:extract_system_includes_preprocess).and_return([])
76
+ end
77
+
78
+ # Regression coverage for #1223: the gcc-based bare pass runs against an
79
+ # isolated copy that can never open another header, so a conditional
80
+ # #include guarded by a macro defined by an earlier #include in the same
81
+ # file evaluates false there and is silently dropped from that pass's own
82
+ # result. extract_bare_includes_from_text (a plain literal-text scan, no
83
+ # conditional evaluation at all) still sees it. Reconciliation should keep
84
+ # it once the accurate pass (user_includes here) also confirms it's real.
85
+ it "keeps an entry the gcc bare pass missed but the text-scan bare pass and the accurate pass both found" do
86
+ allow(@includes_handler).to receive(:extract_bare_includes).and_return(
87
+ [ Include.new('Types.h') ]
88
+ )
89
+ allow(@includes_handler).to receive(:extract_bare_includes_from_text).and_return(
90
+ [ Include.new('Types.h'), Include.new('types2.h') ]
91
+ )
92
+ allow(@includes_handler).to receive(:extract_user_includes_preprocess).and_return(
93
+ [ UserInclude.new('Types.h'), UserInclude.new('types2.h') ]
94
+ )
95
+
96
+ result = call_it()
97
+
98
+ expect(result.map(&:filename)).to include('types2.h')
99
+ end
100
+
101
+ # The union only ever adds candidates for reconcile to match against the
102
+ # accurate pass -- it must never single-handedly promote an entry neither
103
+ # gcc's bare pass nor the accurate pass itself ever reported.
104
+ it "does not introduce an entry the text-scan bare pass found but the accurate pass never confirms" do
105
+ allow(@includes_handler).to receive(:extract_bare_includes).and_return([])
106
+ allow(@includes_handler).to receive(:extract_bare_includes_from_text).and_return(
107
+ [ Include.new('phantom.h') ]
108
+ )
109
+ allow(@includes_handler).to receive(:extract_user_includes_preprocess).and_return([])
110
+
111
+ result = call_it()
112
+
113
+ expect(result.map(&:filename)).not_to include('phantom.h')
114
+ end
115
+
116
+ # Both bare sources finding the same entry must not produce a duplicate
117
+ # (the union is deduplicated by filename before being handed to reconcile).
118
+ it "does not duplicate an entry both bare passes agree on" do
119
+ allow(@includes_handler).to receive(:extract_bare_includes).and_return(
120
+ [ Include.new('Types.h') ]
121
+ )
122
+ allow(@includes_handler).to receive(:extract_bare_includes_from_text).and_return(
123
+ [ Include.new('Types.h') ]
124
+ )
125
+ allow(@includes_handler).to receive(:extract_user_includes_preprocess).and_return(
126
+ [ UserInclude.new('Types.h') ]
127
+ )
128
+
129
+ result = call_it()
130
+
131
+ expect(result.map(&:filename)).to eq(['Types.h'])
132
+ end
133
+
134
+ end
135
+
136
+ end
@@ -18,7 +18,7 @@ extern "C"
18
18
 
19
19
  #define CEXCEPTION_VERSION_MAJOR 1
20
20
  #define CEXCEPTION_VERSION_MINOR 3
21
- #define CEXCEPTION_VERSION_BUILD 4
21
+ #define CEXCEPTION_VERSION_BUILD 5
22
22
  #define CEXCEPTION_VERSION ((CEXCEPTION_VERSION_MAJOR << 16) | (CEXCEPTION_VERSION_MINOR << 8) | CEXCEPTION_VERSION_BUILD)
23
23
 
24
24
  //To Use CException, you have a number of options:
@@ -231,8 +231,8 @@
231
231
  #- ReportGenerator # Use ReportGenerator to create the specified reports.
232
232
  :reports: # Specify one or more reports to generate.
233
233
  # Make an HTML summary report.
234
- - HtmlBasic
235
- # - HtmlDetailed
234
+ # - HtmlBasic
235
+ - HtmlDetailed
236
236
  # - Text
237
237
  # - Cobertura
238
238
  # - SonarQube
@@ -13,7 +13,7 @@ volatile int TestingTheFallbackId;
13
13
 
14
14
  void setUp(void)
15
15
  {
16
- CExceptionFrames[0].pFrame = NULL;
16
+ CExceptionFrames[0].pFrame = 0;
17
17
  TestingTheFallback = 0;
18
18
  }
19
19
 
@@ -20,17 +20,11 @@ extern volatile int TestingTheFallbackId;
20
20
  #define CEXCEPTION_NONE (1234)
21
21
 
22
22
  // Optionally define a special handler for unhandled exceptions
23
- #define CEXCEPTION_NO_CATCH_HANDLER(id) \
24
- { \
25
- if (!TestingTheFallback) \
26
- { \
27
- TEST_FAIL_MESSAGE("Unexpected Exception!"); \
28
- } \
29
- else \
30
- { \
31
- TestingTheFallbackId = id; \
32
- TestingTheFallback--; \
33
- } \
23
+ #define CEXCEPTION_NO_CATCH_HANDLER(id) \
24
+ { \
25
+ TEST_ASSERT_GREATER_THAN_INT_MESSAGE(0, TestingTheFallback, "Unexpected Exception!"); \
26
+ TestingTheFallbackId = id; \
27
+ TestingTheFallback--; \
34
28
  }
35
29
 
36
30
  // Multi-Tasking environments will need a couple of macros defined to make this library
@@ -18,35 +18,36 @@ Prior to 2008, the project was an internal project and not released to the publi
18
18
  New Features:
19
19
 
20
20
  - Significant improvements to array and pointer handling:
21
- - Arrays are now passed as arrays. Yes, even multidimensional ones. (Fixes #69, #119, #213, #422)
22
- - Array plugin now supports comparing `char*` (string) arguments as byte arrays via `_ExpectWithArray`, while still treating them as strings via `_Expect` (Fixes #262 and #177)
23
- - Improved automatic detection of pointer/length argument pairs (Fixes #520)
24
- - When a pointer is auto-paired with a size argument, `_ExpectWithArrayExtended` is also generated as a fallback to allow explicit depth override (Fixes #476)
25
- - `void*` arguments now default to pointer comparison without the array plugin, and to byte-by-byte comparison when the array plugin is active (Fixes #400)
26
- - Handles *simple* preprocessor features like #if 1 and #if 0 (Fixes #163)
27
- - Ignores static assertions of various types (Fixes #128)
28
- - Added option to trace all mock setup and mocked calls (Implements #403)
21
+ - Arrays are now passed as arrays. Yes, even multidimensional ones. (Fixes [#69](https://github.com/ThrowTheSwitch/CMock/issues/69)
22
+ , [#119](https://github.com/ThrowTheSwitch/CMock/issues/119), [#213](https://github.com/ThrowTheSwitch/CMock/issues/213), [#422](https://github.com/ThrowTheSwitch/CMock/issues/422))
23
+ - Array plugin now supports comparing `char*` (string) arguments as byte arrays via `_ExpectWithArray`, while still treating them as strings via `_Expect` (Fixes [#262](https://github.com/ThrowTheSwitch/CMock/issues/262) and [#177](https://github.com/ThrowTheSwitch/CMock/issues/177))
24
+ - Improved automatic detection of pointer/length argument pairs (Fixes [#520](https://github.com/ThrowTheSwitch/CMock/issues/520))
25
+ - When a pointer is auto-paired with a size argument, `_ExpectWithArrayExtended` is also generated as a fallback to allow explicit depth override (Fixes [#476](https://github.com/ThrowTheSwitch/CMock/issues/476))
26
+ - `void*` arguments now default to pointer comparison without the array plugin, and to byte-by-byte comparison when the array plugin is active (Fixes [#400](https://github.com/ThrowTheSwitch/CMock/issues/400))
27
+ - Handles *simple* preprocessor features like #if 1 and #if 0 (Fixes [#163](https://github.com/ThrowTheSwitch/CMock/issues/163))
28
+ - Ignores static assertions of various types (Fixes [#128](https://github.com/ThrowTheSwitch/CMock/issues/128))
29
+ - Added option to trace all mock setup and mocked calls (Implements [#403](https://github.com/ThrowTheSwitch/CMock/issues/403))
29
30
  - Significant improvements to header parsing speed
30
31
 
31
32
  Significant Bugfixes:
32
33
 
33
- - Fixed matching of pointer/len argument pairs in reverse order (Fixes #479)
34
- - Fixed handling of array of pointers or a pointer to an array (Fixes #450)
35
- - Fixed const and pointer order handling issues (Fixes #484 and #485)
36
- - Fixed handling of skeleton paths (Fixes #488)
37
- - Fixed handling of memory alignment issues (Fixes #178)
38
- - Fixed handling of failures in teardown (#67)
39
- - Improved handling of function-looking structs (Fixes #513 and #334)
40
- - Improved handling of function-looking macros (Fixes #502)
41
- - Improved handling of volatiles (Fixes #110 and #135)
42
- - Improved handling of stub and callback counters (Fixes #132)
43
- - Improved handling and testing of Windows (Fixes #435)
34
+ - Fixed matching of pointer/len argument pairs in reverse order (Fixes [#479](https://github.com/ThrowTheSwitch/CMock/issues/479))
35
+ - Fixed handling of array of pointers or a pointer to an array (Fixes [#450](https://github.com/ThrowTheSwitch/CMock/issues/450))
36
+ - Fixed const and pointer order handling issues (Fixes [#484](https://github.com/ThrowTheSwitch/CMock/issues/484) and [#485](https://github.com/ThrowTheSwitch/CMock/issues/485))
37
+ - Fixed handling of skeleton paths (Fixes [#488](https://github.com/ThrowTheSwitch/CMock/issues/488))
38
+ - Fixed handling of memory alignment issues (Fixes [#178](https://github.com/ThrowTheSwitch/CMock/issues/178))
39
+ - Fixed handling of failures in teardown ([#67](https://github.com/ThrowTheSwitch/CMock/issues/67))
40
+ - Improved handling of function-looking structs (Fixes [#513](https://github.com/ThrowTheSwitch/CMock/issues/513) and [#334](https://github.com/ThrowTheSwitch/CMock/issues/334))
41
+ - Improved handling of function-looking macros (Fixes [#502](https://github.com/ThrowTheSwitch/CMock/issues/502))
42
+ - Improved handling of volatiles (Fixes #110 and [#135](https://github.com/ThrowTheSwitch/CMock/issues/135))
43
+ - Improved handling of stub and callback counters (Fixes [#132](https://github.com/ThrowTheSwitch/CMock/issues/132))
44
+ - Improved handling and testing of Windows (Fixes [#435](https://github.com/ThrowTheSwitch/CMock/issues/435))
44
45
 
45
46
  Other:
46
47
 
47
- - Added verification that memory errors are reported and stop tests (Verifies #463)
48
- - Added verification that CMock features pass Valgrind (Verifies #506)
49
- - Documented custom type support (#124)
48
+ - Added verification that memory errors are reported and stop tests (Verifies [#463](https://github.com/ThrowTheSwitch/CMock/issues/463))
49
+ - Added verification that CMock features pass Valgrind (Verifies [#506](https://github.com/ThrowTheSwitch/CMock/issues/506))
50
+ - Documented custom type support ([#124](https://github.com/ThrowTheSwitch/CMock/issues/124))
50
51
 
51
52
  #### Major Code/Doc Contributors
52
53
 
@@ -137,10 +137,11 @@ File.open(TEST_MAKEFILE, 'w') do |mkfile|
137
137
  mkfile.puts ''
138
138
 
139
139
  # Collect mocks to generate
140
- system_mocks = cfg[:includes][:system].select { |name| name =~ MOCK_MATCHER }
141
- raise 'Mocking of system headers is not yet supported!' unless system_mocks.empty?
140
+ local_mocks = cfg[:includes][:headers].select do |name|
141
+ raise 'Mocking of system headers is not yet supported!' if name =~ /^</
142
142
 
143
- local_mocks = cfg[:includes][:local].select { |name| name =~ MOCK_MATCHER }
143
+ (name =~ MOCK_MATCHER)
144
+ end
144
145
 
145
146
  module_names_to_mock = local_mocks.map { |name| name.sub(/#{MOCK_PREFIX}/, '').to_s }
146
147
  headers_to_mock = []
@@ -12,7 +12,7 @@
12
12
 
13
13
  #define CMOCK_VERSION_MAJOR 2
14
14
  #define CMOCK_VERSION_MINOR 7
15
- #define CMOCK_VERSION_BUILD 0
15
+ #define CMOCK_VERSION_BUILD 2
16
16
  #define CMOCK_VERSION ((CMOCK_VERSION_MAJOR << 16) | (CMOCK_VERSION_MINOR << 8) | CMOCK_VERSION_BUILD)
17
17
 
18
18
  /* should be big enough to index full range of CMOCK_MEM_MAX */
@@ -18,7 +18,7 @@ extern "C"
18
18
 
19
19
  #define CEXCEPTION_VERSION_MAJOR 1
20
20
  #define CEXCEPTION_VERSION_MINOR 3
21
- #define CEXCEPTION_VERSION_BUILD 4
21
+ #define CEXCEPTION_VERSION_BUILD 5
22
22
  #define CEXCEPTION_VERSION ((CEXCEPTION_VERSION_MAJOR << 16) | (CEXCEPTION_VERSION_MINOR << 8) | CEXCEPTION_VERSION_BUILD)
23
23
 
24
24
  //To Use CException, you have a number of options:
@@ -231,8 +231,8 @@
231
231
  #- ReportGenerator # Use ReportGenerator to create the specified reports.
232
232
  :reports: # Specify one or more reports to generate.
233
233
  # Make an HTML summary report.
234
- - HtmlBasic
235
- # - HtmlDetailed
234
+ # - HtmlBasic
235
+ - HtmlDetailed
236
236
  # - Text
237
237
  # - Cobertura
238
238
  # - SonarQube
@@ -13,7 +13,7 @@ volatile int TestingTheFallbackId;
13
13
 
14
14
  void setUp(void)
15
15
  {
16
- CExceptionFrames[0].pFrame = NULL;
16
+ CExceptionFrames[0].pFrame = 0;
17
17
  TestingTheFallback = 0;
18
18
  }
19
19
 
@@ -20,17 +20,11 @@ extern volatile int TestingTheFallbackId;
20
20
  #define CEXCEPTION_NONE (1234)
21
21
 
22
22
  // Optionally define a special handler for unhandled exceptions
23
- #define CEXCEPTION_NO_CATCH_HANDLER(id) \
24
- { \
25
- if (!TestingTheFallback) \
26
- { \
27
- TEST_FAIL_MESSAGE("Unexpected Exception!"); \
28
- } \
29
- else \
30
- { \
31
- TestingTheFallbackId = id; \
32
- TestingTheFallback--; \
33
- } \
23
+ #define CEXCEPTION_NO_CATCH_HANDLER(id) \
24
+ { \
25
+ TEST_ASSERT_GREATER_THAN_INT_MESSAGE(0, TestingTheFallback, "Unexpected Exception!"); \
26
+ TestingTheFallbackId = id; \
27
+ TestingTheFallback--; \
34
28
  }
35
29
 
36
30
  // Multi-Tasking environments will need a couple of macros defined to make this library
@@ -71,24 +71,30 @@ class UnityTestRunnerGenerator
71
71
  source = File.read(input_file)
72
72
  source = source.force_encoding('ISO-8859-1').encode('utf-8', replace: nil)
73
73
  tests = find_tests(source)
74
- headers = find_includes(source)
75
- testfile_includes = @options[:use_system_files] ? (headers[:local] + headers[:system]) : headers[:local]
76
- used_mocks = find_mocks(testfile_includes)
77
- testfile_includes = (testfile_includes - used_mocks)
78
- testfile_includes.delete_if { |inc| inc =~ /(unity|cmock)/ }
74
+ includes = find_includes(source)
75
+ headers = includes[:headers]
76
+ used_mocks = find_mocks(headers)
77
+ headers = (headers - used_mocks)
78
+ headers.delete_if { |inc| inc =~ /(unity|cmock)/ }
79
79
  find_setup_and_teardown(source)
80
80
 
81
81
  # build runner file
82
- generate(input_file, output_file, tests, used_mocks, testfile_includes)
82
+ generate(input_file, output_file, tests, used_mocks, headers)
83
83
 
84
84
  # determine which files were used to return them
85
85
  all_files_used = [input_file, output_file]
86
- all_files_used += testfile_includes.map { |filename| "#{filename}.c" } unless testfile_includes.empty?
86
+ all_files_used += headers.reject { |filename| filename =~ /^</ }.map { |filename| "#{filename}.c" } unless headers.empty?
87
87
  all_files_used += @options[:includes] unless @options[:includes].empty?
88
- all_files_used += headers[:linkonly] unless headers[:linkonly].empty?
88
+ all_files_used += includes[:linkonly] unless includes[:linkonly].empty?
89
89
  all_files_used.uniq
90
90
  end
91
91
 
92
+ # Generate a test file for the given features:
93
+ # input_file - the name of the test file this is based on
94
+ # output_file - the name of the test runner file to generate
95
+ # tests - an array of all the tests which can be run from this test runner
96
+ # used_mocks - an array of all mock files which are used by this test runner
97
+ # testfile_includes - an array of all included headers, in order, where system headers still have their <> attached
92
98
  def generate(input_file, output_file, tests, used_mocks, testfile_includes)
93
99
  File.open(output_file, 'w') do |output|
94
100
  create_header(output, used_mocks, testfile_includes)
@@ -100,16 +106,17 @@ class UnityTestRunnerGenerator
100
106
  create_suite_setup(output)
101
107
  create_suite_teardown(output)
102
108
  create_reset(output)
103
- create_run_test(output) unless tests.empty?
109
+ create_run_test(output)
104
110
  create_args_wrappers(output, tests)
105
111
  create_shuffle_tests(output) if @options[:shuffle_tests]
112
+ tests = create_warning_test(output, input_file, tests)
106
113
  create_main(output, input_file, tests, used_mocks)
107
114
  end
108
115
 
109
116
  return unless @options[:header_file] && !@options[:header_file].empty?
110
117
 
111
118
  File.open(@options[:header_file], 'w') do |output|
112
- create_h_file(output, @options[:header_file], tests, testfile_includes, used_mocks)
119
+ create_h_file(output, @options[:header_file], tests, headers, used_mocks)
113
120
  end
114
121
  end
115
122
 
@@ -211,10 +218,14 @@ class UnityTestRunnerGenerator
211
218
  source.gsub!(/\/\*.*?\*\//m, '') # remove block comments
212
219
  source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain)
213
220
 
214
- # parse out includes
221
+ # parse out includes (NOTICE: system includes KEEP the angle-brackets in the string, to preserve this information)
222
+ headers = if @options[:use_system_files]
223
+ source.scan(/^\s*#include\s+(?:(<)|")\s*(.+\.#{@options[:include_extensions]})\s*(?:(>)|")/).map(&:join).flatten
224
+ else
225
+ source.scan(/^\s*#include\s+"\s*(.+\.#{@options[:include_extensions]})\s*"/).flatten
226
+ end
215
227
  {
216
- local: source.scan(/^\s*#include\s+"\s*(.+\.#{@options[:include_extensions]})\s*"/).flatten,
217
- system: source.scan(/^\s*#include\s+<\s*(.+)\s*>/).flatten.map { |inc| "<#{inc}>" },
228
+ headers: headers,
218
229
  linkonly: source.scan(/^TEST_SOURCE_FILE\(\s*"\s*(.+\.#{@options[:source_extensions]})\s*"/).flatten
219
230
  }
220
231
  end
@@ -251,7 +262,7 @@ class UnityTestRunnerGenerator
251
262
  end
252
263
  end
253
264
 
254
- def create_header(output, mocks, testfile_includes = [])
265
+ def create_header(output, mocks, headers = [])
255
266
  output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
256
267
  output.puts("\n/*=======Automagically Detected Files To Include=====*/")
257
268
  output.puts('extern "C" {') if @options[:externcincludes]
@@ -274,10 +285,7 @@ class UnityTestRunnerGenerator
274
285
  if @options[:header_file] && !@options[:header_file].empty?
275
286
  output.puts("#include \"#{File.basename(@options[:header_file])}\"")
276
287
  else
277
- @options[:includes].flatten.uniq.compact.each do |inc|
278
- output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}")
279
- end
280
- testfile_includes.each do |inc|
288
+ [@options[:includes], headers].flatten.uniq.compact.each do |inc|
281
289
  output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}")
282
290
  end
283
291
  end
@@ -406,10 +414,43 @@ class UnityTestRunnerGenerator
406
414
  end
407
415
 
408
416
  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)}")
417
+ output.puts('/*=======Test Runner Used To Run Each Test=====*/')
418
+ output.puts('static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num)')
419
+ output.puts('{')
420
+ output.puts(' Unity.CurrentTestName = name;')
421
+ output.puts(' Unity.CurrentTestLineNumber = (UNITY_UINT) line_num;')
422
+ output.puts('#ifdef UNITY_USE_COMMAND_LINE_ARGS')
423
+ output.puts(' if (!UnityTestMatches())')
424
+ output.puts(' return;')
425
+ output.puts('#endif')
426
+ output.puts(' Unity.NumberOfTests++;')
427
+ output.puts(' UNITY_CLR_DETAILS();')
428
+ output.puts(' UNITY_EXEC_TIME_START();')
429
+ output.puts(' CMock_Init();')
430
+ output.puts(' if (TEST_PROTECT())')
431
+ output.puts(' {')
432
+ if @options[:plugins].include?(:cexception)
433
+ output.puts(' volatile CEXCEPTION_T e;')
434
+ output.puts(' Try {')
435
+ output.puts(" #{@options[:setup_name]}();")
436
+ output.puts(' func();')
437
+ output.puts(' } Catch(e) {')
438
+ output.puts(' TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!");')
439
+ output.puts(' }')
440
+ else
441
+ output.puts(" #{@options[:setup_name]}();")
442
+ output.puts(' func();')
443
+ end
444
+ output.puts(' }')
445
+ output.puts(' if (TEST_PROTECT())')
446
+ output.puts(' {')
447
+ output.puts(" #{@options[:teardown_name]}();")
448
+ output.puts(' CMock_Verify();')
449
+ output.puts(' }')
450
+ output.puts(' CMock_Destroy();')
451
+ output.puts(' UNITY_EXEC_TIME_STOP();')
452
+ output.puts(' UnityConcludeTest();')
453
+ output.puts('}')
413
454
  end
414
455
 
415
456
  def create_args_wrappers(output, tests)
@@ -428,6 +469,22 @@ class UnityTestRunnerGenerator
428
469
  end
429
470
  end
430
471
 
472
+ def create_warning_test(output, filename, tests)
473
+ if count_tests(tests) == 0
474
+ warning_test = {
475
+ :test => 'test_empty_warning',
476
+ :line_number => 0
477
+ }
478
+ output.puts("\n/*=======Warning Test=====*/")
479
+ output.puts("static void #{warning_test[:test]}(void)")
480
+ output.puts('{')
481
+ output.puts(" TEST_IGNORE_MESSAGE(\"Test file '#{filename.gsub(/\\/, '\\\\\\')}' contains no tests.\");")
482
+ output.puts("}\n")
483
+ tests = [warning_test]
484
+ end
485
+ tests
486
+ end
487
+
431
488
  def create_shuffle_tests(output)
432
489
  output.puts("\n/*=======Shuffle Test Order=====*/")
433
490
  output.puts('static void shuffleTests(struct UnityRunTestParameters run_test_params_arr[], int num_of_tests)')
@@ -453,13 +510,15 @@ class UnityTestRunnerGenerator
453
510
  end
454
511
  output.puts("#{@options[:main_export_decl]} int #{main_name}(int argc, char** argv)")
455
512
  output.puts('{')
513
+ output.puts('(void)argc;')
514
+ output.puts('(void)argv;')
456
515
  output.puts('#ifdef UNITY_USE_COMMAND_LINE_ARGS')
457
516
  output.puts(' int parse_status = UnityParseOptions(argc, argv);')
458
517
  output.puts(' if (parse_status != 0)')
459
518
  output.puts(' {')
460
519
  output.puts(' if (parse_status < 0)')
461
520
  output.puts(' {')
462
- output.puts(" UnityPrint(\"#{filename.gsub('.c', '').gsub(/\\/, '\\\\\\')}.\");")
521
+ output.puts(" UnityPrint(\"#{filename.gsub(/\\/, '\\\\\\')}\");")
463
522
  output.puts(' UNITY_PRINT_EOL();')
464
523
  tests.each do |test|
465
524
  if !@options[:use_param_tests] || test[:args].nil? || test[:args].empty?
@@ -533,7 +592,7 @@ class UnityTestRunnerGenerator
533
592
  output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty?
534
593
  if @options[:has_suite_teardown]
535
594
  if @options[:omit_begin_end]
536
- output.puts(' (void) suite_teardown(0);')
595
+ output.puts(' (void) suiteTearDown(0);')
537
596
  else
538
597
  output.puts(' return suiteTearDown(UNITY_END());')
539
598
  end
@@ -543,17 +602,14 @@ class UnityTestRunnerGenerator
543
602
  output.puts('}')
544
603
  end
545
604
 
546
- def create_h_file(output, filename, tests, testfile_includes, used_mocks)
605
+ def create_h_file(output, filename, tests, headers, used_mocks)
547
606
  filename = File.basename(filename).gsub(/[-\/\\.,\s]/, '_').upcase
548
607
  output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
549
608
  output.puts("#ifndef _#{filename}")
550
609
  output.puts("#define _#{filename}\n\n")
551
610
  output.puts("#include \"#{@options[:framework]}.h\"")
552
611
  output.puts('#include "cmock.h"') unless used_mocks.empty?
553
- @options[:includes].flatten.uniq.compact.each do |inc|
554
- output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}")
555
- end
556
- testfile_includes.each do |inc|
612
+ [@options[:includes], headers].flatten.uniq.compact.each do |inc|
557
613
  output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}")
558
614
  end
559
615
  output.puts "\n"
@@ -29,6 +29,7 @@ Significant Bugfixes:
29
29
  - display of failures fixed on ARM processors, particularly with arrays (#807)
30
30
  - fixed each-equal assertion for memory (#797)
31
31
  - fix many warnings.
32
+ - Test runner generator calls custom suite teardown when begin/end calls are omitted. @94xhn
32
33
 
33
34
  Other:
34
35
 
@@ -250,4 +250,12 @@
250
250
  */
251
251
  /* #define UNITY_INCLUDE_EXEC_TIME */
252
252
 
253
+ /* Define this macro to redefine what the UnityPrintChar() function considers
254
+ * a printable character.
255
+ *
256
+ * Example, for printing UTF-8:
257
+ * #define UNITY_IS_PRINTABLE_CHAR(c) ((128 <= (c)) && ((c) <= 255))
258
+ */
259
+ /* #define UNITY_IS_PRINTABLE_CHAR(c) ((32 <= (c)) && ((c) <= 126)) */
260
+
253
261
  #endif /* UNITY_CONFIG_H */
@@ -7,6 +7,8 @@
7
7
 
8
8
  #include "unity.h"
9
9
 
10
+ #include <stdbool.h>
11
+
10
12
  #ifndef UNITY_PROGMEM
11
13
  #define UNITY_PROGMEM
12
14
  #endif
@@ -88,8 +90,14 @@ static const char UNITY_PROGMEM UnityStrDetail2Name[] = " " UNITY_DET
88
90
  /* Local helper function to print characters. */
89
91
  static void UnityPrintChar(const char* pch)
90
92
  {
93
+ #ifdef UNITY_IS_PRINTABLE_CHAR
94
+ const int isPrintable = UNITY_IS_PRINTABLE_CHAR(*pch);
95
+ #else
96
+ const int isPrintable = ((32 <= *pch) && (*pch <= 126));
97
+ #endif
98
+
91
99
  /* printable characters plus CR & LF are printed */
92
- if ((*pch <= 126) && (*pch >= 32))
100
+ if (isPrintable)
93
101
  {
94
102
  UNITY_OUTPUT_CHAR(*pch);
95
103
  }
@@ -11,7 +11,7 @@
11
11
 
12
12
  #define UNITY_VERSION_MAJOR 2
13
13
  #define UNITY_VERSION_MINOR 7
14
- #define UNITY_VERSION_BUILD 0
14
+ #define UNITY_VERSION_BUILD 2
15
15
  #define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | (UNITY_VERSION_MINOR << 8) | UNITY_VERSION_BUILD)
16
16
 
17
17
  #ifdef __cplusplus
@@ -19,6 +19,7 @@ TEMP_DIRS = [
19
19
 
20
20
  TEMP_DIRS.each do |dir|
21
21
  directory(dir)
22
+ CLEAN.include(File.join(dir, '*.*'))
22
23
  CLOBBER.include(dir)
23
24
  end
24
25
 
@@ -167,7 +168,7 @@ namespace :style do
167
168
 
168
169
  desc "Attempt to Autocorrect style"
169
170
  task :auto => ['style:clean'] do
170
- execute("rubocop ../auto ../examples ../extras --auto-correct --config .rubocop.yml")
171
+ execute("rubocop ../auto ../examples ../extras --autocorrect --config .rubocop.yml")
171
172
  report "Autocorrected What We Could."
172
173
  end
173
174
 
@@ -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) {}