Skip to content

Conversation

@tikkss
Copy link
Contributor

@tikkss tikkss commented Jul 4, 2025

This reverts commit 572b28a.

GitHub: GH-320

We need to use another approach for it.

Reported by Mamoru TASAKA. Thanks!!!

This reverts commit 572b28a.

GitHub: test-unitGH-320

We need to use another approach for it.

Reported by Mamoru TASAKA. Thanks!!!

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
@tikkss tikkss force-pushed the revert-use-require-relative-instead-of-autoload branch from 7b84ac0 to 68996f8 Compare July 4, 2025 22:14
@tikkss
Copy link
Contributor Author

tikkss commented Jul 4, 2025

I confirmed that ruby-gettext/gettext's tests are successful below:

$ ruby -I ~/src/github.com/test-unit/test-unit/lib test/run-test.rb --version
run-test 3.7.0

$ ruby -I ~/src/github.com/test-unit/test-unit/lib test/run-test.rb
Loaded suite test/run-test
Started
O
================================================================================================================================================================
Omission: Per thread $SAFE is removed since Ruby 2.6. [test_safe_mode(TestGetText)]
/Users/zzz/src/github.com/ruby-gettext/gettext/test/test_gettext.rb:382:in 'TestGetText#test_safe_mode'
================================================================================================================================================================
Finished in 5.116956 seconds.............
----------------------------------------------------------------------------------------------------------------------------------------------------------------
399 tests, 779 assertions, 0 failures, 0 errors, 0 pendings, 1 omissions, 0 notifications
100% passed
----------------------------------------------------------------------------------------------------------------------------------------------------------------
77.98 tests/s, 152.24 assertions/s

@kou kou merged commit 84b93a0 into test-unit:master Jul 5, 2025
36 checks passed
@tikkss tikkss deleted the revert-use-require-relative-instead-of-autoload branch July 5, 2025 21:18
@tikkss
Copy link
Contributor Author

tikkss commented Jul 5, 2025

Thanks for your review!

@nevans
Copy link
Contributor

nevans commented Jul 7, 2025

autoload is great... but it would be nice if ruby added either an autoload_relative or a kwarg for autoload name, path, relative_to: __dir__.

We need to use another approach for it.

For what it's worth, I generally accomplish this by just interpolating the expanded path into the autoload path. For example, in net/imap.rb:

    dir = File.expand_path("imap", __dir__)
    autoload :ConnectionState,        "#{dir}/connection_state"
    autoload :ResponseReader,         "#{dir}/response_reader"
    autoload :SASL,                   "#{dir}/sasl"
    autoload :SASLAdapter,            "#{dir}/sasl_adapter"
    autoload :SequenceSet,            "#{dir}/sequence_set"
    autoload :StringPrep,             "#{dir}/stringprep"

If we were willing to override const_missing, maybe try overriding autoload instead?

module Test
  module Unit
    class << self
      def autoload(name, path, relative_to: nil)
        path = File.expand_path(path, relative_to) if relative_to
        super(name, path)
      end
    end
    autoload :TestCase,   "test/unit/testcase",   relative_to: __dir__
    autoload :AutoRunner, "test/unit/autorunner", relative_to: __dir__
  end
end

@tikkss
Copy link
Contributor Author

tikkss commented Jul 8, 2025

Thanks for your knowledge. Sounds nice that autoload and absolute path approach. Because it does not depends $LOAD_PATH. I'll try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants