summaryrefslogtreecommitdiff
path: root/tool/lib/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tool/lib/test/unit')
-rw-r--r--tool/lib/test/unit/assertions.rb51
-rw-r--r--tool/lib/test/unit/parallel.rb20
-rw-r--r--tool/lib/test/unit/testcase.rb78
3 files changed, 53 insertions, 96 deletions
diff --git a/tool/lib/test/unit/assertions.rb b/tool/lib/test/unit/assertions.rb
index 065a7a0a46..aad422f7e7 100644
--- a/tool/lib/test/unit/assertions.rb
+++ b/tool/lib/test/unit/assertions.rb
@@ -193,6 +193,22 @@ module Test
end
##
+ # Fails unless +obj+ is true
+
+ def assert_true obj, msg = nil
+ msg = message(msg) { "Expected #{mu_pp(obj)} to be true" }
+ assert obj == true, msg
+ end
+
+ ##
+ # Fails unless +obj+ is false
+
+ def assert_false obj, msg = nil
+ msg = message(msg) { "Expected #{mu_pp(obj)} to be false" }
+ assert obj == false, msg
+ end
+
+ ##
# For testing with binary operators.
#
# assert_operator 5, :<=, 4
@@ -345,20 +361,6 @@ module Test
end
##
- # Returns details for exception +e+
-
- def exception_details e, msg
- [
- "#{msg}",
- "Class: <#{e.class}>",
- "Message: <#{e.message.inspect}>",
- "---Backtrace---",
- "#{Test::filter_backtrace(e.backtrace).join("\n")}",
- "---------------",
- ].join "\n"
- end
-
- ##
# Fails with +msg+
def flunk msg = nil
@@ -527,11 +529,9 @@ module Test
end
alias omit pend
- # TODO: Removed this and enabled to raise NoMethodError with skip
- alias skip pend
- # def skip(msg = nil, bt = caller)
- # raise NoMethodError, "use omit or pend", caller
- # end
+ def skip(msg = nil, bt = caller)
+ raise NoMethodError, "use omit or pend", caller
+ end
##
# Was this testcase skipped? Meant for #teardown.
@@ -563,10 +563,6 @@ module Test
assert yield, *msgs
end
- def assert_raises(*exp, &b)
- raise NoMethodError, "use assert_raise", caller
- end
-
# :call-seq:
# assert_nothing_thrown( failure_message = nil, &block )
#
@@ -772,7 +768,14 @@ EOT
e = assert_raise(SyntaxError, mesg) do
syntax_check(src, fname, line)
end
- assert_match(error, e.message, mesg)
+
+ # Prism adds ANSI escape sequences to syntax error messages to
+ # colorize and format them. We strip them out here to make them easier
+ # to match against in tests.
+ message = e.message
+ message.gsub!(/\e\[.*?m/, "")
+
+ assert_match(error, message, mesg)
e
end
end
diff --git a/tool/lib/test/unit/parallel.rb b/tool/lib/test/unit/parallel.rb
index 47ff0b360a..ac297d4a0e 100644
--- a/tool/lib/test/unit/parallel.rb
+++ b/tool/lib/test/unit/parallel.rb
@@ -1,12 +1,6 @@
# frozen_string_literal: true
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../.."
-require 'test/unit'
-require "profile_test_all" if ENV.key?('RUBY_TEST_ALL_PROFILE')
-require "tracepointchecker"
-require "zombie_hunter"
-require "iseq_loader_checker"
-require "gc_checker"
+require_relative "../../../test/init"
module Test
module Unit
@@ -31,6 +25,10 @@ module Test
end
end
+ def _start_method(inst)
+ _report "start", Marshal.dump([inst.class.name, inst.__name__])
+ end
+
def _run_suite(suite, type) # :nodoc:
@partial_report = []
orig_testout = Test::Unit::Runner.output
@@ -107,7 +105,7 @@ module Test
case buf.chomp
when /^loadpath (.+?)$/
@old_loadpath = $:.dup
- $:.push(*Marshal.load($1.unpack("m")[0].force_encoding("ASCII-8BIT"))).uniq!
+ $:.push(*Marshal.load($1.unpack1("m").force_encoding("ASCII-8BIT"))).uniq!
when /^run (.+?) (.+?)$/
_report "okay"
@@ -182,7 +180,7 @@ module Test
else
error = ProxyError.new(error)
end
- _report "record", Marshal.dump([suite.name, method, assertions, time, error])
+ _report "record", Marshal.dump([suite.name, method, assertions, time, error, suite.instance_method(method).source_location])
super
end
end
@@ -204,5 +202,9 @@ if $0 == __FILE__
end
end
require 'rubygems'
+ begin
+ require 'rake'
+ rescue LoadError
+ end
Test::Unit::Worker.new.run(ARGV)
end
diff --git a/tool/lib/test/unit/testcase.rb b/tool/lib/test/unit/testcase.rb
index 241421d6d9..51ffff37eb 100644
--- a/tool/lib/test/unit/testcase.rb
+++ b/tool/lib/test/unit/testcase.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'test/unit/assertions'
+require_relative 'assertions'
require_relative '../../core_assertions'
module Test
@@ -137,6 +137,9 @@ module Test
attr_reader :__name__ # :nodoc:
+ # Method name of this test.
+ alias method_name __name__
+
PASSTHROUGH_EXCEPTIONS = [NoMemoryError, SignalException,
Interrupt, SystemExit] # :nodoc:
@@ -144,8 +147,7 @@ module Test
# Runs the tests reporting the status to +runner+
def run runner
- @options = runner.options
-
+ @__runner_options__ = runner.options
trap "INFO" do
runner.report.each_with_index do |msg, i|
warn "\n%3d) %s" % [i + 1, msg]
@@ -159,10 +161,9 @@ module Test
start_time = Time.now
result = ""
- srand(runner.options[:seed])
begin
- @passed = nil
+ @__passed__ = nil
self.before_setup
self.setup
self.after_setup
@@ -170,11 +171,11 @@ module Test
result = "." unless io?
time = Time.now - start_time
runner.record self.class, self.__name__, self._assertions, time, nil
- @passed = true
+ @__passed__ = true
rescue *PASSTHROUGH_EXCEPTIONS
raise
rescue Exception => e
- @passed = Test::Unit::PendedError === e
+ @__passed__ = Test::Unit::PendedError === e
time = Time.now - start_time
runner.record self.class, self.__name__, self._assertions, time, e
result = runner.puke self.class, self.__name__, e
@@ -185,7 +186,7 @@ module Test
rescue *PASSTHROUGH_EXCEPTIONS
raise
rescue Exception => e
- @passed = false
+ @__passed__ = false
runner.record self.class, self.__name__, self._assertions, time, e
result = runner.puke self.class, self.__name__, e
end
@@ -207,12 +208,12 @@ module Test
def initialize name # :nodoc:
@__name__ = name
@__io__ = nil
- @passed = nil
- @@current = self # FIX: make thread local
+ @__passed__ = nil
+ @@__current__ = self # FIX: make thread local
end
def self.current # :nodoc:
- @@current # FIX: make thread local
+ @@__current__ # FIX: make thread local
end
##
@@ -237,20 +238,6 @@ module Test
reset
- ##
- # Make diffs for this TestCase use #pretty_inspect so that diff
- # in assert_equal can be more details. NOTE: this is much slower
- # than the regular inspect but much more usable for complex
- # objects.
-
- def self.make_my_diffs_pretty!
- require 'pp'
-
- define_method :mu_pp do |o|
- o.pretty_inspect
- end
- end
-
def self.inherited klass # :nodoc:
@@test_suites[klass] = true
super
@@ -267,53 +254,18 @@ module Test
end
def self.test_suites # :nodoc:
- suites = @@test_suites.keys
-
- case self.test_order
- when :random
- # shuffle test suites based on CRC32 of their names
- salt = "\n" + rand(1 << 32).to_s
- crc_tbl = (0..255).map do |i|
- (0..7).inject(i) {|c,| (c & 1 == 1) ? (0xEDB88320 ^ (c >> 1)) : (c >> 1) }
- end
- suites = suites.sort_by do |suite|
- crc32 = 0xffffffff
- "#{suite.name}#{salt}".each_byte do |data|
- crc32 = crc_tbl[(crc32 ^ data) & 0xff] ^ (crc32 >> 8)
- end
- crc32 ^ 0xffffffff
- end
- when :nosort
- suites
- else
- suites.sort_by { |ts| ts.name.to_s }
- end
+ @@test_suites.keys
end
def self.test_methods # :nodoc:
- methods = public_instance_methods(true).grep(/^test/).map { |m| m.to_s }
-
- case self.test_order
- when :parallel
- max = methods.size
- ParallelEach.new methods.sort.sort_by { rand max }
- when :random then
- max = methods.size
- methods.sort.sort_by { rand max }
- when :alpha, :sorted then
- methods.sort
- when :nosort
- methods
- else
- raise "Unknown test_order: #{self.test_order.inspect}"
- end
+ public_instance_methods(true).grep(/^test/)
end
##
# Returns true if the test passed.
def passed?
- @passed
+ @__passed__
end
##