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

Show chdir option as a command #552

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/rake/file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def sh(*cmd, &block)
verbose = options.delete :verbose
noop = options.delete(:noop) || Rake::FileUtilsExt.nowrite_flag

Rake.rake_output_message sh_show_command cmd if verbose
Rake.rake_output_message sh_show_command(cmd, options) if verbose

unless noop
res = (Hash === cmd.last) ? system(*cmd) : system(*cmd, options)
Expand All @@ -68,7 +68,7 @@ def create_shell_runner(cmd) # :nodoc:
end
private :create_shell_runner

def sh_show_command(cmd) # :nodoc:
def sh_show_command(cmd, options = nil) # :nodoc:
cmd = cmd.dup

if Hash === cmd.first
Expand All @@ -77,7 +77,12 @@ def sh_show_command(cmd) # :nodoc:
cmd[0] = env
end

cmd.join " "
cmd = cmd.join " "
if options and chdir = options[:chdir]
"(cd #{chdir} && #{cmd})"
else
cmd
end
end
private :sh_show_command

Expand Down
6 changes: 5 additions & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TaskManager
include Rake::TaskManager
end

RUBY = File.realpath(ENV["RUBY"] || Gem.ruby)
RUBY = (ENV["RUBY"] || Gem.ruby)

def setup
ARGV.clear
Expand Down Expand Up @@ -124,5 +124,9 @@ def jruby9?
jruby? && (JRUBY_VERSION >= "9.0.0.0")
end

def jruby90?
jruby? && JRUBY_VERSION.start_with?("9.0.")
end

include RakefileDefinitions
end
20 changes: 17 additions & 3 deletions test/test_rake_file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def test_sh_with_multiple_arguments
end

def test_sh_with_spawn_options
omit "JRuby does not support spawn options" if jruby?
omit "JRuby does not support spawn options" if jruby90?

echocommand

Expand Down Expand Up @@ -240,10 +240,24 @@ def test_sh_noop
assert true, "should not fail"
end

def test_sh_chdir
omit "JRuby does not support spawn options" if jruby90?

Dir.mkdir "chdir_test"
out, err = capture_output do
verbose(true) {
sh "echo ok", chdir: "chdir_test", verbose: true, noop: true
}
end

assert_equal "(cd chdir_test && echo ok)\n", err
assert_empty out
end

def test_sh_bad_option
# Skip on JRuby because option checking is performed by spawn via system
# now.
omit "JRuby does not support spawn options" if jruby?
omit "JRuby does not support spawn options" if jruby90?

shellcommand

Expand Down Expand Up @@ -388,7 +402,7 @@ def assert_echoes_fully
end

def test_ruby_with_multiple_arguments
omit if jruby9? # https://github.com/jruby/jruby/issues/3653
omit if jruby90? # https://github.com/jruby/jruby/issues/3653

check_no_expansion

Expand Down