Skip to content

Commit d5077de

Browse files
authored
Merge pull request #542 from probcomp/docstring-test-fix
Fix docstring tests on Julia nightly / 1.11.
2 parents 5f8520b + 977a442 commit d5077de

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

test/dsl/dynamic_dsl.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,24 @@ end
534534

535535
@testset "docstrings" begin
536536

537+
function doc_to_str(doc)
538+
if doc isa Base.Docs.DocStr
539+
# Handle @doc behavior in Julia 1.11 when REPL is not loaded
540+
return doc.text[1]
541+
else
542+
# Handle pre-Julia 1.11 behavior of @doc
543+
return string(doc)
544+
end
545+
end
546+
537547
"""
538548
my documentation
539549
"""
540550
@gen function foo(x)
541551
return x + 1
542552
end
543553

544-
io = IOBuffer()
545-
print(io, @doc foo)
546-
@test String(take!(io)) == "my documentation\n"
554+
@test doc_to_str(@doc(foo)) == "my documentation\n"
547555

548556
end
549557

test/dsl/static_dsl.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,16 @@ trace, = generate(foo, (), constraints)
558558
end
559559

560560
@testset "docstrings" begin
561-
io = IOBuffer()
562-
print(io, @doc model)
563-
@test String(take!(io)) == "my documentation\n"
561+
function doc_to_str(doc)
562+
if doc isa Base.Docs.DocStr
563+
# Handle @doc behavior in Julia 1.11 when REPL is not loaded
564+
return doc.text[1]
565+
else
566+
# Handle pre-Julia 1.11 behavior of @doc
567+
return string(doc)
568+
end
569+
end
570+
@test doc_to_str(@doc(model)) == "my documentation\n"
564571
end
565572

566573
@testset "one-line definitions" begin

0 commit comments

Comments
 (0)