-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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 cannot match on exceptions with blank lines in them #14210
Comments
Correct. The problem is that we don't know exactly how to address this without introducing ambiguities or without requiring a full blown Markdown parsing engine. One option we considered is to make exceptions match on the message prefix. Because in those case, you most likely don't want to match on the whole message anyway, as it could even lead to fragility. For example, we may rephrase something and now your suite fails while behaviour is effectively the same. In those case, the exception type and the first sentence is enough. |
I think that would also work, at least for my use case. Do you have any thoughts about prefix matching vs explicitly only matching until the first blank newline? |
It may be that prefix matching will lead to easier to understand error messages in case they don't match, because we would simply wrap |
Good point. I'm easy either way. |
A nice way to address this could be to add some support for ellipsis in doctests, i.e. be able to add iex> MyFoo.foo(%MyFoo{...})
** (KeyError) key :bar not found in: nil
... iex> MyFoo.foo(self())
** (MyError) something happened with pid: ... Prior-art wise, I think that Python had something like this: https://docs.python.org/3/library/doctest.html#doctest.ELLIPSIS. Of course, there might be a lot of edge cases to consider and it's probably not so trivial to add. |
I think this would actually be quite trivial to implement, both at compile-time and runtime, it would be clearer and backwards compatible, so it gets a 👍 from me. |
Will try to send a PR later this week then! |
Elixir and Erlang/OTP versions
Erlang/OTP 27 [erts-15.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]
Elixir 1.18.1 (compiled with Erlang/OTP 27)
Operating system
NixOS
Current behavior
I have a function that raises the following error under some expected circumstances:
I'm tring to introduce a doctest that verifies this behavior, but it seems like that's not possible?
Here is my doctest:
Upon running the test I get this error:
Expected behavior
The current behavior follows the documentation, but it's pretty inconvenient. I would expect ExUnit to cut off anything in the error message after a blank line. That would enable me to write the doctest like this:
The text was updated successfully, but these errors were encountered: