From dd70d40adff5594e5a7597c0cffbc106f11217dc Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Fri, 29 May 2026 10:29:30 -0400 Subject: [PATCH] Make sure that examples get run with ci, and using appropriate settings. --- examples/example_3/rakefile_helper.rb | 8 +++--- test/rakefile | 26 +++++++++++-------- test/rakefile_helper.rb | 34 +++++++++++++++++-------- test/tests/test_generate_test_runner.rb | 3 --- 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/examples/example_3/rakefile_helper.rb b/examples/example_3/rakefile_helper.rb index 0bc932c..1a7d99f 100644 --- a/examples/example_3/rakefile_helper.rb +++ b/examples/example_3/rakefile_helper.rb @@ -16,9 +16,9 @@ TARGETS_PATH = File.join(__dir__, '..', '..', 'test', 'targets').freeze PROJECT_FILE = File.join(__dir__, 'project.yml').freeze def load_configuration(config_file) - $cfg_file = config_file =~ /[\\\/]/ ? config_file : File.join(TARGETS_PATH, config_file) + $unity_example_config_file = config_file =~ /[\\\/]/ ? config_file : File.join(TARGETS_PATH, config_file) project = YamlHelper.load_file(PROJECT_FILE) - target = YamlHelper.load_file($cfg_file) + target = YamlHelper.load_file($unity_example_config_file) # Toolchain settings (tools, extensions) come from the target YML. # Path and project settings come from project.yml and take precedence. @@ -130,7 +130,7 @@ end def compile(file, defines = []) build_path = $cfg[:project][:build_root] - out_file = File.join(build_path, File.basename(file, C_EXTENSION)) + $cfg[:extension][:object] + out_file = File.join(build_path, File.basename(file, C_EXTENSION)) + ($cfg[:extension][:object] || '.o') cmd_str = build_command_string($cfg[:tools][:test_compiler], [file, out_file], defines) execute(cmd_str) out_file @@ -138,7 +138,7 @@ end def link_it(exe_name, obj_list) build_path = $cfg[:project][:build_root] - exe_file = File.join(build_path, File.basename(exe_name, '.*')) + $cfg[:extension][:executable] + exe_file = File.join(build_path, File.basename(exe_name, '.*')) + ($cfg[:extension][:executable] || '') cmd_str = build_command_string($cfg[:tools][:test_linker], [obj_list, exe_file]) execute(cmd_str) exe_file diff --git a/test/rakefile b/test/rakefile index b992b34..3c9f9bb 100644 --- a/test/rakefile +++ b/test/rakefile @@ -28,30 +28,30 @@ include RakefileHelpers # Load proper GCC as defult configuration DEFAULT_CONFIG_FILE = 'gcc_64_auto_stdint.yml' -configure_toolchain(DEFAULT_CONFIG_FILE) +$unity_test_config_file = DEFAULT_CONFIG_FILE ############# ALL THE SELF-TESTS WE CAN PERFORM namespace :test do desc "Build and test Unity" task :all => [:clean, :prepare_for_tests, 'test:scripts', 'test:unit', :style, 'test:fixture', 'test:memory', 'test:summary'] - task :ci => [:clean, :prepare_for_tests, 'test:scripts', 'test:unit', :style, 'test:make', 'test:fixture', 'test:memory', 'test:summary'] + task :ci => [:clean, :prepare_for_tests, 'test:scripts', 'test:unit', :style, 'test:make', 'test:fixture', 'test:memory', 'test:examples', 'test:summary'] desc "Test unity with its own unit tests" - task :unit => [:prepare_for_tests] do + task :unit => [:config_toolchain, :prepare_for_tests] do run_tests unit_test_files end namespace :unit do unit_test_files.each do |f| desc "test this unit only" - task File.basename(f,'.c').sub('test_unity_','') => [:prepare_for_tests] do + task File.basename(f,'.c').sub('test_unity_','') => [:config_toolchain, :prepare_for_tests] do run_tests [f] end end end desc "Test unity's helper scripts" - task :scripts => [:prepare_for_tests] do + task :scripts => [:config_toolchain, :prepare_for_tests] do begin Dir['tests/test_*.rb'].each do |scriptfile| require "./"+scriptfile @@ -66,27 +66,27 @@ namespace :test do end desc "Test unity triggered from make" - task :make => [:prepare_for_tests] do + task :make => [:config_toolchain, :prepare_for_tests] do run_make_tests() end desc "Test unity fixture addon" - task :fixture => [:prepare_for_tests] do + task :fixture => [:config_toolchain, :prepare_for_tests] do test_fixtures() end desc "Test unity memory addon" - task :memory => [:prepare_for_tests] do + task :memory => [:config_toolchain, :prepare_for_tests] do test_memory() end desc "Test unity examples" - task :examples => [:prepare_for_tests] do + task :examples => [:config_toolchain, :prepare_for_tests] do run_examples end desc "Run all rspecs" - task :spec => [:prepare_for_tests] do + task :spec => [:config_toolchain, :prepare_for_tests] do output = execute("rspec spec/**/*_spec.rb", true) rspec_ok = $?.exitstatus.zero? report output @@ -115,7 +115,11 @@ task :default => [:clobber, :all] desc "Load configuration" task :config, :config_file do |t, args| - configure_toolchain(args[:config_file]) + $unity_test_config_file = args[:config_file] +end + +task :config_toolchain do + configure_toolchain($unity_test_config_file) end task :no_color do diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index a28a182..80e0486 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -13,16 +13,19 @@ require_relative '../auto/yaml_helper' module RakefileHelpers C_EXTENSION = '.c'.freeze + def load_configuration(config_file) return if $configured - if config_file =~ /[\\|\/]/ - $cfg_file = config_file + $cfg_file_base = config_file + cfg_file = if config_file =~ /[\\|\/]/ + $unity_test_config_file_in_targets = false + config_file else - $cfg_file_base = config_file - $cfg_file = "targets/#{config_file}" + $unity_test_config_file_in_targets = true + "targets/#{config_file}" end - $cfg = YamlHelper.load_file($cfg_file) + $cfg = YamlHelper.load_file(cfg_file) $cfg[:paths] ||= {} $cfg[:paths][:test] = (Array($cfg[:paths][:test]) + ['src/', '../src/', 'testdata/', 'tests/']).uniq $colour_output = false unless $cfg['colour'] @@ -418,11 +421,22 @@ module RakefileHelpers def run_examples() report "\nRunning Unity Examples" total_tests = total_ignored = 0 - [ - "cd ../examples/example_1 && make -s ci", - "cd ../examples/example_2 && make -s ci", - "cd ../examples/example_3 && rake config[#{$cfg_file_base || 'gcc_64'}] default" - ].each do |cmd| + + # If we're set up to use gcc, the makefiles should work too. otherwise, just run example 3 + examples = if $cfg_file_base.nil? || ($cfg_file_base =~ /gcc/) + [ + "cd ../examples/example_1 && make -s ci", + "cd ../examples/example_2 && make -s ci" + ] + else + [] + end + if $unity_test_config_file_in_targets + ["cd ../examples/example_3 && rake config[#{$cfg_file_base}] default"] + else + ["cd ../examples/example_3 && rake config[\"../#{$unity_test_config_file}\"] default"] + end + + examples.each do |cmd| execute(cmd, false).each_line do |line| if line =~ /(\d+) Tests \d+ Failures (\d+) Ignored/ total_tests += Regexp.last_match(1).to_i diff --git a/test/tests/test_generate_test_runner.rb b/test/tests/test_generate_test_runner.rb index 5e0133f..201c24d 100644 --- a/test/tests/test_generate_test_runner.rb +++ b/test/tests/test_generate_test_runner.rb @@ -1241,9 +1241,6 @@ RUNNER_TESTS = [ ] def runner_test(test, runner, expected, test_defines, cmdline_args, features) - # Tack on TEST define for compiling unit tests - load_configuration($cfg_file) - # Drop Out if we're skipping this type of test if $cfg[:skip_tests] && features if $cfg[:skip_tests].include?(:parameterized) && features.include?(:parameterized)