From bb4e74042a34afff658285ad9449d5245ae99f8a Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Wed, 24 Feb 2021 18:01:47 +0000 Subject: [PATCH] formula_assertions: use minitest We are migrating away from using system gems, and we already have minitest in our dependency tree, so we might as well use it. --- Library/Homebrew/Gemfile | 1 + Library/Homebrew/Gemfile.lock | 1 + Library/Homebrew/dev-cmd/test.rb | 2 ++ Library/Homebrew/formula_assertions.rb | 38 +++++++++++++++++++++++--- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/Gemfile b/Library/Homebrew/Gemfile index 80ff8819be..28f415b817 100644 --- a/Library/Homebrew/Gemfile +++ b/Library/Homebrew/Gemfile @@ -6,6 +6,7 @@ source "https://rubygems.org" gem "bootsnap", require: false gem "byebug", require: false gem "codecov", require: false +gem "minitest", require: false gem "nokogiri", require: false gem "parallel_tests", require: false gem "ronn", require: false diff --git a/Library/Homebrew/Gemfile.lock b/Library/Homebrew/Gemfile.lock index d141c138e4..b117ea153a 100644 --- a/Library/Homebrew/Gemfile.lock +++ b/Library/Homebrew/Gemfile.lock @@ -179,6 +179,7 @@ DEPENDENCIES codecov concurrent-ruby mechanize + minitest nokogiri parallel_tests patchelf diff --git a/Library/Homebrew/dev-cmd/test.rb b/Library/Homebrew/dev-cmd/test.rb index 271c682b93..7a8ba4502a 100644 --- a/Library/Homebrew/dev-cmd/test.rb +++ b/Library/Homebrew/dev-cmd/test.rb @@ -35,6 +35,8 @@ module Homebrew def test args = test_args.parse + Homebrew.install_bundler_gems! + require "formula_assertions" require "formula_free_port" diff --git a/Library/Homebrew/formula_assertions.rb b/Library/Homebrew/formula_assertions.rb index 2ab9bfc036..4c1e88f479 100644 --- a/Library/Homebrew/formula_assertions.rb +++ b/Library/Homebrew/formula_assertions.rb @@ -8,8 +8,38 @@ module Homebrew module Assertions include Context - require "test/unit/assertions" - include ::Test::Unit::Assertions + require "minitest" + require "minitest/assertions" + include ::Minitest::Assertions + + attr_writer :assertions + + def assertions + @assertions ||= 0 + end + + # Test::Unit backwards compatibility methods + { + assert_raise: :assert_raises, + assert_not_empty: :refute_empty, + assert_not_equal: :refute_equal, + assert_not_in_delta: :refute_in_delta, + assert_not_in_epsilon: :refute_in_epsilon, + assert_not_includes: :refute_includes, + assert_not_instance_of: :refute_instance_of, + assert_not_kind_of: :refute_kind_of, + assert_no_match: :refute_match, + assert_not_nil: :refute_nil, + assert_not_operator: :refute_operator, + assert_not_predicate: :refute_predicate, + assert_not_respond_to: :refute_respond_to, + assert_not_same: :refute_same, + }.each do |old_method, new_method| + define_method(old_method) do |*args| + # odeprecated old_method, new_method + send(new_method, *args) + end + end # Returns the output of running cmd, and asserts the exit status. # @api public @@ -18,7 +48,7 @@ module Homebrew output = `#{cmd}` assert_equal result, $CHILD_STATUS.exitstatus output - rescue Test::Unit::AssertionFailedError + rescue Minitest::Assertion puts output if verbose? raise end @@ -35,7 +65,7 @@ module Homebrew end assert_equal result, $CHILD_STATUS.exitstatus unless result.nil? output - rescue Test::Unit::AssertionFailedError + rescue Minitest::Assertion puts output if verbose? raise end