From 0ff1213633e255edd4d2c8d8597d7bfc35e070a3 Mon Sep 17 00:00:00 2001 From: Michael Hatherly Date: Sun, 1 Jan 2017 20:56:36 +0200 Subject: [PATCH] Fix world age for `show` methods in doctests Fixes #398. --- src/DocChecks.jl | 2 +- test/examples/make.jl | 20 ++++++++++++++++++++ test/examples/src/index.md | 13 +++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/DocChecks.jl b/src/DocChecks.jl index 7d229d65ca..8772122161 100644 --- a/src/DocChecks.jl +++ b/src/DocChecks.jl @@ -271,7 +271,7 @@ end function result_to_string(buf, value) dis = text_display(buf) - value === nothing || display(dis, value) + value === nothing || eval(Expr(:call, display, dis, QuoteNode(value))) sanitise(buf) end diff --git a/test/examples/make.jl b/test/examples/make.jl index 8c1bef650a..c0906efc10 100644 --- a/test/examples/make.jl +++ b/test/examples/make.jl @@ -79,6 +79,25 @@ module AutoDocs end end +module Issue398 + +immutable TestType{T} end + +function _show end +Base.show(io::IO, t::TestType) = _show(io, t) + +macro define_show_and_make_object(x, y) + z = Expr(:quote, x) + esc(quote + $(Issue398)._show(io::IO, t::$(Issue398).TestType{$z}) = print(io, $y) + const $x = $(Issue398).TestType{$z}() + end) +end + +export @define_show_and_make_object + +end # module + # Build example docs using Documenter @@ -89,6 +108,7 @@ examples_markdown_doc = makedocs( debug = true, root = examples_root, build = "builds/markdown", + doctest = false, ) info("Building mock package docs: HTMLWriter") diff --git a/test/examples/src/index.md b/test/examples/src/index.md index ad8eede5bc..d004503a8b 100644 --- a/test/examples/src/index.md +++ b/test/examples/src/index.md @@ -136,3 +136,16 @@ julia> fullname(Base.Pkg) julia> current_module() Main ``` + +# Issue398 + +```@meta +DocTestSetup = quote + using Issue398 +end +``` + +```jldoctest +julia> @define_show_and_make_object q "abcd" +abcd +```