-
Notifications
You must be signed in to change notification settings - Fork 484
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 filters have to match both output and expected output #2277
Comments
For context, this comes from JuliaMath/Primes.jl#140 |
OK maybe this is a hint: if I use
But if I use
|
So, this is non-obvious, but caused by the Line 283 in e50da5d
Both output and expected output have to match before filtering is applied. I am unsure of the usecase, but it was intentionally added as a bugfix: #588 Minimally, this should be documented though. |
#
does not work
So I was thinking about this a bit. We have 4 cases that can happen when we apply a filter to a doctest:
For (1) we apply the filtering, and everyone is happy. For (2), the filtering would have no effect anyway, so it doesn't really matter if we apply it or not. The question is whether we should also apply the filter in cases (3) and (4). Currently we don't. Let's suppose we have output like In case (3), where we would filter when the evaluated output matches the filter, but reference doesn't, you would run into the case where following doctest would pass:
This is not what the user would expect -- they clearly expect the part after One argument here could be then that, since the expected output doesn't have the pattern anyway, then why are you even filtering this? But this case can happen when you use global doctest filters (e.g. Case (4), where expected output matches, but evaluated doesn't, would lead to the opposite doctest passing:
Here I think the user definitely wants the doctest to fail if the number after Some closing thoughts:
|
Presumably this is the same bug, but this surprised me: in the doc markdown files, I have
and it seems to work: julia> replace("AffineMap([1.9999999999999996 0.4999999999999999; -5.551115123125783e-16 2.0], [0.9999999999999999, 1.0000000000000002])", [r"1\.9999\d+" => "2.0", r"0\.49999\d+" => "0.5", r"[ -]\d\.\d+e-\d\d" => "0.0", r"0\.9999\d+" => "1.0", r"1\.0000\d+" => "1.0"]...)
"AffineMap([2.0 0.5; 0.0 2.0], [1.0, 1.0])"
but that's pretty non-obvious. |
Can't your
case be handled simply by writing the filter more carefully, e.g., |
I don't find the reasoning
for the example
very compelling. I could just as well argue "clearly the user expected 1234 to occur there, or "the user expected a number starting with 1 there". And what is with this example, which I expect will pass since the regex applies to both outputs?
Overall for global regex filters I am sure it will be frequent that they get applied to things which the author did not have in mind -- I actually think that's a (difficult) design issue with the entire regex filter system. Which is not meant as a complaint, this is after all a difficult problem and I certainly don't have a great alternative in mind. I merely want to point out that this is IMHO a systematic issue. Anyway, I don't expect to be able to change minds, and it may be too late anyway (perhaps even breaking people's existing tests). So I hope it can at least be documented at https://documenter.juliadocs.org/stable/man/doctests/#Filtering-Doctests (and perhaps illustrated with an example). (Perhaps I can find some time to write something but I don't want to make promises I can't keep, sorry) |
Personally I'd say this is worth fixing in the long run (Documenter 2.0), but certainly documenting this limitation in the short run makes sense. |
Here is an MWE:
I would expect this to pass, but it doesn't. Doing
ENV["JULIA_DEBUG"] = "Documenter"
reveals that the filter is not (?) applied:(note the confusing "Evaluated output (filtered)", fixed by PR #2276)
The text was updated successfully, but these errors were encountered: