2012-05-04 17:46:01 -04:00
|
|
|
# encoding: utf-8
|
2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2012-05-04 17:46:01 -04:00
|
|
|
|
|
|
|
require 'tempfile'
|
|
|
|
require 'stringio'
|
|
|
|
require 'minitest/autorun'
|
|
|
|
|
2012-08-20 20:39:57 -04:00
|
|
|
class MiniTest::Unit::TestCase
|
|
|
|
def clean s
|
|
|
|
s.gsub(/^ {6}/, '')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
class MetaMetaMetaTestCase < MiniTest::Unit::TestCase
|
2012-08-20 20:39:57 -04:00
|
|
|
def assert_report expected, flags = %w[--seed 42]
|
|
|
|
header = clean <<-EOM
|
|
|
|
Run options: #{flags.map { |s| s =~ /\|/ ? s.inspect : s }.join " "}
|
2012-05-04 17:46:01 -04:00
|
|
|
|
|
|
|
# Running tests:
|
|
|
|
|
|
|
|
EOM
|
|
|
|
|
2012-11-28 22:23:11 -05:00
|
|
|
with_output do
|
|
|
|
@tu.run flags
|
|
|
|
end
|
2012-08-20 20:39:57 -04:00
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
output = @output.string.dup
|
|
|
|
output.sub!(/Finished tests in .*/, "Finished tests in 0.00")
|
|
|
|
output.sub!(/Loaded suite .*/, 'Loaded suite blah')
|
2012-05-09 00:09:25 -04:00
|
|
|
|
2012-07-11 19:52:04 -04:00
|
|
|
output.gsub!(/ = \d+.\d\d s = /, ' = 0.00 s = ')
|
2012-08-20 20:39:57 -04:00
|
|
|
output.gsub!(/0x[A-Fa-f0-9]+/, '0xXXX')
|
2012-07-11 19:52:04 -04:00
|
|
|
|
2012-05-09 00:09:25 -04:00
|
|
|
if windows? then
|
2012-05-07 22:23:15 -04:00
|
|
|
output.gsub!(/\[(?:[A-Za-z]:)?[^\]:]+:\d+\]/, '[FILE:LINE]')
|
|
|
|
output.gsub!(/^(\s+)(?:[A-Za-z]:)?[^:]+:\d+:in/, '\1FILE:LINE:in')
|
|
|
|
else
|
|
|
|
output.gsub!(/\[[^\]:]+:\d+\]/, '[FILE:LINE]')
|
|
|
|
output.gsub!(/^(\s+)[^:]+:\d+:in/, '\1FILE:LINE:in')
|
|
|
|
end
|
2012-05-09 00:09:25 -04:00
|
|
|
|
2012-08-20 20:39:57 -04:00
|
|
|
assert_equal header + expected, output
|
2012-05-04 17:46:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
srand 42
|
|
|
|
MiniTest::Unit::TestCase.reset
|
|
|
|
@tu = MiniTest::Unit.new
|
2012-11-28 22:23:11 -05:00
|
|
|
|
2012-05-04 17:46:01 -04:00
|
|
|
MiniTest::Unit.runner = nil # protect the outer runner from the inner tests
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
super
|
2012-11-28 22:23:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def with_output
|
|
|
|
synchronize do
|
|
|
|
begin
|
2015-10-07 09:55:07 -04:00
|
|
|
save = MiniTest::Unit.output
|
2012-11-28 22:23:11 -05:00
|
|
|
@output = StringIO.new("")
|
|
|
|
MiniTest::Unit.output = @output
|
|
|
|
|
|
|
|
yield
|
|
|
|
ensure
|
2015-10-07 09:55:07 -04:00
|
|
|
MiniTest::Unit.output = save
|
2012-11-28 22:23:11 -05:00
|
|
|
end
|
|
|
|
end
|
2012-05-04 17:46:01 -04:00
|
|
|
end
|
|
|
|
end
|