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.
This commit is contained in:
KJ Tsanaktsidis 2024-08-09 10:35:54 +10:00 коммит произвёл Hiroshi SHIBATA
Родитель 5e3dd6d395
Коммит 927a44b43f
2 изменённых файлов: 7 добавлений и 2 удалений

Просмотреть файл

@ -7,5 +7,6 @@ Init_class(void)
{
VALUE mBug = rb_define_module("Bug");
VALUE mod = rb_define_module_under(mBug, "Class");
rb_define_class_under(mod, "TestClassDefinedInC", rb_cObject);
TEST_INIT_FUNCS(init);
}

Просмотреть файл

@ -721,9 +721,13 @@ class TestClass < Test::Unit::TestCase
assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}")
begin;
Date = (class C\u{1f5ff}; self; end).new
module Bug
module Class
TestClassDefinedInC = (class C\u{1f5ff}; self; end).new
end
end
assert_raise_with_message(TypeError, /C\u{1f5ff}/) {
require 'date'
require '-test-/class'
}
end;
end