Exit with a failure if any test files failed to load

This commit is contained in:
Nobuyoshi Nakada 2023-06-02 20:25:08 +09:00
parent 1bb7c3c447
commit 4589056384
Notes: git 2023-06-03 11:22:30 +00:00
3 changed files with 31 additions and 1 deletions

View File

@ -813,6 +813,7 @@ module Test
warn ""
@warnings.uniq! {|w| w[1].message}
@warnings.each do |w|
@errors += 1
warn "#{w[0]}: #{w[1].message} (#{w[1].class})"
end
warn ""
@ -1282,8 +1283,13 @@ module Test
puts "#{f}: #{$!}"
end
}
@load_failed = errors.size.nonzero?
result
end
def run(*)
super or @load_failed
end
end
module RepeatOption # :nodoc: all
@ -1680,7 +1686,7 @@ module Test
break unless report.empty?
end
return failures + errors if self.test_count > 0 # or return nil...
return (failures + errors).nonzero? # or return nil...
rescue Interrupt
abort 'Interrupted'
end

View File

@ -0,0 +1 @@
raise LoadError, "no-such-library"

View File

@ -0,0 +1,23 @@
# frozen_string_literal: true
require 'test/unit'
class TestLoadFailure < Test::Unit::TestCase
def test_load_failure
assert_not_predicate(load_failure, :success?)
end
def test_load_failure_parallel
assert_not_predicate(load_failure("-j2"), :success?)
end
private
def load_failure(*args)
IO.popen([*@options[:ruby], "#{__dir__}/../runner.rb",
"#{__dir__}/test4test_load_failure.rb",
"--verbose", *args], err: [:child, :out]) {|f|
assert_include(f.read, "test4test_load_failure.rb")
}
$?
end
end