summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_argf.rb34
-rw-r--r--test/ruby/test_io.rb37
2 files changed, 65 insertions, 6 deletions
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index 7fb9348c1e..8243a6ed86 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -771,26 +771,54 @@ class TestArgf < Test::Unit::TestCase
assert_ruby_status(["-e", "2.times {STDIN.tty?; readlines}"], "", bug5952)
end
+ def test_lines
+ ruby('-W1', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ $stderr = $stdout
+ s = []
+ ARGF.lines {|l| s << l }
+ p s
+ SRC
+ assert_match(/deprecated/, f.gets)
+ assert_equal("[\"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\"]\n", f.read)
+ end
+ end
+
+ def test_lines
+ ruby('-W1', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ $stderr = $stdout
+ print Marshal.dump(ARGF.bytes.to_a)
+ SRC
+ assert_match(/deprecated/, f.gets)
+ assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
+ end
+ end
+
def test_bytes
- ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ ruby('-W1', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ $stderr = $stdout
print Marshal.dump(ARGF.bytes.to_a)
SRC
+ assert_match(/deprecated/, f.gets)
assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
end
end
def test_chars
- ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ ruby('-W1', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ $stderr = $stdout
print [Marshal.dump(ARGF.chars.to_a)].pack('m')
SRC
+ assert_match(/deprecated/, f.gets)
assert_equal(["1", "\n", "2", "\n", "3", "\n", "4", "\n", "5", "\n", "6", "\n"], Marshal.load(f.read.unpack('m').first))
end
end
def test_codepoints
- ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ ruby('-W1', '-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ $stderr = $stdout
print Marshal.dump(ARGF.codepoints.to_a)
SRC
+ assert_match(/deprecated/, f.gets)
assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
end
end
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index d509a9bfe2..0b3b5591e3 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -260,6 +260,19 @@ class TestIO < Test::Unit::TestCase
}
end
+ def test_codepoints
+ make_tempfile {|t|
+ bug2959 = '[ruby-core:28650]'
+ a = ""
+ File.open(t, 'rt') {|f|
+ assert_warn(/deprecated/) {
+ f.codepoints {|c| a << c}
+ }
+ }
+ assert_equal("foo\nbar\nbaz\n", a, bug2959)
+ }
+ end
+
def test_rubydev33072
t = make_tempfile
path = t.path
@@ -1303,21 +1316,28 @@ class TestIO < Test::Unit::TestCase
end
def test_lines
+ verbose, $VERBOSE = $VERBOSE, nil
pipe(proc do |w|
w.puts "foo"
w.puts "bar"
w.puts "baz"
w.close
end, proc do |r|
- e = r.lines
+ e = nil
+ assert_warn(/deprecated/) {
+ e = r.lines
+ }
assert_equal("foo\n", e.next)
assert_equal("bar\n", e.next)
assert_equal("baz\n", e.next)
assert_raise(StopIteration) { e.next }
end)
+ ensure
+ $VERBOSE = verbose
end
def test_bytes
+ verbose, $VERBOSE = $VERBOSE, nil
pipe(proc do |w|
w.binmode
w.puts "foo"
@@ -1325,27 +1345,38 @@ class TestIO < Test::Unit::TestCase
w.puts "baz"
w.close
end, proc do |r|
- e = r.bytes
+ e = nil
+ assert_warn(/deprecated/) {
+ e = r.bytes
+ }
(%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c|
assert_equal(c.ord, e.next)
end
assert_raise(StopIteration) { e.next }
end)
+ ensure
+ $VERBOSE = verbose
end
def test_chars
+ verbose, $VERBOSE = $VERBOSE, nil
pipe(proc do |w|
w.puts "foo"
w.puts "bar"
w.puts "baz"
w.close
end, proc do |r|
- e = r.chars
+ e = nil
+ assert_warn(/deprecated/) {
+ e = r.chars
+ }
(%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c|
assert_equal(c, e.next)
end
assert_raise(StopIteration) { e.next }
end)
+ ensure
+ $VERBOSE = verbose
end
def test_readbyte