samedi 24 décembre 2016

Elixir "mix test" considers @doc examples as tests

Recently I wrote a the following function:

  @doc """
  Creates a new deck, shuffles its cards and retrieves a hand of
  cards from it.
  The `hand_size` argument indicates the size of the hand.

  ## Examples
      iex> {hand, _deck_remainder} = Cards.create_hand 2
      iex> hand
      ["Ace of Clubs", "Four of Hearts"]
  """
  def create_hand(hand_size) do
    create_deck
    |> shuffle
    |> deal(hand_size)
  end

Points to consider:

  • create_deck/0 returns a list of strings like ["Two of Clubs", "Four of Hearts"]
  • shuffle/1 takes a list of strings and shuffles them using Enum.shuffle/1
  • deal/2 returns a tuple like {["Ace of Spades"], ["Five of Clubs"]}

Then I ran the mix test task and the following error appeared:

Raised error

It looks like mix test is considering the examples in @doc annotations as unit tests.

I'd like to exclude those examples from mix test... Is it a good idea to do it? If so, how can I exclude them?

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire