2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2018-09-29 20:50:43 -04:00
|
|
|
require_relative "abstract_unit"
|
2008-11-22 12:06:08 -05:00
|
|
|
|
|
|
|
class BacktraceCleanerFilterTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@bc = ActiveSupport::BacktraceCleaner.new
|
2016-08-06 12:03:25 -04:00
|
|
|
@bc.add_filter { |line| line.gsub("/my/prefix", "") }
|
2008-11-22 12:06:08 -05:00
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2012-06-18 21:23:28 -04:00
|
|
|
test "backtrace should filter all lines in a backtrace, removing prefixes" do
|
|
|
|
assert_equal \
|
2017-07-16 05:11:03 -04:00
|
|
|
["/my/class.rb", "/my/module.rb"],
|
|
|
|
@bc.clean(["/my/prefix/my/class.rb", "/my/prefix/my/module.rb"])
|
2008-11-22 12:06:08 -05:00
|
|
|
end
|
2010-03-27 12:47:39 -04:00
|
|
|
|
|
|
|
test "backtrace cleaner should allow removing filters" do
|
|
|
|
@bc.remove_filters!
|
|
|
|
assert_equal "/my/prefix/my/class.rb", @bc.clean(["/my/prefix/my/class.rb"]).first
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2008-11-22 12:06:08 -05:00
|
|
|
test "backtrace should contain unaltered lines if they dont match a filter" do
|
|
|
|
assert_equal "/my/other_prefix/my/class.rb", @bc.clean([ "/my/other_prefix/my/class.rb" ]).first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class BacktraceCleanerSilencerTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@bc = ActiveSupport::BacktraceCleaner.new
|
2016-08-06 12:03:25 -04:00
|
|
|
@bc.add_silencer { |line| line.include?("mongrel") }
|
2008-11-22 12:06:08 -05:00
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2008-11-22 12:06:08 -05:00
|
|
|
test "backtrace should not contain lines that match the silencer" do
|
|
|
|
assert_equal \
|
2010-08-14 01:13:00 -04:00
|
|
|
[ "/other/class.rb" ],
|
2008-11-22 12:06:08 -05:00
|
|
|
@bc.clean([ "/mongrel/class.rb", "/other/class.rb", "/mongrel/stuff.rb" ])
|
|
|
|
end
|
2014-07-19 15:49:52 -04:00
|
|
|
|
|
|
|
test "backtrace cleaner should allow removing silencer" do
|
|
|
|
@bc.remove_silencers!
|
|
|
|
assert_equal ["/mongrel/stuff.rb"], @bc.clean(["/mongrel/stuff.rb"])
|
|
|
|
end
|
2008-11-22 12:06:08 -05:00
|
|
|
end
|
|
|
|
|
2013-06-20 08:51:01 -04:00
|
|
|
class BacktraceCleanerMultipleSilencersTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@bc = ActiveSupport::BacktraceCleaner.new
|
2016-08-06 12:03:25 -04:00
|
|
|
@bc.add_silencer { |line| line.include?("mongrel") }
|
|
|
|
@bc.add_silencer { |line| line.include?("yolo") }
|
2013-06-20 08:51:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "backtrace should not contain lines that match the silencers" do
|
|
|
|
assert_equal \
|
|
|
|
[ "/other/class.rb" ],
|
|
|
|
@bc.clean([ "/mongrel/class.rb", "/other/class.rb", "/mongrel/stuff.rb", "/other/yolo.rb" ])
|
|
|
|
end
|
|
|
|
|
|
|
|
test "backtrace should only contain lines that match the silencers" do
|
|
|
|
assert_equal \
|
|
|
|
[ "/mongrel/class.rb", "/mongrel/stuff.rb", "/other/yolo.rb" ],
|
|
|
|
@bc.clean([ "/mongrel/class.rb", "/other/class.rb", "/mongrel/stuff.rb", "/other/yolo.rb" ],
|
|
|
|
:noise)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-22 12:06:08 -05:00
|
|
|
class BacktraceCleanerFilterAndSilencerTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@bc = ActiveSupport::BacktraceCleaner.new
|
|
|
|
@bc.add_filter { |line| line.gsub("/mongrel", "") }
|
2016-08-06 12:03:25 -04:00
|
|
|
@bc.add_silencer { |line| line.include?("mongrel") }
|
2008-11-22 12:06:08 -05:00
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2008-11-22 12:06:08 -05:00
|
|
|
test "backtrace should not silence lines that has first had their silence hook filtered out" do
|
|
|
|
assert_equal [ "/class.rb" ], @bc.clean([ "/mongrel/class.rb" ])
|
|
|
|
end
|
2010-03-27 12:47:39 -04:00
|
|
|
end
|
2018-08-05 21:06:01 -04:00
|
|
|
|
|
|
|
class BacktraceCleanerDefaultFilterAndSilencerTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@bc = ActiveSupport::BacktraceCleaner.new
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should format installed gems correctly" do
|
|
|
|
backtrace = [ "#{Gem.default_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
|
|
|
|
result = @bc.clean(backtrace, :all)
|
|
|
|
assert_equal "nosuchgem (1.2.3) lib/foo.rb", result[0]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should format installed gems not in Gem.default_dir correctly" do
|
|
|
|
target_dir = Gem.path.detect { |p| p != Gem.default_dir }
|
|
|
|
# skip this test if default_dir is the only directory on Gem.path
|
|
|
|
if target_dir
|
|
|
|
backtrace = [ "#{target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
|
|
|
|
result = @bc.clean(backtrace, :all)
|
|
|
|
assert_equal "nosuchgem (1.2.3) lib/foo.rb", result[0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should format gems installed by bundler" do
|
|
|
|
backtrace = [ "#{Gem.default_dir}/bundler/gems/nosuchgem-1.2.3/lib/foo.rb" ]
|
|
|
|
result = @bc.clean(backtrace, :all)
|
|
|
|
assert_equal "nosuchgem (1.2.3) lib/foo.rb", result[0]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should silence gems from the backtrace" do
|
|
|
|
backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
|
|
|
|
result = @bc.clean(backtrace)
|
|
|
|
assert_empty result
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should silence stdlib" do
|
|
|
|
backtrace = ["#{RbConfig::CONFIG["rubylibdir"]}/lib/foo.rb"]
|
|
|
|
result = @bc.clean(backtrace)
|
|
|
|
assert_empty result
|
|
|
|
end
|
|
|
|
end
|