Say you write a macro or a package, which goes through the usual course of software life-cycle. How would you define a set of tests, and have this set run automatically to make sure that changes to the code are in compatible, in some sense of the word?
|
I think there are three broad categories for unit testing in TeX based on:
Log file outputJoseph has already mentioned the log-file-based testing used for LaTeX2e and for expl3, but it's worth noting that these tests can also be used for checking the contents of boxes and output, so they're quite general in their scope. For example:
Generated outputFor One of the main problems with this approach is the presence of false positives due to off-by-one pixel rounding errors in the rasterisation. (And, possibly, installing new fonts changing the outputs of the tests.) On thing I like about comparing PDFs, though, is that I've then got a useable document based on the test suite for demonstration purposes. No reason this couldn't be done as a by-product of any of the other testing processes, however. Using a DVI-based comparison as suggested by other commenters may be more reliable, but I haven't looked into the various options there. Programming checksBoth of the above techniques require As an example from
|
|||||
|
|
If you're adding new features, and you have a collection of LaTeX (or TeX) files that don't use the new features, you can check that none of those files are affected by the change by using For example, I have a large collection of LaTeX files that I use for testing a document class. I have a script #! /bin/sh # We assume that the argument is the name of a dvi file. # We write the message digest to standard output. dvii -p -M1 $* and for each file myfile.tex I've run
#!/bin/sh
for f in *tex;do
for i in `seq 1 6`;do
latex $f
done
done
for f in *.dvi;do
makedigest $f > ${f}.digest.new
done
echo
echo "Checking for errors:"
grep rror *.log
echo "Checking for warnings:"
grep Warning *.log
echo "Comparing new digests with old:"
for f in *.dvi;do
echo "${f}:"
diff ${f}.digest.old ${f}.digest.new
done
This quickly runs LaTeX enough times to get a stable version, checks for errors or warnings, and compares the new digests with the old. Thus, I quickly see which pages of which test documents have been changed unexpectedly. |
|||||||||
|
|
For both the LaTeX2e kernel and the current LaTeX3 code, there are a long series of automated tests which use log data only. These test things at the programming end of the spectrum, where you can write the results to the log. A bit of post-processing results in a file containing only the things you need to test and not the variable stuff (for example, which |
|||
|
|
|
I've been wondering about writing unit tests for my LaTeX packages. For now, what I'm doing is testing the produced PDFs. I just started today doing this using The moderntimeline package now has unit tests based on the produced PDF. The unit tests are in the I've integrated the tests into Travis CI to achieve continuous integration of the package. See the |
||||
|
|

svn-multiI made several (~50) test bench files which I can run automatically using a Makefile. You can have a look at them with the SVN browser of my website. ATM the Makefile only tests for compile errors. Some of the test files compare the results and cause such an error on purpose if the result isn't as expected. I wanted to create a real test package which a lot of macros to test packages, but never found the time. – Martin Scharrer♦ Feb 25 '11 at 17:47tikz-timingpackage to check if the timing transients are still correct. – Martin Scharrer♦ Feb 25 '11 at 18:18