Skip to content

Commit d9bd59a

Browse files
committed
handle older Julia versions
1 parent 4ecafcb commit d9bd59a

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/DataSets.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ function Base.show(io::IO, ::MIME"text/plain", d::DataSet)
173173
catch e
174174
@debug "Failed to serialize DataSet to TOML" exception = (e, catch_backtrace())
175175
print(io, "\n... <unserializable>")
176+
print(io, "\nSet JULIA_DEBUG=DataSets to see the error")
176177
end
177178
end
178179

test/runtests.jl

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,23 @@ end
6969
proj = DataSets.load_project(config)
7070
ds = dataset(proj, "a_text_file")
7171
let s = sprint(show, "text/plain", ds)
72-
parsed = TOML.parse(s)
73-
@test parsed isa Dict
74-
@test parsed["name"] == "a_text_file"
75-
@test parsed["uuid"] == "b498f769-a7f6-4f67-8d74-40b770398f26"
76-
@test parsed["foo"] == "<unserializable>"
77-
@test parsed["bar"] == [1, 2, "<unserializable>", Dict("x" => "<unserializable>", "y" => "y")]
78-
@test parsed["baz"] == Dict("x" => "<unserializable>", "y" => "y")
72+
# It looks like that in Julia <= 1.8.0, the TOML.print(f, ...) variant
73+
# for arbitrary types does not actually work, since it's missing the fallback
74+
# implementation and has other bugs, depending on the Julia version.
75+
#
76+
# So the `show()`-ed TOML will not parse again. But since we have a try-catch anyway,
77+
# we don't care too much, so we just run a simplified test in that case.
78+
if VERSION >= v"1.9.0"
79+
parsed = TOML.parse(s)
80+
@test parsed isa Dict
81+
@test parsed["name"] == "a_text_file"
82+
@test parsed["uuid"] == "b498f769-a7f6-4f67-8d74-40b770398f26"
83+
@test parsed["foo"] == "<unserializable>"
84+
@test parsed["bar"] == [1, 2, "<unserializable>", Dict("x" => "<unserializable>", "y" => "y")]
85+
@test parsed["baz"] == Dict("x" => "<unserializable>", "y" => "y")
86+
else
87+
@test occursin("<unserializable>", s)
88+
end
7989
end
8090

8191
# Also test bad keys
@@ -86,7 +96,7 @@ end
8696
proj = DataSets.load_project(config)
8797
ds = dataset(proj, "a_text_file")
8898
let s = sprint(show, "text/plain", ds)
89-
endswith(s, "\n... <unserializable>")
99+
endswith(s, "\n... <unserializable>\nSet JULIA_DEBUG=DataSets to see the error")
90100
end
91101
end
92102

0 commit comments

Comments
 (0)