summaryrefslogtreecommitdiff
path: root/test/ruby/test_whileuntil.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-28 18:22:23 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-28 18:22:23 +0000
commit4dc8ff965bea4226c36acae8880dc359e05414dd (patch)
treec5a7e0786508c6cad0054210fb2a35cd47e2fc1e /test/ruby/test_whileuntil.rb
parenta9c2a18cc796fa59d5d696ef9d99d41b1149a242 (diff)
refine previous change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_whileuntil.rb')
-rw-r--r--test/ruby/test_whileuntil.rb110
1 files changed, 56 insertions, 54 deletions
diff --git a/test/ruby/test_whileuntil.rb b/test/ruby/test_whileuntil.rb
index 5e8ce4b211..df5bda450d 100644
--- a/test/ruby/test_whileuntil.rb
+++ b/test/ruby/test_whileuntil.rb
@@ -3,71 +3,73 @@ require 'tmpdir'
class TestWhileuntil < Test::Unit::TestCase
def test_while
- tmpfilename = "#{Dir.tmpdir}/ruby_while_tmp.#{$$}"
+ Dir.mktmpdir("ruby_while_tmp") {|tmpdir|
+ tmpfilename = "#{tmpdir}/ruby_while_tmp.#{$$}"
- tmp = open(tmpfilename, "w")
- tmp.print "tvi925\n";
- tmp.print "tvi920\n";
- tmp.print "vt100\n";
- tmp.print "Amiga\n";
- tmp.print "paper\n";
- tmp.close
+ tmp = open(tmpfilename, "w")
+ tmp.print "tvi925\n";
+ tmp.print "tvi920\n";
+ tmp.print "vt100\n";
+ tmp.print "Amiga\n";
+ tmp.print "paper\n";
+ tmp.close
- tmp = open(tmpfilename, "r")
- assert_instance_of(File, tmp)
-
- while line = tmp.gets()
- break if /vt100/ =~ line
- end
+ tmp = open(tmpfilename, "r")
+ assert_instance_of(File, tmp)
+
+ while line = tmp.gets()
+ break if /vt100/ =~ line
+ end
- assert(!tmp.eof?)
- assert_match(/vt100/, line)
- tmp.close
+ assert(!tmp.eof?)
+ assert_match(/vt100/, line)
+ tmp.close
- tmp = open(tmpfilename, "r")
- while line = tmp.gets()
- next if /vt100/ =~ line
+ tmp = open(tmpfilename, "r")
+ while line = tmp.gets()
+ next if /vt100/ =~ line
+ assert_no_match(/vt100/, line)
+ end
+ assert(tmp.eof?)
assert_no_match(/vt100/, line)
- end
- assert(tmp.eof?)
- assert_no_match(/vt100/, line)
- tmp.close
+ tmp.close
- tmp = open(tmpfilename, "r")
- while line = tmp.gets()
- lastline = line
- line = line.gsub(/vt100/, 'VT100')
- if lastline != line
- line.gsub!('VT100', 'Vt100')
- redo
+ tmp = open(tmpfilename, "r")
+ while line = tmp.gets()
+ lastline = line
+ line = line.gsub(/vt100/, 'VT100')
+ if lastline != line
+ line.gsub!('VT100', 'Vt100')
+ redo
+ end
+ assert_no_match(/vt100/, line)
+ assert_no_match(/VT100/, line)
end
- assert_no_match(/vt100/, line)
- assert_no_match(/VT100/, line)
- end
- assert(tmp.eof?)
- tmp.close
+ assert(tmp.eof?)
+ tmp.close
- sum=0
- for i in 1..10
- sum += i
- i -= 1
- if i > 0
- redo
+ sum=0
+ for i in 1..10
+ sum += i
+ i -= 1
+ if i > 0
+ redo
+ end
end
- end
- assert_equal(220, sum)
+ assert_equal(220, sum)
- tmp = open(tmpfilename, "r")
- while line = tmp.gets()
- break if 3
- assert_no_match(/vt100/, line)
- assert_no_match(/Amiga/, line)
- assert_no_match(/paper/, line)
- end
- tmp.close
+ tmp = open(tmpfilename, "r")
+ while line = tmp.gets()
+ break if 3
+ assert_no_match(/vt100/, line)
+ assert_no_match(/Amiga/, line)
+ assert_no_match(/paper/, line)
+ end
+ tmp.close
- File.unlink tmpfilename or `/bin/rm -f "#{tmpfilename}"`
- assert(!File.exist?(tmpfilename))
+ File.unlink tmpfilename or `/bin/rm -f "#{tmpfilename}"`
+ assert(!File.exist?(tmpfilename))
+ }
end
def test_until