Skip to content

fix(scripts): read the defaulted args in unity_test_summary - #850

Merged
mvandervoord merged 1 commit into
ThrowTheSwitch:masterfrom
youdie006:fix-unity-test-summary-defaults
Sep 9, 2026
Merged

fix(scripts): read the defaulted args in unity_test_summary#850
mvandervoord merged 1 commit into
ThrowTheSwitch:masterfrom
youdie006:fix-unity-test-summary-defaults

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

🍍

What

auto/unity_test_summary.rb computes defaults for the result directory and the root path, then reads the un-defaulted ARGV instead of the defaulted args. The defaults are dead.

    args[0] ||= './'
    targets = "#{ARGV[0].tr('\\', '/')}**/*.test*"   # reads ARGV, not args
...
    args[1] ||= "#{Dir.pwd}/"
    uts.root = ARGV[1]                                # reads ARGV, not args

auto/unity_test_summary.rb:126-136

Why this is a regression, not a design choice

The repo's own history says the defaults were meant to be read. e47ac34 ("Fix default path in unity test summarizer", Mark VanderVoord, 2015-07-21) introduced opts, args = ARGV.partition {...} and moved both defaults from ARGV onto args, but left both readers pointed at ARGV:

-    ARGV[0] ||= './'
+    args[0] ||= './'
     targets = "#{ARGV[0].gsub(/\\/, '/')}**/*.test*"
...
-    ARGV[1] ||= File.expand_path(File.dirname(__FILE__)) + '/'
+    args[1] ||= Dir.pwd + '/'
     uts.set_root_path(ARGV[1])

Since args is what ARGV.partition produced, ARGV is never mutated any more, so the two ||= lines have had no effect for the whole life of that commit.

Effect

Measured on a directory holding one *.testfail:

invocation before after
(no arguments) ERROR: undefined method 'tr' for nil:NilClass + usage works; failures prefixed with Dir.pwd
./ works, failures printed with no root prefix works; failures prefixed with Dir.pwd
./ /root/ works, prefixed \root\ identical
--verbose ./ ERROR: No *.testpass, *.testfail, or *.testresults files found in '--verbose**/*.test*' works

Two of those four are the documented usage — usage prints result_file_directory/ and root_path/ as the argument list and the script defaults both, so calling it with fewer arguments is supposed to work. The option-partitioning case is broken for the same reason: with the option string still in ARGV[0], the glob is built from --verbose.

Please note the one behaviour change that is not an error-to-working transition: the second row. Given only a result directory, failure lines now carry the Dir.pwd prefix that args[1] ||= "#{Dir.pwd}/" assigns. That is the value the line was written to produce; I am calling it out explicitly because it changes output for a currently-working invocation. Happy to restrict the change to args[0] alone if you would rather keep that row byte-identical.

Fix

Read args[0] and args[1].

Test

test/tests/test_unity_test_summary.rb (new) runs the CLI in a sandbox directory holding one *.testfail and asserts the two defaults. It joins the existing test:scripts task and uses the same $generate_test_runner_tests / $generate_test_runner_failures tallies as its neighbours, so the task's count goes 69 -> 71.

Verification I ran locally (Ruby 3.2.3):

  • Green: both new cases PASS on the patched script.
  • Red: with auto/unity_test_summary.rb restored from master, both FAIL.
  • Mutation, one line at a time — reverting only :127 fails only UnityTestSummary_DefaultsResultDirectoryToCurrentDirectory; reverting only :136 fails only UnityTestSummary_DefaultsRootPathToCurrentDirectory. Disjoint, so each assertion pins its own line.
  • cd test && rake ci exits 0: 71 Tests 0 Failures 0 Ignored on test:scripts, 3068 TOTAL TESTS 0 TOTAL FAILURES 56 IGNORED overall, and :style (rubocop 1.57.2, the version CI pins) reports no offenses on ../auto.

The path separator in the assertion is not platform-dependent: get_details ends with .gsub(/\//, '\\') unconditionally (auto/unity_test_summary.rb:98), so the test builds its expectation the same way.

Changelog

Added under ### Unity 2.7.2 -> Significant Bugfixes: per docs/CONTRIBUTING.md:101. No issue exists for this, so the line carries only the username. Note #821 also touches docs/UnityChangeLog.md; if that lands first this is a one-line rebase.


Assisted-by: Claude Code:claude-opus-5

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 <youdie006@users.noreply.github.com>
@mvandervoord
mvandervoord merged commit 0012495 into ThrowTheSwitch:master Sep 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants