grych

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.

First 9 of 9 Posts Switch mode

OvermindDL1

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

grych

Creator of Drab

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_raise is working correctly in this case, function raises CompileError as expected. The only small issue is this warning, which I can live with, but it is annoying :slight_smile:

OvermindDL1

OvermindDL1

In that case I’d probably consider the warning a bug and silence it properly. ^.^

grych

grych

Creator of Drab

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 :slight_smile:

And of course, I would like to test this case.

Anyway, looks like I need to live with the warning :wink:

OvermindDL1

OvermindDL1

Can’t you just do _u = u in the generated code?

grych

grych

Creator of Drab

Nope. u still does not exists :slight_smile:

This is what I am testing:

<%= for u <- @users do %>
  <%= if u != @excluded do %><%= u %> <% end %>
<% end %>

When you update @excluded only, Drab tries to re-evaluate only that part: <%= if u != @excluded do %><%= u %> <% end %>. u does not exists there.

(BTW solution for this is there, it is to update @users and @excluded in the one poke, I just want to tell developer what to do - with better error message in CompileError).

ryanwinchester

ryanwinchester

Interesting, I’m @deprecating some 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 to assert_raise) or something that “catches” it and stops it from being printed, which I could also use to check the deprecated message.

grych

grych

Creator of Drab

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

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.

— All posts loaded —

Where Next?

Trending in Questions Top

jonnycharles
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
spammy
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
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
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
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
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
michallepicki
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 Top

JesseHerrick
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
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
type1fool
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
akoutmos
@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

We're in Beta

About us Mission Statement