refactor, 'tmp_dir',... -> Runner class

the methods 'tmp_dir', 'tmp_work_dir' and 'tmp_cmdtest_dir'
are needed in 'cmdtest.rb' too, so moving them to the
Runner class.
This commit is contained in:
Johan Holmberg 2015-08-08 00:26:17 +02:00
parent c03de8c577
commit b82c90232c
3 changed files with 31 additions and 26 deletions

View File

@ -263,6 +263,8 @@ module Cmdtest
attr_reader :opts, :orig_cwd, :method_filter
ORIG_CWD = Dir.pwd
def initialize(project_dir, incremental, opts)
@project_dir = project_dir
@opts = opts
@ -281,6 +283,26 @@ module Cmdtest
@project_dir.test_files_top
end
#----------
def tmp_cmdtest_dir
File.join(ORIG_CWD, "tmp-cmdtest-%d" % [$cmdtest_level])
end
def tmp_dir
if ! @opts.slave
File.join(tmp_cmdtest_dir, "top")
else
File.join(tmp_cmdtest_dir, @opts.slave)
end
end
def tmp_work_dir
File.join(tmp_dir, "work")
end
#----------
def run(clog)
@orig_cwd = Dir.pwd
ENV["PATH"] = Dir.pwd + _path_separator + ENV["PATH"]
@ -410,6 +432,7 @@ module Cmdtest
pr.add("", "--xml", "write summary on JUnit format", type: String, metavar: "FILE")
pr.add("", "--no-exit-code", "exit with 0 status even after errors")
pr.add("-i", "--incremental", "incremental mode")
pr.add("", "--slave", "run in slave mode", type: String)
pr.addpos("arg", "testfile or pattern", nargs: 0..999)
return pr.parse_args(ARGV, patterns: [], ruby_s: Util.windows?)
end

View File

@ -70,7 +70,7 @@ module Cmdtest
@_clog = clog
@_runner = runner
@_work_dir = Workdir.new(self, runner)
@_cwd = self.tmp_work_dir
@_cwd = @_runner.tmp_work_dir
@_env = Hash.new
@_in_cmd = false
@_comment_str = nil
@ -78,24 +78,6 @@ module Cmdtest
@_t1 = @_t2 = 0
end
#------------------------------
def tmp_cmdtest_dir
File.join(ORIG_CWD, "tmp-cmdtest-%d" % [$cmdtest_level])
end
def tmp_dir
if @_runner.opts.parallel == 1
File.join(tmp_cmdtest_dir, "top")
else
File.join(tmp_cmdtest_dir, @_test_method.as_filename)
end
end
def tmp_work_dir
File.join(tmp_dir, "work")
end
#------------------------------
# Import file into the "workdir" from the outside world.
# The source is found relative to the current directory when "cmdtest"
@ -788,7 +770,7 @@ module Cmdtest
#------------------------------
def _wait_for_new_second
Util.wait_for_new_second(tmp_dir, tmp_work_dir)
Util.wait_for_new_second(@_runner.tmp_dir, @_runner.tmp_work_dir)
end
#------------------------------

View File

@ -33,8 +33,8 @@ module Cmdtest
def initialize(testcase, runner)
@testcase = testcase
@runner = runner
@path = @testcase.tmp_work_dir
@hardlinkdir = File.join(testcase.tmp_dir, "hardlinks")
@path = @runner.tmp_work_dir
@hardlinkdir = File.join(@runner.tmp_dir, "hardlinks")
FileUtils.rm_rf(@path)
FileUtils.rm_rf(@hardlinkdir)
FileUtils.mkdir_p(@path)
@ -64,7 +64,7 @@ module Cmdtest
end
def _tmp_redirect_sh
File.join(@testcase.tmp_dir,
File.join(@runner.tmp_dir,
Util.windows? ? "tmp-redirect.bat" : "tmp-redirect.sh")
end
@ -73,7 +73,7 @@ module Cmdtest
end
def _tmp_command_sh
File.join(@testcase.tmp_dir, _tmp_command_name)
File.join(@runner.tmp_dir, _tmp_command_name)
end
def _tmp_stdout_name
@ -85,11 +85,11 @@ module Cmdtest
end
def _tmp_stdout_log
File.join(@testcase.tmp_dir, _tmp_stdout_name)
File.join(@runner.tmp_dir, _tmp_stdout_name)
end
def _tmp_stderr_log
File.join(@testcase.tmp_dir, _tmp_stderr_name)
File.join(@runner.tmp_dir, _tmp_stderr_name)
end
def _ENV_strs(env)