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
Prefer command -v <cmd> to which <cmd> (heroku#1716)
* Prefer `command -v <cmd>` to `which <cmd>`
Mentioned in heroku#1714 (comment)
`command -v <cmd>` is a POSIX shell builtin that prints the path of a command (or the alias/function definition) if it exists, and returns a non-zero exit code if it doesn't. Because it's a shell builtin, it's available in any POSIX-compliant shell (bash, zsh, dash, sh, etc.) without depending on an external binary.
https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script
* Fix failure
```
1) LanguagePack::Helpers::BinstubCheck can determine if a file is binary or not
Failure/Error: out = `command -v ruby`.strip
Errno::ENOENT:
No such file or directory - command
# ./spec/helpers/binstub_check_spec.rb:5:in ``'
# ./spec/helpers/binstub_check_spec.rb:5:in `get_ruby_path!'
# ./spec/helpers/binstub_check_spec.rb:29:in `block (2 levels) in <top (required)>'
# ./vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.6/lib/rspec/core/example.rb:263:in `instance_exec'
# ./vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.6/lib/rspec/core/example.rb:263:in `block in run'
# ./vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.6/lib/rspec/core/example.rb:511:in `block in with_around_and_singleton_context_hooks'
# ./vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.6/lib/rspec/core/example.rb:468:in `block in with_around_example_hooks'
# ./vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.6/lib/rspec/core/hooks.rb:486:in `block in run'
# ./vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.6/lib/rspec/core/hooks.rb:626:in `block in run_around_example_hooks_for'
# ./vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.6/lib/rspec/core/example.rb:352:in `call'
# ./vendor/bundle/ruby/3.3.0/gems/rspec-retry-0.6.2/lib/rspec/retry.rb:124:in `block in run'
# <internal:kernel>:187:in `loop'
```
The belief is that the failure mode is due to Ruby trying to lookup `command` on the PATH and not finding it. This behavior is documented in Kernel#exec https://www.rubydoc.info/stdlib/core/Kernel:exec but not on backticks (they use different codepaths, just noting).
Backticks https://ruby-doc.org/3.4.1/Kernel.html#method-i-60 have an issue reported but closed https://bugs.ruby-lang.org/issues/4477.
Adding a stderr redirect triggers the correct behavior.
0 commit comments