rake
rake copied to clipboard
TestTask fails with -n but works with --name
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.
-- rake, version 13.0.6
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
).
What can be done is to pass TESTOPTS
as opts, not as files I guess.
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.