Skip to content

Commit

Permalink
+ Minitest.filter_backtrace returns original backtrace if filter come…
Browse files Browse the repository at this point in the history
…s back empty.

+ Minitest::BacktraceFilter now returns entire backtrace if $MT_DEBUG set in env.

This should fix #837 and
bypasses the need for a release of
rails/rails#39304.

[git-p4: depot-paths = "//src/minitest/dev/": change = 12653]
  • Loading branch information
zenspider committed May 15, 2020
1 parent 6257210 commit 65664a1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ def self.process_args args = [] # :nodoc:
end

def self.filter_backtrace bt # :nodoc:
backtrace_filter.filter bt
result = backtrace_filter.filter bt
result = bt.dup if result.empty?
result
end

##
Expand Down Expand Up @@ -1005,12 +1007,13 @@ class BacktraceFilter
MT_RE = %r%lib/minitest% #:nodoc:

##
# Filter +bt+ to something useful. Returns the whole thing if $DEBUG.
# Filter +bt+ to something useful. Returns the whole thing if
# $DEBUG (ruby) or $MT_DEBUG (env).

def filter bt
return ["No backtrace"] unless bt

return bt.dup if $DEBUG
return bt.dup if $DEBUG || ENV["MT_DEBUG"]

new_bt = bt.take_while { |line| line !~ MT_RE }
new_bt = bt.select { |line| line !~ MT_RE } if new_bt.empty?
Expand Down
19 changes: 19 additions & 0 deletions test/minitest/metametameta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,27 @@ class Minitest::Test
def clean s
s.gsub(/^ {6}/, "")
end

def with_empty_backtrace_filter
original = Minitest.backtrace_filter

obj = Minitest::BacktraceFilter.new
def obj.filter _bt
[]
end

Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
begin
Minitest.backtrace_filter = obj
yield
ensure
Minitest.backtrace_filter = original
end
end
end
end


class FakeNamedTest < Minitest::Test
@@count = 0

Expand Down
16 changes: 16 additions & 0 deletions test/minitest/test_minitest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,22 @@ def assert_success spec
(1 + 1).must_equal 2
end
end

# https://github.com/seattlerb/minitest/issues/837
# https://github.com/rails/rails/pull/39304
it "deprecates expectation used without _ with empty backtrace_filter" do
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]

@assertion_count += 3

exp = /DEPRECATED: global use of must_equal from/

with_empty_backtrace_filter do
assert_output "", exp do
(1 + 1).must_equal 2
end
end
end
end

it "needs to verify throw" do
Expand Down
10 changes: 7 additions & 3 deletions test/minitest/test_minitest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ def test_filter_backtrace_unit_starts
assert_equal ex, fu
end

# def test_default_runner_is_minitest_unit
# assert_instance_of Minitest::Unit, Minitest::Unit.runner
# end
def test_filter_backtrace__empty
with_empty_backtrace_filter do
bt = %w[first second third]
fu = Minitest.filter_backtrace bt.dup
assert_equal bt, fu
end
end

def test_infectious_binary_encoding
@tu = Class.new FakeNamedTest do
Expand Down

0 comments on commit 65664a1

Please sign in to comment.