[latex3-commits] [git/LaTeX3-latex3-l3build] master: Revise testing of PDF files (a137f8c)

Joseph Wright joseph.wright at morningstar2.co.uk
Sat Jul 28 23:11:21 CEST 2018


Repository : https://github.com/latex3/l3build
On branch  : master
Link       : https://github.com/latex3/l3build/commit/a137f8c39b0e24b2151b5dc90c41a6130ed5432f

>---------------------------------------------------------------

commit a137f8c39b0e24b2151b5dc90c41a6130ed5432f
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Sat Jul 28 22:10:52 2018 +0100

    Revise testing of PDF files


>---------------------------------------------------------------

a137f8c39b0e24b2151b5dc90c41a6130ed5432f
 l3build-arguments.lua                      |    6 --
 l3build-check.lua                          |  120 ++++++++++++++--------------
 l3build-variables.lua                      |    1 +
 l3build.dtx                                |   35 +++-----
 testfiles/00-test-2.pdf                    |  Bin 0 -> 9101 bytes
 testfiles/{00-test-1.lvt => 00-test-2.pvt} |    2 -
 6 files changed, 76 insertions(+), 88 deletions(-)

diff --git a/l3build-arguments.lua b/l3build-arguments.lua
index 499e2c4..960f288 100644
--- a/l3build-arguments.lua
+++ b/l3build-arguments.lua
@@ -85,12 +85,6 @@ option_list =
         short = "h",
         type  = "boolean"
       },
-    pdf =
-      {
-        desc  = "Check/save PDF files",
-        short = "p",
-        type  = "boolean"
-      },
     quiet =
       {
         desc  = "Suppresses TeX output when unpacking",
diff --git a/l3build-check.lua b/l3build-check.lua
index c2364a9..f70b522 100644
--- a/l3build-check.lua
+++ b/l3build-check.lua
@@ -489,32 +489,43 @@ function runcheck(name, hide)
   if options["engine"] then
     checkengines = options["engine"]
   end
+  -- Used for both .lvt and .pvt tests
+  local function check_and_diff(ext,engine,enginename,comp,pdftest)
+    runtest(name,engine,hide,ext,pdftest,true)
+    local errorlevel = comp(name,enginename)
+    if errorlevel ~= 0 and options["halt-on-error"] then
+      showfaileddiff()
+      return 1
+    end
+    return errorlevel
+  end
   local errorlevel = 0
-  for _,i in ipairs(checkengines) do
+  -- First check by log
+  if fileexists(testfiledir .. "/" .. name .. lvtext) then
+    for _,i in pairs(checkengines) do
     -- Allow for luatex == luajittex for .tlg purposes
-    local engine = i
-    if i == "luajittex" then
-      engine = "luatex"
-    end
-    checkpdf = setup_check(name, engine)
-    runtest(name, i, hide, lvtext, checkpdf, true)
-    -- Generation of results depends on test type
-    local errlevel
-    if checkpdf then
-      errlevel = compare_pdf(name, engine)
-    else
-      errlevel = compare_tlg(name, engine)
-    end
-    if errlevel ~= 0 and options["halt-on-error"] then
-      showfaileddiff()
-      if errlevel ~= 0 then
+      local engine = i
+      if i == "luajittex" then
+        engine = "luatex"
+      end
+      setup_check(name, engine)
+      local errlevel = 0
+      errlevel = check_and_diff(lvtext,i,engine,compare_tlg)
+      if errlevel ~= 0 and options["halt-on-error"] then
         return 1
       end
+      if errlevel > errorlevel then
+        errorlevel = errlevel
+      end
     end
-    if errlevel > errorlevel then
-      errorlevel = errlevel
-    end
   end
+  -- Then check by PDF
+  if fileexists(testfiledir .. "/" .. name .. pvtext) then
+    setup_check(name, stdengine)
+    errorlevel = check_and_diff(pvtext,stdengine,stdengine,compare_pdf,true)
+      + errorlevel
+  end
+  -- Return everything
   return errorlevel
 end
 
@@ -563,9 +574,6 @@ function setup_check(name, engine)
       pdffile,
       gsub(pdffile, pdfext .. "$", ".ref" .. pdfext)
     )
-    return true
-  else
-    return false
   end
 end
 
@@ -751,7 +759,8 @@ end
 
 -- Look for a test: could be in the testfiledir or the unpackdir
 function testexists(test)
