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

Doctest filter matches line by line by default #1679

Closed
TorkelE opened this issue Aug 17, 2021 · 5 comments · Fixed by #1720
Closed

Doctest filter matches line by line by default #1679

TorkelE opened this issue Aug 17, 2021 · 5 comments · Fixed by #1720

Comments

@TorkelE
Copy link

TorkelE commented Aug 17, 2021

I am trying to get the regex filter function to work for a simple doctest (with the goal of creating a filter which checks whenever there was an error or not).

Checking from here #452, it seems that filter = r".*" should create something which accepts any output. So I try:
(in all code blocks I will use ' to denote those things which create code in markdown, so to avoid messing up the formatting).

'''jldoctest; filter = r".*"
1
# output
1
'''

and

'''jldoctest; filter = r".*"
1
# output
2
'''

which both works.

However, if I try anything a little bit complicated, it fails, e.g.

'''jldoctest; filter = r".*"
[1,2]
# output
2
'''

however, if it is a bit more similar, it does work:

'''jldoctest; filter = r".*"
[1,2]
# output
2-element Vector{Int64}:
 1
 3
'''

I also tried modifying the regex for multiple lines, e.g. filter = r"\_.\{-}". Not sure whenever that is needed/correct though (in either case, didn't work)

@mortenpi
Copy link
Member

mortenpi commented Aug 20, 2021

I think the issue is that the replace call here is not greedy enough and keeps line endings:

julia> replace("""
       foo
       bar
       """, r".*" => "")
"\n\n"

So in the end the strings that get compared have a different number of newlines, and so don't match.

It does feel like a bug.. I think the filtering should probably be maximally greedy.

@fredrikekre
Copy link
Member

You can use the s modifier to let . match newlines (see docs for @r_str):

julia> replace("""
       foo
       bar
       """, r".*"s => "")
""

@TorkelE
Copy link
Author

TorkelE commented Aug 20, 2021

Just confirming that

'''jldoctest; filter = r".*"s
[1,2]

# output

3
'''

works.

Thanks a lot!

@TorkelE
Copy link
Author

TorkelE commented Aug 20, 2021

Although maybe I was too fast. But the continuation problem might be separate, so created a new issue: https://github.com/JuliaDocs/Documenter.jl/issues/new

@mortenpi mortenpi changed the title Unable to get simple regex filter to work Doctest filter matches line by line by default Aug 21, 2021
@mortenpi
Copy link
Member

I'll re-open this to leave it as a documentation issue -- we should mention in the docs that the filtering happens line by line.

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

Successfully merging a pull request may close this issue.

3 participants