[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 коммит произвёл Hiroshi SHIBATA
Родитель 50bce2065d
Коммит f7f849e30c
1 изменённых файлов: 17 добавлений и 12 удалений

Просмотреть файл

@ -15,21 +15,26 @@ class TestTmpdir < Test::Unit::TestCase
skip "no meaning on this platform" if /mswin|mingw/ =~ RUBY_PLATFORM
Dir.mktmpdir do |tmpdir|
# 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
assert_equal(tmpdir, Dir.tmpdir)
File.chmod(0777, tmpdir)
assert_not_equal(tmpdir, Dir.tmpdir)
newdir = Dir.mktmpdir("d", tmpdir) do |dir|
assert_file.directory? dir
assert_equal(tmpdir, File.dirname(dir))
dir
envs.each do |e|
ENV[e] = tmpdir
assert_equal(tmpdir, Dir.tmpdir)
File.chmod(0777, tmpdir)
assert_not_equal(tmpdir, Dir.tmpdir)
newdir = Dir.mktmpdir("d", tmpdir) do |dir|
assert_file.directory? dir
assert_equal(tmpdir, File.dirname(dir))
dir
end
assert_file.not_exist?(newdir)
File.chmod(01777, tmpdir)
assert_equal(tmpdir, Dir.tmpdir)
ENV[e] = nil
end
assert_file.not_exist?(newdir)
File.chmod(01777, tmpdir)
assert_equal(tmpdir, Dir.tmpdir)
ensure
ENV["TMPDIR"] = olddir
ENV.update(oldenv)
end
end
end