From b82c90232cc9c82a9b87e2290624db0a084e4cbe Mon Sep 17 00:00:00 2001 From: Johan Holmberg Date: Sat, 8 Aug 2015 00:26:17 +0200 Subject: [PATCH] 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. --- bin/cmdtest.rb | 23 +++++++++++++++++++++++ lib/cmdtest/testcase.rb | 22 ++-------------------- lib/cmdtest/workdir.rb | 12 ++++++------ 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/bin/cmdtest.rb b/bin/cmdtest.rb index 7278115..17410e8 100755 --- a/bin/cmdtest.rb +++ b/bin/cmdtest.rb @@ -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 diff --git a/lib/cmdtest/testcase.rb b/lib/cmdtest/testcase.rb index 344eaf4..61045f0 100644 --- a/lib/cmdtest/testcase.rb +++ b/lib/cmdtest/testcase.rb @@ -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 #------------------------------ diff --git a/lib/cmdtest/workdir.rb b/lib/cmdtest/workdir.rb index ef5103c..214b96b 100644 --- a/lib/cmdtest/workdir.rb +++ b/lib/cmdtest/workdir.rb @@ -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)