Hello,
I am trying locally to debug my code with using IO.puts
and IO.inspect
. When I run mix test
I hope to see the output, but it usually is ignored. I found multiple solutions in the net, but nothing is working.
For example,
config :logger,
backends: [:console],
compile_time_purge_level: :debug
- Here is the code for the inspection:
def filter(cellar, color, [year: year]) do
wines = Keyword.get_values(cellar, color)
IO.inspect("PLEASE SHOW SOMETHING")
results = filter_by_year(wines, year)
results
end
What do I miss and is there a simple way to just see debugging information when running tests like a parameter when calling mix test
?
Hi! Print debugging with IO.inspect
should work out of the box without taking any of the extra steps you’ve described… you can run mix test
without MIX_ENV=test
prepended in front of the command because that is already set by default when running mix test
. You shouldn’t have to create any extra config files, please remove the file config/test.exs
just to be sure it doesn’t break anything.
My guess is that you can’t get the debug message to show up because your code really isn’t executing. The pattern matching in your function head on [year: year]
looks suspicious. It shouldn’t be part of a valid solution to this task, just FYI. I suspect you might have another function definition before that, with a more permissive pattern matching on its arguments, that always matches.
Could you copy-paste for me two extra things?
- The full
lib/wine_cellar.ex
file
- The full output of running
mix test
2 Likes
Oh, I was completely wrong with my debugging approach.
When I put the IO.inspect
into another function, it immediately worked.
So it pattern matched earlier. Thank you for helping me!
2 Likes