Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctests for modules are troublesome (premature end of input) #35114

Open
timholy opened this issue Mar 15, 2020 · 3 comments
Open

Doctests for modules are troublesome (premature end of input) #35114

timholy opened this issue Mar 15, 2020 · 3 comments
Labels
docsystem The documentation building system

Comments

@timholy
Copy link
Sponsor Member

timholy commented Mar 15, 2020

In #35094 I initially used jldoctest for the demonstration, but I got several errors that, in the end, I gave up trying to fix. I suspect this is mostly because it created a new module. Suspiciously, the modules chapter of the manual is entirely free of doctests.

The fundamental error is

 ```jldoctest
│ julia> module Hinter

│        only_int(x::Int)      = 1
│        any_number(x::Number) = 2

│        function __init__()
│            register_error_hint(MethodError) do io, exc, argtypes, kwargs
│                if exc.f == only_int
│                     print(io, "\nDid you mean to call ")
│                     printstyled(io, "`any_number`?", color=:light_magenta)
│                end
│            end
│        end

│        end
│ Main.Hinter

│ julia> Hinter.only_int(1.0)
│ ERROR: MethodError: no method matching only_int(::Float64)
│ Did you mean to call `any_number`?
│ Closest candidates are:
│ [...]
```
│ 
│ Subexpression:
│ 
│ module Hinter
│ 
│ Evaluated output:
│ 
│ ERROR: syntax: incomplete: premature end of input
│ Stacktrace:
│  [1] top-level scope at none:180
│ 
│ Expected output:
│ 
│ 
│        only_int(x::Int)      = 1any_number(x::Number) = 2
│ 
│        function __init__()
│            register_error_hint(MethodError) do io, exc, argtypes, kwargs
│                if exc.f == only_int
│                     print(io, "\nDid you mean to call ")
│                     printstyled(io, "`any_number`?", color=:light_magenta)
│                endendend
│ 
│        end
│ Main.Hinter
│ 
│   diff =
│    Warning: Diff output requires color.
│    
│           only_int(x::Int)      = 1any_number(x::Number) = 2
│    
│           function __init__()
│               register_error_hint(MethodError) do io, exc, argtypes, kwargs
│                   if exc.f == only_int
│                        print(io, "\nDid you mean to call ")
│                        printstyled(io, "`any_number`?", color=:light_magenta)
│                   endendend
│    
│           end
│    Main.HinterERROR: syntax: incomplete: premature end of input
│    Stacktrace:
│     [1] top-level scope at none:180
└ @ Documenter.DocTests ~/src/julia-master/doc/deps/packages/Documenter/HmOsT/src/DocTests.jl:369
┌ Error: doctest failure in errorshow.jl
@timholy timholy added the docsystem The documentation building system label Mar 15, 2020
@timholy timholy changed the title Doctests for modules are troublesome (premature end of output) Doctests for modules are troublesome (premature end of input) Mar 15, 2020
@fredrikekre
Copy link
Member

This is probably due to Documenters heuristics on how to split input from output.

@fredrikekre
Copy link
Member

Probably works if you write it with not empty lines, i.e.

julia> module Hinter
       only_int(x::Int)      = 1
       any_number(x::Number) = 2
       function __init__()
           register_error_hint(MethodError) do io, exc, argtypes, kwargs
               if exc.f == only_int
                    print(io, "\nDid you mean to call ")
                    printstyled(io, "`any_number`?", color=:light_magenta)
               end
           end
       end
       end

@tkf
Copy link
Member

tkf commented Mar 15, 2020

xref JuliaDocs/Documenter.jl#963

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docsystem The documentation building system
Projects
None yet
Development

No branches or pull requests

3 participants