summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-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
6 files changed, 81 insertions, 11 deletions
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