Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 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.
* 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.
Expand Down
24 changes: 24 additions & 0 deletions demo/03_runner_reliability.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
18 changes: 17 additions & 1 deletion lib/rubytest/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rubytest.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading