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

Use logging system for doctest-failure reporting. #958

Merged
merged 1 commit into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@

* ![Enhancement][badge-enhancement] The HTML output now also supports SVG, WebP, GIF and JPEG logos. ([#953][github-953])

* ![Enhancement][badge-enhancement] Reporting of failed doctests are now using the logging
system to be consistent with the rest of Documenter's output. ([#958][github-958])

* ![Bugfix][badge-bugfix] Paths in `include` calls in `@eval`, `@example`, `@repl` and `jldoctest`
blocks are now interpreted to be relative `pwd`, which is set to the output directory of the
resulting file. ([#941][github-941])
Expand Down Expand Up @@ -248,6 +251,7 @@
[github-946]: https://github.com/JuliaDocs/Documenter.jl/pull/946
[github-948]: https://github.com/JuliaDocs/Documenter.jl/pull/948
[github-953]: https://github.com/JuliaDocs/Documenter.jl/pull/953
[github-958]: https://github.com/JuliaDocs/Documenter.jl/pull/958

[documenterlatex]: https://github.com/JuliaDocs/DocumenterLaTeX.jl
[documentermarkdown]: https://github.com/JuliaDocs/DocumenterMarkdown.jl
Expand Down
46 changes: 20 additions & 26 deletions src/DocTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,34 +258,28 @@ end
import .Utilities.TextDiff

function report(result::Result, str, doc::Documents.Document)
iob = IOBuffer()
ioc = IOContext(iob, :color => Base.have_color)
println(ioc, "=====[Test Error]", "="^30)
println(ioc)
printstyled(ioc, "> Location: ", result.file, color=:cyan)
printstyled(ioc, Utilities.find_block_in_file(result.block.code, result.file), color=:cyan)
printstyled(ioc, "\n\n> Code block:\n", color=:cyan)
println(ioc, "\n```$(result.block.language)")
println(ioc, result.block.code)
println(ioc, "```")
if !isempty(result.input)
printstyled(ioc, "\n> Subexpression:\n", color=:cyan)
print_indented(ioc, result.input; indent = 4)
end
warning = Base.have_color ? "" : " (REQUIRES COLOR)"
printstyled(ioc, "\n> Output Diff", warning, ":\n\n", color=:cyan)
diff = TextDiff.Diff{TextDiff.Words}(result.output, rstrip(str))
Utilities.TextDiff.showdiff(ioc, diff)
println(ioc, "\n\n", "=====[End Error]=", "="^30)
push!(doc.internal.errors, :doctest)
printstyled(String(take!(iob)), color=:normal)
end
lines = Utilities.find_block_in_file(result.block.code, result.file)
@error("""
doctest failure in $(Utilities.locrepr(result.file, lines))

function print_indented(buffer::IO, str::AbstractString; indent = 4)
println(buffer)
for line in split(str, '\n')
println(buffer, " "^indent, line)
end
```$(result.block.language)
$(result.block.code)
```

Subexpression:

$(result.input)
fredrikekre marked this conversation as resolved.
Show resolved Hide resolved

Output:

$(result.output)

Expected output:

$(rstrip(str))

""", diff)
fredrikekre marked this conversation as resolved.
Show resolved Hide resolved
fredrikekre marked this conversation as resolved.
Show resolved Hide resolved
end

function fix_doctest(result::Result, str, doc::Documents.Document)
Expand Down
8 changes: 2 additions & 6 deletions src/Utilities/TextDiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,11 @@ end
prefix(::Diff{Lines}, s::Symbol) = s === :green ? "+ " : s === :red ? "- " : " "
prefix(::Diff{Words}, ::Symbol) = ""

function showdiff(io::IO, diff::Diff)
function Base.show(io::IO, diff::Diff)
get(io, :color, false) || println(io, "Warning: Diff output requires color.")
fredrikekre marked this conversation as resolved.
Show resolved Hide resolved
for (color, text) in diff.diff
printstyled(io, prefix(diff, color), text, color=color)
end
end

function Base.show(io::IO, diff::Diff)
printstyled(io, color=:normal) # Reset colors.
showdiff(io, diff)
end

end
2 changes: 1 addition & 1 deletion src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end
function locrepr(file, line=nothing)
str = Base.contractuser(file) # TODO: Maybe print this relative the doc-root??
line !== nothing && (str = str * "$(line)")
return "`$(str)`"
return str
end

# Directory paths.
Expand Down