Skip to content

Commit

Permalink
Fix doc string tests in prep for Julia v1.11 release
Browse files Browse the repository at this point in the history
The change in JuliaLang/julia#54499 fixed the ability to access/copy
doc strings without needing to take an explicit dependency on the
REPL package, but the returned object does not trivially reduce back
to a string, as described in issue JuliaLang/julia#54664.

Instead of waiting for that issue to get resolved at the Julia level
to fix our tests, just add a helper shim to the tests to access the
desired information. The goal is to just ensure that the macro
`@__doc__` expression is correctly used to permit documenting the
generated type definitions, so we don't really care about the specific
form as long as Julia uses it correctly within the docs system.
  • Loading branch information
jmert committed Jun 19, 2024
1 parent f858546 commit e1f25c0
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
using BitFlags
using Test, Serialization

# workaround for https://github.com/JuliaLang/julia/issues/54664
function extractdoc(doc)
# On v1.11 without REPL loaded, the @doc macro returns a Base.Docs.DocStr object;
# extract the stored string from the object.
doc isa Base.Docs.DocStr && return doc.text[1]
# Otherwise, assume we get something like a Markdown.MD object and just turn it into
# a string. (Strip trailing newline for consistency with above form.)
return strip(string(doc))
end

macro macrocall(ex)
@assert Meta.isexpr(ex, :macrocall)
ex.head = :call
Expand Down Expand Up @@ -95,10 +105,10 @@ end
#@testset "Documentation" begin
# docstring literal
"""My Docstring""" @bitflag DocFlag1 docflag1a
@test string(@doc(DocFlag1)) == "My Docstring\n"
@test extractdoc(@doc(DocFlag1)) == "My Docstring"
# docstring macro for non-string literals
@doc raw"""Raw Docstring""" @bitflag DocFlag2 docflag2a
@test string(@doc(DocFlag2)) == "Raw Docstring\n"
@test extractdoc(@doc(DocFlag2)) == "Raw Docstring"
#end

#@testset "Type properties" begin
Expand Down Expand Up @@ -333,9 +343,9 @@ end

# Documentation
"""My Docstring""" @bitflagx SDocFlag1 docflag
@test string(@doc(SDocFlag1)) == "My Docstring\n"
@test extractdoc(@doc(SDocFlag1)) == "My Docstring"
@doc raw"""Raw Docstring""" @bitflagx SDocFlag2 docflag
@test string(@doc(SDocFlag2)) == "Raw Docstring\n"
@test extractdoc(@doc(SDocFlag2)) == "Raw Docstring"

# Error conditions
# Too few arguments
Expand Down

0 comments on commit e1f25c0

Please sign in to comment.