mirror of
https://github.com/ruby/ruby.git
synced 2025-09-22 03:53:58 +02:00
* pack.c (pack_pack): Warn when an invalid character is found in the
format string when $VERBOSE is true. [ruby-trunk - Feature #5219] * pack.c (pack_unpack): ditto * test/ruby/test_pack.rb (class TestPack): Test for warnings on invalid format characters. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
38ce9797c1
commit
6ba4bd5858
3 changed files with 47 additions and 0 deletions
|
@ -651,4 +651,39 @@ class TestPack < Test::Unit::TestCase
|
|||
assert_nil("".unpack("i") {|x| result = x}, bug4059)
|
||||
assert_equal(:ok, result)
|
||||
end
|
||||
|
||||
def test_pack_garbage
|
||||
assert_silent do
|
||||
assert_equal "\000", [0].pack("*U")
|
||||
end
|
||||
|
||||
verbose = $VERBOSE
|
||||
$VERBOSE = true
|
||||
|
||||
_, err = capture_io do
|
||||
assert_equal "\000", [0].pack("*U")
|
||||
end
|
||||
|
||||
assert_match %r%unknown pack directive '\*' in '\*U'$%, err
|
||||
ensure
|
||||
$VERBOSE = verbose
|
||||
end
|
||||
|
||||
def test_unpack_garbage
|
||||
assert_silent do
|
||||
assert_equal [0], "\000".unpack("*U")
|
||||
end
|
||||
|
||||
verbose = $VERBOSE
|
||||
$VERBOSE = true
|
||||
|
||||
_, err = capture_io do
|
||||
assert_equal [0], "\000".unpack("*U")
|
||||
end
|
||||
|
||||
assert_match %r%unknown unpack directive '\*' in '\*U'$%, err
|
||||
ensure
|
||||
$VERBOSE = verbose
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue