[ruby/tmpdir] Test also TMP and TEMP environment variables

https://github.com/ruby/tmpdir/commit/414c00ebe6
This commit is contained in:
Nobuyoshi Nakada 2020-07-13 19:44:52 +09:00 committed by Hiroshi SHIBATA
parent 50bce2065d
commit f7f849e30c

View File

@ -15,8 +15,11 @@ class TestTmpdir < Test::Unit::TestCase
skip "no meaning on this platform" if /mswin|mingw/ =~ RUBY_PLATFORM skip "no meaning on this platform" if /mswin|mingw/ =~ RUBY_PLATFORM
Dir.mktmpdir do |tmpdir| Dir.mktmpdir do |tmpdir|
# ToDo: fix for parallel test # ToDo: fix for parallel test
olddir, ENV["TMPDIR"] = ENV["TMPDIR"], tmpdir envs = %w[TMPDIR TMP TEMP]
oldenv = envs.each_with_object({}) {|v, h| h[v] = ENV.delete(v)}
begin begin
envs.each do |e|
ENV[e] = tmpdir
assert_equal(tmpdir, Dir.tmpdir) assert_equal(tmpdir, Dir.tmpdir)
File.chmod(0777, tmpdir) File.chmod(0777, tmpdir)
assert_not_equal(tmpdir, Dir.tmpdir) assert_not_equal(tmpdir, Dir.tmpdir)
@ -28,8 +31,10 @@ class TestTmpdir < Test::Unit::TestCase
assert_file.not_exist?(newdir) assert_file.not_exist?(newdir)
File.chmod(01777, tmpdir) File.chmod(01777, tmpdir)
assert_equal(tmpdir, Dir.tmpdir) assert_equal(tmpdir, Dir.tmpdir)
ENV[e] = nil
end
ensure ensure
ENV["TMPDIR"] = olddir ENV.update(oldenv)
end end
end end
end end