summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2019-07-23 16:09:46 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-08-02 21:09:43 +0900
commiteb638b75b33c7be30021d1de57f44498c6b5f6d6 (patch)
tree7ab66ca2559b769b2d7551cc543f3bb2b59d48b6 /tool
parent9921b63ac48ca7c195bc8b9db96eb1f434ce9e8a (diff)
It can be share to use CoreAssertions for default gems.
ref. https://github.com/ruby/logger/pull/35
Diffstat (limited to 'tool')
-rw-r--r--tool/lib/test/unit/core_assertions.rb33
1 files changed, 29 insertions, 4 deletions
diff --git a/tool/lib/test/unit/core_assertions.rb b/tool/lib/test/unit/core_assertions.rb
index 21be860176..5533c54634 100644
--- a/tool/lib/test/unit/core_assertions.rb
+++ b/tool/lib/test/unit/core_assertions.rb
@@ -1,11 +1,36 @@
# frozen_string_literal: true
-require_relative '../../envutil'
-
module Test
module Unit
module CoreAssertions
- include MiniTest::Assertions
+ if defined?(MiniTest)
+ require_relative '../../envutil'
+ # for ruby core testing
+ include MiniTest::Assertions
+ else
+ require 'pp'
+ require_relative 'envutil'
+ include Test::Unit::Assertions
+
+ def _assertions= n # :nodoc:
+ @_assertions = n
+ end
+
+ def _assertions # :nodoc:
+ @_assertions ||= 0
+ end
+
+ ##
+ # Returns a proc that will output +msg+ along with the default message.
+
+ def message msg = nil, ending = nil, &default
+ proc {
+ msg = msg.call.chomp(".") if Proc === msg
+ custom_message = "#{msg}.\n" unless msg.nil? or msg.to_s.empty?
+ "#{custom_message}#{default.call}#{ending || "."}"
+ }
+ end
+ end
def mu_pp(obj) #:nodoc:
obj.pretty_inspect.chomp
@@ -99,7 +124,7 @@ module Test
end
src = <<eom
# -*- coding: #{line += __LINE__; src.encoding}; -*-
- require #{__dir__.dump};include Test::Unit::Assertions
+ require "test/unit";include Test::Unit::Assertions;require #{(__dir__ + "/core_assertions").dump};include Test::Unit::CoreAssertions
END {
puts [Marshal.dump($!)].pack('m'), "assertions=\#{self._assertions}"
}