Is there are way to partially test the output of a function when using doctest?

So today I came across doctest and it is really awesome! But while learning about it I was thinking about edge cases. One of those could be for example a docblock that only contains a partial output. For example:

@doc """
  A discription...

  ## Example
    iex> Foobar.something
    [ "A very large output that is correct up to the triple dots", "some more",
    "this would normally take, for example, 100 of lines, but we limit it to 3",
    "because else the docblock would get ridiculously large", ...
     ...

  Some more info here about the function
"""" 

The above would fail if this module contained a function with the above doc block, because it would try and match the 3 lines given with the actually (huge) output. Is there a way of telling it to only match the first part or if that is not possible, how to disable the doctest for this one function.

The above is all theoretical. I don’t actually have a need to do this right now, but it is just something I was wondering while learning about this feature.

1 Like

you can use part of result or check the result like this:

@doc """
  A discription...

  ## Example
    iex> r = Foobar.something
    iex> r |> String.contains?("something")
    true

  Some more info here about the function
"""" 
2 Likes

Ah nice! Awesome :slight_smile:

1 Like