summaryrefslogtreecommitdiff
path: root/test/test_tmpdir.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-07-13 19:44:52 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-09-14 18:21:59 +0900
commitf7f849e30cbf462e521b0843a9bb2cbea1bd4d11 (patch)
tree8f5dd985cb4f713834429737fc3ed361e76e4d3e /test/test_tmpdir.rb
parent50bce2065d5376b38a6eef86ab5c3df809db4787 (diff)
[ruby/tmpdir] Test also TMP and TEMP environment variables
https://github.com/ruby/tmpdir/commit/414c00ebe6
Diffstat (limited to 'test/test_tmpdir.rb')
-rw-r--r--test/test_tmpdir.rb29
1 files changed, 17 insertions, 12 deletions
diff --git a/test/test_tmpdir.rb b/test/test_tmpdir.rb
index 5cd0b5e..039b5be 100644
--- a/test/test_tmpdir.rb
+++ b/test/test_tmpdir.rb
@@ -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