diff options
author | Karl Berry <karl@freefriends.org> | 2018-08-04 20:54:38 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-08-04 20:54:38 +0000 |
commit | e701677aa361258a69f40dad5187444352c6e14b (patch) | |
tree | b4ff67b9a9fe0330e3f30b2d4a83acee43730681 /Master/texmf-dist/scripts/l3build/l3build-check.lua | |
parent | b37c9b96f81e82408f83040ed006fb21a236538e (diff) |
l3build (4aug18)
git-svn-id: svn://tug.org/texlive/trunk@48348 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.lua | 184 |
1 files changed, 85 insertions, 99 deletions
diff --git a/Master/texmf-dist/scripts/l3build/l3build-check.lua b/Master/texmf-dist/scripts/l3build/l3build-check.lua index 7cac25a7d93..f5d1716de9e 100644 --- a/Master/texmf-dist/scripts/l3build/l3build-check.lua +++ b/Master/texmf-dist/scripts/l3build/l3build-check.lua @@ -83,9 +83,20 @@ function checkinit() execute(os_ascii .. ">" .. testdir .. "/ascii.tcx") end +local function rewrite(source,result,processor,...) + local file = assert(open(source,"rb")) + local content = gsub(file:read("*all") .. "\n","\r\n","\n") + close(file) + local new_content = processor(content,...) + local newfile = open(result,"w") + output(newfile) + write(new_content) + close(newfile) +end + -- Convert the raw log file into one for comparison/storage: keeps only -- the 'business' part from the tests and removes system-dependent stuff -local function formatlog(logfile, newfile, engine, errlevels) +local function normalize_log(content,engine,errlevels) local maxprintline = maxprintline if engine == "luatex" or engine == "luajittex" then maxprintline = maxprintline + 1 -- Deal with an out-by-one error @@ -239,14 +250,10 @@ local function formatlog(logfile, newfile, engine, errlevels) return line, lastline end local lastline = "" - local newlog = "" + local new_content = "" local prestart = true local skipping = false - -- Read the entire log file as a binary: deals with ^@/^[, etc. - local file = assert(open(logfile, "rb")) - local contents = gsub(file:read("*all") .. "\n", "\r\n", "\n") - close(file) - for line in gmatch(contents, "([^\n]*)\n") do + for line in gmatch(content, "([^\n]*)\n") do if line == "START-TEST-LOG" then prestart = false elseif line == "END-TEST-LOG" or @@ -259,24 +266,23 @@ local function formatlog(logfile, newfile, engine, errlevels) elseif not prestart and not skipping then line, lastline = normalize(line, lastline) if not match(line, "^ *$") and not killcheck(line) then - newlog = newlog .. line .. os_newline + new_content = new_content .. line .. os_newline end end end - local newfile = open(newfile, "w") - output(newfile) - write(newlog) if recordstatus then - write('***************\n') + new_content = new_content .. '***************' .. os_newline for i = 1, checkruns do - write('Compilation ' .. i .. ' of test file completed with exit status ' .. errlevels[i] .. '\n') + new_content = new_content .. + 'Compilation ' .. i .. ' of test file completed with exit status ' .. + errlevels[i] .. os_newline end end - close(newfile) + return new_content end -- Additional normalization for LuaTeX -local function formatlualog(logfile, newfile, luatex) +local function normalize_lua_log(content,luatex) local function normalize(line, lastline, dropping) -- Find \discretionary or \whatsit lines: -- These may come back later @@ -468,34 +474,24 @@ local function formatlualog(logfile, newfile, luatex) -- uses a different number to the other engines return gsub(line, "^%s+", ""), "" end - local newlog = "" + local new_content = "" local lastline = "" local dropping = false - -- Read the entire log file as a binary: deals with ^@/^[, etc. - local file = assert(open(logfile, "rb")) - local contents = gsub(file:read("*all") .. "\n", "\r\n", "\n") - close(file) - for line in gmatch(contents, "([^\n]*)\n") do + for line in gmatch(content, "([^\n]*)\n") do line, lastline, dropping = normalize(line, lastline, dropping) if not match(line, "^ *$") then - newlog = newlog .. line .. os_newline + new_content = new_content .. line .. os_newline end end - local newfile = open(newfile, "w") - output(newfile) - write(newlog) - close(newfile) + return new_content 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 function normalize_pdf(content) local new_content = "" local stream_content = "" local binary = false local stream = false - for line in gmatch(contents, "([^\n]*)\n") do + for line in gmatch(content,"([^\n]*)\n") do if stream then if match(line,"endstream") then stream = false @@ -524,15 +520,13 @@ local function normalise_pdf(pdffile,npdffile) new_content = new_content .. line .. os_newline end end - local newfile = open(npdffile, "w") - output(newfile) - write(new_content) - close(newfile) + return new_content end -- Run one test which may have multiple engine-dependent comparisons -- Should create a difference file for each failed test function runcheck(name, hide) + if not testexists(name) then return 1 end local checkengines = checkengines if options["engine"] then checkengines = options["engine"] @@ -548,30 +542,25 @@ function runcheck(name, hide) return errorlevel end local errorlevel = 0 - -- 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 - 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 + for _,engine in pairs(checkengines) do + local enginename = engine + -- Allow for luatex == luajittex for .tlg/.tpf purposes + if engine == "luajittex" then + engine = "luatex" + end + setup_check(name,engine) + local errlevel = 0 + if fileexists(testfiledir .. "/" .. name .. pvtext) then + errlevel = check_and_diff(pvtext,engine,enginename,compare_pdf,true) + else + errlevel = check_and_diff(lvtext,engine,enginename,compare_tlg) + end + if errlevel ~= 0 and options["halt-on-error"] then + return 1 + 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 @@ -596,7 +585,7 @@ function setup_check(name, engine) ) exit(1) end - runtest(name, engine, true, lveext, true, false) + runtest(name, engine, true, lveext) ren(testdir, testname .. logext, testname .. tlgext) else -- Install comparison files found @@ -613,15 +602,14 @@ function setup_check(name, engine) end function compare_pdf(name,engine,cleanup) - local errorlevel local testname = name .. "." .. engine - local difffile = testdir .. "/" .. name .. pdfext .. os_diffext + local difffile = testdir .. "/" .. testname .. pdfext .. os_diffext local pdffile = testdir .. "/" .. testname .. pdfext - local tpffile = testdir .. "/" .. name .. tpfext + local tpffile = locate({testdir}, {testname .. tpfext, name .. tpfext}) if not tpffile then return 1 end - errorlevel = execute(os_diffexe .. " " + local errorlevel = execute(os_diffexe .. " " .. normalize_path(tpffile .. " " .. pdffile .. " > " .. difffile)) if errorlevel == 0 or cleanup then remove(difffile) @@ -650,8 +638,8 @@ function compare_tlg(name, engine,cleanup) lualogfile = testdir .. "/" .. testname .. ".tmp" .. logext end local luatlgfile = testdir .. "/" .. testname .. tlgext - formatlualog(tlgfile, luatlgfile, false) - formatlualog(logfile, lualogfile, true) + rewrite(tlgfile,luatlgfile,normalize_lua_log) + rewrite(logfile,lualogfile,normalize_lua_log,true) errorlevel = execute(os_diffexe .. " " .. normalize_path(luatlgfile .. " " .. lualogfile .. " > " .. difffile)) if cleanup then @@ -669,7 +657,7 @@ function compare_tlg(name, engine,cleanup) end -- Run one of the test files: doesn't check the result so suitable for --- both creating and verifying .tlg files +-- both creating and verifying function runtest(name, engine, hide, ext, pdfmode, breakout) local lvtfile = name .. (ext or lvtext) cp(lvtfile, fileexists(testfiledir .. "/" .. lvtfile) @@ -677,13 +665,11 @@ function runtest(name, engine, hide, ext, pdfmode, breakout) local engine = engine or stdengine -- Set up the format file name if it's one ending "...tex" local realengine = engine - local format + local format = "" if match(checkformat, "tex$") and not match(engine, checkformat) then format = " -fmt=" .. gsub(engine, "(.*)tex$", "%1") .. checkformat - else - format = "" end -- Special casing for e-LaTeX format if @@ -720,10 +706,11 @@ function runtest(name, engine, hide, ext, pdfmode, breakout) exit(1) end end - local logfile = testdir .. "/" .. name .. logext - local newfile = testdir .. "/" .. name .. "." .. engine .. logext - local pdffile = testdir .. "/" .. name .. pdfext - local npffile = testdir .. "/" .. name .. "." .. engine .. pdfext + local basename = testdir .. "/" .. name + local logfile = basename .. logext + local newfile = basename .. "." .. engine .. logext + local pdffile = basename .. pdfext + local npffile = basename .. "." .. engine .. pdfext local asciiopt = "" for _,i in ipairs(asciiengines) do if realengine == i then @@ -760,12 +747,12 @@ function runtest(name, engine, hide, ext, pdfmode, breakout) -- Break the loop if the result is stable if breakout and i < checkruns then if pdfmode then - normalise_pdf(pdffile,npffile) + rewrite(pdffile,npffile,normalize_pdf) if compare_pdf(name,engine,true) == 0 then break end else - formatlog(logfile, newfile, engine, errlevels) + rewrite(logfile,newfile,normalize_log,engine,errlevels) if compare_tlg(name,engine,true) == 0 then break end @@ -776,9 +763,9 @@ function runtest(name, engine, hide, ext, pdfmode, breakout) dvitopdf(name, testdir, engine, hide) end if pdfmode then - normalise_pdf(pdffile,npffile) + rewrite(pdffile,npffile,normalize_pdf) else - formatlog(logfile, newfile, engine, errlevels) + rewrite(logfile,newfile,normalize_log,engine,errlevels) end -- Store secondary files for this engine for _,filetype in pairs(auxfiles) do @@ -794,6 +781,7 @@ function runtest(name, engine, hide, ext, pdfmode, breakout) end end end + return 0 end -- A hook to allow additional tasks to run for the tests @@ -807,8 +795,6 @@ function testexists(test) {test .. lvtext, test .. pvtext})) end --- Standard versions of the main targets for building modules - function check(names) local errorlevel = 0 if testfiledir ~= "" and direxists(testfiledir) then @@ -950,37 +936,37 @@ function save(names) for _,name in pairs(names) do 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 + local testengine = ((engine == stdengine and "") or "." .. engine) + local function save_test(test_ext,gen_ext,out_ext,pdfmode) + local out_file = name .. testengine .. out_ext + local gen_file = name .. "." .. engine .. gen_ext + print("Creating and copying " .. out_file) + runtest(name,engine,false,test_ext,pdfmode) + ren(testdir,gen_file,out_file) + cp(out_file,testdir,testfiledir) + if fileexists(unpackdir .. "/" .. out_file) then + print("Saved " .. out_ext .. " file overrides unpacked version of the same name") + return 1 end + return 0 + end + local errorlevel + if fileexists(testfiledir .. "/" .. name .. lvtext) then + errorlevel = save_test(lvtext,logext,tlgext) else - -- 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) + errorlevel = save_test(pvtext,pdfext,tpfext,true) end - return 0 + if errorlevel ~=0 then return errorlevel end end elseif locate({unpackdir, testfiledir}, {name .. lveext}) then print("Saved " .. tlgext .. " file overrides a " .. lveext .. " file of the same name") + return 1 else print('Test "'.. name .. '"not found') return 1 end end + return 0 end - |