From 10dccaf6ddd560a97d7e9fa427dc7614c6fa0a14 Mon Sep 17 00:00:00 2001 From: Thomas Sawyer Date: Tue, 17 Nov 2026 09:14:13 -0500 Subject: [PATCH 1/2] Report where a load error was raised An error raised outside of a test, such as while a test file loads, ended the run with only `ERROR: `. Print the error's class, the first backtrace line, and a pointer to --debug. Co-Authored-By: Claude Fable 5.2 --- HISTORY.md | 3 +++ demo/03_runner_reliability.md | 24 ++++++++++++++++++++++++ lib/rubytest/runner.rb | 18 +++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 21a1239..dce384e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,9 @@ ## Unreleased +* Report an error raised outside of a test, such as while a test file loads, + with its class, where it was raised, and a pointer to `--debug`, instead of + the bare message. * Bring summary, outline, and progress reporters into Rubytest and add a TAP 13 reporter that counts completed results, including skipped and broken cases. * Remove CLI shortcuts for the unbundled TAP-Y and TAP-J formats. diff --git a/demo/03_runner_reliability.md b/demo/03_runner_reliability.md index 70c4f6a..1e3ff75 100644 --- a/demo/03_runner_reliability.md +++ b/demo/03_runner_reliability.md @@ -120,3 +120,27 @@ The `--config` option accepts an alternate configuration file. cli = Test::CLI.new cli.options.parse!(['--config', 'custom-test.rb']) cli.config_file.assert == 'custom-test.rb' + +### Errors outside of tests + +An error raised outside of any test, such as one raised while a test file +loads, ends the run. The report names the error's class, says where it was +raised, and points to the full backtrace. + + load_error = begin + ''.freeze << 'x' + rescue FrozenError => error + error + end + + report = Test.error_report(load_error) + lines = report.lines.map(&:chomp) + + lines[0].assert.start_with?('ERROR: FrozenError: ') + lines[1].assert.start_with?(' at ') + lines[1].include?(load_error.backtrace.first).assert == true + lines[2].include?('--debug').assert == true + +An error without a message or a backtrace still names its class. + + Test.error_report(RuntimeError.new).lines.first.chomp.assert == 'ERROR: RuntimeError' diff --git a/lib/rubytest/runner.rb b/lib/rubytest/runner.rb index 4812ccc..1cb2f24 100644 --- a/lib/rubytest/runner.rb +++ b/lib/rubytest/runner.rb @@ -21,11 +21,27 @@ def self.run!(config=nil, &config_proc) exit -1 unless success rescue => error raise error if $DEBUG - $stderr.puts('ERROR: ' + error.to_s) + $stderr.puts(error_report(error)) exit -1 end end + # What `run!` prints for an error raised outside of any test, such as one + # raised while a test file loads: the error's class and message, where it + # was raised, and how to see the rest of the backtrace. + # + # @return [String] + def self.error_report(error) + message = error.message.to_s + report = "ERROR: #{error.class}" + report << ": #{message}" unless message.empty? || message == error.class.name + if location = (error.backtrace || []).first + report << "\n at #{location}" + end + report << "\n(Use --debug, or ruby -d, for the full backtrace.)" + report + end + # The Test::Runner class handles the execution of tests. # class Runner From 372ed3f9b12e8f4c1cd3dcd65341f604d8e467fc Mon Sep 17 00:00:00 2001 From: Thomas Sawyer Date: Tue, 17 Nov 2026 09:14:13 -0500 Subject: [PATCH 2/2] Support Ruby 2.7 and 3.0 Nothing in the code needs 3.1. On older Rubies Bundler resolves ansi 1.5.0, qed 2.9.2 and ae 1.8.2, the last releases before those gems required 3.1. Add both versions to the CI matrix. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/test.yml | 2 +- HISTORY.md | 1 + rubytest.gemspec | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9eb6151..36ff2a8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby: ['3.1', '3.2', '3.3', '3.4'] + ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4'] steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 diff --git a/HISTORY.md b/HISTORY.md index dce384e..ce90a91 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ ## Unreleased +* Support Ruby 2.7 and 3.0 again (0.9.0 required 3.1). * Report an error raised outside of a test, such as while a test file loads, with its class, where it was raised, and a pointer to `--debug`, instead of the bare message. diff --git a/rubytest.gemspec b/rubytest.gemspec index 3ab09c5..6c745f0 100644 --- a/rubytest.gemspec +++ b/rubytest.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.homepage = 'https://github.com/rubyworks/rubytest' s.license = 'BSD-2-Clause' - s.required_ruby_version = '>= 3.1' + s.required_ruby_version = '>= 2.7' s.files = Dir['lib/**/*', 'bin/*', 'LICENSE.txt', 'README.md', 'HISTORY.md', 'demo/**/*'] s.bindir = 'bin'