Skip to content

Commit 760550b

Browse files
committed
test: fix tests on Elixir 1.15+
Since Elixir 1.15, compilation error messages are now printed to `:stderr` instead of being part of the `CompileError` exception. We fix this by asserting the message on the captured `:stderr` instead of the exception. Refs: #31
1 parent 446acca commit 760550b

2 files changed

Lines changed: 28 additions & 26 deletions

File tree

test/typed_struct/plugin_test.exs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,21 @@ defmodule TypedStruct.PluginTest do
150150
############################################################################
151151

152152
test "the code inserted by init/1 is scoped to the typedstruct block" do
153-
assert_raise CompileError,
154-
~r"undefined function function_from_plugin/0",
155-
fn ->
156-
defmodule UseImportedFunctionOutsideOfBlock do
157-
use TypedStruct
158-
159-
typedstruct do
160-
# TestPlugin.init/1 imports function_from_plugin/0.
161-
plugin TestPlugin
162-
end
163-
164-
# function_from_plugin/0 must not be available here.
165-
def call_function_from_plugin, do: function_from_plugin()
166-
end
153+
assert capture_io(:stderr, fn ->
154+
assert_raise CompileError, fn ->
155+
defmodule UseImportedFunctionOutsideOfBlock do
156+
use TypedStruct
157+
158+
typedstruct do
159+
# TestPlugin.init/1 imports function_from_plugin/0.
160+
plugin TestPlugin
167161
end
162+
163+
# function_from_plugin/0 must not be available here.
164+
def call_function_from_plugin, do: function_from_plugin()
165+
end
166+
end
167+
end) =~ "undefined function function_from_plugin/0"
168168
end
169169

170170
test "defining field/3 emits a deprecation warning" do

test/typed_struct_test.exs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,20 @@ defmodule TypedStructTest do
8787
############################################################################
8888

8989
test "TypedStruct macros are available only in the typedstruct block" do
90-
assert_raise CompileError, ~r"undefined function field/2", fn ->
91-
defmodule ScopeTest do
92-
use TypedStruct
93-
94-
typedstruct do
95-
field :in_scope, term()
96-
end
97-
98-
# Let’s try to use field/2 outside the block.
99-
field :out_of_scope, term()
100-
end
101-
end
90+
assert capture_io(:stderr, fn ->
91+
assert_raise CompileError, fn ->
92+
defmodule ScopeTest do
93+
use TypedStruct
94+
95+
typedstruct do
96+
field :in_scope, term()
97+
end
98+
99+
# Let’s try to use field/2 outside the block.
100+
field :out_of_scope, term()
101+
end
102+
end
103+
end) =~ "undefined function field/2"
102104
end
103105

104106
test "the name of a field must be an atom" do

0 commit comments

Comments
 (0)