tests: don't hardcode path to temporary directory

This commit is contained in:
Moritz Bunkus 2021-07-06 19:05:15 +02:00
parent 0a96f4a19b
commit 15962e1b10
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85
3 changed files with 11 additions and 8 deletions

View File

@ -90,5 +90,8 @@ EOHELP
exit controller.num_failed > 0 ? 1 : 0 exit controller.num_failed > 0 ? 1 : 0
end end
setup Dir.mktmpdir do |dir|
main $temp_dir = dir
setup
main
end

View File

@ -67,7 +67,7 @@ class SimpleTest
end end
def tmp_name_prefix def tmp_name_prefix
[ "/tmp/mkvtoolnix-auto-test-#{self.class.name}", $$.to_s, Thread.current[:number] ].join("-") + "-" [ "#{$temp_dir}/mkvtoolnix-auto-test-#{self.class.name}", $$.to_s, Thread.current[:number] ].join("-") + "-"
end end
def tmp_name def tmp_name
@ -104,8 +104,8 @@ class SimpleTest
def unlink_tmp_files def unlink_tmp_files
return if ENV["KEEP_TMPFILES"] == "1" return if ENV["KEEP_TMPFILES"] == "1"
re = %r{^#{self.tmp_name_prefix}} re = %r{^#{self.tmp_name_prefix}}
Dir.entries("/tmp").each do |entry| Dir.entries($temp_dir).each do |entry|
file = "/tmp/#{entry}" file = "#{$temp_dir}/#{entry}"
File.unlink(file) if re.match(file) and File.exists?(file) File.unlink(file) if re.match(file) and File.exists?(file)
end end
end end

View File

@ -23,8 +23,8 @@ class Test
def unlink_tmp_files def unlink_tmp_files
return if (ENV["KEEP_TMPFILES"] == "1") return if (ENV["KEEP_TMPFILES"] == "1")
re = /^#{self.tmp_name_prefix}/ re = /^#{self.tmp_name_prefix}/
Dir.entries("/tmp").each do |entry| Dir.entries($temp_dir).each do |entry|
file = "/tmp/#{entry}" file = "#{$temp_dir}/#{entry}"
File.unlink(file) if re.match(file) and File.exists?(file) File.unlink(file) if re.match(file) and File.exists?(file)
end end
end end
@ -59,7 +59,7 @@ class Test
end end
def tmp_name_prefix def tmp_name_prefix
[ "/tmp/mkvtoolnix-auto-test", $$.to_s, Thread.current[:number] ].join("-") + "-" [ "#{$temp_dir}/mkvtoolnix-auto-test", $$.to_s, Thread.current[:number] ].join("-") + "-"
end end
def tmp_name def tmp_name