From b0bbcc7a87c03c1127d55629d28aeff16e0426a4 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 6 Jul 2021 13:36:58 +0200 Subject: [PATCH] tests: Windows: run commands through explicit bash & temp shell script Makes some of the commands work on Windows where system is cmd.exe --- tests/test.d/simple_test.rb | 2 +- tests/test.d/test.rb | 5 ++++- tests/test.d/util.rb | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/test.d/simple_test.rb b/tests/test.d/simple_test.rb index 3980ce7a6..fbd8834fd 100644 --- a/tests/test.d/simple_test.rb +++ b/tests/test.d/simple_test.rb @@ -324,7 +324,7 @@ class SimpleTest puts "COMMAND #{command}" if ENV['DEBUG'] exit_code = 0 - if !system(command) + if !run_bash command exit_code = $? >> 8 self.error "system command failed: #{command} (#{exit_code})" if options[:exit_code] != exit_code end diff --git a/tests/test.d/test.rb b/tests/test.d/test.rb index fa7290b18..bc165e051 100644 --- a/tests/test.d/test.rb +++ b/tests/test.d/test.rb @@ -65,7 +65,10 @@ class Test command << " >/dev/null 2>/dev/null " unless (/>/.match(command)) puts "COMMAND #{command}" if ENV['DEBUG'] - error "system command failed: #{command} (" + ($? >> 8).to_s + ")" if !system(command) && ((arg.size == 0) || ((arg[0] << 8) != $?)) + + result = run_bash command + + error "system command failed: #{command} (" + ($? >> 8).to_s + ")" if !result && ((arg.size == 0) || ((arg[0] << 8) != $?)) end def tmp_name_prefix diff --git a/tests/test.d/util.rb b/tests/test.d/util.rb index d227e5c49..aa90da562 100644 --- a/tests/test.d/util.rb +++ b/tests/test.d/util.rb @@ -51,3 +51,15 @@ else `md5sum #{name}`.chomp.gsub(/\s+.*/, "") end end + +def run_bash command + return system command if !$is_windows + + cmd_file = Tempfile.new + cmd_file.write command + cmd_file.close + + FileUtils.chmod 0700, cmd_file.path + + system "bash -c #{cmd_file.path}" +end