Update documentation for tests
Signed-off-by: Hongchang Wu <wuhc85@gmail.com>
This commit is contained in:
parent
8d5bd6819f
commit
3b875f0937
|
@ -62,8 +62,8 @@ so for instance the ``jbuild`` file might look like this:
|
||||||
.. code:: scheme
|
.. code:: scheme
|
||||||
|
|
||||||
(library
|
(library
|
||||||
((name foo)
|
(name foo)
|
||||||
(preprocess (pps (ppx_inline_test)))))
|
(preprocess (pps ppx_inline_test)))
|
||||||
|
|
||||||
In order to instruct dune that our library contains inline tests,
|
In order to instruct dune that our library contains inline tests,
|
||||||
all we have to do is add an ``inline_tests`` field:
|
all we have to do is add an ``inline_tests`` field:
|
||||||
|
@ -71,9 +71,9 @@ all we have to do is add an ``inline_tests`` field:
|
||||||
.. code:: scheme
|
.. code:: scheme
|
||||||
|
|
||||||
(library
|
(library
|
||||||
((name foo)
|
(name foo)
|
||||||
(inline_tests)
|
(inline_tests)
|
||||||
(preprocess (pps (ppx_inline_test)))))
|
(preprocess (pps ppx_inline_test)))
|
||||||
|
|
||||||
We can now build and execute this test by running ``dune runtest``. For
|
We can now build and execute this test by running ``dune runtest``. For
|
||||||
instance, if we make the test fail by replacing ``120`` by ``0`` we get:
|
instance, if we make the test fail by replacing ``120`` by ``0`` we get:
|
||||||
|
@ -97,8 +97,8 @@ field:
|
||||||
.. code:: scheme
|
.. code:: scheme
|
||||||
|
|
||||||
(library
|
(library
|
||||||
((name foo)
|
(name foo)
|
||||||
(inline_tests ((backend qtest)))))
|
(inline_tests (backend qtest)))
|
||||||
|
|
||||||
|
|
||||||
Inline expectation tests
|
Inline expectation tests
|
||||||
|
@ -142,9 +142,9 @@ your list of ppx rewriters as follow:
|
||||||
.. code:: scheme
|
.. code:: scheme
|
||||||
|
|
||||||
(library
|
(library
|
||||||
((name foo)
|
(name foo)
|
||||||
(inline_tests)
|
(inline_tests)
|
||||||
(preprocess (pps (ppx_expect)))))
|
(preprocess (pps ppx_expect)))
|
||||||
|
|
||||||
Then calling ``dune runtest`` will run these tests and in case of
|
Then calling ``dune runtest`` will run these tests and in case of
|
||||||
mismatch dune will print a diff of the original source file and
|
mismatch dune will print a diff of the original source file and
|
||||||
|
@ -190,9 +190,9 @@ a ``deps`` field the the ``inline_tests`` field. The argument of this
|
||||||
.. code:: ocaml
|
.. code:: ocaml
|
||||||
|
|
||||||
(library
|
(library
|
||||||
((name foo)
|
(name foo)
|
||||||
(inline_tests ((deps (data.txt))))
|
(inline_tests (deps data.txt))
|
||||||
(preprocess (pps (ppx_expect)))))
|
(preprocess (pps ppx_expect)))
|
||||||
|
|
||||||
Passing special arguments to the test runner
|
Passing special arguments to the test runner
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
|
@ -205,9 +205,9 @@ as:
|
||||||
.. code:: ocaml
|
.. code:: ocaml
|
||||||
|
|
||||||
(library
|
(library
|
||||||
((name foo)
|
(name foo)
|
||||||
(inline_tests ((flags (-foo bar))))
|
(inline_tests (flags (-foo bar)))
|
||||||
(preprocess (pps (ppx_expect)))))
|
(preprocess (pps ppx_expect)))
|
||||||
|
|
||||||
The argument of the ``flags`` field follows the :ref:`ordered-set-language`.
|
The argument of the ``flags`` field follows the :ref:`ordered-set-language`.
|
||||||
|
|
||||||
|
@ -222,9 +222,9 @@ such libraries using a ``libraries`` field, such as:
|
||||||
.. code:: ocaml
|
.. code:: ocaml
|
||||||
|
|
||||||
(library
|
(library
|
||||||
((name foo)
|
(name foo)
|
||||||
(inline_tests ((backend qtest)
|
(inline_tests (backend qtest)
|
||||||
(libraries (bar))))))
|
(libraries bar)))
|
||||||
|
|
||||||
Defining your own inline test backend
|
Defining your own inline test backend
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
@ -305,10 +305,10 @@ The backend for such a framework looks like this:
|
||||||
.. code:: scheme
|
.. code:: scheme
|
||||||
|
|
||||||
(library
|
(library
|
||||||
((name simple_tests)
|
(name simple_tests)
|
||||||
(inline_tests.backend
|
(inline_tests.backend
|
||||||
((generate_runner (run sed "s/(\\*TEST:\\(.*\\)\\*)/let () = \\1;;/" %{impl-files}))
|
(generate_runner (run sed "s/(\\*TEST:\\(.*\\)\\*)/let () = \\1;;/" %{impl-files}))
|
||||||
))))
|
))
|
||||||
|
|
||||||
Now all you have to do is write ``(inline_tests ((backend
|
Now all you have to do is write ``(inline_tests ((backend
|
||||||
simple_tests)))`` wherever you want to write such tests. Note that
|
simple_tests)))`` wherever you want to write such tests. Note that
|
||||||
|
@ -327,8 +327,8 @@ running your testsuite, simply add this to a jbuild file:
|
||||||
.. code:: scheme
|
.. code:: scheme
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
((name runtest)
|
(name runtest)
|
||||||
(action (run ./tests.exe))))
|
(action (run ./tests.exe)))
|
||||||
|
|
||||||
Hence to define an a test a pair of alias and executable stanzas are required.
|
Hence to define an a test a pair of alias and executable stanzas are required.
|
||||||
To simplify this common pattern, dune provides a :ref:`tests-stanza` stanza to
|
To simplify this common pattern, dune provides a :ref:`tests-stanza` stanza to
|
||||||
|
@ -353,8 +353,8 @@ command. For instance let's consider this test:
|
||||||
(with-stdout-to tests.output (run ./tests.exe)))
|
(with-stdout-to tests.output (run ./tests.exe)))
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
((name runtest)
|
(name runtest)
|
||||||
(action (diff tests.expected test.output))))
|
(action (diff tests.expected test.output)))
|
||||||
|
|
||||||
After having run ``tests.exe`` and dumping its output to ``tests.output``, dune
|
After having run ``tests.exe`` and dumping its output to ``tests.output``, dune
|
||||||
will compare the latter to ``tests.expected``. In case of mismatch, dune will
|
will compare the latter to ``tests.expected``. In case of mismatch, dune will
|
||||||
|
|
Loading…
Reference in New Issue