summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-30 17:35:56 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-30 17:35:56 +0000
commit4af525b16a91625b2c18edefe66bf835f67de95a (patch)
treee74967f005aed18b0c2cbde830dc0df3a28f49f4 /test
parent5925c930a8120ac5033f513a22a891b0329b29b8 (diff)
merge revision(s) 51594: [Backport #11444]
* io.c (rb_io_each_codepoint): raise an exception at incomplete character before EOF when conversion takes place. [Bug #11444] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@52804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_io_m17n.rb51
1 files changed, 35 insertions, 16 deletions
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 17a427a12b..054aef4289 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -1,6 +1,7 @@
# coding: US-ASCII
require 'test/unit'
require 'tmpdir'
+require 'tempfile'
require 'timeout'
class TestIO_M17N < Test::Unit::TestCase
@@ -2565,22 +2566,40 @@ EOT
end
def test_each_codepoint_need_more
- code = <<-'end;'
- c = nil
- begin
- STDIN.set_encoding(Encoding::UTF_8).each_codepoint{|i| c = i}
- rescue ArgumentError => e
- STDERR.puts e.message
- else
- printf "%x", c
- end
- end;
- args = ['-e', code]
bug11444 = '[ruby-core:70379] [Bug #11444]'
- assert_in_out_err(args, "\u{1f376}".b[0,3], [],
- ["invalid byte sequence in UTF-8"],
- bug11444, timeout: 1)
- assert_in_out_err(args, "x"*8190+"\u{1f376}", ["1f376"], [],
- bug11444, timeout: 1)
+ tests = [
+ ["incomplete multibyte", "\u{1f376}".b[0,3], [], ["invalid byte sequence in UTF-8"]],
+ ["multibyte at boundary", "x"*8190+"\u{1f376}", ["1f376"], []],
+ ]
+ failure = []
+ ["bin", "text"].product(tests) do |mode, (test, data, out, err)|
+ code = <<-"end;"
+ c = nil
+ begin
+ open(ARGV[0], "r#{mode[0]}:utf-8") do |f|
+ f.each_codepoint{|i| c = i}
+ end
+ rescue ArgumentError => e
+ STDERR.puts e.message
+ else
+ printf "%x", c
+ end
+ end;
+ Tempfile.create("codepoint") do |f|
+ args = ['-e', code, f.path]
+ f.print data
+ f.close
+ begin
+ assert_in_out_err(args, "", out, err,
+ "#{bug11444}: #{test} in #{mode} mode",
+ timeout: 1)
+ rescue Exception => e
+ failure << e
+ end
+ end
+ end
+ unless failure.empty?
+ flunk failure.join("\n---\n")
+ end
end
end