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

Improve warnings in fix_doctest #2602

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions src/doctests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -490,21 +490,23 @@
r = Regex(rcode)
codeidx = findfirst(r, content)
if codeidx === nothing
@warn "could not find code block in source file"
@warn "could not find code block in source file $filename"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it would be kinda helpful if one would see the code block. Any reason why I shouldn't just print it here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be fine. I think we do that for some other messages already.

return
end
# use the capture group to identify indentation
indent = match(r, content).captures[1]
# write everything up until the code block
write(io, content[1:prevind(content, first(codeidx))])
data = content[1:prevind(content, first(codeidx))]

Check warning on line 499 in src/doctests.jl

View check run for this annotation

Codecov / codecov/patch

src/doctests.jl#L499

Added line #L499 was not covered by tests
write(io, data)
# next look for the particular input string in the given code block
# make a regex of the input that matches leading whitespace (for multiline input)
composed = prefix.content * result.raw_input
rinput = replace(Documenter.regex_escape(composed), "\\n" => "\\n\\h*")
r = Regex(rinput)
inputidx = findfirst(r, code)
if inputidx === nothing
@warn "could not find input line in code block"
startline = count("\n", data)
@warn "could not find input line in code block in $filename:$startline"

Check warning on line 509 in src/doctests.jl

View check run for this annotation

Codecov / codecov/patch

src/doctests.jl#L508-L509

Added lines #L508 - L509 were not covered by tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here the "current" code block which was found: any particular reason not to print it here? Would have been helpful to me in the past

return
end
# construct the new code-snippet (without indent)
Expand Down
Loading