-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Added Minitest::Compress#compress and added it to UnexpectedError
[git-p4: depot-paths = "//src/minitest/dev/": change = 14004]
- Loading branch information
Showing
5 changed files
with
245 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
module Minitest | ||
## | ||
# Compresses backtraces. | ||
|
||
module Compress | ||
|
||
## | ||
# Takes a backtrace (array of strings) and compresses repeating | ||
# cycles in it to make it more readable. | ||
|
||
def compress orig | ||
ary = orig | ||
|
||
eswo = ->(ary, n, off) { # each_slice_with_offset | ||
if off.zero? then | ||
ary.each_slice n | ||
else | ||
# [ ...off... [...n...] [...n...] ... ] | ||
front, back = ary.take(off), ary.drop(off) | ||
[front].chain back.each_slice n | ||
end | ||
} | ||
|
||
3.times do # maybe don't use loop do here? | ||
index = ary # [ a b c b c b c d ] | ||
.size | ||
.times # 0...size | ||
.group_by { |i| ary[i] } # { a: [0] b: [1 3 5], c: [2 4 6], d: [7] } | ||
|
||
order = index | ||
.reject { |k, v| v.size == 1 } # { b: [1 3 5], c: [2 4 6] } | ||
.sort_by { |k, ary| ### sort by max dist + min offset | ||
d = ary.each_cons(2).sum { |a, b| b-a } | ||
[-d, ary.first] | ||
} # b: [1 3 5] c: [2 4 6] | ||
|
||
ranges = order | ||
.map { |k, ary| # [[1..2 3..4] [2..3 4..5]] | ||
ary | ||
.each_cons(2) | ||
.map { |a, b| a..b-1 } | ||
} | ||
|
||
big_ranges = ranges | ||
.flat_map { |a| # [1..2 3..4 2..3 4..5] | ||
a.sort_by { |r| [-r.size, r.first] }.first 5 | ||
} | ||
.first(100) | ||
|
||
culprits = big_ranges | ||
.map { |r| | ||
eswo[ary, r.size, r.begin] # [o1 s1 s1 s2 s2] | ||
.chunk_while { |a,b| a == b } # [[o1] [s1 s1] [s2 s2]] | ||
.map { |a| [a.size, a.first] } # [[1 o1] [2 s1] [2 s2]] | ||
} | ||
.select { |chunks| | ||
chunks.any? { |a| a.first > 1 } # compressed anything? | ||
} | ||
|
||
min = culprits | ||
.min_by { |a| a.flatten.size } # most compressed | ||
|
||
break unless min | ||
|
||
ary = min.flat_map { |(n, lines)| | ||
if n > 1 then | ||
[ | ||
" +->> #{n} cycles of #{lines.size} lines:", | ||
*lines.map { |s| " | #{s}" }, | ||
" +-<<", | ||
] | ||
else | ||
lines | ||
end | ||
} | ||
end | ||
|
||
ary | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters