Skip to content

Commit e1f25c0

Browse files
committed
Fix doc string tests in prep for Julia v1.11 release
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.
1 parent f858546 commit e1f25c0

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

test/runtests.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
using BitFlags
22
using Test, Serialization
33

4+
# workaround for https://github.com/JuliaLang/julia/issues/54664
5+
function extractdoc(doc)
6+
# On v1.11 without REPL loaded, the @doc macro returns a Base.Docs.DocStr object;
7+
# extract the stored string from the object.
8+
doc isa Base.Docs.DocStr && return doc.text[1]
9+
# Otherwise, assume we get something like a Markdown.MD object and just turn it into
10+
# a string. (Strip trailing newline for consistency with above form.)
11+
return strip(string(doc))
12+
end
13+
414
macro macrocall(ex)
515
@assert Meta.isexpr(ex, :macrocall)
616
ex.head = :call
@@ -95,10 +105,10 @@ end
95105
#@testset "Documentation" begin
96106
# docstring literal
97107
"""My Docstring""" @bitflag DocFlag1 docflag1a
98-
@test string(@doc(DocFlag1)) == "My Docstring\n"
108+
@test extractdoc(@doc(DocFlag1)) == "My Docstring"
99109
# docstring macro for non-string literals
100110
@doc raw"""Raw Docstring""" @bitflag DocFlag2 docflag2a
101-
@test string(@doc(DocFlag2)) == "Raw Docstring\n"
111+
@test extractdoc(@doc(DocFlag2)) == "Raw Docstring"
102112
#end
103113

104114
#@testset "Type properties" begin
@@ -333,9 +343,9 @@ end
333343

334344
# Documentation
335345
"""My Docstring""" @bitflagx SDocFlag1 docflag
336-
@test string(@doc(SDocFlag1)) == "My Docstring\n"
346+
@test extractdoc(@doc(SDocFlag1)) == "My Docstring"
337347
@doc raw"""Raw Docstring""" @bitflagx SDocFlag2 docflag
338-
@test string(@doc(SDocFlag2)) == "Raw Docstring\n"
348+
@test extractdoc(@doc(SDocFlag2)) == "Raw Docstring"
339349

340350
# Error conditions
341351
# Too few arguments

0 commit comments

Comments
 (0)