Skip to content

Commit 226438f

Browse files
committed
Refactor an assertion in Kernel.OverridableTest
This test was using an arcane dance to assert that some code would raise an exception (with try/rescue, flunk, and so on) and using :elixir.eval/2 as well; these remains of ancient times have been replaced with Code.eval_string/1 and assert_raise/3 for more modern Elixir code.
1 parent 9252a16 commit 226438f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/elixir/test/elixir/kernel/overridable_test.exs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,17 @@ defmodule Kernel.OverridableTest do
172172
end
173173

174174
test "invalid super call" do
175-
try do
176-
:elixir.eval 'defmodule Foo.Forwarding do\ndef bar, do: 1\ndefoverridable [bar: 0]\ndef foo, do: super()\nend', []
177-
flunk "expected eval to fail"
178-
rescue
179-
error ->
180-
assert Exception.message(error) ==
181-
"nofile:4: no super defined for foo/0 in module Foo.Forwarding. " <>
182-
"Overridable functions available are: bar/0"
175+
message =
176+
"nofile:4: no super defined for foo/0 in module Foo.Forwarding. " <>
177+
"Overridable functions available are: bar/0"
178+
assert_raise CompileError, message, fn ->
179+
Code.eval_string """
180+
defmodule Foo.Forwarding do
181+
def bar(), do: 1
182+
defoverridable bar: 0
183+
def foo(), do: super()
184+
end
185+
"""
183186
end
184187
end
185188

0 commit comments

Comments
 (0)