summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/l3build/l3build-check.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-08-03 21:16:27 +0000
committerKarl Berry <karl@freefriends.org>2018-08-03 21:16:27 +0000
commit5010c435d5c9e266b90f68227f41610b19b88465 (patch)
tree6b809d1324d4fac1a92e21c3920a5b459c088dc8 /Master/texmf-dist/scripts/l3build/l3build-check.lua
parent97b66e90dd2d069b12f64e3339c7486b748d222d (diff)
l3build (3aug18)
git-svn-id: svn://tug.org/texlive/trunk@48340 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/l3build/l3build-check.lua')
-rw-r--r--Master/texmf-dist/scripts/l3build/l3build-check.lua291
1 files changed, 178 insertions, 113 deletions
diff --git a/Master/texmf-dist/scripts/l3build/l3build-check.lua b/Master/texmf-dist/scripts/l3build/l3build-check.lua
index 442bd916814..7cac25a7d93 100644
--- a/Master/texmf-dist/scripts/l3build/l3build-check.lua
+++ b/Master/texmf-dist/scripts/l3build/l3build-check.lua
@@ -55,7 +55,9 @@ local remove = os.remove
-- Set up the check system files: needed for checking one or more tests and
-- for saving the test files
function checkinit()
- cleandir(testdir)
+ if not options["dirty"] then
+ cleandir(testdir)
+ end
depinstall(checkdeps)
-- Copy dependencies to the test directory itself: this makes the paths
-- a lot easier to manage, and is important for dealing with the log and
@@ -207,6 +209,9 @@ local function formatlog(logfile, newfile, engine, errlevels)
if match(line, "^%.*\\special%{pdf: docinfo << /Creator") then
return ""
end
+ if match(line, "^%.*\\special%{dvipdfmx:config") then
+ return ""
+ end
-- Remove the \special line possibly present in DVI mode for paper size
if match(line, "^%.*\\special%{papersize") then
return ""
@@ -482,6 +487,49 @@ local function formatlualog(logfile, newfile, luatex)
close(newfile)
end
+local function normalise_pdf(pdffile,npdffile)
+ local file = assert(open(pdffile, "rb"))
+ local contents = gsub(file:read("*all") .. "\n", "\r\n", "\n")
+ close(file)
+ local new_content = ""
+ local stream_content = ""
+ local binary = false
+ local stream = false
+ for line in gmatch(contents, "([^\n]*)\n") do
+ if stream then
+ if match(line,"endstream") then
+ stream = false
+ if binary then
+ new_content = new_content .. "[BINARY STREAM]" .. os_newline
+ else
+ new_content = new_content .. stream_content .. line .. os_newline
+ end
+ binary = false
+ else
+ for i = 0, 31 do
+ if match(line,char(i)) then
+ binary = true
+ break
+ end
+ end
+ if not binary and not match(line, "^ *$") then
+ stream_content = stream_content .. line .. os_newline
+ end
+ end
+ elseif match(line,"^stream$") then
+ binary = false
+ stream = true
+ stream_content = "stream" .. os_newline
+ elseif not match(line, "^ *$") then
+ new_content = new_content .. line .. os_newline
+ end
+ end
+ local newfile = open(npdffile, "w")
+ output(newfile)
+ write(new_content)
+ close(newfile)
+end
+
-- Run one test which may have multiple engine-dependent comparisons
-- Should create a difference file for each failed test
function runcheck(name, hide)
@@ -489,64 +537,70 @@ 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
- end
- if errlevel > errorlevel then
- errorlevel = errlevel
+ if errlevel > errorlevel then
+ errorlevel = errlevel
+ end
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
function setup_check(name, engine)
local testname = name .. "." .. engine
- local pdffile = locate(
- {testfiledir, unpackdir},
- {testname .. pdfext, name .. pdfext}
- )
local tlgfile = locate(
{testfiledir, unpackdir},
{testname .. tlgext, name .. tlgext}
)
+ local tpffile = locate(
+ {testfiledir, unpackdir},
+ {testname .. tpfext, name .. tpfext}
+ )
-- Attempt to generate missing reference file from expectation
- if not (pdffile or tlgfile) then
+ if not (tlgfile or tpffile) then
if not locate({unpackdir, testfiledir}, {name .. lveext}) then
print(
- "Error: failed to find " .. pdfext .. ", " .. tlgext .. " or "
+ "Error: failed to find " .. tlgext .. ", " .. tlpext .. " or "
.. lveext .. " file for " .. name .. "!"
)
exit(1)
end
runtest(name, engine, true, lveext, true, false)
- pdffile = testdir .. "/" .. testname .. pdfext
- -- If a PDF is generated use it for comparisons
- if not fileexists(pdffile) then
- pdffile = nil
- ren(testdir, testname .. logext, testname .. tlgext)
- end
+ ren(testdir, testname .. logext, testname .. tlgext)
else
-- Install comparison files found
- for _,v in pairs({pdffile, tlgfile}) do
+ for _,v in pairs({tlgfile, tpffile}) do
if v then
cp(
match(v, ".*/(.*)"),
@@ -556,36 +610,21 @@ function setup_check(name, engine)
end
end
end
- if pdffile then
- local pdffile = match(pdffile, ".*/(.*)")
- ren(
- testdir,
- pdffile,
- gsub(pdffile, pdfext .. "$", ".ref" .. pdfext)
- )
- return true
- else
- return false
- end
end
-function compare_pdf(name, engine)
+function compare_pdf(name,engine,cleanup)
local errorlevel
local testname = name .. "." .. engine
- local cmpfile = testdir .. "/" .. testname .. os_cmpext
- local pdffile = testdir .. "/" .. testname .. pdfext
- local refpdffile = locate(
- {testdir}, {testname .. ".ref" .. pdfext, name .. ".ref" .. pdfext}
- )
- if not refpdffile then
- return
+ local difffile = testdir .. "/" .. name .. pdfext .. os_diffext
+ local pdffile = testdir .. "/" .. testname .. pdfext
+ local tpffile = testdir .. "/" .. name .. tpfext
+ if not tpffile then
+ return 1
end
- errorlevel = execute(
- os_cmpexe .. " " .. normalize_path(refpdffile)
- .. " " .. pdffile .. " > " .. cmpfile
- )
- if errorlevel == 0 then
- remove(cmpfile)
+ errorlevel = execute(os_diffexe .. " "
+ .. normalize_path(tpffile .. " " .. pdffile .. " > " .. difffile))
+ if errorlevel == 0 or cleanup then
+ remove(difffile)
end
return errorlevel
end
@@ -631,7 +670,7 @@ end
-- Run one of the test files: doesn't check the result so suitable for
-- both creating and verifying .tlg files
-function runtest(name, engine, hide, ext, makepdf, breakout)
+function runtest(name, engine, hide, ext, pdfmode, breakout)
local lvtfile = name .. (ext or lvtext)
cp(lvtfile, fileexists(testfiledir .. "/" .. lvtfile)
and testfiledir or unpackdir, testdir)
@@ -660,7 +699,7 @@ function runtest(name, engine, hide, ext, makepdf, breakout)
end
-- Special casing for XeTeX engine
local checkopts = checkopts
- if match(engine, "xetex") and not makepdf then
+ if match(engine, "xetex") and not pdfmode then
checkopts = checkopts .. " -no-pdf"
end
-- Special casing for ConTeXt
@@ -683,6 +722,8 @@ function runtest(name, engine, hide, ext, makepdf, breakout)
end
local logfile = testdir .. "/" .. name .. logext
local newfile = testdir .. "/" .. name .. "." .. engine .. logext
+ local pdffile = testdir .. "/" .. name .. pdfext
+ local npffile = testdir .. "/" .. name .. "." .. engine .. pdfext
local asciiopt = ""
for _,i in ipairs(asciiengines) do
if realengine == i then
@@ -718,16 +759,27 @@ function runtest(name, engine, hide, ext, makepdf, breakout)
)
-- Break the loop if the result is stable
if breakout and i < checkruns then
- formatlog(logfile, newfile, engine, errlevels)
- if compare_tlg(name,engine,true) == 0 then
- break
+ if pdfmode then
+ normalise_pdf(pdffile,npffile)
+ if compare_pdf(name,engine,true) == 0 then
+ break
+ end
+ else
+ formatlog(logfile, newfile, engine, errlevels)
+ if compare_tlg(name,engine,true) == 0 then
+ break
+ end
end
end
end
- if makepdf and fileexists(testdir .. "/" .. name .. dviext) then
+ if pdfmode and fileexists(testdir .. "/" .. name .. dviext) then
dvitopdf(name, testdir, engine, hide)
end
- formatlog(logfile, newfile, engine, errlevels)
+ if pdfmode then
+ normalise_pdf(pdffile,npffile)
+ else
+ formatlog(logfile, newfile, engine, errlevels)
+ end
-- Store secondary files for this engine
for _,filetype in pairs(auxfiles) do
for _,file in pairs(filelist(testdir, filetype)) do
@@ -751,7 +803,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
@@ -769,15 +822,36 @@ function check(names)
names = names or { }
-- No names passed: find all test files
if not next(names) then
- for _,i in pairs(filelist(testfiledir, "*" .. lvtext)) do
- insert(names, jobname(i))
+ local excludenames = { }
+ for _,glob in pairs(excludetests) do
+ for _,name in pairs(filelist(testfiledir, glob .. lvtext)) do
+ excludenames[jobname(name)] = true
+ end
+ for _,name in pairs(filelist(unpackdir, glob .. lvtext)) do
+ excludenames[jobname(name)] = true
+ end
+ for _,name in pairs(filelist(testfiledir, glob .. pvtext)) do
+ excludenames[jobname(name)] = true
+ end
end
- for _,i in ipairs(filelist(unpackdir, "*" .. lvtext)) do
- if fileexists(testfiledir .. "/" .. i) then
- print("Duplicate test file: " .. i)
- return 1
- else
- insert(names, jobname(i))
+ local function addname(name)
+ if not excludenames[jobname(name)] then
+ insert(names,jobname(name))
+ end
+ end
+ for _,glob in pairs(includetests) do
+ for _,name in pairs(filelist(testfiledir, glob .. lvtext)) do
+ addname(name)
+ end
+ for _,name in pairs(filelist(testfiledir, glob .. pvtext)) do
+ addname(name)
+ end
+ for _,name in pairs(filelist(unpackdir, glob .. lvtext)) do
+ if fileexists(testfiledir .. "/" .. name) then
+ print("Duplicate test file: " .. i)
+ return 1
+ end
+ addname(name)
end
end
sort(names)
@@ -853,9 +927,6 @@ function checkdiff()
for _,i in ipairs(filelist(testdir, "*" .. os_diffext)) do
print(" - " .. testdir .. "/" .. i)
end
- for _,i in ipairs(filelist(testdir, "*" .. os_cmpext)) do
- print(" - " .. testdir .. "/" .. i)
- end
print("")
end
@@ -871,50 +942,44 @@ function showfaileddiff()
print(content)
print("-----------------------------------------------------------------------------------")
end
- for _,i in ipairs(filelist(testdir, "*" .. os_cmpext)) do
- print(" - " .. testdir .. "/" .. i)
- end
end
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 .tpf file
+ print("Creating and copying " .. tpfext)
+ local tpffile = name .. tpfext
+ local newfile = name .. "." .. engine .. pdfext
+ runtest(name,engine,false,pvtext,true)
+ ren(testdir,newfile,tpffile)
+ cp(tpffile,testdir,testfiledir)
end
- 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 0
end
+ 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