From e1f25c0b4d908aff66a722f933575d4085afe73c Mon Sep 17 00:00:00 2001 From: Justin Willmert Date: Wed, 19 Jun 2024 11:05:22 -0500 Subject: [PATCH] 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. --- test/runtests.jl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index f3b58fc..918c61a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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 @@ -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