Use end_line from Elixir v1.15.0-rc.2

This commit is contained in:
José Valim 2023-05-30 20:05:39 +02:00
parent 294bf69c8d
commit 0961deaa88

View file

@ -60,23 +60,31 @@ defmodule Livebook.Runtime.Evaluator.Doctests do
doctest_line = test.tags.doctest_line doctest_line = test.tags.doctest_line
[prompt_line | _] = lines = Enum.drop(lines, doctest_line - 1) [prompt_line | _] = lines = Enum.drop(lines, doctest_line - 1)
# TODO: end_line must come from Elixir to be reliable interval =
doctest_lines = Enum.take_while(lines, &(not end_of_doctest?(&1))) if end_line = test.tags[:doctest_data][:end_line] do
end_line - doctest_line + 1
else
# TODO: Remove this branch once we require Elixir v1.15+
lines
|> Enum.take_while(&(not end_of_doctest?(&1)))
|> length()
end
interval = interval =
with {:error, %ExUnit.AssertionError{}, [{_, _, _, location} | _]} <- failure, with {:error, %ExUnit.AssertionError{}, [{_, _, _, location} | _]} <- failure,
assertion_line = location[:line], assertion_line = location[:line],
true <- is_integer(assertion_line) and assertion_line >= doctest_line do true <- assertion_line in doctest_line..(doctest_line + interval) do
length(doctest_lines) - interval -
length( length(
doctest_lines lines
|> Enum.take(interval)
|> Enum.drop(assertion_line - doctest_line) |> Enum.drop(assertion_line - doctest_line)
|> Enum.drop_while(&prompt?(&1)) |> Enum.drop_while(&prompt?(&1))
|> Enum.drop_while(&(not prompt?(&1))) |> Enum.drop_while(&(not prompt?(&1)))
) )
else else
_ -> _ ->
length(doctest_lines) interval
end end
result = %{ result = %{