-  return(locate({testfiledir, unpackdir}, {test .. lvtext}))
+  return(locate({testfiledir, unpackdir},
+    {test .. lvtext, test .. pvtext}))
 end
 
 -- Standard versions of the main targets for building modules
@@ -772,6 +781,9 @@ function check(names)
       for _,i in pairs(filelist(testfiledir, "*" .. lvtext)) do
         insert(names, jobname(i))
       end
+      for _,i in pairs(filelist(testfiledir, "*" .. pvtext)) do
+        insert(names, jobname(i))
+      end
       for _,i in ipairs(filelist(unpackdir, "*" .. lvtext)) do
         if fileexists(testfiledir .. "/" .. i) then
           print("Duplicate test file: " .. i)
@@ -880,44 +892,36 @@ function save(names)
   checkinit()
   local engines = options["engine"] or {stdengine}
   for _,name in pairs(names) do
-    local engine
-    for _,engine in pairs(engines) do
-      local tlgengine = ((engine == stdengine and "") or "." .. engine)
-      local tlgfile  = name .. tlgengine .. tlgext
-      local spdffile = name .. tlgengine .. pdfext
-      local newfile  = name .. "." .. engine .. logext
-      local pdffile  = name .. "." .. engine .. pdfext
-      local refext = ((options["pdf"] and pdfext) or tlgext)
-      if testexists(name) then
-        print("Creating and copying " .. refext)
-        runtest(name, engine, false, lvtext, options["pdf"])
-        if options["pdf"] then
-          ren(testdir, pdffile, spdffile)
-          cp(spdffile, testdir, testfiledir)
+    if testexists(name) then
+      for _,engine in pairs(engines) do
+        local testengine = ((engine == stdengine and "") or "." .. engine)
+        if fileexists(testfiledir .. "/" .. name .. lvtext) then
+        -- Create one or more .tlg files        
+          print("Creating and copying " .. tlgext)
+          local tlgfile  = name .. testengine .. tlgext
+          local newfile  = name .. "." .. engine .. logext
+          runtest(name,engine,false,lvtext)
+          ren(testdir,newfile,tlgfile)
+          cp(tlgfile,testdir,testfiledir)
+          if fileexists(unpackdir .. "/" .. tlgfile) then
+            print("Saved " .. tlgext
+              .. " file overrides unpacked version of the same name")
+          end
         else
-          ren(testdir, newfile, tlgfile)
-          cp(tlgfile, testdir, testfiledir)
-        end
-        if fileexists(unpackdir .. "/" .. tlgfile) then
-          print(
-            "Saved " .. tlgext
-              .. " file overrides unpacked version of the same name"
-          )
+          -- Create one or more reference .pdf files
+          print("Creating and copying " .. pdfext)
+          local pdffile  = name .. pdfext
+          runtest(name,engine,false,pvtext,true)
+          cp(pdffile,testdir,testfiledir)
         end
         return 0
-      elseif locate({unpackdir, testfiledir}, {name .. lveext}) then
-        print(
-          "Saved " .. tlgext .. " file overrides a "
-            .. lveext .. " file of the same name"
-        )
-      else
-        print(
-          "Test input \"" .. testfiledir .. "/" .. name .. lvtext
-            .. "\" not found"
-        )
-        return 1
       end
-      return 0
+    elseif locate({unpackdir, testfiledir}, {name .. lveext}) then
+      print("Saved " .. tlgext .. " file overrides a "
+        .. lveext .. " file of the same name")
+    else
+      print('Test "'.. name .. '"not found')
+      return 1     
     end
   end
 end
diff --git a/l3build-variables.lua b/l3build-variables.lua
index 14fd5a9..1321535 100644
--- a/l3build-variables.lua
+++ b/l3build-variables.lua
@@ -172,6 +172,7 @@ logext = logext or ".log"
 lveext = lveext or ".lve"
 lvtext = lvtext or ".lvt"
 pdfext = pdfext or ".pdf"
+pvtext = pvtext or ".pvt"
 psext  = psext  or ".ps"
 tlgext = tlgext or ".tlg"
 
diff --git a/l3build.dtx b/l3build.dtx
index b178ab0..d95c174 100644
--- a/l3build.dtx
+++ b/l3build.dtx
@@ -102,10 +102,11 @@
 \luavarseparator
 \luavarset{bakext}{".bak"}{Extension of backup files}
 \luavarset{dviext}{".dvi"}{Extension of DVI files}
