![]() |
Automatic tests | ![]() |
TeXmacs has three kinds of automatic tests, which test different layers: C++ unit tests of the kernel, Scheme regression tests of converters and other Scheme code, and document test suites which run whole documents through the converters and the typesetter and compare the results with a reference run. There is no continuous integration configuration in the repository; the tests are run by hand.
The directory
tests/
mirrors the source tree and contains one test program per file, for instance
tests/Data/String/analyze_test.cpp
or
tests/Kernel/Containers/hashmap_test.cpp
(about twenty files: strings, trees, containers, URLs, XML parsing, image files, fonts, lengths, keyword parsing, the Qt and macOS utilities). Each file is a QtTest test class:
#include <QtTest/QtTest>
#include "analyze.hpp"
class TestAnalyze: public QObject {
Q_OBJECT
private slots:
void test_is_alpha ();
…
}; |
tests/CMakeLists.txt
globs all *.cpp files and makes one executable per file, linked against the object library texmacs_body of the main build, with a CTest test of the same name, a time limit of 5 seconds, and TEXMACS_PATH set to the
TeXmacs/
directory of the sources (needed for instance by the tests of utf8_to_cork, which load dictionaries).
tests/README.md
explains how to run them with ctest or directly.
TeXmacs/progs/kernel/boot/debug.scm
) groups tests of a function:
(define (regtest-htmltm-grouping)
(regression-test-group
"htmltm, grouping markup" "grouping"
shtml->stm :none
(test "div" '(div "a") '(document "a"))
(test "span" '(span "a") "a"))) |
(from
convert/html/htmltm-test.scm
).
The third and fourth arguments are functions applied to the input and to the expected value of each test (:none for the identity). Each (test name input expected) checks that the results are equal, test-fails that they differ. The first failure prints both values and raises an error, so the remaining tests of the run are not executed. The group evaluates to the number of tests. The macro regtest-table-library defines shorthands (cell, row, table, tformat) for writing tables in tests.
For code with side effects, integration-test-group takes a setup and a teardown expression which are run around each test; every test is run, even after a failure, each result is reported as PASS or FAIL, and the group prints a summary.
TeXmacs/progs/check/check-master.scm
loads the test modules and defines
The pure regression tests: HTML import and export, XML, lengths, environment, MathML, TMML, program formatting and citation sorting.
The tests with side effects, mainly for the TeXmacs server (deletion plans, notifications, backups, caches).
Exports every .tm file under dir to LaTeX, runs pdflatex and reports export failures, LaTeX errors and empty outputs. (run-checks) does this for $TEXMACS_CHECKS/latex-export.
These functions are declared lazily in
init-texmacs.scm
, so that they can be called from the command line, for instance
texmacs -x "(run-all-tests)" -q |
or from a Scheme session.
The module
TeXmacs/progs/utils/test/test-convert.scm
runs collections of documents through TeXmacs. A test suite is a directory whose subdirectories are named after the kind of their contents:
TeXmacs documents, which are exported to PDF and to LaTeX.
, arxivLaTeX documents (possibly as tar or gzip archives, as downloaded from arXiv), which are imported, typeset and exported to PDF. In a directory with several .tex files, the one with a \documentclass (or one called main.tex, paper.tex or article.tex) is used.
The documentation manuals (build-manual) can be part of the run as well. The entry points, also available as command line options (see the main program), are:
Unpacks dir into dir-ref and produces all outputs there. This is done once with a version which is known to be good.
Does the same into dir-check and then compares it with dir-ref, if that directory exists. Text outputs (.tex, .tm) count as changed when their edit distance (string-distance) to the reference is 5 or more, PDF files when their size changes by more than 150 bytes or when the output of pdfinfo (without creation date and file size) differs. The result is written to dir-check/status-report.tm, which lists missing directories and files and changed files; it is removed if there is nothing to report.
Outputs are only regenerated when the source is newer than the output (should-update?), so a second run is fast. The functions take continuations, and the command line options pass delayed-quit so that TeXmacs exits when the run is complete. A separate module,
utils/test/test-latex-export.scm
, defines run-latex-export-suite, which exports the documents of a directory to LaTeX with several styles.
texmacs.cpp
contains a compile time hook for ad hoc C++ tests: if ENABLE_TESTS is defined (the #define is commented out), texmacs_entrypoint calls test_routines before starting Scheme, which currently runs test_math (
src/Graphics/Mathematics/test_math.cpp
), a demonstration which prints computations with vectors, matrices, polynomials and balls.
The C++ unit tests are not part of the CMake build: neither
CMakeLists.txt
nor
src/CMakeLists.txt
contains add_subdirectory (tests) or enable_testing (), so the instructions of
tests/README.md
do not work as written.
Even when
tests/
is added, its
CMakeLists.txt
links Qt5::Test unconditionally, whereas the default build uses Qt 6 when it is available.
integration-test-group is documented (in a comment in
debug.scm
) to signal an error at the end if any test failed, but its expansion only prints the summary and returns the number of tests (kernel/boot/debug.scm:296-303), so a failing integration run is not detectable from its result.
Some test modules are not run by run-all-tests: for instance
kernel/texmacs/tm-convert-test.scm
(whose regtest-format is a private define),
kernel/regexp/regexp-test.scm
and
kernel/logic/logic-test.scm
.
run-latex-export-suite is not declared lazily and is not loaded by any other module, so it is only available after loading (utils test test-latex-export) by hand.
In compare-text-file (and compare-pdf-file), a missing output is recorded as missing but then still loaded and compared, because the second test checks that the directories exist rather than the files.
Only files present in the reference are compared: new outputs which have no counterpart in dir-ref are not reported.
In headless mode, the -test-suite and -reference-suite options have no effect unless -X is given, because the automatic quit-TeXmacs runs first; see the main program.