Skip to content

Commit 677bdd2

Browse files
committed
Fix regression in doctests
1 parent 7454333 commit 677bdd2

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/ex_unit/lib/ex_unit/doc_test.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,10 @@ defmodule ExUnit.DocTest do
513513
defp test_import(mod, _), do: [quote(do: import(unquote(mod)))]
514514

515515
defp string_to_quoted(location, stack, expr, doctest) do
516+
expr = IO.iodata_to_binary(expr)
517+
516518
try do
517-
Code.string_to_quoted!(IO.iodata_to_binary(expr), location)
519+
Code.string_to_quoted!(expr, location)
518520
rescue
519521
e ->
520522
ex_message = "(#{inspect(e.__struct__)}) #{Exception.message(e)}"

lib/ex_unit/test/ex_unit/doc_test_test.exs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ defmodule ExUnit.DocTestTest.Invalid do
239239
1 + * 1
240240
"""
241241
def result, do: :ok
242+
243+
@doc """
244+
iex> 123 +
245+
:mixed
246+
"""
247+
def mixed, do: :ok
242248
end
243249
|> ExUnit.BeamHelpers.write_beam()
244250

@@ -781,7 +787,21 @@ defmodule ExUnit.DocTestTest do
781787
test/ex_unit/doc_test_test.exs:#{starting_line + 54}: ExUnit.DocTestTest.Invalid (module)
782788
"""
783789

784-
assert output =~ "9 doctests, 9 failures"
790+
assert output =~ """
791+
10) doctest ExUnit.DocTestTest.Invalid.mixed/0 (10) (ExUnit.DocTestTest.InvalidCompiled)
792+
test/ex_unit/doc_test_test.exs:#{doctest_line}
793+
Doctest did not compile, got: (TokenMissingError) test/ex_unit/doc_test_test.exs:#{starting_line + 61}:6: syntax error: expression is incomplete
794+
#{line_placeholder(starting_line + 61)} |
795+
#{starting_line + 61} | 123 +
796+
#{line_placeholder(starting_line + 61)} | ^
797+
doctest:
798+
iex> 123 +
799+
:mixed
800+
stacktrace:
801+
test/ex_unit/doc_test_test.exs:#{starting_line + 61}: ExUnit.DocTestTest.Invalid (module)
802+
"""
803+
804+
assert output =~ "10 doctests, 10 failures"
785805
end
786806

787807
test "pattern matching assertions in doctests" do

0 commit comments

Comments
 (0)