Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I was trying to figure out how to test my xpeek package (see https://github.com/jcsalomon/xpeek) and I came across What's the folk-lore on automatic testing of TeX programming? and Testing Framework API for LaTeX. Both of these mention the qstest package, but I’m having trouble understanding how to use it.

To be concrete, consider this test of xspace (xpeek can be used to implement \xspace, so this is not far removed from what I want to do):

\documentclass{article}
\usepackage{xspace, qstest}
\begin{document}

\begin{qstest}{test xspace}{}
  \Expect{foo\xspace.}{foo.}
\end{qstest}

\end{document}

This fails, yielding this error message:

! Package qstest Error: Failed: test xspace
 \Expect: foo\xspace .
 <foo.
 >foo\xspace ..

See the qstest package documentation for explanation.

Obviously I’m missing something fundamental here, but reading the qstest package documentation is not making things any clearer to me. Can anyone explain to me how to write the test so it succeeds?

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

"foo\xspace." and "foo." are indeed different, thus the test must fail. \Expect can expand the arguments if they are preceded by a star:

\Expect*{foo\xspace.}{foo.}

However, this will not help either, because \xspace is not expandable (\futurelet and other assignments). But we can put the argument in a box and measure the width. If \xspace would insert a space, the width of the box would be larger.

\begin{qstest}{test xspace}{}
  \sbox0{foo\xspace.}
  \sbox2{foo.}
  \Expect*{\the\wd0}*{\the\wd2}
\end{qstest}
share|improve this answer
    
Is that what the test macros inside your packages boil down to? Seems like quite a limitation. BTW, you & Will Robertson are the only ones whose packages on CTAN use qstest that I can find. –  J. C. Salomon Aug 15 '12 at 16:32
    
@Salomon, you can take LuaTeX and look into the contents of boxes using Lua and check, whether is a space. Testing is sometimes something like finding relevant properties of a feature that can be checked against the expectations. –  Heiko Oberdiek Aug 15 '12 at 16:41
    
LuaTeX is a rabbit-hole I’m not looking to climb down at the moment, but it’s good to know about. I’ve added a simple test-suite based on your answer to xpeek at this commit. –  J. C. Salomon Aug 15 '12 at 19:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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