Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestTask fails with -n but works with --name #490

Open
akostadinov opened this issue Apr 6, 2023 · 4 comments
Open

TestTask fails with -n but works with --name #490

akostadinov opened this issue Apr 6, 2023 · 4 comments

Comments

@akostadinov
Copy link

akostadinov commented Apr 6, 2023

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

@fatkodima
Copy link

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.

@fatkodima
Copy link

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).

@akostadinov
Copy link
Author

What can be done is to pass TESTOPTS as opts, not as files I guess.

@fatkodima
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants