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

When fixing doctests with errors, don't overwrite [...] #2642

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fingolfin
Copy link
Contributor

Sometimes it is useful to show errors in doctests. However if those contain stacktraces, this can be problematic as those contain line numbers which will change over time (and often also when e.g. Julia or some dependencies change). And sometimes it is simply desirable to shorten the error message for other reasons.

For this reason Documenter supports replacing part of the error message with [...] which can be used to omit e.g. a stacktrace while still passing doctest checks.

However so far using Documenter's doctest=:fix feature would replace all uses of [...] by the full error message, making it unnecessarily tedious to update doctests in packages that use this feature.

This patch changes that by skipping doctest fixups for tests where the reference output ends with [...] and otherwise matches the actual error message as a prefix.

Resolves #2511

CC @thofma

Sometimes it is useful to show errors in doctests. However if those
contain stacktraces, this can be problematic as those contain line
numbers which will change over time (and often also when e.g. Julia or
some dependencies change). And sometimes it is simply desirable to
shorten the error message for other reasons.

For this reason Documenter supports replacing part of the error message
with `[...]` which can be used to omit e.g. a stacktrace while still
passing doctest checks.

However so far using Documenter's `doctest=:fix` feature would replace
all uses of `[...]` by the full error message, making it unnecessarily
tedious to update doctests in packages that use this feature.

This patch changes that by skipping doctest fixups for tests where the
reference output ends with `[...]` and otherwise matches the actual
error message as a prefix.
@fingolfin fingolfin force-pushed the mh/doctest-fix-skip-stacktrace branch from 92af617 to 583b3eb Compare March 5, 2025 19:54
@fingolfin
Copy link
Contributor Author

@mortenpi @fredrikekre any thoughts on this? it works well for me and saves me quite some work :-)

Copy link
Member

@mortenpi mortenpi left a comment

Choose a reason for hiding this comment

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

This makes a lot of sense to me, and LGTM. Thank you!

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.

Doctest fix versus exceptions
2 participants