From acfe51b850b7d2fec1a6a92f86eea08e5e42bb40 Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Thu, 31 Aug 2023 12:59:54 -0400 Subject: [PATCH] Filter Sorbet in backtrace --- test/test_helper.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 94fda1e01a..93b48ac6cc 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -13,8 +13,8 @@ require "debug" require "mocha/minitest" -sorbet_paths = Gem.loaded_specs["sorbet-runtime"].full_require_paths.freeze -DEBUGGER__::CONFIG[:skip_path] = Array(DEBUGGER__::CONFIG[:skip_path]) + sorbet_paths +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"] Minitest::Reporters::SpecReporter.new(color: true) @@ -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