Skip to content

Commit 21da887

Browse files
authored
Merge pull request #155 from tkf/unlimit
Fix how IOContext :limit is handled
2 parents 688bae9 + b7d50b9 commit 21da887

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/groups.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,21 @@ tagrepr(tags) = string("[", join(map(repr, tags), ", "), "]")
267267
Base.summary(io::IO, group::BenchmarkGroup) = print(io, "$(length(group))-element BenchmarkGroup($(tagrepr(group.tags)))")
268268

269269
function Base.show(io::IO, group::BenchmarkGroup)
270+
limit = get(io, :limit, true)
271+
if !(limit isa Bool)
272+
msg = (
273+
"`show(IOContext(io, :limit => number), group::BenchmarkGroup)` is" *
274+
" deprecated. Please use `IOContext(io, :boundto => number)` to" *
275+
" bound the number of elements to be shown."
276+
)
277+
Base.depwarn(msg, :show)
278+
nbound = get(io, :boundto, limit)
279+
elseif limit === false
280+
nbound = Inf
281+
else
282+
nbound = get(io, :boundto, 10)
283+
end
284+
270285
println(io, "$(length(group))-element BenchmarkTools.BenchmarkGroup:")
271286
pad = get(io, :pad, "")
272287
print(io, pad, " tags: ", tagrepr(group.tags))
@@ -275,7 +290,7 @@ function Base.show(io::IO, group::BenchmarkGroup)
275290
println(io)
276291
print(io, pad, " ", repr(k), " => ")
277292
show(IOContext(io, :pad => "\t"*pad), v)
278-
count > get(io, :limit, 10) && (println(io); print(io, pad, ""); break)
293+
count > nbound && (println(io); print(io, pad, ""); break)
279294
count += 1
280295
end
281296
end

test/GroupsTests.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,37 @@ g2[[1, "a", :b]] = "hello" # should create higher levels on the fly
277277

278278
@test g1 == g2
279279

280+
# pretty printing #
281+
#-----------------#
282+
283+
g1 = BenchmarkGroup(["1", "2"])
284+
g1["a"] = t1a
285+
g1["b"] = t1b
286+
g1["c"] = tc
287+
288+
@test sprint(show, g1) == """
289+
3-element BenchmarkTools.BenchmarkGroup:
290+
tags: ["1", "2"]
291+
"c" => TrialEstimate(1.000 ns)
292+
"b" => TrialEstimate(4.123 μs)
293+
"a" => TrialEstimate(32.000 ns)"""
294+
@test sprint(show, g1; context = :boundto => 1) == """
295+
3-element BenchmarkTools.BenchmarkGroup:
296+
tags: ["1", "2"]
297+
"c" => TrialEstimate(1.000 ns)
298+
"b" => TrialEstimate(4.123 μs)
299+
"""
300+
@test sprint(show, g1; context = :limit => false) == """
301+
3-element BenchmarkTools.BenchmarkGroup:
302+
tags: ["1", "2"]
303+
"c" => TrialEstimate(1.000 ns)
304+
"b" => TrialEstimate(4.123 μs)
305+
"a" => TrialEstimate(32.000 ns)"""
306+
@test @test_deprecated(sprint(show, g1; context = :limit => 1)) == """
307+
3-element BenchmarkTools.BenchmarkGroup:
308+
tags: ["1", "2"]
309+
"c" => TrialEstimate(1.000 ns)
310+
"b" => TrialEstimate(4.123 μs)
311+
"""
280312

281313
# end # module

0 commit comments

Comments
 (0)