From 927a44b43f1db2527a4fe6709ec0867dea3ca58f Mon Sep 17 00:00:00 2001 From: KJ Tsanaktsidis Date: Fri, 9 Aug 2024 10:35:54 +1000 Subject: [PATCH] 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. --- ext/-test-/class/init.c | 1 + test/ruby/test_class.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/-test-/class/init.c b/ext/-test-/class/init.c index ed715c1942..108ff7525c 100644 --- a/ext/-test-/class/init.c +++ b/ext/-test-/class/init.c @@ -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); } diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 38a6e9eb9f..456362ef21 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -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