tests: Windows: run commands through explicit bash & temp shell script

Makes some of the commands work on Windows where system is cmd.exe
This commit is contained in:
Moritz Bunkus 2021-07-06 13:36:58 +02:00
parent f681458bfc
commit b0bbcc7a87
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85
3 changed files with 17 additions and 2 deletions

View File

@ -324,7 +324,7 @@ class SimpleTest
puts "COMMAND #{command}" if ENV['DEBUG'] puts "COMMAND #{command}" if ENV['DEBUG']
exit_code = 0 exit_code = 0
if !system(command) if !run_bash command
exit_code = $? >> 8 exit_code = $? >> 8
self.error "system command failed: #{command} (#{exit_code})" if options[:exit_code] != exit_code self.error "system command failed: #{command} (#{exit_code})" if options[:exit_code] != exit_code
end end

View File

@ -65,7 +65,10 @@ class Test
command << " >/dev/null 2>/dev/null " unless (/>/.match(command)) command << " >/dev/null 2>/dev/null " unless (/>/.match(command))
puts "COMMAND #{command}" if ENV['DEBUG'] 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 end
def tmp_name_prefix def tmp_name_prefix

View File

@ -51,3 +51,15 @@ else
`md5sum #{name}`.chomp.gsub(/\s+.*/, "") `md5sum #{name}`.chomp.gsub(/\s+.*/, "")
end end
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