From 6cb572c9b99d2706ce17163eb8ace452d3bae48a Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Sun, 5 Dec 2021 13:29:05 -0500 Subject: [PATCH] fix tests on 1.0 --- src/trials.jl | 4 ++-- test/TrialsTests.jl | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/trials.jl b/src/trials.jl index a6032984..506885a8 100644 --- a/src/trials.jl +++ b/src/trials.jl @@ -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) @@ -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 diff --git a/test/TrialsTests.jl b/test/TrialsTests.jl index 48af8417..64a6954a 100644 --- a/test/TrialsTests.jl +++ b/test/TrialsTests.jl @@ -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 # ######### @@ -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 #=