Skip to content

Conversation

@tikkss
Copy link
Contributor

@tikkss tikkss commented Jun 11, 2025

GitHub: GH-311

This patch will reduce dependency on $LOAD_PATH.

It replaces require with require_relative for internal library
files. This change is applied only when the replacement can be done
statically and simply.

More advanced replacements are out of scope for this patch, such as:

  • Using autoload
  • Changes under test/

@tikkss
Copy link
Contributor Author

tikkss commented Jun 11, 2025

Can these line be removed?
It seems redundant because we no longer depend on $LOAD_PATH.

@kou
Copy link
Member

kou commented Jun 12, 2025

Hmm. Could you remove test/ changes from this PR?
We may want to use test/ for tests against installed test-unit.

Let's work on it as a separated PR.

@tikkss
Copy link
Contributor Author

tikkss commented Jun 12, 2025

Hmm. Could you remove test/ changes from this PR?
We may want to use test/ for tests against installed test-unit.

Yes, I'll remove test/ changes from this PR.

Oh, I didn't know that test/ could be used to test the installed gem.
Since test/ isn't included in the gem, require_relative wouldn't work in this context.
Thanks!

Let's work on it as a separated PR.

Sure!

GitHub: test-unitGH-311

This patch will reduce dependency on `$LOAD_PATH`.

It replaces `require` with `require_relative` for internal library
files. This change is applied only when the replacement can be done
statically and simply.

More advanced replacements are out of scope for this patch, such as:

  * Using `autoload`
  * Changes under `test/`

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
@tikkss tikkss force-pushed the use-require-relative branch from e564ff0 to 54ea7f5 Compare June 12, 2025 21:06
@tikkss
Copy link
Contributor Author

tikkss commented Jun 12, 2025

The remaining require can be categorized as follows.
This list is based on the following command:

$ git grep --line-number --word-regexp require -- :^doc/ :^sample/ :^test/

External libraries

  • Rakefile:16:require "erb"
  • Rakefile:17:require "yaml"
  • Rakefile:18:require "rubygems"
  • Rakefile:19:require "rake/clean"
  • Rakefile:20:require "yard"
  • Rakefile:21:require "bundler/gem_helper"
  • Rakefile:22:require "packnga"
  • lib/test/unit/assertion-failed-error.rb:41: require "debug"
  • lib/test/unit/assertions.rb:13: require 'power_assert'
  • lib/test/unit/assertions.rb:2078: require "pp" unless defined?(PP)
  • lib/test/unit/autorunner.rb:1:require "English"
  • lib/test/unit/autorunner.rb:2:require "optparse"
  • lib/test/unit/autorunner.rb:501: require "yaml"
  • lib/test/unit/autorunner.rb:523: require "shellwords"
  • lib/test/unit/collector/xml.rb:12:require 'rexml/document'
  • lib/test/unit/collector/xml.rb:13:require 'rexml/streamlistener'
  • lib/test/unit/data.rb:259: require 'csv'
  • lib/test/unit/data.rb:305: require "csv"
  • lib/test/unit/fault-location-detector.rb:5:require "English"
  • lib/test/unit/priority.rb:20: require "fileutils"
  • lib/test/unit/priority.rb:21: require "tmpdir"
  • lib/test/unit/test-suite-runner.rb:9:require "etc"
  • lib/test/unit/ui/console/testrunner.rb:10: require 'io/console'
  • lib/test/unit/ui/console/testrunner.rb:13:require "pathname"
  • lib/test/unit/collector/load.rb:1:require 'pathname'
  • lib/test/unit/ui/xml/testrunner.rb:8:require 'erb'
  • lib/test/unit/ui/xml/testrunner.rb:9:require 'time'
  • lib/test/unit/util/backtracefilter.rb:2: require 'power_assert'
  • lib/test/unit/util/output.rb:16: require 'stringio'

More advanced replacements

  • bin/test-unit:3:require "test/unit"

Just comments

  • lib/test/unit.rb:81: # "require 'test/unit'", plus his code to improve it even more by
  • lib/test/unit.rb:180: # * require 'test/unit' in your test script.
  • lib/test/unit.rb:192: # require 'test/unit'
  • lib/test/unit.rb:213: # runner is automatically invoked for you if you require
  • lib/test/unit.rb:218: # require 'test/unit'
  • lib/test/unit.rb:234: # these up automatically when you require
  • lib/test/unit.rb:238: # require 'test/unit'
  • lib/test/unit.rb:239: # require 'test_myfirsttests'
  • lib/test/unit.rb:240: # require 'test_moretestsbyme'
  • lib/test/unit.rb:241: # require 'test_anothersetoftests'
  • lib/test/unit/assertions.rb:1840: # require "objspace"
  • lib/test/unit/assertions.rb:1851: # require "objspace"

No change needed

These are require calls, but $LOAD_PATH is unshifted just before, so they sould be fine.

  • lib/test/unit/collector/dir.rb:91: @req.require(name)
  • lib/test/unit/collector/dir.rb:93: require(name)
  • lib/test/unit/collector/load.rb:118: require(expanded_path.to_s)

Test::Unit::UI::TestRunnerUtilities#start_command_line_test doesn't seem to be called, so it should also be fine.

  • lib/test/unit/ui/testrunnerutilities.rb:35: require ARGV[0].gsub(/.+::/, '')

Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
@kou kou merged commit 5914658 into test-unit:master Jun 13, 2025
36 checks passed
@tikkss tikkss deleted the use-require-relative branch June 13, 2025 03:43
tikkss added a commit to tikkss/test-unit that referenced this pull request Jun 27, 2025
GitHub: fix test-unitGH-311

This is a follow-up to test-unitGH-312 and the final patch to fix test-unitGH-311.
This patch will reduce dependency on `$LOAD_PATH`.

It replaces `require` with `require_relative` for internal library
files in `test/`.

If you want to run tests against the installed `test-unit`, you can
still use the `test/` directory like this:

This example runs tests against the installed `test-unit` version 3.6.8.

```console
$ ruby -I $(gem env home)/gems/test-unit-3.6.8/lib test-unit test
```
tikkss added a commit to tikkss/test-unit that referenced this pull request Jun 27, 2025
GitHub: fix test-unitGH-311

This is a follow-up to test-unitGH-312 and the final patch to fix test-unitGH-311.
This patch will reduce dependency on `$LOAD_PATH`.

It replaces `require` with `require_relative` for internal library
files in `test/`.

If you want to run tests against the installed `test-unit`, you can
still use the `test/` directory like this:

This example runs tests against the installed `test-unit` version 3.6.8.

```console
$ ruby -I $(gem env home)/gems/test-unit-3.6.8/lib bin/test-unit test
```
kou pushed a commit that referenced this pull request Jun 28, 2025
GitHub: fix GH-311

This is a follow-up to GH-312 and the final patch to fix GH-311.
This patch will reduce dependency on `$LOAD_PATH`.

It replaces `require` with `require_relative` for internal library files
in `test/`.

If you want to run tests against the installed `test-unit`, you can
still use the `test/` directory like this:

This example runs tests against the installed `test-unit` version 3.6.8.

```console
$ ruby -I $(gem env home)/gems/test-unit-3.6.8/lib bin/test-unit test
```
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.

2 participants