diff --git a/Project.toml b/Project.toml index a28cb5a8..9ef95106 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BenchmarkTools" uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" -version = "1.6.1" +version = "1.6.2" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" diff --git a/src/serialization.jl b/src/serialization.jl index 5aa7cced..c3358018 100644 --- a/src/serialization.jl +++ b/src/serialization.jl @@ -29,6 +29,19 @@ function JSON.lower(x::Union{values(SUPPORTED_TYPES)...}) return [string(nameof(typeof(x))), d] end +# Special support is needed for JSON@1, because it doesn't know how to support +# NTuple{N,String} as a dictionary key. +# +# Upstream issue: https://github.com/JuliaIO/JSON.jl/issues/399 +# +# This method may be removed if the upstream issue is fixed. +function JSON.lower(x::BenchmarkGroup) + d = Dict{String,Any}( + "data" => Dict(string(k) => v for (k, v) in x.data), "tags" => x.tags + ) + return ["BenchmarkGroup", d] +end + # a minimal 'eval' function, mirroring KeyTypes, but being slightly more lenient safeeval(@nospecialize x) = x safeeval(x::QuoteNode) = x.value diff --git a/test/SerializationTests.jl b/test/SerializationTests.jl index e24314a1..3d4ab165 100644 --- a/test/SerializationTests.jl +++ b/test/SerializationTests.jl @@ -124,4 +124,11 @@ end @test BenchmarkTools.load(json_io) == [params] end +@testset "issue_400_tuple_as_dict_key" begin + grp = BenchmarkTools.BenchmarkGroup() + grp["a", "b"] = BenchmarkTools.BenchmarkGroup() + contents = sprint(io -> BenchmarkTools.save(io, grp)) + @test occursin(""""data":{"(\\\"a\\", \\"b\\")":[""", contents) +end + end # module