Drathier
Drathier

Reputation: 14519

IEx.configure equivalent for mix test?

When debugging tests, it's easy to put some IO.inspect statements in there to see what's going on. This works great, until objects grow too big.

What is the mix equivalent of iex's IEx.configure [inspect: [limit: 1000]] when running mix test?

Upvotes: 1

Views: 179

Answers (1)

Dogbert
Dogbert

Reputation: 222040

IEx.configure [inspect: [limit: 1000]] only changes the options for the automatic inspect call made by iex for every expression entered, and does not change the behavior of the actual IO.inspect function. You'll have to create a wrapper around IO.inspect and use that instead of IO.inspect:

test "the truth" do
  list = Enum.to_list(1..100)
  IO.inspect list
  i list
end

defp i(item, opts \\ []) do
  IO.inspect(item, Keyword.put(opts, :limit, 1000))
end

Output:

$ mix test
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
 43, 44, 45, 46, 47, 48, 49, 50, ...]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
.

Finished in 0.03 seconds
1 test, 0 failures

Upvotes: 3

Related Questions