zachallaun/mneme

give a better compiler error when using `auto_assert` in the wrong place.

Closed this issue · 1 comments

I had some obviously incorrect code:

describe "foo" do
  auto_assert String.length("foo")
end

and this compiler error:

== Compilation error in file ... ==
** (MatchError) no match of right hand side value: nil

I was confused for a second. Not sure if this can be easily improved?

Yep, this could/should be improved. One option would be to require (for now) that the macro is called in the context of a :”test …” function. Basically something like:

with {name, 1} <- __CALLER__.function,
     “test ” <> _ <- to_string(name) do
  :ok 
else
  _ -> raise “not in a test, ya silly goose”
end

But maybe with a different error message :)

This may be somewhat relying on an implementation detail of ExUnit, but I don’t think it’s one that is likely to change, and given that it’s primarily about providing more/better error messages, I’m not too worried. Open to any other suggestions though!