6

After writing some code with LaTeX3 I discovered the ability of l3build to compare a newly produced output to a normalized test output. As it sounds quite useful I tried writing some tests myself and I just didn't (and don't) quite understand it (ergo: I didn't manage to make it work).

Suppose I have the given .dtx file defining

  • \DoubleIt to print every character twice (Hello -> HHeelloo) and

  • \ChangeToNumber (not yet fully written) which will be equal to \int_from_alph:n (x -> 24)

Given those macros, how can I define a normalized output file for tests?

doublefoo.dtx file:

% \iffalse  meta-comment
% !TEX program  = pdfLaTeX
%
%<*internal>
\iffalse
%</internal>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input l3docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble

\endpreamble
%\postamble


%\endpostamble
\usedir{tex/latex/doublefoo}
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/doublefoo}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble 
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%<*driver> 
\documentclass [
        onlydoc,
]{l3doc}

\usepackage{doublefoo}


\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% 
% \GetFileInfo{\jobname.sty}
%
% \begin{documentation}
%
% \DoubleIt {Hello}
%
% \ChangeToNumber {x}
%
% \end{documentation}
%  
% \begin{implementation}
%
%    \begin{macrocode}
%<@@=doublefoo>
%    \end{macrocode}
%
%    \begin{macrocode}
\@ifpackageloaded {xparse} 
  { } 
  { \RequirePackage {xparse} }
\@ifpackageloaded {expl3} 
  { } 
  { \RequirePackage {expl3} }
%    \end{macrocode}
%    \begin{macrocode}
\ProvidesExplPackage
  {doublefoo}
  {2016/06/31}
  {42}
  {A foo to double up your bar.}
%    \end{macrocode}
%
%    \begin{macrocode}
\NewDocumentCommand \DoubleIt { m }
  {
    \tl_map_inline:nn {#1} { ##1 ##1 }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\NewDocumentCommand \ChangeToNumber { m }
  {
    %% not yet defined.
  }
%    \end{macrocode}
%
% \end{implementation}
%
% \endinput

build.lua file:

#!/usr/bin/env texlua

module = "doublefoo"

unpackfiles = {"*.dtx"}

kpse.set_program_name("kpsewhich") 
dofile(kpse.lookup("l3build.lua"))

testfiles/Versuch.lvt (pretty much the same as in chapter 2.3 of l3build)

\documentclass{article} 
\input{regression-test} 
\usepackage{doublefoo} 

\begin{document}
\ExplSyntaxOn
\box_new:N \l_tmp_box 
\hbox_set:Nn \l_tmp_box {\DoubleIt{Hallo}} 
\box_show:N \l_tmp_box 
\ExplSyntaxOff 
\end{document}

Next I did the following steps (in the correct directory):

  1. Run texlua build.lua save Versuch
  2. Change in doublefoo.dtx the command \DoubleIt to

    \NewDocumentCommand \DoubleIt { m }
      {
        Change
        \tl_map_inline:nn {#1} { ##1 ##1 }
      }
    

    and safe the file. (Also compile it to make sure I changed the output.)

  3. Run texlua build.lua check

Doing that the terminal prints

Running checks on
  Versuch

  All checks passed

which cannot be true as \DoubleIt is different then before.


As a side note here is a (correct working, thanks to the answer) test with a .lve file:

testfiles/Versuch2.lvt

\documentclass{article} 
\input{regression-test} 
\usepackage{doublefoo} 

\begin{document}
\ExplSyntaxOn

\START

\OMIT
\hbox_set:Nn \l_tmpa_box { \ChangeToNumber { x } } 
\TIMO

\box_show:N \l_tmpa_box 

\END

testfiles/Versuch2.lve:

\documentclass{article} 
\input{regression-test} 
\usepackage{doublefoo} 

\begin{document}

\START

\ExplSyntaxOn

\OMIT
\hbox_set:Nn \l_tmpa_box { 24 } 
\TIMO

\box_show:N \l_tmpa_box 

\END

Afterwards for example texlua build.lua check Versuch2.

1
  • No relevant to the issue, but I would remove the \CharacterTable: this was useful 20 years ago but the team have dropped them from the sources now. – Joseph Wright Sep 15 '16 at 14:55
8

Your problem is that you've not got any content in the .tlg file. The reason for that is you've not told the test system that the 'useful' part of the .log has started (there is lots of material in a raw log that you don't want). You need to have \START somewhere in the test input to mark the point after which 'useful' material appears. I'd probably go for something like

\documentclass{article} 
\input{regression-test} 
\usepackage{doublefoo} 

\begin{document}
\ExplSyntaxOn

\START

\OMIT
\box_new:N \l_tmp_box 
\hbox_set:Nn \l_tmp_box {\DoubleIt{Hallo}} 
\TIMO

\box_show:N \l_tmp_box 

\END

here. With a single test we don't necessarily need the \OMIT block ( could just move the \START), but for a more complex situation might have

\documentclass{article} 
\input{regression-test} 
\usepackage{doublefoo} 

\begin{document}
\ExplSyntaxOn

\START

\TEST { Basic~use#of~\token_to_str:N \DoubleIt }
  {
    \OMIT
    \hbox_set:Nn \l_tmpa_box {\DoubleIt{Hallo}} 
    \TIMO
    \box_show:N \l_tmpa_box
  }

...

\END

Notice that the code that is part of the test 'set up' but not being tested is inside an \OMIT block (in case there is some stray issue elsewhere). I've also used the standard \l_tmpa_box as in test files this is 'safe' (there should be no risk of a clash).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.