DenisGorbachev
Is there a way to suppress warnings about unused variables?
Our tests are structured like this:
response = say("Place order")
response = say("BITTREX 1 LTC 0.0116 BTC")
response = say("0.0109")
response = say("0.0159")
When we run them, we get a lot of warning: variable "response" is unused. Of course, we could just add underscore, but it’s inconvenient - sometimes “response” variable is actually used in assertion.
Is there a way to suppress the warning: variable "response" is unused in a general way, without underscoring its name?
Marked As Solved
DenisGorbachev
To answer my own question:
defmodule ModuleName do
@compile :nowarn_unused_vars
end
Also Liked
NobbZ
I do still hope though, that you reconsider your current API to something more explicit and less side-efficty despite the compiler-switch…
NobbZ
Why in a variable at all?
response = say("foo")
assert "sayed foo" = response
This snippet will totally obfuscate your assertion when ExUnit prints it in the failure case. Instead of how the actual value was produced you’ll only get printed response didn’t match, where by using the function call directly you will be told that say("foo") didn’t match the expectation, which in my opinion is much more obvious.
Besides of that, assuming purity, it does not make sense to what you did there. Either you care for the returned value and assert against it, or you are only interested in the side effect which you then mark explicitely with an underscore(d name), or you are interested in both, this is usually when assert against the return value first and then against the expected effects.
Qqwy
Why is it inconvenient to replace response with _ or _response in the cases where it is not used? It would make your code easier to read and understand for other developers.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









