Skip to content

Commit 96618f9

Browse files
committed
Strip extra TruffleRuby stacktrace lines from test output
This is a workaround to avoid a failure like this: Integration::MinitestRedisTest test_junit_reporter FAIL (17.45s) --- expected +++ actual @@ -47,6 +47,9 @@ Failure: test_bar(BTest) [test/dummy_test.rb]: TypeError: String can't be coerced into Integer + <internal:core> core/numeric.rb:200:in `math_coerce_error' + <internal:core> core/numeric.rb:182:in `math_coerce' + <internal:core> core/numeric.rb:221:in `redo_coerced' test/dummy_test.rb:37:in `+' test/dummy_test.rb:37:in `test_bar' ]]> /Users/rwstauner/src/github.com/Shopify/ci-queue/ruby/test/integration/minitest_redis_test.rb:499:in `test_junit_reporter'
1 parent 10d895f commit 96618f9

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
class BacktraceFilters
4+
PATTERNS = [
5+
# truffleruby has some extra lines before the usual ruby ones:
6+
# "<internal:core> core/numeric.rb:182:in `math_coerce'"
7+
%r{^<internal:},
8+
]
9+
10+
def initialize(original_filter)
11+
@original_filter = original_filter
12+
end
13+
14+
def add_filter(*args)
15+
@original_filter.add_filter(*args)
16+
end
17+
18+
def filter(backtrace)
19+
backtrace = @original_filter.filter(backtrace) if @original_filter
20+
21+
backtrace.reject do |line|
22+
PATTERNS.any? { |pattern| line.match?(pattern) }
23+
end
24+
end
25+
end

ruby/test/fixtures/test/test_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@
66
end
77

88
require 'minitest/autorun'
9+
require_relative './backtrace_filters'
10+
11+
Minitest.backtrace_filter = BacktraceFilters.new(
12+
Minitest.backtrace_filter
13+
)

ruby/test/integration/minitest_redis_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ def test_junit_reporter
496496
output = normalize(out.lines.last.strip)
497497
assert_equal 'Ran 9 tests, 6 assertions, 1 failures, 1 errors, 1 skips, 2 requeues in X.XXs', output
498498

499+
# NOTE: To filter the TypeError backtrace below see test/fixtures/test/backtrace_filters.rb
500+
499501
assert_equal <<~XML, normalize_xml(File.read(@junit_path))
500502
<?xml version="1.1" encoding="UTF-8"?>
501503
<testsuites>

0 commit comments

Comments
 (0)