Define a custom assertion failure error for cross-version compat

Fixes #2840.
This commit is contained in:
Misty De Meo 2017-06-29 17:38:44 -07:00
parent 1503c9fcb2
commit 5b464babf8
2 changed files with 14 additions and 1 deletions

View File

@ -83,7 +83,7 @@ module Homebrew
exec(*args)
end
end
rescue MiniTest::Assertion => e
rescue Homebrew::Assertions::AssertionFailed => e
ofail "#{f.full_name}: failed"
puts e.message
rescue Exception => e

View File

@ -3,6 +3,19 @@ module Homebrew
require "test/unit/assertions"
include ::Test::Unit::Assertions
# Custom name here for cross-version compatibility.
# In Ruby 2.0, Test::Unit::Assertions raise a MiniTest::Assertion,
# but they raise Test::Unit::AssertionFailedError in 2.3.
# If neither is defined, this might be a completely different
# version of Ruby.
if defined?(MiniTest::Assertion)
AssertionFailed = MiniTest::Assertion
elsif defined?(Test::Unit::AssertionFailedError)
AssertionFailed = Test::Unit::AssertionFailedError
else
raise NameError, "Unable to find an assertion class for this version of Ruby (#{RUBY_VERSION})"
end
# Returns the output of running cmd, and asserts the exit status
def shell_output(cmd, result = 0)
ohai cmd