summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-26 03:08:10 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-26 03:08:10 +0000
commitb171d9204637e3790fce7bfb32fe9a54014d8301 (patch)
tree51e6ad07ad00e4aac1f1e2976b37d7585c07fecb /test
parent7f69d4e41f1cd77e142b786596dd005891a233f3 (diff)
Revert "parse.y: remove "shadowing outer local variable" warning"
I forgot to add the copyright of the patch... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/lib/test/unit/assertions.rb10
-rw-r--r--test/ripper/test_parser_events.rb7
-rw-r--r--test/ruby/test_parse.rb6
-rw-r--r--test/ruby/test_rubyoptions.rb14
4 files changed, 25 insertions, 12 deletions
diff --git a/test/lib/test/unit/assertions.rb b/test/lib/test/unit/assertions.rb
index dfa929a136..789e2d6c3d 100644
--- a/test/lib/test/unit/assertions.rb
+++ b/test/lib/test/unit/assertions.rb
@@ -693,16 +693,6 @@ eom
assert_warning(*args) {$VERBOSE = false; yield}
end
- def assert_no_warning(pat, msg = nil)
- stderr = EnvUtil.verbose_warning {
- EnvUtil.with_default_internal(pat.encoding) {
- yield
- }
- }
- msg = message(msg) {diff pat, stderr}
- refute(pat === stderr, msg)
- end
-
def assert_no_memory_leak(args, prepare, code, message=nil, limit: 2.0, rss: false, **opt)
# TODO: consider choosing some appropriate limit for MJIT and stop skipping this once it does not randomly fail
skip 'assert_no_memory_leak may consider MJIT memory usage as leak' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 95ec661fcf..a420bfbf81 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -1487,6 +1487,13 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
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_warning_ignored_magic_comment
fmt, *args = warning("1; #-*- frozen-string-literal: true -*-")
assert_match(/ignored after any tokens/, fmt)
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index c7aeeecb61..6160aa1452 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -911,8 +911,10 @@ x = __ENCODING__
assert_equal(expected, actual, bug5614)
end
- def test_no_shadowing_variable_warning
- assert_no_warning(/shadowing outer local variable/) {eval("a=1; tap {|a|}")}
+ def test_shadowing_variable
+ assert_warning(/shadowing outer local variable/) {eval("a=1; tap {|a|}")}
+ a = "\u{3042}"
+ assert_warning(/#{a}/o) {eval("#{a}=1; tap {|#{a}|}")}
end
def test_unused_variable
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index 69521b1d23..4a26d6bfc7 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -782,6 +782,20 @@ class TestRubyOptions < Test::Unit::TestCase
assert_in_out_err(["-w", "-"], "eval('a=1')", [], [], feature7730)
end
+ def test_shadowing_variable
+ bug4130 = '[ruby-dev:42718]'
+ assert_in_out_err(["-we", "def foo\n"" a=1\n"" 1.times do |a| end\n"" a\n""end"],
+ "", [], ["-e:3: warning: shadowing outer local variable - a"], bug4130)
+ assert_in_out_err(["-we", "def foo\n"" a=1\n"" 1.times do |a| end\n""end"],
+ "", [],
+ ["-e:3: warning: shadowing outer local variable - a",
+ "-e:2: warning: assigned but unused variable - a",
+ ], bug4130)
+ feature6693 = '[ruby-core:46160]'
+ assert_in_out_err(["-we", "def foo\n"" _a=1\n"" 1.times do |_a| end\n""end"],
+ "", [], [], feature6693)
+ end
+
def test_script_from_stdin
begin
require 'pty'