Skip to content

Commit 927a44b

Browse files
KJTsanaktsidishsbt
authored andcommitted
Rewrite #test_redefinition_mismatch to use a dedicated test class
This test is checking what happens if you try and define a class in a C extension where that constant is already not a class. It was doing this by overriding ::Date and then trying to require 'date. The issue with this is that if we ever add 'date' as a dependency for the test runner, this test will break because the test runner files get implicitly required in an `assert_separately` block. Better use an explicit class for this purpose which can't be accidentally required elsewhere.
1 parent 5e3dd6d commit 927a44b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ext/-test-/class/init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ Init_class(void)
77
{
88
VALUE mBug = rb_define_module("Bug");
99
VALUE mod = rb_define_module_under(mBug, "Class");
10+
rb_define_class_under(mod, "TestClassDefinedInC", rb_cObject);
1011
TEST_INIT_FUNCS(init);
1112
}

test/ruby/test_class.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,13 @@ def test_redefinition_mismatch
721721

722722
assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}")
723723
begin;
724-
Date = (class C\u{1f5ff}; self; end).new
724+
module Bug
725+
module Class
726+
TestClassDefinedInC = (class C\u{1f5ff}; self; end).new
727+
end
728+
end
725729
assert_raise_with_message(TypeError, /C\u{1f5ff}/) {
726-
require 'date'
730+
require '-test-/class'
727731
}
728732
end;
729733
end

0 commit comments

Comments
 (0)