-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter Sorbet in backtrace #959
Conversation
@@ -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]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to a constant that we can reference it from BacktraceWithoutSorbetFilter
.
|
7a933fa
to
acfe51b
Compare
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi @st0012 - I changed this so it inherits
What happens if we have a runtime typechecking error? How does it show up? |
It'll show like this:
|
test/test_helper.rb
Outdated
def filter(bt) | ||
return ["No backtrace"] unless bt | ||
|
||
return bt.dup if $DEBUG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this? When is $DEBUG
true?
class BacktraceWithoutSorbetFilter < Minitest::BacktraceFilter | ||
extend T::Sig | ||
sig { override.params(bt: T.nilable(T::Array[String])).returns(T::Array[String]) } | ||
def filter(bt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of replicating what Minitest is doing, can we not use super here?
def filter(bt)
super.select { |line| SORBET_PATHS.none? { |path| line.include?(path) } }
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, updated.
acfe51b
to
0e53c25
Compare
@@ -28,3 +28,15 @@ class Test | |||
Minitest::Test.make_my_diffs_pretty! | |||
end | |||
end | |||
|
|||
class BacktraceWithoutSorbetFilter < Minitest::BacktraceFilter | |||
extend T::Sig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extend T::Sig | |
extend T::Sig | |
0e53c25
to
c6cdfee
Compare
We could potentially ship this with Spoom: Shopify/spoom#456 |
Co-authored-by: Andy Waite <[email protected]>
Paired on with @st0012
Motivation
When working on Ruby LSP, test failures contain Sorbet frames in the backtrace. This adds considerable noise and is generally not helpful for understand a failure.
Implementation
There is not much guidance in the Minitest documentation for this, so this solution is based on Minitest's default filter.
Automated Tests
n/a
Manual Tests
Add something to a test which triggers a error, and run the test. Ensure the backtrace filter does not include any Sorbet frames.