- OCaml 87%
- Shell 10%
- Go 2%
- Python 1%
junit #
JUnit XML test reports for OCaml: a typed model of the report most test runners write, read and written through nox-xml codecs.
A JUnit report says how each test case of a run ended: passed, failed on an
assertion, errored on an exception, or skipped, with its time, its output
and where it is. alcotest writes one into junit/ of its log directory,
pytest with --junitxml, gotestsum for go test with --junitfile, cargo
nextest with its JUnit profile, and the JVM and JavaScript runners through
their JUnit reporters. No standard defines the format: this library reads the shape
those runners share, the de facto schema of Apache Ant's JUnit task as
Jenkins and GitLab read it.
Installation #
$ opam install nox-junit
Usage #
let report =
{|<testsuites><testsuite name="s" tests="2" failures="1">
<testcase name="ok" classname="s.t" time="0.001"/>
<testcase name="bad" classname="s.t"><failure message="FAIL" type="Check_error">expected 1</failure></testcase>
</testsuite></testsuites>|}
let failed =
match Junit.of_string report with
| Error e -> Fmt.failwith "%a" Xml.Error.pp e
| Ok r ->
List.concat_map
(fun (s : Junit.suite) ->
List.filter_map
(fun (c : Junit.case) ->
match c.outcome with Failed _ -> Some c.name | _ -> None)
s.cases)
r.suites
# failed;;
- : string list = ["bad"]
Junit.to_string writes a report back, its counts (tests, failures,
errors, skipped) derived from its cases.
Interop traces #
The tests read reports the runners wrote themselves, committed under
test/interop/<runner>/traces: alcotest, pytest 8.3.3 and gotestsum
v1.13.0 over go test, each running a small fixture of passing, failing,
erroring, skipped and printing cases. The gotestsum test skips until its
trace is committed. To rewrite the pytest and gotestsum traces, from this
directory, with python3 and go on the PATH:
$ REGEN=1 dune build @test/interop/pytest/traces @test/interop/gotestsum/traces
pytest installs into a venv and gotestsum into a GOPATH, both under
_build, so the run needs pypi.org, files.pythonhosted.org,
proxy.golang.org and sum.golang.org.
Related work #
- junit on opam writes JUnit reports from OCaml test runners (OUnit, Alcotest) and reads none. This library reads them, whatever runner wrote them, and writes the same model back.
- jsont is the design nox-xml's codecs follow, and so the shape of this one.
License #
ISC. See LICENSE.md.