mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Made method-local instance variables local variables
This commit is contained in:
parent
5c2ff88be2
commit
ea18c8bb96
1 changed files with 16 additions and 24 deletions
|
@ -88,60 +88,52 @@ class TestDir < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_chdir
|
def test_chdir
|
||||||
@pwd = Dir.pwd
|
pwd = Dir.pwd
|
||||||
@env_home = ENV["HOME"]
|
env_home = ENV["HOME"]
|
||||||
@env_logdir = ENV["LOGDIR"]
|
env_logdir = ENV["LOGDIR"]
|
||||||
ENV.delete("HOME")
|
ENV.delete("HOME")
|
||||||
ENV.delete("LOGDIR")
|
ENV.delete("LOGDIR")
|
||||||
|
|
||||||
assert_raise(Errno::ENOENT) { Dir.chdir(@nodir) }
|
assert_raise(Errno::ENOENT) { Dir.chdir(@nodir) }
|
||||||
assert_raise(ArgumentError) { Dir.chdir }
|
assert_raise(ArgumentError) { Dir.chdir }
|
||||||
ENV["HOME"] = @pwd
|
ENV["HOME"] = pwd
|
||||||
Dir.chdir do
|
Dir.chdir do
|
||||||
assert_equal(@pwd, Dir.pwd)
|
assert_equal(pwd, Dir.pwd)
|
||||||
assert_raise(RuntimeError) { Dir.chdir(@root) }
|
assert_raise(RuntimeError) { Dir.chdir(@root) }
|
||||||
assert_equal(@pwd, Dir.pwd)
|
assert_equal(pwd, Dir.pwd)
|
||||||
Dir.chdir(@root) do
|
Dir.chdir(@root) do
|
||||||
assert_equal(@root, Dir.pwd)
|
assert_equal(@root, Dir.pwd)
|
||||||
end
|
end
|
||||||
assert_equal(@pwd, Dir.pwd)
|
assert_equal(pwd, Dir.pwd)
|
||||||
end
|
end
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
begin
|
begin
|
||||||
Dir.chdir(@pwd)
|
Dir.chdir(pwd)
|
||||||
rescue
|
rescue
|
||||||
abort("cannot return the original directory: #{ @pwd }")
|
abort("cannot return the original directory: #{ pwd }")
|
||||||
end
|
|
||||||
if @env_home
|
|
||||||
ENV["HOME"] = @env_home
|
|
||||||
else
|
|
||||||
ENV.delete("HOME")
|
|
||||||
end
|
|
||||||
if @env_logdir
|
|
||||||
ENV["LOGDIR"] = @env_logdir
|
|
||||||
else
|
|
||||||
ENV.delete("LOGDIR")
|
|
||||||
end
|
end
|
||||||
|
ENV["HOME"] = env_home
|
||||||
|
ENV["LOGDIR"] = env_logdir
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_chdir_conflict
|
def test_chdir_conflict
|
||||||
@pwd = Dir.pwd
|
pwd = Dir.pwd
|
||||||
q = Queue.new
|
q = Queue.new
|
||||||
t = Thread.new do
|
t = Thread.new do
|
||||||
q.pop
|
q.pop
|
||||||
Dir.chdir(@pwd) rescue $!
|
Dir.chdir(pwd) rescue $!
|
||||||
end
|
end
|
||||||
Dir.chdir(@pwd) do
|
Dir.chdir(pwd) do
|
||||||
q.push nil
|
q.push nil
|
||||||
assert_instance_of(RuntimeError, t.value)
|
assert_instance_of(RuntimeError, t.value)
|
||||||
end
|
end
|
||||||
|
|
||||||
t = Thread.new do
|
t = Thread.new do
|
||||||
q.pop
|
q.pop
|
||||||
Dir.chdir(@pwd){} rescue $!
|
Dir.chdir(pwd){} rescue $!
|
||||||
end
|
end
|
||||||
Dir.chdir(@pwd) do
|
Dir.chdir(pwd) do
|
||||||
q.push nil
|
q.push nil
|
||||||
assert_instance_of(RuntimeError, t.value)
|
assert_instance_of(RuntimeError, t.value)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue