diff --git a/auto/unity_test_summary.rb b/auto/unity_test_summary.rb index 05930381..a91d9cde 100755 --- a/auto/unity_test_summary.rb +++ b/auto/unity_test_summary.rb @@ -124,7 +124,7 @@ def parse_test_summary(summary) begin # look in the specified or current directory for result files args[0] ||= './' - targets = "#{ARGV[0].tr('\\', '/')}**/*.test*" + targets = "#{args[0].tr('\\', '/')}**/*.test*" results = Dir[targets] raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty? @@ -133,7 +133,7 @@ def parse_test_summary(summary) # set the root path args[1] ||= "#{Dir.pwd}/" - uts.root = ARGV[1] + uts.root = args[1] # run the summarizer puts uts.run diff --git a/docs/UnityChangeLog.md b/docs/UnityChangeLog.md index d1eab9a3..6e73e27c 100644 --- a/docs/UnityChangeLog.md +++ b/docs/UnityChangeLog.md @@ -18,6 +18,7 @@ Prior to 2008, the project was an internal project and not released to the publi Significant Bugfixes: - Default `UNITY_INCLUDE_EXEC_TIME` macros compile as ISO C99, are statement-safe, and accept `-Wsign-conversion` (#838) + - `unity_test_summary.rb` honors its own default result directory and root path again. @youdie006 ### Unity 2.7.0 (July 2026) diff --git a/test/tests/test_unity_test_summary.rb b/test/tests/test_unity_test_summary.rb new file mode 100644 index 00000000..72cc0636 --- /dev/null +++ b/test/tests/test_unity_test_summary.rb @@ -0,0 +1,58 @@ +# ========================================================================= +# Unity - A Test Framework for C +# ThrowTheSwitch.org +# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams +# SPDX-License-Identifier: MIT +# ========================================================================= + +require 'fileutils' +require_relative '../../auto/colour_reporter' + +# the 'test:scripts' rake task tallies these, so only initialize them if we are loaded first +$generate_test_runner_tests ||= 0 +$generate_test_runner_failures ||= 0 +$unity_test_summary_failures = 0 + +SUMMARY_SCRIPT = File.expand_path('../../auto/unity_test_summary.rb', __dir__) +SUMMARY_SANDBOX = File.expand_path('../sandbox/test_summary', __dir__) +SUMMARY_RESULTS = <<~RESULTS + test/test_a.c:12:test_thing:PASS + test/test_b.c:34:test_broken:FAIL: Expected 1 Was 2 + test/test_c.c:56:test_skipped:IGNORE: not ready + + ----------------------- + 3 Tests 1 Failures 1 Ignored +RESULTS + +def summary_test(name, passed) + if passed + report "#{name}:PASS" + else + report "#{name}:FAIL" + $generate_test_runner_failures += 1 + $unity_test_summary_failures += 1 + end + $generate_test_runner_tests += 1 +end + +FileUtils.rm_rf(SUMMARY_SANDBOX) +FileUtils.mkdir_p(SUMMARY_SANDBOX) +File.write(File.join(SUMMARY_SANDBOX, 'test_sample.testfail'), SUMMARY_RESULTS) + +begin + Dir.chdir(SUMMARY_SANDBOX) do + # with no arguments at all, the result files are looked for in the current directory + output = `ruby "#{SUMMARY_SCRIPT}" 2>&1` + summary_test('UnityTestSummary_DefaultsResultDirectoryToCurrentDirectory', + $?.success? && output.include?('3 TOTAL TESTS 1 TOTAL FAILURES 1 IGNORED')) + + # with only a result directory given, the root path defaults to the current directory + expected = "#{Dir.pwd}/test/test_b.c:34".tr('/', '\\') + output = `ruby "#{SUMMARY_SCRIPT}" ./ 2>&1` + summary_test('UnityTestSummary_DefaultsRootPathToCurrentDirectory', output.include?(expected)) + end +ensure + FileUtils.rm_rf(SUMMARY_SANDBOX) +end + +raise "There were #{$unity_test_summary_failures} failures while testing unity_test_summary.rb" if $unity_test_summary_failures > 0