Skip to content

Commit

Permalink
Expose Test.filter_backtrace for the default gems.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Aug 29, 2023
1 parent c4fc947 commit 27e86f4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 36 deletions.
37 changes: 37 additions & 0 deletions tool/lib/core_assertions.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
# frozen_string_literal: true

module Test

class << self
##
# Filter object for backtraces.

attr_accessor :backtrace_filter
end

class BacktraceFilter # :nodoc:
def filter bt
return ["No backtrace"] unless bt

new_bt = []
pattern = %r[/(?:lib\/test/|core_assertions\.rb:)]

unless $DEBUG then
bt.each do |line|
break if pattern.match?(line)
new_bt << line
end

new_bt = bt.reject { |line| pattern.match?(line) } if new_bt.empty?
new_bt = bt.dup if new_bt.empty?
else
new_bt = bt.dup
end

new_bt
end
end

self.backtrace_filter = BacktraceFilter.new

def self.filter_backtrace bt # :nodoc:
backtrace_filter.filter bt
end

module Unit
module Assertions
def assert_raises(*exp, &b)
Expand Down
36 changes: 0 additions & 36 deletions tool/lib/test/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,6 @@ def warn(message, category: nil, **kwargs)
# See Test::Unit
module Test

class << self
##
# Filter object for backtraces.

attr_accessor :backtrace_filter
end

class BacktraceFilter # :nodoc:
def filter bt
return ["No backtrace"] unless bt

new_bt = []
pattern = %r[/(?:lib\/test/|core_assertions\.rb:)]

unless $DEBUG then
bt.each do |line|
break if pattern.match?(line)
new_bt << line
end

new_bt = bt.reject { |line| pattern.match?(line) } if new_bt.empty?
new_bt = bt.dup if new_bt.empty?
else
new_bt = bt.dup
end

new_bt
end
end

self.backtrace_filter = BacktraceFilter.new

def self.filter_backtrace bt # :nodoc:
backtrace_filter.filter bt
end

##
# Test::Unit is an implementation of the xUnit testing framework for Ruby.
module Unit
Expand Down

0 comments on commit 27e86f4

Please sign in to comment.