`close': Bad file descriptor - filename (Errno::EBADF)

While upgrading rubicon from 1.6 to 1.8, I bumped into
this problem in the builtin/TestIO.rb file.
http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests

I have extracted the code which reproduces the problem.
Any ideas on how to solve it, would be nice.

rm testtest
ruby a.rb
a.rb:5:in close': Bad file descriptor - testtest (Errno::EBADF) from a.rb:5:in open’
from a.rb:5
expand -t2 a.rb
file = “testtest”
File.open(file, “w”) do |f|
10.times { |i| f.printf “%02d: This is a line\n”, i }
end
File.open(file, “w”) do |f|
io = IO.new(f.fileno, “w”)
io << 1 << “\n” << “dummy” << “\n” << “cat\n”
io.close
end

···


Simon Strandgaard

Hi,

While upgrading rubicon from 1.6 to 1.8, I bumped into
this problem in the builtin/TestIO.rb file.
http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests

It’s a bug in rubicon. Try test suites bundled with 1.8.1 or later.

File.open(file, “w”) do |f|
io = IO.new(f.fileno, “w”)
io << 1 << “\n” << “dummy” << “\n” << “cat\n”
io.close <= close io here.
end <= open close io at the end of block (i.e. double close)

						matz.
···

In message “`close’: Bad file descriptor - filename (Errno::EBADF)” on 04/02/16, Simon Strandgaard neoneye@adslhome.dk writes:

While upgrading rubicon from 1.6 to 1.8, I bumped into
this problem in the builtin/TestIO.rb file.
http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests

It’s a bug in rubicon. Try test suites bundled with 1.8.1 or later.
[snip code]

Chad Fowler and I are working on upgrading rubicon for ruby-1.8.1.
We have made a transition from rubyunit to now use testunit.

I am working with the CVS version (I don’t think there is a newer rubicon
suite?) :wink:

You can see the pending bugs here:
http://rubyforge.org/tracker/?func=browse&group_id=179&atid=751
Please comment on these :slight_smile:

The code which I am looking at is

def test_LSHIFT # ‘<<’
File.open(@file, “w”) do |file|
io = IO.new(file.fileno, “w”)
io << 1 << “\n” << Dummy.new << “\n” << “cat\n”
io.close
end
expected = [ “1\n”, “dummy\n”, “cat\n”]
IO.foreach(@file) do |line|
assert_equal(expected.shift, line)
end
assert_equal(, expected)
end

Why make an instance of the IO class, when its the ‘<<’ leftshift
operator we want to test?

···

On Mon, 16 Feb 2004 22:51:36 +0900, Yukihiro Matsumoto wrote:

on 04/02/16, Simon Strandgaard <neoneye@adslhome.dk> writes:


Simon Strandgaard

Chad Fowler and I are working on upgrading rubicon for ruby-1.8.1.
We have made a transition from rubyunit to now use testunit.

You can see the pending bugs here:
http://rubyforge.org/tracker/?func=browse&group_id=179&atid=751
Please comment on these :slight_smile:

Ok I have one last problem with Bad File Descriptor.
The source code for TestIO.rb is here:
http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/rubicon/builtin/TestIO.rb?cvsroot=rubytests

ruby TestIO.rb
Loaded suite TestIO
Started
…S…E…S…S…
Finished in 0.833549 seconds.

  1. Error:
    test_closed?(TestIO):
    Errno::EBADF: Bad file descriptor - _test/_99lines
    TestIO.rb:19:in close' TestIO.rb:19:in open’
    TestIO.rb:19:in `setup’

53 tests, 1242 assertions, 0 failures, 1 errors

···

On Mon, 16 Feb 2004 17:02:50 +0100, Simon Strandgaard wrote:


Simon Strandgaard

[snip]

Solved… It was a typo I had made, writing ‘clone’ where I meant ‘close’.

Sorry for the noise.

···

On Mon, 16 Feb 2004 18:09:08 +0100, Simon Strandgaard wrote:

Ok I have one last problem with Bad File Descriptor.

Simon Strandgaard