Raise when doctest function is undefined

41 views
Skip to first unread message

Rudolf Manusadzhian

unread,
Mar 4, 2022, 4:43:56 AM3/4/22
to elixir-lang-core
Hi there! I faced a behaviour when in doctest we pass option :only with the functions to test, but the module actually doesn't have those functions listed publicly - doctest just gets ignored and doesn't even report about that.

The issue is, if I rename the function but forget to update its docs and doctest - the whole will not point that out but rather just pass with less tests. And leaves me with outdated and non tested docs.

The small example:

defmodule DoctestOnly do
@doc """ Hello world. ## Examples iex> DoctestOnly.hello() :world """ def foo do :world end 
end

and the test

defmodule DoctestOnlyTest do use ExUnit.Case doctest DoctestOnly, only: [hello: 0] end

I would expect test to crash with some message like "function DoctestOnly.hello/0 is undefined or private"

I put up together a commit that somewhat solves the issue for me. Not sure if it's desirable, though:

José Valim

unread,
Mar 4, 2022, 11:44:43 AM3/4/22
to elixir-lang-core
A PR would be great, thank you! I have already dropped some comments in the commit. :)

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/a8060300-4176-4d59-a444-cf08daa701d5n%40googlegroups.com.

Rudolf Manusadzhian

unread,
Mar 4, 2022, 12:46:47 PM3/4/22
to elixir-lang-core
Thank you, José!
Reply all
Reply to author
Forward
0 new messages