Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cvar overtaken tests #4251

Merged
merged 1 commit into from
Mar 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions test/ruby/test_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,61 @@ def test_singleton_class_included_class_variable
assert_equal(1, o.singleton_class.class_variable_get(:@@foo))
end

def test_cvar_overtaken_by_parent_class
error = eval <<~EORB
class Parent
end

class Child < Parent
@@cvar = 1

def self.cvar
@@cvar
end
end

assert_equal 1, Child.cvar

class Parent
@@cvar = 2
end

assert_raise RuntimeError do
Child.cvar
end
EORB

assert_equal "class variable @@cvar of TestVariable::Child is overtaken by TestVariable::Parent", error.message
end

def test_cvar_overtaken_by_module
error = eval <<~EORB
class ParentForModule
@@cvar = 1

def self.cvar
@@cvar
end
end

assert_equal 1, ParentForModule.cvar

module Mixin
@@cvar = 2
end

class ParentForModule
include Mixin
end

assert_raise RuntimeError do
ParentForModule.cvar
end
EORB

assert_equal "class variable @@cvar of TestVariable::ParentForModule is overtaken by TestVariable::Mixin", error.message
end

class IncludeRefinedModuleClassVariableNoWarning
module Mod
@@_test_include_refined_module_class_variable = true
Expand Down