mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
7fbf13f7f2
* test/ruby/ut_eof.rb, test/ruby/test_file.rb, test/ruby/test_pipe.rb, test/stringio/test_stringio.rb: add EOF test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
43 lines
888 B
Ruby
43 lines
888 B
Ruby
require 'test/unit'
|
|
require 'tempfile'
|
|
$:.replace([File.dirname(File.expand_path(__FILE__))] | $:)
|
|
require 'ut_eof'
|
|
|
|
$KCODE = 'none'
|
|
|
|
class TestFile < Test::Unit::TestCase
|
|
|
|
# I don't know Ruby's spec about "unlink-before-close" exactly.
|
|
# This test asserts current behaviour.
|
|
def test_unlink_before_close
|
|
filename = File.basename(__FILE__) + ".#{$$}"
|
|
w = File.open(filename, "w")
|
|
w << "foo"
|
|
w.close
|
|
r = File.open(filename, "r")
|
|
begin
|
|
if /(mswin|bccwin|mingw|emx)/ =~ RUBY_PLATFORM
|
|
begin
|
|
File.unlink(filename)
|
|
assert(false)
|
|
rescue Errno::EACCES
|
|
assert(true)
|
|
end
|
|
else
|
|
File.unlink(filename)
|
|
assert(true)
|
|
end
|
|
ensure
|
|
r.close
|
|
File.unlink(filename) if File.exist?(filename)
|
|
end
|
|
end
|
|
|
|
include TestEOF
|
|
def open_file(content)
|
|
f = Tempfile.new("test-eof")
|
|
f << content
|
|
f.rewind
|
|
yield f
|
|
end
|
|
end
|