Skip to content

Commit 214d95d

Browse files
committed
fix tests on 1.0
1 parent 81d42da commit 214d95d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/trials.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
471471

472472
# Here nextfloat() ensures both endpoints included, will only matter for
473473
# artificial cases such as: Trial(Parameters(), [3,4,5], [0,0,0], 0, 0)
474-
fences = range(histmin, nextfloat(float(histmax)), length=histwidth)
474+
fences = range(histmin, stop=nextfloat(float(histmax)), length=histwidth) # stop necc. for Julia 1.0
475475
bins = histogram_bindata(t.times, fences)
476476
# Last bin is everything right of last fence, introduce a gap for printing:
477477
_lastbin = pop!(bins)
@@ -523,7 +523,7 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
523523
for r in axes(hist, 1)
524524
println(io)
525525
printstyled(io, pad, "", boxspace; color=boxcolor)
526-
istop = findlast(!=(' '), view(hist, r, :))
526+
istop = findlast(c -> c != ' ', view(hist, r, :))
527527
for (i, bar) in enumerate(view(hist, r, :))
528528
i > istop && break # don't print trailing spaces, as they waste space when line-wrapped
529529
if i == avgpos

test/TrialsTests.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ module TrialsTests
33
using BenchmarkTools
44
using Test
55

6+
if !isdefined(@__MODULE__(), :contains)
7+
# added in Julia 1.5, defined here to make tests pass on 1.0
8+
contains(haystack::AbstractString, needle) = occursin(needle, haystack)
9+
end
10+
611
#########
712
# Trial #
813
#########
@@ -284,8 +289,12 @@ s456 = sprint(show, "text/plain", t456)
284289
# Compact show & arrays of Trials
285290
@test sprint(show, t001) == "Trial(3.142 ms)"
286291
@test sprint(show, t003) == "Trial(0.010 ns)"
287-
@test sprint(show, "text/plain", [t001, t003]) == "2-element Vector{BenchmarkTools.Trial}:\n 3.142 ms\n 0.010 ns"
288-
@test_skip sprint(show, "text/plain", [t0]) == "1-element Vector{BenchmarkTools.Trial}:\n ??"
292+
if VERSION >= v"1.6" # 1.5 prints Array{T,1}
293+
@test sprint(show, "text/plain", [t001, t003]) == "2-element Vector{BenchmarkTools.Trial}:\n 3.142 ms\n 0.010 ns"
294+
@test_skip sprint(show, "text/plain", [t0]) == "1-element Vector{BenchmarkTools.Trial}:\n ??"
295+
# this is an error on BenchmarkTools v1.2.1, and v0.4.3, probably long before:
296+
# MethodError: reducing over an empty collection is not allowed
297+
end
289298

290299
#=
291300

0 commit comments

Comments
 (0)