Skip to content

Commit

Permalink
fix tests on 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Dec 8, 2021
1 parent 7251f28 commit 6cb572c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/trials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)

# Here nextfloat() ensures both endpoints included, will only matter for
# artificial cases such as: Trial(Parameters(), [3,4,5], [0,0,0], 0, 0)
fences = range(histmin, nextfloat(float(histmax)), length=histwidth)
fences = range(histmin, stop=nextfloat(float(histmax)), length=histwidth) # stop necc. for Julia 1.0
bins = histogram_bindata(t.times, fences)
# Last bin is everything right of last fence, introduce a gap for printing:
_lastbin = pop!(bins)
Expand Down Expand Up @@ -523,7 +523,7 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
for r in axes(hist, 1)
println(io)
printstyled(io, pad, "", boxspace; color=boxcolor)
istop = findlast(!=(' '), view(hist, r, :))
istop = findlast(c -> c != ' ', view(hist, r, :))
for (i, bar) in enumerate(view(hist, r, :))
i > istop && break # don't print trailing spaces, as they waste space when line-wrapped
if i == avgpos
Expand Down
13 changes: 11 additions & 2 deletions test/TrialsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ module TrialsTests
using BenchmarkTools
using Test

if !isdefined(@__MODULE__(), :contains)
# added in Julia 1.5, defined here to make tests pass on 1.0
contains(haystack::AbstractString, needle) = occursin(needle, haystack)
end

#########
# Trial #
#########
Expand Down Expand Up @@ -284,8 +289,12 @@ s456 = sprint(show, "text/plain", t456)
# Compact show & arrays of Trials
@test sprint(show, t001) == "Trial(3.142 ms)"
@test sprint(show, t003) == "Trial(0.010 ns)"
@test sprint(show, "text/plain", [t001, t003]) == "2-element Vector{BenchmarkTools.Trial}:\n 3.142 ms\n 0.010 ns"
@test_skip sprint(show, "text/plain", [t0]) == "1-element Vector{BenchmarkTools.Trial}:\n ??"
if VERSION >= v"1.6" # 1.5 prints Array{T,1}
@test sprint(show, "text/plain", [t001, t003]) == "2-element Vector{BenchmarkTools.Trial}:\n 3.142 ms\n 0.010 ns"
@test_skip sprint(show, "text/plain", [t0]) == "1-element Vector{BenchmarkTools.Trial}:\n ??"
# this is an error on BenchmarkTools v1.2.1, and v0.4.3, probably long before:
# MethodError: reducing over an empty collection is not allowed
end

#=
Expand Down

0 comments on commit 6cb572c

Please sign in to comment.