mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
don't generate temporary files under current directory.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
228728325e
commit
a9c2a18cc7
8 changed files with 106 additions and 87 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
require 'scanf.rb'
|
||||
require 'test/unit'
|
||||
require 'tmpdir'
|
||||
|
||||
# Comment out either of these lines to skip those tests.
|
||||
|
||||
|
@ -295,15 +296,17 @@ end
|
|||
class TestIOScanf
|
||||
include Scanf
|
||||
extend ScanfTests
|
||||
|
||||
tmpfilename = "#{Dir.tmpdir}/iotest.dat"
|
||||
|
||||
i = 1
|
||||
self.tests.each do |test|
|
||||
define_method("test_#{i}") do ||
|
||||
File.open("iotest.dat", "w") {|fh| fh.print test[1]}
|
||||
File.open("iotest.dat", "r") { |fh|
|
||||
File.open(tmpfilename, "w") {|fh| fh.print test[1]}
|
||||
File.open(tmpfilename, "r") { |fh|
|
||||
assert_equal(test[2], fh.scanf(test[0]))
|
||||
}
|
||||
File.delete("iotest.dat")
|
||||
File.delete(tmpfilename)
|
||||
end
|
||||
i += 1
|
||||
end
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
require 'test/unit'
|
||||
require 'scanf'
|
||||
require 'tmpdir'
|
||||
|
||||
class TestScanfBlock < Test::Unit::TestCase
|
||||
|
||||
|
@ -49,8 +50,8 @@ alias set_up setup
|
|||
end
|
||||
|
||||
def test_io1
|
||||
File.open("iotest.dat", "w") { |fh| fh.puts(@str) }
|
||||
fh = File.open("iotest.dat", "rb")
|
||||
File.open("#{Dir.tmpdir}/iotest.dat", "w") { |fh| fh.puts(@str) }
|
||||
fh = File.open("#{Dir.tmpdir}/iotest.dat", "rb")
|
||||
res = fh.scanf("%s%d") { |name, year| "#{name} was born in #{year}." }
|
||||
|
||||
assert_equal(
|
||||
|
@ -61,18 +62,18 @@ alias set_up setup
|
|||
"Brahms was born in 1833." ],res)
|
||||
fh.close
|
||||
ensure
|
||||
File.delete("iotest.dat")
|
||||
File.delete("#{Dir.tmpdir}/iotest.dat")
|
||||
end
|
||||
|
||||
def test_io2
|
||||
File.open("iotest.dat", "w").close
|
||||
fh = File.open("iotest.dat","rb")
|
||||
File.open("#{Dir.tmpdir}/iotest.dat", "w").close
|
||||
fh = File.open("#{Dir.tmpdir}/iotest.dat","rb")
|
||||
assert_equal(fh.scanf("") {}, [])
|
||||
fh.seek(0)
|
||||
assert_equal(fh.scanf("%d%f%s") {}, [])
|
||||
fh.close
|
||||
ensure
|
||||
File.delete("iotest.dat")
|
||||
File.delete("#{Dir.tmpdir}/iotest.dat")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue