Skip to content

Commit 8c90f7b

Browse files
authored
Merge pull request #3 from nobu/tmpdir-tests
Tmpdir tests
2 parents b08fec4 + 84684d8 commit 8c90f7b

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

test/test_tmpdir.rb

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class TestTmpdir < Test::Unit::TestCase
66
def test_tmpdir_modifiable
77
tmpdir = Dir.tmpdir
8-
assert_equal(false, tmpdir.frozen?)
8+
assert_not_predicate(tmpdir, :frozen?)
99
tmpdir_org = tmpdir.dup
1010
tmpdir << "foo"
1111
assert_equal(tmpdir_org, Dir.tmpdir)
@@ -15,21 +15,34 @@ def test_world_writable
1515
skip "no meaning on this platform" if /mswin|mingw/ =~ RUBY_PLATFORM
1616
Dir.mktmpdir do |tmpdir|
1717
# ToDo: fix for parallel test
18-
olddir, ENV["TMPDIR"] = ENV["TMPDIR"], tmpdir
18+
envs = %w[TMPDIR TMP TEMP]
19+
oldenv = envs.each_with_object({}) {|v, h| h[v] = ENV.delete(v)}
1920
begin
20-
assert_equal(tmpdir, Dir.tmpdir)
21-
File.chmod(0777, tmpdir)
22-
assert_not_equal(tmpdir, Dir.tmpdir)
23-
newdir = Dir.mktmpdir("d", tmpdir) do |dir|
24-
assert_file.directory? dir
25-
assert_equal(tmpdir, File.dirname(dir))
26-
dir
21+
envs.each do |e|
22+
tmpdirx = File.join(tmpdir, e)
23+
ENV[e] = tmpdirx
24+
assert_not_equal(tmpdirx, Dir.tmpdir)
25+
File.write(tmpdirx, "")
26+
assert_not_equal(tmpdirx, Dir.tmpdir)
27+
File.unlink(tmpdirx)
28+
ENV[e] = tmpdir
29+
assert_equal(tmpdir, Dir.tmpdir)
30+
File.chmod(0555, tmpdir)
31+
assert_not_equal(tmpdir, Dir.tmpdir)
32+
File.chmod(0777, tmpdir)
33+
assert_not_equal(tmpdir, Dir.tmpdir)
34+
newdir = Dir.mktmpdir("d", tmpdir) do |dir|
35+
assert_file.directory? dir
36+
assert_equal(tmpdir, File.dirname(dir))
37+
dir
38+
end
39+
assert_file.not_exist?(newdir)
40+
File.chmod(01777, tmpdir)
41+
assert_equal(tmpdir, Dir.tmpdir)
42+
ENV[e] = nil
2743
end
28-
assert_file.not_exist?(newdir)
29-
File.chmod(01777, tmpdir)
30-
assert_equal(tmpdir, Dir.tmpdir)
3144
ensure
32-
ENV["TMPDIR"] = olddir
45+
ENV.update(oldenv)
3346
end
3447
end
3548
end

0 commit comments

Comments
 (0)