From bcddcc19b510f3366817fb670d1fade3ce94fc94 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Wed, 8 Jul 2026 16:00:43 -0400 Subject: [PATCH] Add ability to specify random seed value in tests. --- test/rakefile | 7 +++++++ test/rakefile_helper.rb | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/rakefile b/test/rakefile index 1813894..b5c15e2 100644 --- a/test/rakefile +++ b/test/rakefile @@ -29,6 +29,7 @@ end $cmock_test_config_file = DEFAULT_CONFIG_FILE $cmock_test_overlay_file = nil +$cmock_test_seed = nil task :prep_system_tests => SYSTEM_TEST_SUPPORT_DIRS task :default => [:test] @@ -41,6 +42,12 @@ task :config, [:config_file, :cmock_overlay] do |t, args| $cmock_test_overlay_file = args[:cmock_overlay] end +desc "Fix the minitest random seed for repeatable Ruby unit test ordering" +task :seed, [:seed_value] do |t, args| + $cmock_test_seed = args[:seed_value] + ENV['TESTOPTS'] = "#{ENV['TESTOPTS']} --seed=#{$cmock_test_seed}".strip +end + task :config_toolchains do configure_toolchain($cmock_test_config_file, $cmock_test_overlay_file) end diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index 040033c..d9712f7 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -315,7 +315,8 @@ module RakefileHelpers total_runs = total_failures = total_errors = total_skips = 0 Dir['unit/*_test.rb'].sort.each do |tst| report "\nRunning #{tst.to_s}" - output = execute("ruby -I. #{tst} -v", true, false) + seed_opt = $cmock_test_seed ? " --seed=#{$cmock_test_seed}" : '' + output = execute("ruby -I. #{tst} -v#{seed_opt}", true, false) output.each_line do |line| if line =~ /(\d+) runs, \d+ assertions, (\d+) failures, (\d+) errors, (\d+) skips/ total_runs += Regexp.last_match(1).to_i