Skip to content

Commit 4589056

Browse files
committed
Exit with a failure if any test files failed to load
1 parent 1bb7c3c commit 4589056

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

tool/lib/test/unit.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ def _run_parallel suites, type, result
813813
warn ""
814814
@warnings.uniq! {|w| w[1].message}
815815
@warnings.each do |w|
816+
@errors += 1
816817
warn "#{w[0]}: #{w[1].message} (#{w[1].class})"
817818
end
818819
warn ""
@@ -1282,8 +1283,13 @@ def non_options(files, options)
12821283
puts "#{f}: #{$!}"
12831284
end
12841285
}
1286+
@load_failed = errors.size.nonzero?
12851287
result
12861288
end
1289+
1290+
def run(*)
1291+
super or @load_failed
1292+
end
12871293
end
12881294

12891295
module RepeatOption # :nodoc: all
@@ -1680,7 +1686,7 @@ def _run args = []
16801686
break unless report.empty?
16811687
end
16821688

1683-
return failures + errors if self.test_count > 0 # or return nil...
1689+
return (failures + errors).nonzero? # or return nil...
16841690
rescue Interrupt
16851691
abort 'Interrupted'
16861692
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
raise LoadError, "no-such-library"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
require 'test/unit'
3+
4+
class TestLoadFailure < Test::Unit::TestCase
5+
def test_load_failure
6+
assert_not_predicate(load_failure, :success?)
7+
end
8+
9+
def test_load_failure_parallel
10+
assert_not_predicate(load_failure("-j2"), :success?)
11+
end
12+
13+
private
14+
15+
def load_failure(*args)
16+
IO.popen([*@options[:ruby], "#{__dir__}/../runner.rb",
17+
"#{__dir__}/test4test_load_failure.rb",
18+
"--verbose", *args], err: [:child, :out]) {|f|
19+
assert_include(f.read, "test4test_load_failure.rb")
20+
}
21+
$?
22+
end
23+
end

0 commit comments

Comments
 (0)