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
end
setup
main
Dir.mktmpdir do |dir|
$temp_dir = dir
setup
main
end

View File

@ -67,7 +67,7 @@ class SimpleTest
end
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
def tmp_name
@ -104,8 +104,8 @@ class SimpleTest
def unlink_tmp_files
return if ENV["KEEP_TMPFILES"] == "1"
re = %r{^#{self.tmp_name_prefix}}
Dir.entries("/tmp").each do |entry|
file = "/tmp/#{entry}"
Dir.entries($temp_dir).each do |entry|
file = "#{$temp_dir}/#{entry}"
File.unlink(file) if re.match(file) and File.exists?(file)
end
end

View File

@ -23,8 +23,8 @@ class Test
def unlink_tmp_files
return if (ENV["KEEP_TMPFILES"] == "1")
re = /^#{self.tmp_name_prefix}/
Dir.entries("/tmp").each do |entry|
file = "/tmp/#{entry}"
Dir.entries($temp_dir).each do |entry|
file = "#{$temp_dir}/#{entry}"
File.unlink(file) if re.match(file) and File.exists?(file)
end
end
@ -59,7 +59,7 @@ class Test
end
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
def tmp_name