From e21f1875b770caed1dd04adaa1a0043d45cb59d7 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 14 Oct 2015 04:58:47 +0000 Subject: parse.y: fix ripper warnings * parse.y (parser_nextc): send a warning to ripper, not to STDERR always. * parse.y (rb_warn1, rb_warning1): move argument conversions to callers. PRIsVALUE is not valid in String#%. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ripper/test_parser_events.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/ripper/test_parser_events.rb') diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb index 46204bcec6..5ed17b6924 100644 --- a/test/ripper/test_parser_events.rb +++ b/test/ripper/test_parser_events.rb @@ -24,6 +24,14 @@ class TestRipper::ParserEvents < Test::Unit::TestCase parse(str, :compile_error) {|e, msg| return msg} end + def warning(str) + parse(str, :warning) {|e, *args| return args} + end + + def warn(str) + parse(str, :warn) {|e, *args| return args} + end + def test_program thru_program = false assert_equal '[void()]', parse('', :on_program) {thru_program = true} @@ -1261,4 +1269,17 @@ class TestRipper::ParserEvents < Test::Unit::TestCase assert_equal("`$%' is not allowed as a global variable name", compile_error('$%')) assert_equal("`$' without identifiers is not allowed as a global variable name", compile_error('$')) end + + def test_warning_shadowing + fmt, *args = warning("x = 1; tap {|;x|}") + assert_match(/shadowing outer local variable/, fmt) + assert_equal("x", args[0]) + assert_match(/x/, fmt % args) + end + + def test_warn_cr_in_middle + fmt = nil + assert_warn("") {fmt, *args = warn("\r;")} + assert_match(/encountered/, fmt) + end end if ripper_test -- cgit v1.2.3