summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-08-24 17:11:06 -0700
committerJeremy Evans <code@jeremyevans.net>2019-10-16 12:50:40 -0700
commit2993b24a1ecc5fa3cc9f140bfd80669c3a3b7b9c (patch)
treea7a4720d0dd5232fdf1ebd3fcf809ad6d9066eec /test/ruby
parentdb84123600a2112063441dec4411ab5af6c3a78e (diff)
Warn for calling public/protected/private/module_function without arguments inside method
Calling these methods without an argument does not have the desired effect inside a method. Fixes [Bug #13249]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2562
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_class.rb42
-rw-r--r--test/ruby/test_module.rb11
2 files changed, 53 insertions, 0 deletions
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb
index 6960ab5971..407b0aa4b8 100644
--- a/test/ruby/test_class.rb
+++ b/test/ruby/test_class.rb
@@ -131,6 +131,48 @@ class TestClass < Test::Unit::TestCase
[:module_function, :extend_object, :append_features, :prepend_features])
end
+ def test_visibility_inside_method
+ assert_warn(/calling private without arguments inside a method may not have the intended effect/, '[ruby-core:79751]') do
+ Class.new do
+ def self.foo
+ private
+ end
+ foo
+ end
+ end
+
+ assert_warn(/calling protected without arguments inside a method may not have the intended effect/, '[ruby-core:79751]') do
+ Class.new do
+ def self.foo
+ protected
+ end
+ foo
+ end
+ end
+
+ assert_warn(/calling public without arguments inside a method may not have the intended effect/, '[ruby-core:79751]') do
+ Class.new do
+ def self.foo
+ public
+ end
+ foo
+ end
+ end
+
+ assert_warn(/calling private without arguments inside a method may not have the intended effect/, '[ruby-core:79751]') do
+ Class.new do
+ class << self
+ alias priv private
+ end
+
+ def self.foo
+ priv
+ end
+ foo
+ end
+ end
+ end
+
def test_method_redefinition
feature2155 = '[ruby-dev:39400]'
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 8b95ecedc4..79f7965623 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -1394,6 +1394,17 @@ class TestModule < Test::Unit::TestCase
assert_match(/: warning: previous definition of foo/, stderr)
end
+ def test_module_function_inside_method
+ assert_warn(/calling module_function without arguments inside a method may not have the intended effect/, '[ruby-core:79751]') do
+ Module.new do
+ def self.foo
+ module_function
+ end
+ foo
+ end
+ end
+ end
+
def test_protected_singleton_method
klass = Class.new
x = klass.new