Doctest with @typedoc

ExUnit.DocTest.doctest/2 retrieves @moduledoc and @doc for functions, but does not @typedoc. Are there any way to test example codes in @typedoc ?

My function has many argument pattern like below:

def my_func({:a, options})
def my_func({:b, options})
def my_func({:c, options})

Then, I defines types:

@type a :: {:a, x: number}
@type b :: {:b, y: [number]}
@type c :: {:c, z: String.t}

Because this function will accept many type of arguments, I want to put example codes on @typedoc rather than @doc for my_func/1.

@typedoc """
Type explanation for a
    iex> my_func({:a, 5})
    [a: 5]
"""
@type a :: {:a, number}

@doc """
Simple function explanation
"""
def my_func({:a, options})

I expected code example in @typedoc is handled by DocTest, but it isn’t. It is maybe since doctest/2 treats docs from only functions and macros.

Is my approach against any conventions, or is there any way to test them?

1 Like

Please open up an issue and/or send a PR. :slight_smile: I see no reason at the moment to not support it too.

2 Likes

Sure, I will do soon. Thank you :grinning:


After a while, I created a PR.

2 Likes