fix(scripts): read the defaulted args in unity_test_summary

Commit e47ac34 ("Fix default path in unity test summarizer") moved the
result-directory and root-path defaults off ARGV and onto the args array
that ARGV.partition produces, but both readers were left on ARGV. The
defaults are therefore computed and discarded: running the summarizer
with no arguments raises NoMethodError on nil, and passing only a result
directory leaves root nil so failures print without the path prefix the
usage text promises. Passing an option such as --verbose also shifts the
option string into ARGV[0] and breaks the result glob.

Read args[0] and args[1] so the assigned defaults are the values used.

Add test/tests/test_unity_test_summary.rb covering both defaults; it runs
under the existing test:scripts task.

Signed-off-by: manon <[email protected]>
This commit is contained in:
manon
2026-09-09 12:28:38 +09:00
parent 43f5ce1737
commit 6635784422
3 changed files with 61 additions and 2 deletions
+2 -2
View File
@@ -124,7 +124,7 @@ if $0 == __FILE__
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 @@ if $0 == __FILE__
# set the root path
args[1] ||= "#{Dir.pwd}/"
uts.root = ARGV[1]
uts.root = args[1]
# run the summarizer
puts uts.run
+1
View File
@@ -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)
+58
View File
@@ -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