summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--ext/stringio/stringio.c6
-rw-r--r--test/ruby/test_beginendblock.rb2
-rw-r--r--test/ruby/test_file.rb11
-rw-r--r--test/ruby/test_pipe.rb14
-rw-r--r--test/ruby/test_system.rb2
-rw-r--r--test/ruby/ut_eof.rb46
-rw-r--r--test/stringio/test_stringio.rb17
8 files changed, 93 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 1e8418d517..b6bc740afe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Dec 5 11:54:45 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/stringio/stringio.c (strio_read): follow IO#read.
+
+ * test/ruby/ut_eof.rb, test/ruby/test_file.rb, test/ruby/test_pipe.rb,
+ test/stringio/test_stringio.rb: add EOF test.
+
Fri Dec 5 02:49:35 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/test/unit/assertions.rb (Test::Unit::Assertions::assert_raises):
@@ -15,7 +22,7 @@ Thu Dec 4 23:32:26 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (read_all): do not depend on lseek position.
[ruby-dev:22026]
-
+
Thu Dec 4 22:37:26 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_eval): preserve $! value when retry happens in the
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 0fb60069de..725b5be192 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -866,10 +866,12 @@ strio_read(argc, argv, self)
rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc);
}
str = rb_str_substr(ptr->string, ptr->pos, len);
- if (len > 0 &&
- (NIL_P(str) || (ptr->pos += RSTRING(str)->len) >= RSTRING(ptr->string)->len)) {
+ if (NIL_P(str)) {
ptr->flags |= STRIO_EOF;
}
+ else {
+ ptr->pos += RSTRING(str)->len;
+ }
return str;
}
diff --git a/test/ruby/test_beginendblock.rb b/test/ruby/test_beginendblock.rb
index e8d25a102d..b56b596a65 100644
--- a/test/ruby/test_beginendblock.rb
+++ b/test/ruby/test_beginendblock.rb
@@ -1,6 +1,6 @@
require 'test/unit'
require 'tempfile'
-$:.unshift(File.dirname(File.expand_path(__FILE__)))
+$:.replace([File.dirname(File.expand_path(__FILE__))] | $:)
require 'envutil'
class TestBeginEndBlock < Test::Unit::TestCase
diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb
index 0d0ea389a4..f51e55f0c6 100644
--- a/test/ruby/test_file.rb
+++ b/test/ruby/test_file.rb
@@ -1,4 +1,7 @@
require 'test/unit'
+require 'tempfile'
+$:.replace([File.dirname(File.expand_path(__FILE__))] | $:)
+require 'ut_eof'
$KCODE = 'none'
@@ -29,4 +32,12 @@ class TestFile < Test::Unit::TestCase
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
diff --git a/test/ruby/test_pipe.rb b/test/ruby/test_pipe.rb
new file mode 100644
index 0000000000..a6363ef78b
--- /dev/null
+++ b/test/ruby/test_pipe.rb
@@ -0,0 +1,14 @@
+require 'test/unit'
+$:.replace([File.dirname(File.expand_path(__FILE__))] | $:)
+require 'ut_eof'
+require 'envutil'
+
+$KCODE = 'none'
+
+class TestPipe < Test::Unit::TestCase
+ include TestEOF
+ def open_file(content)
+ f = IO.popen("echo -n #{content}")
+ yield f
+ end
+end
diff --git a/test/ruby/test_system.rb b/test/ruby/test_system.rb
index ed7f8b8fd1..d756e4a2d5 100644
--- a/test/ruby/test_system.rb
+++ b/test/ruby/test_system.rb
@@ -1,5 +1,5 @@
require 'test/unit'
-$:.unshift(File.dirname(File.expand_path(__FILE__)))
+$:.replace([File.dirname(File.expand_path(__FILE__))] | $:)
require 'envutil'
$KCODE = 'none'
diff --git a/test/ruby/ut_eof.rb b/test/ruby/ut_eof.rb
new file mode 100644
index 0000000000..d1ad9a5fea
--- /dev/null
+++ b/test/ruby/ut_eof.rb
@@ -0,0 +1,46 @@
+require 'test/unit'
+
+module TestEOF
+ def test_eof_0
+ open_file("") {|f|
+ assert_equal("", f.read(0))
+ assert_equal("", f.read(0))
+ assert_equal("", f.read)
+ assert_equal(nil, f.read(0))
+ assert_equal(nil, f.read(0))
+ }
+ open_file("") {|f|
+ assert_equal(nil, f.read(1))
+ assert_equal(nil, f.read)
+ assert_equal(nil, f.read(1))
+ }
+ end
+
+ def test_eof_1
+ open_file("a") {|f|
+ assert_equal("", f.read(0))
+ assert_equal("a", f.read(1))
+ assert_equal("" , f.read(0))
+ assert_equal("" , f.read(0))
+ assert_equal("", f.read)
+ assert_equal(nil, f.read(0))
+ assert_equal(nil, f.read(0))
+ }
+ open_file("a") {|f|
+ assert_equal("a", f.read(1))
+ assert_equal(nil, f.read(1))
+ }
+ open_file("a") {|f|
+ assert_equal("a", f.read(2))
+ assert_equal(nil, f.read(1))
+ assert_equal(nil, f.read)
+ assert_equal(nil, f.read(1))
+ }
+ open_file("a") {|f|
+ assert_equal("a", f.read)
+ assert_equal(nil, f.read(1))
+ assert_equal(nil, f.read)
+ assert_equal(nil, f.read(1))
+ }
+ end
+end
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index 10390fc6da..3449e33e61 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -1,15 +1,14 @@
require 'test/unit'
require 'stringio'
+dir = File.expand_path(__FILE__)
+2.times {dir = File.dirname(dir)}
+$:.replace([File.join(dir, "ruby")] | $:)
+require 'ut_eof'
class TestStringIO < Test::Unit::TestCase
- def test_empty_file
- f = StringIO.new("")
- assert_equal("", f.read(0))
- assert_equal("", f.read)
- assert_equal(nil, f.read(0))
- f = StringIO.new("")
- assert_equal(nil, f.read(1))
- assert_equal(nil, f.read)
- assert_equal(nil, f.read(1))
+ include TestEOF
+ def open_file(content)
+ f = StringIO.new(content)
+ yield f
end
end