Skip to content

Commit

Permalink
Merge pull request #542 from probcomp/docstring-test-fix
Browse files Browse the repository at this point in the history
Fix docstring tests on Julia nightly / 1.11.
  • Loading branch information
ztangent authored Sep 5, 2024
2 parents 5f8520b + 977a442 commit d5077de
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 11 additions & 3 deletions test/dsl/dynamic_dsl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -534,16 +534,24 @@ end

@testset "docstrings" begin

function doc_to_str(doc)
if doc isa Base.Docs.DocStr
# Handle @doc behavior in Julia 1.11 when REPL is not loaded
return doc.text[1]
else
# Handle pre-Julia 1.11 behavior of @doc
return string(doc)
end
end

"""
my documentation
"""
@gen function foo(x)
return x + 1
end

io = IOBuffer()
print(io, @doc foo)
@test String(take!(io)) == "my documentation\n"
@test doc_to_str(@doc(foo)) == "my documentation\n"

end

Expand Down
13 changes: 10 additions & 3 deletions test/dsl/static_dsl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,16 @@ trace, = generate(foo, (), constraints)
end

@testset "docstrings" begin
io = IOBuffer()
print(io, @doc model)
@test String(take!(io)) == "my documentation\n"
function doc_to_str(doc)
if doc isa Base.Docs.DocStr
# Handle @doc behavior in Julia 1.11 when REPL is not loaded
return doc.text[1]
else
# Handle pre-Julia 1.11 behavior of @doc
return string(doc)
end
end
@test doc_to_str(@doc(model)) == "my documentation\n"
end

@testset "one-line definitions" begin
Expand Down

0 comments on commit d5077de

Please sign in to comment.