You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just noticed an issue with TestTask that it doesn't properly recognize the -n option as a shorthand of --n as documented:
$ bundle exec rake test TESTOPTS='--help'
...
-n, --name=NAME Runs tests matching NAME.
Use '/PATTERN/' for NAME to use regular expression.
Regular expression accepts options.
Example: '/taRget/i' matches 'target' and 'TARGET'
...
It works when I run:
🐚 bundle exec rake test TEST=test/gnuplot_printer_test.rb TESTOPTS='--name=/write/'
/home/user/.asdf/installs/ruby/3.2.2/bin/ruby -w -I"lib" /home/user/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb "test/gnuplot_printer_test.rb" --name=/write/
Loaded suite /home/user/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rake-13.0.6/lib/rake/rake_test_loader
Started
.
Finished in 0.001170365 seconds.
--------------------------------------------------------------------------------
1 tests, 4 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
--------------------------------------------------------------------------------
But it fails when I use a shorthand:
🐚 bundle exec rake test TEST=test/gnuplot_printer_test.rb TESTOPTS='-n /write/'
/home/user/.asdf/installs/ruby/3.2.2/bin/ruby -w -I"lib" /home/user/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb "test/gnuplot_printer_test.rb" -n /write/
File does not exist: /write
rake aborted!
Command failed with status (1): [ruby -w -I"lib" /home/user/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb "test/gnuplot_printer_test.rb" -n /write/]
/home/user/.asdf/installs/ruby/3.2.2/bin/bundle:25:in `load'
/home/user/.asdf/installs/ruby/3.2.2/bin/bundle:25:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)
In case that matters, using Test::Unit 3.5.7 framework.
That --name option comes from Test::Unit. This is how rake invokes test tasks - https://github.com/ruby/rake/blob/master/lib/rake/rake_test_loader.rb. It just forwards arguments starting with -, and tries to load as test files all the others. When you use something like --name=test_foo, this is a single argument, but when -n test_foo this 2 arguments and only -n is forwarded, but test_foo is treated as a file name.
The same applies for all other options, not just name, which you pass through single - syntax. I am not sure something can be done in the rake to solve this.
I would expect that file names are actually passed via TEST env variable, and TEST_OPTS consists only options which are passed directly as is. Personally, I use them as I described. Probably it is done this way for convenience (to be able to use only TEST_OPTS).
Probably yes, and I would expect it to behave this way, as I mentioned, but this would introduce backwards incompatible changes for one of the most used gems.
Activity
fatkodima commentedon Apr 17, 2023
That
--nameoption comes fromTest::Unit. This is how rake invokes test tasks - https://github.com/ruby/rake/blob/master/lib/rake/rake_test_loader.rb. It just forwards arguments starting with-, and tries to load as test files all the others. When you use something like--name=test_foo, this is a single argument, but when-n test_foothis 2 arguments and only-nis forwarded, buttest_foois treated as a file name.The same applies for all other options, not just
name, which you pass through single-syntax. I am not sure something can be done in theraketo solve this.fatkodima commentedon Apr 17, 2023
I would expect that file names are actually passed via
TESTenv variable, andTEST_OPTSconsists only options which are passed directly as is. Personally, I use them as I described. Probably it is done this way for convenience (to be able to use onlyTEST_OPTS).akostadinov commentedon Apr 17, 2023
What can be done is to pass
TESTOPTSas opts, not as files I guess.fatkodima commentedon Apr 17, 2023
Probably yes, and I would expect it to behave this way, as I mentioned, but this would introduce backwards incompatible changes for one of the most used gems.
gerrywastaken commentedon May 1, 2025
Yeah this burnt a lot of time. Thanks for pointing out the work around @akostadinov :)