@@ -14,8 +14,8 @@ defmodule ExUnit.Callbacks do
14
14
setup do
15
15
IO.puts "This is a setup callback"
16
16
17
- # Return no extra meta data
18
- [hello: "world"]
17
+ # Returns extra metadata
18
+ { :ok, [hello: "world"] }
19
19
end
20
20
21
21
setup context do
@@ -24,6 +24,9 @@ defmodule ExUnit.Callbacks do
24
24
25
25
# The metadata returned by the previous setup as well
26
26
assert context[:hello] == "world"
27
+
28
+ # No metadata
29
+ :ok
27
30
end
28
31
29
32
test "always pass" do
@@ -115,14 +118,21 @@ defmodule ExUnit.Callbacks do
115
118
116
119
## Helpers
117
120
121
+ def __merge__ ( _mod , other , :ok ) , do: other
122
+ def __merge__ ( _mod , other , { :ok , data } ) , do: Keyword . merge ( other , data )
123
+ def __merge__( mod , _ , failure ) do
124
+ raise "expected ExUnit callback in #{ inspect mod } to return :ok " <>
125
+ " or { :ok, data }, got #{ inspect failure } instead"
126
+ end
127
+
118
128
defp compile_callbacks ( env , kind ) do
119
129
callbacks = Module . get_attribute ( env . module , kind ) |> Enum . reverse
120
130
121
131
acc =
122
132
Enum . reduce callbacks , quote ( do: context ) , fn ( callback , acc ) ->
123
133
quote do
124
134
context = unquote ( acc )
125
- Keyword . merge ( context , unquote ( callback ) ( context ) )
135
+ unquote ( __MODULE__ ) . __merge__ ( __MODULE__ , context , unquote ( callback ) ( context ) )
126
136
end
127
137
end
128
138
0 commit comments