Add method "prepend_path" to control PATH when running commands.
This commit is contained in:
parent
0a15996b2a
commit
54b7536481
@ -160,8 +160,18 @@ module Cmdtest
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prepend_path_dirs(path_dirs)
|
||||||
|
full_path_dirs = path_dirs.map {|dir| File.expand_path(dir, @orig_cwd) }
|
||||||
|
new_env_path = (full_path_dirs + [@orig_envpath]).join(Config::CONFIG["PATH_SEPARATOR"])
|
||||||
|
if new_env_path != ENV["PATH"]
|
||||||
|
ENV["PATH"] = new_env_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
|
@orig_cwd = Dir.pwd
|
||||||
ENV["PATH"] = Dir.pwd + Config::CONFIG["PATH_SEPARATOR"] + ENV["PATH"]
|
ENV["PATH"] = Dir.pwd + Config::CONFIG["PATH_SEPARATOR"] + ENV["PATH"]
|
||||||
|
@orig_envpath = ENV["PATH"]
|
||||||
@n_assert_failures = 0
|
@n_assert_failures = 0
|
||||||
@n_assert_errors = 0
|
@n_assert_errors = 0
|
||||||
@n_assert_successes = 0
|
@n_assert_successes = 0
|
||||||
|
@ -68,6 +68,7 @@ module Cmdtest
|
|||||||
@_work_dir = Workdir.new(runner)
|
@_work_dir = Workdir.new(runner)
|
||||||
@_in_cmd = false
|
@_in_cmd = false
|
||||||
@_comment_str = nil
|
@_comment_str = nil
|
||||||
|
@_prepend_path_dirs = []
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------
|
#------------------------------
|
||||||
@ -131,6 +132,15 @@ module Cmdtest
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#------------------------------
|
||||||
|
# Prepend the given directory to the PATH before running commands.
|
||||||
|
# The path is evaluated realtive to the current directory when 'cmdtest'
|
||||||
|
# was started.
|
||||||
|
|
||||||
|
def prepend_path(dir)
|
||||||
|
@_prepend_path_dirs.unshift(dir)
|
||||||
|
end
|
||||||
|
|
||||||
#==============================
|
#==============================
|
||||||
|
|
||||||
# Used in methods invoked from the "cmd" do-block, in methods that
|
# Used in methods invoked from the "cmd" do-block, in methods that
|
||||||
@ -470,6 +480,7 @@ module Cmdtest
|
|||||||
|
|
||||||
@_runner.notify("cmdline", @_cmdline, @_comment_str)
|
@_runner.notify("cmdline", @_cmdline, @_comment_str)
|
||||||
@_comment_str = nil
|
@_comment_str = nil
|
||||||
|
@_runner.prepend_path_dirs(@_prepend_path_dirs)
|
||||||
@_effects = @_work_dir.run_cmd(@_cmdline)
|
@_effects = @_work_dir.run_cmd(@_cmdline)
|
||||||
|
|
||||||
@_checked_status = false
|
@_checked_status = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user