Documenter.jl icon indicating copy to clipboard operation
Documenter.jl copied to clipboard

jldoctest fails if # output has trailing space

Open jlbosse opened this issue 2 years ago • 7 comments

Currently named doctests fail, if there is a trailing space after the beginning the jldoctest block. Example

a = 1
b = 2
a + b

# output 
3

where I have one trailing space behind the # output line fails with

┌ Warning: invalid doctest block in ...
│ Requires `julia> ` or `# output`
│
│ ```jldoctest mytest

which took me quite a while to find.

jlbosse avatar Sep 16 '22 20:09 jlbosse

We should probably loosen the regex here, by allowing arbitrary whitespace here: https://github.com/JuliaDocs/Documenter.jl/blob/056284a9850a0e74a439a694e267aff20a7311f5/src/DocTests.jl#L193

mortenpi avatar Sep 17 '22 06:09 mortenpi

Why do we want this? Isn't it better to be explicit? Trailing whitespace is usually never a good thing to include. You can configure your editor to automatically remove it.

odow avatar Sep 17 '22 21:09 odow

Yeah, that also crossed my mind. But I do think that the current error you get is not very helpful. I think we have three options here:

  1. We just allow trailing whitespace
  2. We allow whitespace, but issue a warning.
  3. We disallow trailing whitespace (like now), but issue a more helpful error, pointing out that extra whitespace.

mortenpi avatar Sep 17 '22 22:09 mortenpi

I vote 3), just make the warning say `# output` (with no trailing whitespace)

Working around ambiguities just leads to long-term mess.

odow avatar Sep 17 '22 23:09 odow

That is fair enough. If there is a consensus for option 3 I can go ahead and alter my PR to implement that (unless, of coures, somebody else wants to do that)

jlbosse avatar Sep 18 '22 14:09 jlbosse

I can go ahead and alter my PR to implement that

Sure. The lines to change are:

https://github.com/JuliaDocs/Documenter.jl/blob/056284a9850a0e74a439a694e267aff20a7311f5/src/DocTests.jl#L198-L206

odow avatar Sep 18 '22 21:09 odow

Let's go with (3). But I would suggest complaining about the whitespace only if it actually is there. I.e. still update the regex here

https://github.com/JuliaDocs/Documenter.jl/blob/056284a9850a0e74a439a694e267aff20a7311f5/src/DocTests.jl#L193-L194

but @docerror if there we capture any trailing whitespace.

mortenpi avatar Sep 20 '22 09:09 mortenpi