@@ -47,7 +47,7 @@ defmodule ExUnit.DocTestTest.GoodModule do
47
47
def inspect2_test , do: :ok
48
48
end
49
49
50
- defmodule ExUnit.DocTestTest.ExceptionModule do
50
+ defmodule ExUnit.DocTestTest.MultipleExceptions do
51
51
@ doc """
52
52
iex> 1 + ""
53
53
** (ArithmeticError) bad argument in arithmetic expression
@@ -102,14 +102,27 @@ defmodule ExUnit.DocTestTest.NoImport do
102
102
end
103
103
104
104
defmodule ExUnit.DocTestTest.Invalid do
105
- @ doc """
106
- iex> _a = 1
107
- 1
105
+ @ moduledoc """
106
+
107
+ iex> 1 + * 1
108
+ 1
109
+
110
+ iex> 1 + hd(List.flatten([1]))
111
+ 3
112
+
113
+ iex> :oops
114
+ #HashDict<[]>
115
+
116
+ iex> Hello.world
117
+ :world
118
+
119
+ iex> raise "oops"
120
+ ** (WhatIsThis) oops
121
+
122
+ iex> raise "oops"
123
+ ** (RuntimeError) hello
108
124
109
- iex> _a + 1
110
- 2
111
125
"""
112
- def no_leak , do: :ok
113
126
end
114
127
115
128
defmodule ExUnit.DocTestTest.IndentationHeredocs do
@@ -163,7 +176,7 @@ defmodule ExUnit.DocTestTest.Incomplete do
163
176
end
164
177
165
178
defmodule ExUnit.DocTestTest do
166
- use ExUnit.Case , async: true
179
+ use ExUnit.Case
167
180
168
181
# This is intentional. The doctests in DocTest's docs
169
182
# fail for demonstration purposes.
@@ -175,20 +188,79 @@ defmodule ExUnit.DocTestTest do
175
188
doctest ExUnit.DocTestTest.NoImport
176
189
doctest ExUnit.DocTestTest.IndentationHeredocs
177
190
178
- test "multiple exceptions in one test case is not supported" do
179
- assert_raise ExUnit.DocTest.Error , ~r " multiple exceptions in one doctest case are not supported " , fn ->
180
- defmodule NeverCompiled do
181
- import ExUnit.DocTest
182
- doctest ExUnit.DocTestTest.ExceptionModule
183
- end
191
+ import ExUnit.CaptureIO
192
+
193
+ test "doctest failures" do
194
+ defmodule ActuallyCompiled do
195
+ use ExUnit.Case
196
+ doctest ExUnit.DocTestTest.Invalid
184
197
end
198
+
199
+ ExUnit . configure ( seed: 0 )
200
+ output = capture_io ( fn -> ExUnit . run end )
201
+
202
+ assert output =~ """
203
+ 1) test moduledoc at ExUnit.DocTestTest.Invalid (1) (ExUnit.DocTestTest.ActuallyCompiled)
204
+ test/ex_unit/doc_test_test.exs:196
205
+ Doctest did not compile, got: (SyntaxError) test/ex_unit/doc_test_test.exs:104: syntax error before: '*'
206
+ code: 1 + * 1
207
+ stacktrace:
208
+ test/ex_unit/doc_test_test.exs:104: ExUnit.DocTestTest.Invalid (module)
209
+ """
210
+
211
+ assert output =~ """
212
+ 2) test moduledoc at ExUnit.DocTestTest.Invalid (2) (ExUnit.DocTestTest.ActuallyCompiled)
213
+ test/ex_unit/doc_test_test.exs:196
214
+ Doctest failed
215
+ code: 1 + hd(List.flatten([1])) === 3
216
+ lhs: 2
217
+ stacktrace:
218
+ test/ex_unit/doc_test_test.exs:104: ExUnit.DocTestTest.Invalid (module)
219
+ """
220
+
221
+ assert output =~ """
222
+ 3) test moduledoc at ExUnit.DocTestTest.Invalid (3) (ExUnit.DocTestTest.ActuallyCompiled)
223
+ test/ex_unit/doc_test_test.exs:196
224
+ Doctest failed
225
+ code: inspect(:oops) === "#HashDict<[]>"
226
+ lhs: ":oops"
227
+ stacktrace:
228
+ test/ex_unit/doc_test_test.exs:104: ExUnit.DocTestTest.Invalid (module)
229
+ """
230
+
231
+ assert output =~ """
232
+ 4) test moduledoc at ExUnit.DocTestTest.Invalid (4) (ExUnit.DocTestTest.ActuallyCompiled)
233
+ test/ex_unit/doc_test_test.exs:196
234
+ Doctest failed: got UndefinedFunctionError with message undefined function: Hello.world/0
235
+ code: Hello.world
236
+ stacktrace:
237
+ test/ex_unit/doc_test_test.exs:104: ExUnit.DocTestTest.Invalid (module)
238
+ """
239
+
240
+ assert output =~ """
241
+ 5) test moduledoc at ExUnit.DocTestTest.Invalid (5) (ExUnit.DocTestTest.ActuallyCompiled)
242
+ test/ex_unit/doc_test_test.exs:196
243
+ Doctest failed: expected exception WhatIsThis with message "oops" but got RuntimeError with message "oops"
244
+ code: raise "oops"
245
+ stacktrace:
246
+ test/ex_unit/doc_test_test.exs:104: ExUnit.DocTestTest.Invalid (module)
247
+ """
248
+
249
+ assert output =~ """
250
+ 6) test moduledoc at ExUnit.DocTestTest.Invalid (6) (ExUnit.DocTestTest.ActuallyCompiled)
251
+ test/ex_unit/doc_test_test.exs:196
252
+ Doctest failed: expected exception RuntimeError with message "hello" but got RuntimeError with message "oops"
253
+ code: raise "oops"
254
+ stacktrace:
255
+ test/ex_unit/doc_test_test.exs:104: ExUnit.DocTestTest.Invalid (module)
256
+ """
185
257
end
186
258
187
- test "variables in heredocs do not leak " do
188
- assert_raise ArgumentError , fn ->
259
+ test "multiple exceptions in one test case is not supported " do
260
+ assert_raise ExUnit.DocTest.Error , ~r " multiple exceptions in one doctest case are not supported " , fn ->
189
261
defmodule NeverCompiled do
190
262
import ExUnit.DocTest
191
- doctest ExUnit.DocTestTest.Invalid
263
+ doctest ExUnit.DocTestTest.MultipleExceptions
192
264
end
193
265
end
194
266
end
@@ -221,6 +293,5 @@ defmodule ExUnit.DocTestTest do
221
293
doctest ExUnit.DocTestTest.Incomplete
222
294
end
223
295
end
224
-
225
296
end
226
297
end
0 commit comments