-\luavarset{lvtext}{".lvt"}{Extension of test files}
+\luavarset{lvtext}{".lvt"}{Extension of log-based test files}
 \luavarset{tlgext}{".tlg"}{Extension of test file output}
 \luavarset{lveext}{".lve"}{Extension of auto-generating test file output}
 \luavarset{logext}{".log"}{Extension of checking output, before processing it into a \texttt{.tlg}}
+\luavarset{pvtext}{".pvt"}{Extension of PDF-based test files}
 \luavarset{pdfext}{".pdf"}{Extension of PDF file for checking and saving}
 \luavarset{psext} {".ps"} {Extension of PostScript files}
 \luavarseparator
@@ -328,8 +329,6 @@
 %   should stop as soon as possible, rather than running all requested
 %   tests; the difference file is printed in the terminal directly in the case of failure
 %  \item |--last| Name of the last test to run
-% \item |--pdf| (|-p|) Test PDF file against a reference
-%   version rather than using a log comparison
 % \item |--quiet| (|-q|) Suppresses output from unpacking
 % \item |--rerun| Run tests without unpacking/set up
 % \item |--shuffle| Shuffle the order in which tests run
@@ -382,16 +381,6 @@
 % test directory: this may be skipped using the |-s| option.
 % \end{buildcmd}
 %
-% \begin{buildcmd}{check -p}
-% Rather than the log-based checking carried out by the standard
-% |check| target, running with the |-p| option carries out a binary
-% comparison of the PDF files produced by typesetting against those
-% saved in \var{testfiledir}.
-%
-% This functionality requires \TeX{} Live 2016 or later as it needs support
-% from the engines not available in earlier releases.
-% \end{buildcmd}
-%
 % \begin{buildcmd}{clean}
 % This command removes all temporary files used for package bundling and regression testing.
 % In the standard layout, these are all files within the directories defined by \var{localdir}, \var{testdir}, \var{typesetdir} and \var{unpackdir}, as well as all files defined in the \var{cleanfiles} variable in the same directory as the script.
@@ -496,15 +485,6 @@
 % the \enquote{exit status} is zero, else non-zero.
 % \end{buildcmd}
 %
-% \begin{buildcmd}{save -p \meta{name(s)}}
-% This version of |save| will store the PDF files produced from
-% \texttt{\meta{name(s)}.lvt} in addition to the |.tlg| file, and thus allows
-% binary comparison of the result of typesetting.
-%
-% This functionality requires \TeX{} Live 2016 or later as it needs support
-% from the engines not available in earlier releases.
-% \end{buildcmd}
-%
 % \begin{buildcmd}{manifest}
 % Generates a `manifest' file which lists the files of the package as known to \pkg{l3build}.
 % The filename of this file (by default \luavar{manifestfile}) can be set with the variable \var{manifestfile}.
@@ -1116,6 +1096,17 @@
 %   \label{fig:expect-ins}
 % \end{figure}
 %
+% \subsection{PDF-based tests}
+%
+% In most cases, testing is best handled by using the text-based methods
+% outlined above. However, there are cases where the detail of output structure
+% is important. This can only be fully tested by comparing PDF files on a binary
+% level. To support this, \pkg{l3build} can be instructed to build and compare
+% PDF files by setting up tests in \texttt{.pvt} files.
+%
+% Testing on the result of typesetting \texttt{.pvt} files is carried out using
+% only the standard engine, as PDFs are not identical between individual engines.
+%
 % \section{Release-focussed features}
 %
 % \subsection{Automatic tagging}
diff --git a/testfiles/00-test-2.pdf b/testfiles/00-test-2.pdf
new file mode 100644
index 0000000..35534f7
Binary files /dev/null and b/testfiles/00-test-2.pdf differ
diff --git a/testfiles/00-test-1.lvt b/testfiles/00-test-2.pvt
similarity index 96%
copy from testfiles/00-test-1.lvt
copy to testfiles/00-test-2.pvt
index 0a271e9..6814f14 100644
--- a/testfiles/00-test-1.lvt
+++ b/testfiles/00-test-2.pvt
@@ -17,8 +17,6 @@
 
 \newpage
 
-\showoutput
-
 \OMIT
   % Force font loading
   \begin{verbatim}





More information about the latex3-commits mailing list