docs: assert_raise example is a compiler warning in Elixir 1.18
Closed this issue ยท 5 comments
Elixir and Erlang/OTP versions
Erlang/OTP 27 [erts-15.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]
Elixir 1.18.0 (compiled with Erlang/OTP 27)
Operating system
macOS 15.2
Current behavior
The documentation for assert_raise
suggests using 1 + "test"
to get an Arithmetic Error.
https://hexdocs.pm/ex_unit/ExUnit.Assertions.html#assert_raise/2
assert_raise ArithmeticError, fn ->
1 + "test"
end
Expected behavior
While an Arithmetic Error is still the case at runtime, Elixir 1.18 provides a compiler warning for code like this, so maybe it's no longer the best example?
The RuntimeError provided is a better example. Should the ArithmeticError
example be removed?
https://github.com/elixir-lang/elixir/blob/main/lib/ex_unit/lib/ex_unit/assertions.ex#L788
I had a similar issue in a test that needed to deliberately raise. If an ArithmeticError
is still desired, 9 / 0
did the trick without making the compiler barf.
@vanderhoop do you want to send a PR that uses a division by zero?
@josevalim I'm traveling for the holidays at the moment, but I'd be happy to open a quick PR on the 26th if it hasn't been done by then.
I went ahead as I am doing a new release soon!
thank you @vanderhoop and @josevalim -- happy holidays! ๐