GNU TeXmacsUser manualReferenceAboutEnglish
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.

1.C++ unit tests

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.

2.Scheme regression tests

Writing tests.
The macro regression-test-group (
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.

Test modules.
By convention, the tests of a module name.scm are in name-test.scm next to it, which defines a function regtest-name. The master file
TeXmacs/progs/check/check-master.scm

loads the test modules and defines

(run-all-tests)

The pure regression tests: HTML import and export, XML, lengths, environment, MathML, TMML, program formatting and citation sorting.

(run-integration-tests)

The tests with side effects, mainly for the TeXmacs server (deletion plans, notifications, backups, caches).

(check-latex-export dir)

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.

3.Document test suites

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

TeXmacs documents, which are exported to PDF and to LaTeX.

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:

(build-ref-suite dir), option -reference-suite dir

Unpacks dir into dir-ref and produces all outputs there. This is done once with a version which is known to be good.

(run-test-suite dir), option -test-suite dir

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.

4.Other hooks

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.

5.Pitfalls

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".