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

Conversation

fingolfin
Copy link
Contributor

Resolves #2601

TODO:

  • changelog
  • test case
  • perhaps there is a better way to get the startline?
  • perhaps the warning could be improve further by showing what content it failed to match

@fingolfin
Copy link
Contributor Author

@mortenpi does this seem sane? If so I'll go ahead and add tests and a changelog entry.

@@ -490,21 +490,23 @@ function fix_doctest(result::Result, str, doc::Documenter.Document; prefix::Muta
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.

# 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"
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

@mortenpi
Copy link
Member

I haven't tested this, but from the looks of it, LGTM. Any extra context like this in the error messages is good.

It would be good to have a test case, yes. We have some tests here for the fixing here (https://github.com/JuliaDocs/Documenter.jl/tree/master/test/doctests/fix). Not sure how easy it would be to expand those though to somehow test the new things. Maybe a few simple occursin checks on the output would be enough though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message could not find input line in code block by indicating location of that code block
2 participants