Skip to content

Commit 7dbf408

Browse files
committed
Support JSON 1.0 release
1 parent 4102e74 commit 7dbf408

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1414
[compat]
1515
Aqua = "0.8"
1616
Compat = "4.11"
17-
JSON = "0.18, 0.19, 0.20, 0.21"
17+
JSON = "0.18, 0.19, 0.20, 0.21, 1"
1818
Logging = "<0.0.1, 1"
1919
Printf = "<0.0.1, 1"
2020
Profile = "<0.0.1, 1"

src/serialization.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function JSON.lower(x::Union{values(SUPPORTED_TYPES)...})
2424
field = getfield(x, i)
2525
ft = typeof(field)
2626
value = ft <: get(SUPPORTED_TYPES, nameof(ft), Union{}) ? JSON.lower(field) : field
27-
d[name] = value
27+
d[name] = value isa Float64 && !isfinite(value) ? nothing : value
2828
end
2929
return [string(nameof(typeof(x))), d]
3030
end
@@ -41,7 +41,7 @@ end
4141
function recover(x::Vector)
4242
length(x) == 2 || throw(ArgumentError("Expecting a vector of length 2"))
4343
typename = x[1]::String
44-
fields = x[2]::Dict
44+
fields = x[2]::AbstractDict
4545
startswith(typename, "BenchmarkTools.") &&
4646
(typename = typename[(sizeof("BenchmarkTools.") + 1):end])
4747
T = SUPPORTED_TYPES[Symbol(typename)]
@@ -64,7 +64,7 @@ function recover(x::Vector)
6464
convert(ft, fields[fn])
6565
end
6666
end
67-
if T == BenchmarkGroup && xsi isa Dict
67+
if T == BenchmarkGroup && xsi isa AbstractDict
6868
for (k, v) in copy(xsi)
6969
k = k::String
7070
if startswith(k, "(") || startswith(k, ":")
@@ -154,11 +154,11 @@ function load(io::IO, args...)
154154
parsed = JSON.parse(io)
155155
if !isa(parsed, Vector) ||
156156
length(parsed) != 2 ||
157-
!isa(parsed[1], Dict) ||
157+
!isa(parsed[1], AbstractDict) ||
158158
!isa(parsed[2], Vector)
159159
error("Unexpected JSON format. Was this file originally written by BenchmarkTools?")
160160
end
161-
versions = parsed[1]::Dict
161+
versions = parsed[1]::AbstractDict
162162
values = parsed[2]::Vector
163163
return map!(recover, values, values)
164164
end

test/GroupsTests.jl

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -361,28 +361,49 @@ g1["a"] = t1a
361361
g1["b"] = t1b
362362
g1["c"] = tc
363363

364-
@test sprint(show, g1) == """
364+
# Test full output (order-independent)
365+
output_full = sprint(show, g1)
366+
@test startswith(
367+
output_full,
368+
"""
365369
3-element BenchmarkTools.BenchmarkGroup:
366370
tags: ["1", "2"]
367-
"c" => TrialEstimate(1.000 ns)
368-
"b" => TrialEstimate(4.123 μs)
369-
"a" => TrialEstimate(32.000 ns)"""
370-
@test sprint(show, g1; context=:boundto => 1) == """
371+
""",
372+
)
373+
@test occursin(" \"a\" => TrialEstimate(32.000 ns)", output_full)
374+
@test occursin(" \"b\" => TrialEstimate(4.123 μs)", output_full)
375+
@test occursin(" \"c\" => TrialEstimate(1.000 ns)", output_full)
376+
377+
# Test boundto context output
378+
output_boundto = sprint(show, g1; context=:boundto => 1)
379+
@test startswith(
380+
output_boundto,
381+
"""
371382
3-element BenchmarkTools.BenchmarkGroup:
372383
tags: ["1", "2"]
373-
"c" => TrialEstimate(1.000 ns)
374-
"""
375-
@test sprint(show, g1; context=:limit => false) == """
384+
""",
385+
)
386+
387+
# Test limit => false output (order-independent)
388+
output_no_limit = sprint(show, g1; context=:limit => false)
389+
@test startswith(output_no_limit, """
376390
3-element BenchmarkTools.BenchmarkGroup:
377391
tags: ["1", "2"]
378-
"c" => TrialEstimate(1.000 ns)
379-
"b" => TrialEstimate(4.123 μs)
380-
"a" => TrialEstimate(32.000 ns)"""
381-
@test @test_deprecated(sprint(show, g1; context=:limit => 1)) == """
392+
"""
393+
)
394+
@test occursin(" \"a\" => TrialEstimate(32.000 ns)", output_no_limit)
395+
@test occursin(" \"b\" => TrialEstimate(4.123 μs)", output_no_limit)
396+
@test occursin(" \"c\" => TrialEstimate(1.000 ns)", output_no_limit)
397+
398+
# Test deprecated limit context output
399+
output_limit_deprecated = @test_deprecated(sprint(show, g1; context=:limit => 1))
400+
@test startswith(
401+
output_limit_deprecated,
402+
"""
382403
3-element BenchmarkTools.BenchmarkGroup:
383404
tags: ["1", "2"]
384-
"c" => TrialEstimate(1.000 ns)
385-
"""
405+
""",
406+
)
386407

387408
# EasyConfig-style benchmark groups #
388409
#-----------------------------------#

0 commit comments

Comments
 (0)