From 1e6e3ca0a2fa2a728807a975e1f9ecee93fcd4c9 Mon Sep 17 00:00:00 2001 From: Johan Holmberg Date: Fri, 22 Nov 2013 01:36:50 +0100 Subject: [PATCH] handle current directory containing spaces --- lib/cmdtest/util.rb | 5 +++++ lib/cmdtest/workdir.rb | 17 +++++++++++------ t/selftest_utils.rb | 8 +++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/cmdtest/util.rb b/lib/cmdtest/util.rb index ed27e35..8528752 100644 --- a/lib/cmdtest/util.rb +++ b/lib/cmdtest/util.rb @@ -53,6 +53,11 @@ module Cmdtest return tnew end + def self.quote_path(str) + needed = (str =~ /[^a-zA-Z0-9_]/) + return needed ? '"' + str.gsub('"', '\"') + '"' : str + end + def self.windows? RUBY_PLATFORM =~ /mswin32|mingw32/ end diff --git a/lib/cmdtest/workdir.rb b/lib/cmdtest/workdir.rb index 68f2da4..2428d57 100644 --- a/lib/cmdtest/workdir.rb +++ b/lib/cmdtest/workdir.rb @@ -21,6 +21,7 @@ require "cmdtest/fssnapshot" require "cmdtest/cmdeffects" +require "cmdtest/util" require "fileutils" @@ -80,14 +81,14 @@ module Cmdtest end def _chdir_str(dir) - "cd #{dir}" + "cd %s" % _quote(dir) end def _set_env_path_str(env_path) if Util.windows? "set path=" + env_path.join(";") else - "export PATH=" + env_path.join(":") + "export PATH=" + _quote(env_path.join(":")) end end @@ -103,6 +104,10 @@ module Cmdtest end end + def _quote(str) + return Cmdtest::Util::quote_path(str) + end + def run_cmd(cmdline, env_path) File.open(_tmp_command_sh, "w") do |f| f.puts _ENV_strs(@testcase._env) @@ -111,10 +116,10 @@ module Cmdtest f.puts _ruby_S(cmdline) end str = "%s %s > %s 2> %s" % [ - _shell, - _tmp_command_sh, - _tmp_stdout_log, - _tmp_stderr_log, + _quote(_shell), + _quote(_tmp_command_sh), + _quote(_tmp_stdout_log), + _quote(_tmp_stderr_log), ] before = _take_snapshot ok = system(str) diff --git a/t/selftest_utils.rb b/t/selftest_utils.rb index e6a323b..1e3e912 100644 --- a/t/selftest_utils.rb +++ b/t/selftest_utils.rb @@ -36,8 +36,14 @@ module SelftestUtils ] end + def _quote(str) + return Cmdtest::Util::quote_path(str) + end + def cmd_cmdtest(*args) - cmd("ruby #{TOP}/bin/cmdtest.rb --quiet", *args) do + cmdtest = "#{TOP}/bin/cmdtest.rb" + command = "ruby %s --quiet" % _quote(cmdtest) + cmd(command, *args) do comment "running local cmdtest" yield end