From 261db9d88a559a02cd447f93ed20fdf091024477 Mon Sep 17 00:00:00 2001 From: ksss Date: Sat, 10 Oct 2026 14:03:53 +0900 Subject: [PATCH] Remove test/stdlib assertions that do not depend on RBS signatures Tests under test/stdlib exist to detect mismatches between RBS signatures and the actual behavior. Assertions that keep passing even when the corresponding RBS definition is broken only re-test Ruby itself. * Kernel: remove `test_exit!` (checks subprocess exit status only) and the `assert_equal nil, eval('__dir__')` line (the nil path cannot go through `assert_send_type` because the spy is always the caller frame). * Exception: remove redundant `assert_instance_of`. * OpenSSL: rename dead `encrypt_decrypt` to `test_encrypt_decrypt` so it runs (it is the only coverage of `Cipher#padding=`), dropping the plaintext round-trip `assert_equal`. * Regexp: remove `test_TimeoutError`, which only checked Ruby's superclass. * Refinement: check `import_methods` with `refute_send_type` instead of `assert(true)`. Calling it with modules through the spy crashes the VM. * global_variables: make `assert_global_type` also check the value against the RBS global declaration, and fix `$\` test which passed the value instead of the symbol and so never tested `$\`. Co-Authored-By: Claude Opus 5.5 --- test/stdlib/Exception_test.rb | 1 - test/stdlib/Kernel_test.rb | 36 ---------------------------- test/stdlib/OpenSSL_test.rb | 3 +-- test/stdlib/Refinement_test.rb | 23 ++++++------------ test/stdlib/Regexp_test.rb | 4 ---- test/stdlib/global_variables_test.rb | 19 ++++----------- 6 files changed, 12 insertions(+), 74 deletions(-) diff --git a/test/stdlib/Exception_test.rb b/test/stdlib/Exception_test.rb index 61b2fd9ee9..fa6ce91b20 100644 --- a/test/stdlib/Exception_test.rb +++ b/test/stdlib/Exception_test.rb @@ -136,7 +136,6 @@ def test_set_backtrace if_ruby("3.4"..., skip: false) do caller_locations[0].tap do |location| - assert_instance_of Thread::Backtrace::Location, location assert_send_type( "(Array[Thread::Backtrace::Location]) -> Array[Thread::Backtrace::Location]", exception, :set_backtrace, [location] diff --git a/test/stdlib/Kernel_test.rb b/test/stdlib/Kernel_test.rb index aac6ed772b..547feee49e 100644 --- a/test/stdlib/Kernel_test.rb +++ b/test/stdlib/Kernel_test.rb @@ -107,38 +107,6 @@ def test_exit end end - def test_exit! - # Sadly can't use `assert_send_type_error`, so we use exit status to check. - _, status = Process.wait2(Process.spawn(RUBY_EXECUTABLE, '--disable=all', '-e', 'exit!; exit(80)')) - assert_equal 1, status.exitstatus - - _, status = Process.wait2(Process.spawn(RUBY_EXECUTABLE, '--disable=all', '-e', 'exit!(true); exit(80)')) - assert_equal 0, status.exitstatus - - _, status = Process.wait2(Process.spawn(RUBY_EXECUTABLE, '--disable=all', '-e', 'exit!(false); exit(80)')) - assert_equal 1, status.exitstatus - - _, status = Process.wait2(Process.spawn(RUBY_EXECUTABLE, '--disable=all', '-e', 'exit!(12); exit(80)')) - assert_equal 12, status.exitstatus - - _, status = Process.wait2(Process.spawn(RUBY_EXECUTABLE, '--disable=all', '-e', <<~'RUBY')) - # hardcode a "blank slate" object in - class ToInt < BasicObject - instance_methods.each do |im| - next if im == :__id__ - next if im == :__send__ - undef_method im - end - - def to_int = 12 - end - - exit!(ToInt.new) - exit(80) - RUBY - assert_equal 12, status.exitstatus - end - def test_at_exit assert_send_type "() { () -> void } -> Proc", Kernel, :at_exit do end @@ -183,10 +151,6 @@ def test___method__ def test___dir__ assert_send_type '() -> String', Kernel, :__dir__ - - # Make sure it can return `nil`; this can't go through `assert_send_type`, - # as it's only `nil` thru `eval`s - assert_equal nil, eval('__dir__') end def test_autoload diff --git a/test/stdlib/OpenSSL_test.rb b/test/stdlib/OpenSSL_test.rb index e018deb4e3..9a9b259795 100644 --- a/test/stdlib/OpenSSL_test.rb +++ b/test/stdlib/OpenSSL_test.rb @@ -316,7 +316,7 @@ class OpenSSLCipherTest < Test::Unit::TestCase library "openssl" testing "::OpenSSL::Cipher" - def encrypt_decrypt + def test_encrypt_decrypt key = ["2b7e151628aed2a6abf7158809cf4f3c"].pack("H*") iv = ["000102030405060708090a0b0c0d0e0f"].pack("H*") pt = ["6bc1bee22e409f96e93d7e117393172a" \ @@ -329,7 +329,6 @@ def encrypt_decrypt assert_send_type "() -> String", cipher, :final cipher = new_decryptor("aes-128-cbc", key: key, iv: iv, padding: 0) - assert_equal pt, cipher.update(ct) << cipher.final assert_send_type "(String) -> String", cipher, :update, ct assert_send_type "() -> String", diff --git a/test/stdlib/Refinement_test.rb b/test/stdlib/Refinement_test.rb index fdd42f1d12..433cf9e7ac 100644 --- a/test/stdlib/Refinement_test.rb +++ b/test/stdlib/Refinement_test.rb @@ -18,25 +18,16 @@ def test_target end def test_import_methods - assert_fn = method(:assert) + test = self Module.new { refine Integer do - # Due to a bug in Ruby, you can't call `import_methods` outside of `refine` - - begin - import_methods - rescue - assert_fn.call(true) - else - assert_fn.call(false, "import_methods accepts at least one argument?") - end - - import_methods Module.new - assert_fn.call(true) - - import_methods Module.new, Module.new - assert_fn.call(true) + # Due to a bug in Ruby, you can't call `import_methods` outside of `refine`. + # Calling it with modules through `assert_send_type` also crashes the VM + # (`cref_replace_with_duplicated_cref_each_frame: unreachable`), so only the + # no-argument case is checked here. + test.refute_send_type '() -> untyped', + self, :import_methods end } end diff --git a/test/stdlib/Regexp_test.rb b/test/stdlib/Regexp_test.rb index 9854936471..1833e2923d 100644 --- a/test/stdlib/Regexp_test.rb +++ b/test/stdlib/Regexp_test.rb @@ -5,10 +5,6 @@ class RegexpSingletonTest < Test::Unit::TestCase testing 'singleton(::Regexp)' - def test_TimeoutError - assert Regexp::TimeoutError.superclass.equal?(RegexpError) - end - def test_EXTENDED assert_const_type 'Integer', 'Regexp::EXTENDED' diff --git a/test/stdlib/global_variables_test.rb b/test/stdlib/global_variables_test.rb index ce76fa2574..80ff7a8484 100644 --- a/test/stdlib/global_variables_test.rb +++ b/test/stdlib/global_variables_test.rb @@ -7,21 +7,10 @@ def assert_global_type(type, global_name) # I wish there was a `global_variable_get`; alas, `eval`. global = block_given? ? yield : eval(global_name.to_s, nil, $0, $.) - typecheck = RBS::Test::TypeCheck.new( - builder: builder, - sample_size: 100, - unchecked_classes: [] - ) - - value_type = - case type - when String - RBS::Parser.parse_type(type, variables: []) || raise - else - type - end + assert_type type, global - assert typecheck.value(global, value_type), "`#{global_name}` (#{global.inspect}) must be compatible with given type `#{value_type}`" + entry = env.global_decls.fetch(global_name.to_sym) { flunk "Cannot find RBS global declaration of `#{global_name}`" } + assert_type entry.decl.type, global end def test_gvar_exclaimation @@ -295,7 +284,7 @@ def test_gvar_VERBOSE(gvar: :$VERBOSE) def test_gvar_backwards_slash # Don't test other `$\`s as they're deprecated - assert_global_type 'nil', $\ + assert_global_type 'nil', :$\ end def test_gvar_underscore