LivebookTest.Report (livebook_test v0.1.0)

Copy Markdown View Source

Summarizes and formats test run results.

This is the final stage in the LivebookTest pipeline:

Discovery  Exporter  DependencyPatcher  Runner  **Report**

Produces human-readable output and CI-friendly exit codes from a collection of LivebookTest.Runner.run_result structs.

Output format

12 notebooks
11 passed
1 failed
Total time: 14.2s

Failed notebooks are listed with their stderr output for quick debugging.

Summary

Types

t()

Aggregated summary of a test run

Functions

Builds a report from a list of run results.

Returns the CI exit code for a report.

Formats a report as a human-readable string.

Formats a report in verbose mode, including per-notebook details.

Types

t()

@type t() :: %LivebookTest.Report{
  duration_ms: non_neg_integer(),
  empty: boolean(),
  failed: non_neg_integer(),
  failed_notebooks: [LivebookTest.Runner.run_result()],
  passed: non_neg_integer(),
  results: [LivebookTest.Runner.run_result()],
  total: non_neg_integer()
}

Aggregated summary of a test run

Functions

build(results)

@spec build([LivebookTest.Runner.run_result()]) :: t()

Builds a report from a list of run results.

Aggregates pass/fail counts, total duration, and isolates failed notebooks for detailed reporting.

Examples

iex> results = [
...>   %LivebookTest.Runner{notebook_path: "a.livemd", script_path: "a.exs", exit_status: 0, stdout: "", stderr: "", duration_ms: 100, timed_out: false},
...>   %LivebookTest.Runner{notebook_path: "b.livemd", script_path: "b.exs", exit_status: 1, stdout: "", stderr: "oops", duration_ms: 200, timed_out: false}
...> ]
iex> report = LivebookTest.Report.build(results)
iex> report.total
2
iex> report.passed
1
iex> report.failed
1

exit_code(report)

@spec exit_code(t()) :: 0 | 1 | 2

Returns the CI exit code for a report.

Returns 0 if all notebooks passed, 1 if any failed, and 2 if no notebooks were discovered.

Suitable for use in CI/CD pipelines.

Examples

iex> report = %LivebookTest.Report{total: 1, passed: 1, failed: 0, duration_ms: 100, results: [], failed_notebooks: [], empty: false}
iex> LivebookTest.Report.exit_code(report)
0

iex> report = %LivebookTest.Report{total: 1, passed: 0, failed: 1, duration_ms: 100, results: [], failed_notebooks: [], empty: false}
iex> LivebookTest.Report.exit_code(report)
1

iex> report = %LivebookTest.Report{total: 0, passed: 0, failed: 0, duration_ms: 0, results: [], failed_notebooks: [], empty: true}
iex> LivebookTest.Report.exit_code(report)
2

format(report)

@spec format(t()) :: String.t()

Formats a report as a human-readable string.

Output includes:

  • Total notebook count
  • Pass/fail counts
  • Total execution time
  • Details of any failures

Examples

iex> report = %LivebookTest.Report{total: 2, passed: 1, failed: 1, duration_ms: 300, results: [], failed_notebooks: [%LivebookTest.Runner{notebook_path: "b.livemd", script_path: "b.exs", exit_status: 1, stdout: "", stderr: "oops", duration_ms: 200, timed_out: false}]}
iex> output = LivebookTest.Report.format(report)
iex> String.contains?(output, "2 notebooks")
true

format_verbose(report)

@spec format_verbose(t()) :: String.t()

Formats a report in verbose mode, including per-notebook details.

Shows each notebook's status, duration, and output.

Examples

iex> results = [%LivebookTest.Runner{notebook_path: "a.livemd", script_path: "a.exs", exit_status: 0, stdout: "hello", stderr: "", duration_ms: 50, timed_out: false}]
iex> report = LivebookTest.Report.build(results)
iex> output = LivebookTest.Report.format_verbose(report)
iex> String.contains?(output, "a.livemd")
true