grych
Creator of Drab
Capture compiler warnings in tests
Is it possible to capture compiler warnings in tests? I am doing a following test which should raise CompileError (and it does, test is successful):
@tag capture_log: true
test "update child should raise", fixture do
IO.puts("\n--> the following warning is expected:")
assert_raise CompileError, fn -> poke(fixture.socket, excluded: "Hegemon") end
end
But I am getting this warning during the tests:
warning: variable "u" does not exist and is being expanded to "u()", please use parentheses to remove the ambiguity or change the variable name
nofile:6
This behaviour is expected. Indeed, u is not defined in the AST I am processing. Is there a way I can capture this? capture_log did not help.
Trending in Questions
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Hello !
We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
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
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security











First 9 of 9 Posts
OvermindDL1
I use code like this in my macro-heavy projects:
https://github.com/OvermindDL1/typed_elixir/blob/master/test/test_helper.exs
And it’s used like this:
https://github.com/OvermindDL1/typed_elixir/blob/master/test/typed_elixir_test.exs#L23-L29
I probably should pull my test helpers into their own library sometime. They are based on someone else’s but expanded for more features (and a bug fix).
grych
Very interesting, thanks for sharing!
Anyway, I think I can’t use it in my case. The whole stuff is going on in runtime (I am evaluating previously saved AST). Also,
assert_raiseis working correctly in this case, function raisesCompileErroras expected. The only small issue is this warning, which I can live with, but it is annoyingOvermindDL1
In that case I’d probably consider the warning a bug and silence it properly. ^.^
grych
Not in this case. Let me explain more detailed.
There are few cases, when Drab.Live can’t execute the AST (because of limitations). In this case, I catch CompileError exception, and re-raise it with better explanation, so user is not completely lost
And of course, I would like to test this case.
Anyway, looks like I need to live with the warning
OvermindDL1
Can’t you just do
_u = uin the generated code?grych
Nope.
ustill does not existsThis is what I am testing:
When you update
@excludedonly, Drab tries to re-evaluate only that part:<%= if u != @excluded do %><%= u %> <% end %>.udoes not exists there.(BTW solution for this is there, it is to update
@usersand@excludedin the one poke, I just want to tell developer what to do - with better error message in CompileError).ryanwinchester
Interesting, I’m
@deprecatingsome stuff right now but still testing them, and the warnings in the tests are really annoying.I wish we could do an
assert_warn(similar toassert_raise) or something that “catches” it and stops it from being printed, which I could also use to check the deprecated message.grych
Actually I resolved my case by completely rewriting this part of the library. This annoying warning encouraged me to do it, so I think warnings are useful. If you have one, try to find the other way to solve your issue.
ryanwinchester
I want the warning, I just don’t want to see it in my console output in tests. It’s unecessary.
Capturing it and asserting that it’s there however, is what I’d really like to do. Similar to
assert_raise.