mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-10 17:15:09 +08:00
Show summary on failed doctests (#2062)
This commit is contained in:
parent
ff30d0de2d
commit
6bfc6dfab0
3 changed files with 29 additions and 1 deletions
|
@ -53,7 +53,6 @@ defmodule Livebook.Runtime.Evaluator.Doctests do
|
|||
report_doctest_running(test)
|
||||
test = run_test(test)
|
||||
report_doctest_result(test, lines)
|
||||
test
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
@ -2406,6 +2406,7 @@ defmodule LivebookWeb.SessionLive do
|
|||
defp eval_info_to_view(cell, eval_info, data) do
|
||||
%{
|
||||
outputs: cell.outputs,
|
||||
doctest_summary: doctest_summary(eval_info.doctest_reports),
|
||||
validity: eval_info.validity,
|
||||
status: eval_info.status,
|
||||
errored: eval_info.errored,
|
||||
|
@ -2419,6 +2420,16 @@ defmodule LivebookWeb.SessionLive do
|
|||
}
|
||||
end
|
||||
|
||||
defp doctest_summary(doctests) do
|
||||
{doctests_count, failures_count} =
|
||||
Enum.reduce(doctests, {0, 0}, fn
|
||||
{_line, %{status: status}}, {total, failed} ->
|
||||
{total + 1, if(status == :failed, do: failed + 1, else: failed)}
|
||||
end)
|
||||
|
||||
%{doctests_count: doctests_count, failures_count: failures_count}
|
||||
end
|
||||
|
||||
defp input_values_for_cell(cell, data) do
|
||||
input_ids =
|
||||
for output <- cell.outputs,
|
||||
|
|
|
@ -97,6 +97,7 @@ defmodule LivebookWeb.SessionLive.CellComponent do
|
|||
<.cell_status id={@cell_view.id} cell_view={@cell_view} />
|
||||
</div>
|
||||
</div>
|
||||
<.doctest_summary cell_id={@cell_view.id} doctest_summary={@cell_view.eval.doctest_summary} />
|
||||
<.evaluation_outputs
|
||||
cell_view={@cell_view}
|
||||
session_id={@session_id}
|
||||
|
@ -609,6 +610,23 @@ defmodule LivebookWeb.SessionLive.CellComponent do
|
|||
defp rounded_class(:top), do: "rounded-t-lg"
|
||||
defp rounded_class(:bottom), do: "rounded-b-lg"
|
||||
|
||||
defp doctest_summary(assigns) do
|
||||
~H"""
|
||||
<div :if={@doctest_summary.failures_count > 0} class="pt-2" id={"doctest-summary-#{@cell_id}"}>
|
||||
<div class="error-box">
|
||||
<%= doctest_summary_message(@doctest_summary) %>
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
defp doctest_summary_message(%{doctests_count: total, failures_count: failed}) do
|
||||
doctests_pl = pluralize(total, "doctest", "doctests")
|
||||
failures_pl = if failed == 1, do: "failure has", else: "failures have"
|
||||
|
||||
"#{failed} out of #{doctests_pl} failed (#{failures_pl} been reported above)"
|
||||
end
|
||||
|
||||
defp evaluation_outputs(assigns) do
|
||||
~H"""
|
||||
<div
|
||||
|
|
Loading…
Reference in a new issue