diff --git a/examples/temp_sensor/project.yml b/examples/temp_sensor/project.yml new file mode 100644 index 0000000..9377764 --- /dev/null +++ b/examples/temp_sensor/project.yml @@ -0,0 +1,75 @@ +# ========================================================================= +# CMock - Automatic Mock Generation for C +# ThrowTheSwitch.org +# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams +# SPDX-License-Identifier: MIT +# ========================================================================= + +:project: + :build_root: 'build/' + :colour: true + +:paths: + :source: + - 'src/' + :include: + - 'src/' + - '../../src/' + - '../../vendor/unity/src/' + - '../../vendor/unity/examples/example_3/helper/' + - 'build/mocks/' + - 'test/' + :test: 'test/' + :build: 'build/' + :mocks: 'build/mocks/' + +:extension: + :object: '.o' + :executable: '.exe' + +:defines: + :common: + - __monitor + - UNITY_SUPPORT_64 + +:cmock: + # Core configuration + :plugins: [] + :verbosity: 2 + :when_no_prototypes: :warn + + # File configuration + :mock_path: 'build/mocks' + :skeleton_path: '' + :mock_prefix: 'Mock' + :mock_suffix: '' + + # Parser configuration + :strippables: + - '(?:__attribute__\s*\([ (]*.*?[ )]*\)+)' + :attributes: + - __ramfunc + - __irq + - __fiq + - register + - extern + :c_calling_conventions: + - __stdcall + - __cdecl + - __fastcall + :treat_externs: :exclude + :treat_inlines: :exclude + + # Type handling configuration + :memcmp_if_unknown: true + :when_ptr: :compare_data + + # Mock generation configuration + :weak: '' + :enforce_strict_ordering: false + :fail_on_unexpected_calls: true + :callback_include_count: true + :callback_after_arg_check: false + :includes: + - Types.h + :exclude_setjmp_h: false diff --git a/examples/temp_sensor/rakefile_helper.rb b/examples/temp_sensor/rakefile_helper.rb index ff55b8b..1870842 100644 --- a/examples/temp_sensor/rakefile_helper.rb +++ b/examples/temp_sensor/rakefile_helper.rb @@ -24,8 +24,26 @@ module RakefileHelpers def load_configuration(config_file) $cfg_file = config_file - $cfg = load_yaml(File.read("./targets/#{$cfg_file}")) - $colour_output = false unless $cfg['colour'] + $cfg = load_yaml(File.read("../../test/targets/#{$cfg_file}")) + $proj = load_yaml(File.read('./project.yml')) + + # Apply project-level paths, overriding the test-system paths in the target file + $cfg['compiler']['source_path'] = $proj[:paths][:source].first + $cfg['compiler']['unit_tests_path'] = $proj[:paths][:test] + $cfg['compiler']['build_path'] = $proj[:project][:build_root] + $cfg['compiler']['object_files']['destination'] = $proj[:project][:build_root] + $cfg['linker']['object_files']['path'] = $proj[:project][:build_root] + $cfg['linker']['bin_files']['destination'] = $proj[:project][:build_root] + + # Merge includes: keep Array items from target (e.g., IAR tool paths), use project.yml for strings + tool_includes = $cfg['compiler']['includes']['items'].select { |i| i.is_a?(Array) } + $cfg['compiler']['includes']['items'] = tool_includes + $proj[:paths][:include] + + # Merge defines: target-specific first, then project common defines + $cfg['compiler']['defines']['items'] ||= [] + $cfg['compiler']['defines']['items'] |= $proj[:defines][:common] + + $colour_output = $proj[:project][:colour] end def configure_clean @@ -196,13 +214,13 @@ module RakefileHelpers # Build and execute each unit test test_files.each do |test| # Detect dependencies and build required required modules - header_list = (extract_headers(test) + ['cmock.h'] + [$cfg[:cmock][:unity_helper_path]]).compact.uniq + header_list = (extract_headers(test) + ['cmock.h'] + [($proj[:cmock] || {})[:unity_helper_path]]).compact.uniq header_list.each do |header| # create mocks if needed next unless header =~ /Mock/ require '../../lib/cmock' - @cmock ||= CMock.new(".//targets//#{$cfg_file}") + @cmock ||= CMock.new($proj[:cmock]) @cmock.setup_mocks([$cfg['compiler']['source_path'] + header.gsub('Mock', '')]) end @@ -221,7 +239,7 @@ module RakefileHelpers runner_name = "#{test_base}_Runner.c" if $cfg['compiler']['runner_path'].nil? runner_path = "#{$cfg['compiler']['build_path']}#{runner_name}" - test_gen = UnityTestRunnerGenerator.new(".//targets//#{$cfg_file}") + test_gen = UnityTestRunnerGenerator.new($cfg) test_gen.run(test, runner_path) else runner_path = $cfg['compiler']['runner_path'] + runner_name @@ -258,7 +276,7 @@ module RakefileHelpers report 'Building application...' obj_list = [] - load_configuration(".//targets//#{$cfg_file}") + load_configuration($cfg_file) main_path = $cfg['compiler']['source_path'] + main + C_EXTENSION # Detect dependencies and build required required modules diff --git a/test/project.yml b/test/project.yml new file mode 100644 index 0000000..83c3aa1 --- /dev/null +++ b/test/project.yml @@ -0,0 +1,34 @@ +# ========================================================================= +# CMock - Automatic Mock Generation for C +# ThrowTheSwitch.org +# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams +# SPDX-License-Identifier: MIT +# ========================================================================= + +:project: + :build_root: './system/build/' + :colour: true + +:paths: + :source: + - './system/generated/' + :include: + - './system/generated/' + - '../examples/test/' + - '../src/' + - '../vendor/unity/src/' + - '../vendor/c_exception/lib/' + - './system/test_compilation/' + - './' + :build: './system/build/' + :test_compilation: './system/test_compilation/' + +:extension: + :object: '.o' + :executable: '.exe' + +:defines: + :common: + - CMOCK + - UNITY_SUPPORT_64 + diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index de4b083..f76f542 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -32,7 +32,24 @@ module RakefileHelpers def load_configuration(config_file) $cfg_file = config_file $cfg = load_yaml('./targets/' + $cfg_file) - $colour_output = false unless $cfg['colour'] + $proj = load_yaml('./project.yml') + + # Apply project-level paths, overriding any hardcoded paths in the target file + $cfg['compiler']['source_path'] = $proj[:paths][:source].first + $cfg['compiler']['build_path'] = $proj[:project][:build_root] + $cfg['compiler']['object_files']['destination'] = $proj[:project][:build_root] + $cfg['linker']['object_files']['path'] = $proj[:project][:build_root] + $cfg['linker']['bin_files']['destination'] = $proj[:project][:build_root] + + # Merge includes: keep Array items from target (e.g., IAR tool paths), use project.yml for strings + tool_includes = $cfg['compiler']['includes']['items'].select { |i| i.is_a?(Array) } + $cfg['compiler']['includes']['items'] = tool_includes + $proj[:paths][:include] + + # Merge defines: target-specific first, then project common defines + $cfg['compiler']['defines']['items'] ||= [] + $cfg['compiler']['defines']['items'] |= $proj[:defines][:common] + + $colour_output = $proj[:project][:colour] end def configure_clean diff --git a/test/system/test_interactions/doesnt_leave_details_behind.yml b/test/system/test_interactions/doesnt_leave_details_behind.yml index a7bf2b1..03ba22d 100644 --- a/test/system/test_interactions/doesnt_leave_details_behind.yml +++ b/test/system/test_interactions/doesnt_leave_details_behind.yml @@ -75,7 +75,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after an expect and return' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -89,7 +89,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after an expect' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -103,7 +103,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after throw expectation' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -119,7 +119,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after a mock call' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -134,7 +134,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after throw' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -151,7 +151,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after ignore' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -166,7 +166,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after ignored mock' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -181,7 +181,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after callback setup' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -198,7 +198,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after mock with callback' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -214,7 +214,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after expect any args' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -231,7 +231,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after mock which expected any args' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -247,7 +247,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after ignored arg' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -265,7 +265,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after mock which ignored an arg' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -282,7 +282,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after mock which threw a CException' - :verify_error: 'FAIL: Expected 1 Was 2. CustomFail' + :verify_error: 'FAIL: Expected 1 Was 2:CustomFail' :code: | test() { @@ -299,7 +299,7 @@ - :pass: FALSE :should: 'not contain mock details in failed assertion after mock which used a return thru ptr' - :verify_error: 'FAIL: Expected 3 Was 7. CustomFail' + :verify_error: 'FAIL: Expected 3 Was 7:CustomFail' :code: | test() {