Skip to content

Commit 2b298ab

Browse files
author
José Valim
committed
CaptureIO now returns an empty string instead of nil when there is no capture
1 parent 3a36c2e commit 2b298ab

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [Kernel] Using ^ inside function clause heads is deprecated, please use a guard instead
1212

1313
* Backwards incompatible changes
14+
* [ExUnit] `CaptureIO` returns an empty string instead of nil when there is no capture
1415
* [Version] The `Version` module now only works with SemVer. The functions `Version.parse/1` and `Version.parse_requirement/1` now return `{:ok,res} | :error` for the cases you want to handle non SemVer cases manually. All other functions will trigger errors on non semantics versions
1516

1617
# v0.12.3 (2014-02-02)

lib/elixir/test/elixir/kernel/warning_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ defmodule Kernel.WarningTest do
9191
end
9292
end
9393
"""
94-
end) == nil
94+
end) == ""
9595
after
9696
purge Sample
9797
end
@@ -131,7 +131,7 @@ defmodule Kernel.WarningTest do
131131
defp b(arg1 \\ 1, arg2, arg3 \\ 3), do: [arg1, arg2, arg3]
132132
end
133133
"""
134-
end) == nil
134+
end) == ""
135135
after
136136
purge [Sample1, Sample2, Sample3, Sample4]
137137
end
@@ -245,7 +245,7 @@ defmodule Kernel.WarningTest do
245245
generate
246246
end
247247
"""
248-
end) == nil
248+
end) == ""
249249
after
250250
purge [Sample1, Sample2]
251251
end
@@ -292,15 +292,15 @@ defmodule Kernel.WarningTest do
292292
end
293293

294294
test :used_with_local_with_reattached_overridable do
295-
assert nil? capture_err(fn ->
295+
assert capture_err(fn ->
296296
Code.eval_string """
297297
defmodule Sample do
298298
def hello, do: world
299299
defp world, do: :ok
300300
defoverridable [hello: 0, world: 0]
301301
end
302302
"""
303-
end)
303+
end) == ""
304304
after
305305
purge Sample
306306
end

lib/ex_unit/lib/ex_unit/assertions.ex

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,17 @@ defmodule ExUnit.Assertions do
306306
defp do_assert_receive(expected, timeout, message) do
307307
binary = Macro.to_string(expected)
308308

309-
quote do
310-
receive do
311-
unquote(expected) = received -> unquote(expected) = received
312-
after
313-
unquote(timeout) ->
314-
flunk unquote(message) || "Expected to have received message matching #{unquote binary}"
309+
{ :receive, meta, args } =
310+
quote do
311+
receive do
312+
unquote(expected) = received -> received
313+
after
314+
unquote(timeout) ->
315+
flunk unquote(message) || "Expected to have received message matching #{unquote binary}"
316+
end
315317
end
316-
end
318+
319+
{ :receive, [{:export_all, true}|meta], args }
317320
end
318321

319322
@doc """

lib/ex_unit/lib/ex_unit/capture_io.ex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ defmodule ExUnit.CaptureIO do
4040
4141
iex> capture_io(fn -> IO.write "josé" end) == "josé"
4242
true
43-
iex> capture_io(fn -> :ok end) == nil
44-
true
4543
iex> capture_io(:stderr, fn -> IO.write(:stderr, "josé") end) == "josé"
4644
true
4745
iex> capture_io("this is input", fn ->
@@ -97,7 +95,7 @@ defmodule ExUnit.CaptureIO do
9795
end
9896

9997
receive do
100-
{ ^capture_gl, buf } -> buf
98+
{ ^capture_gl, buf } -> buf || ""
10199
end
102100
end
103101

@@ -121,7 +119,7 @@ defmodule ExUnit.CaptureIO do
121119
end
122120

123121
receive do
124-
{ ^capture_io, buf } -> buf
122+
{ ^capture_io, buf } -> buf || ""
125123
end
126124
end
127125

lib/ex_unit/test/ex_unit/capture_io_test.exs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ defmodule ExUnit.CaptureIOTest do
3939

4040
test "with no output" do
4141
assert capture_io(fn ->
42-
end) == nil
42+
end) == ""
4343
end
4444

4545
test "with put chars" do
@@ -82,7 +82,7 @@ defmodule ExUnit.CaptureIOTest do
8282

8383
assert capture_io([capture_prompt: false], fn ->
8484
:io.get_chars(">", 3)
85-
end) == nil
85+
end) == ""
8686

8787
capture_io(fn ->
8888
assert :io.get_chars(">", 3) == :eof
@@ -112,7 +112,7 @@ defmodule ExUnit.CaptureIOTest do
112112

113113
assert capture_io([capture_prompt: false], fn ->
114114
:io.get_line ">"
115-
end) == nil
115+
end) == ""
116116

117117
capture_io(fn ->
118118
assert :io.get_line(">") == :eof
@@ -165,7 +165,7 @@ defmodule ExUnit.CaptureIOTest do
165165

166166
assert capture_io([capture_prompt: false], fn ->
167167
:io.scan_erl_form('>')
168-
end) == nil
168+
end) == ""
169169

170170
capture_io(fn ->
171171
assert :io.scan_erl_form('>') == { :eof, 1 }
@@ -213,7 +213,7 @@ defmodule ExUnit.CaptureIOTest do
213213
test "with setopts" do
214214
assert capture_io(fn ->
215215
:io.setopts({ :encoding, :latin1 })
216-
end) == nil
216+
end) == ""
217217

218218
capture_io(fn ->
219219
assert :io.setopts({ :encoding, :latin1 }) == :ok
@@ -223,7 +223,7 @@ defmodule ExUnit.CaptureIOTest do
223223
test "with getopts" do
224224
assert capture_io(fn ->
225225
:io.getopts
226-
end) == nil
226+
end) == ""
227227

228228
capture_io(fn ->
229229
assert :io.getopts == { :error, :enotsup }
@@ -233,7 +233,7 @@ defmodule ExUnit.CaptureIOTest do
233233
test "with columns" do
234234
assert capture_io(fn ->
235235
:io.columns
236-
end) == nil
236+
end) == ""
237237

238238
capture_io(fn ->
239239
assert :io.columns == { :error, :enotsup }
@@ -243,7 +243,7 @@ defmodule ExUnit.CaptureIOTest do
243243
test "with rows" do
244244
assert capture_io(fn ->
245245
:io.rows
246-
end) == nil
246+
end) == ""
247247

248248
capture_io(fn ->
249249
assert :io.rows == { :error, :enotsup }
@@ -265,7 +265,7 @@ defmodule ExUnit.CaptureIOTest do
265265
test "with unknown io request" do
266266
assert capture_io(fn ->
267267
send_and_receive_io(:unknown)
268-
end) == nil
268+
end) == ""
269269

270270
capture_io(fn ->
271271
assert send_and_receive_io(:unknown) == { :error, :request }

lib/iex/test/iex/server_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ defmodule IEx.ServerTest do
4343
test "does not operate if callback during boot fails" do
4444
assert capture_io(fn ->
4545
boot([], fn -> exit(0) end)
46-
end) == nil
46+
end) == ""
4747
end
4848

4949
test "take over fails when there is no shell" do

0 commit comments

Comments
 (0)