Skip to content

Commit

Permalink
Filter Sorbet in backtrace
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Aug 31, 2023
1 parent c29b4e6 commit 7a933fa
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require "debug"
require "mocha/minitest"

sorbet_paths = Gem.loaded_specs["sorbet-runtime"].full_require_paths.freeze
sorbet_paths = T.let(Gem.loaded_specs["sorbet-runtime"].full_require_paths.freeze, T::Array[String])
DEBUGGER__::CONFIG[:skip_path] = Array(DEBUGGER__::CONFIG[:skip_path]) + sorbet_paths

minitest_reporter = if ENV["SPEC_REPORTER"]
Expand All @@ -28,3 +28,20 @@ class Test
Minitest::Test.make_my_diffs_pretty!
end
end

# based on https://github.com/minitest/minitest/blob/master/lib/minitest.rb
class BacktraceWithoutSorbetFilter < Minitest::BacktraceFilter
extend T::Sig
sig { override.params(bt: T.nilable(T::Array[String])).returns(T::Array[String]) }
def filter(bt)
return ["No backtrace"] unless bt

return bt.dup if $DEBUG

bt.find_all do |line|
line !~ MT_RE && SORBET_PATHS.none? { |path| line.include?(path) }
end
end
end

Minitest.backtrace_filter = BacktraceWithoutSorbetFilter.new(sorbet_paths)

0 comments on commit 7a933fa

Please sign in to comment.