Skip to content

Commit

Permalink
Use logging system for doctest-failure reporting. (#958)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Feb 14, 2019
1 parent 2c06da1 commit 951f577
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
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 @@ -259,34 +259,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)
Output:
$(result.output)
Expected output:
$(rstrip(str))
""", diff)
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.")
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

0 comments on commit 951f577

Please sign in to comment.