- 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.5k
 
Description
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:
iex> foo(%MyFoo{...})
** (KeyError) key :bar not found in: nil
If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
I'm tring to introduce a doctest that verifies this behavior, but it seems like that's not possible?
Here is my doctest:
  @doc ~S"""
  ## Examples
      iex> MyFoo.foo(%MyFoo{...})
      ** (KeyError) key :bar not found in: nil
      If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
  """
  def  foo(%MyFoo{} = my_foo) do
    ...
  endUpon running the test I get this error:
     Doctest failed: wrong message for KeyError
     expected:
       "key :bar not found in: nil"
     actual:
       "key :bar not found in: nil\n\nIf you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map"
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:
  @doc ~S"""
  ## Examples
      iex> MyFoo.foo(%MyFoo{...})
      ** (KeyError) key :bar not found in: nil
  """
  def  foo(%MyFoo{} = my_foo) do
    ...
  endMetadata
Metadata
Assignees
Labels
No labels