From fdf45e87dea227d920698370657e62fdf3208579 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 8 May 2013 15:46:15 +0200 Subject: add test --- Makefile | 22 ++++++++------- README | 1 + lualibs.dtx | 20 +++++++------- test-lualibs.lua | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 19 deletions(-) create mode 100644 test-lualibs.lua diff --git a/Makefile b/Makefile index 4c9edc3..4a08cf0 100644 --- a/Makefile +++ b/Makefile @@ -6,20 +6,21 @@ DOC_DTX = $(patsubst %.dtx, %.pdf, $(DTX)) MODULES = $(wildcard lualibs-*.lua) # Files grouped by generation mode -UNPACKED= lualibs.lua -COMPILED = $(DOC_DTX) -GENERATED = $(UNPACKED) $(DOC_DTX) $(MERGED) -SOURCE = $(DTX) $(MODULES) LICENSE README Makefile NEWS -MERGED = lualibs-basic-merged.lua lualibs-extended-merged.lua +TESTSCRIPT = test-lualibs.lua +UNPACKED = lualibs.lua lualibs-extended.lua lualibs-basic.lua +COMPILED = $(DOC_DTX) +GENERATED = $(UNPACKED) $(DOC_DTX) $(MERGED) +SOURCE = $(DTX) $(MODULES) $(TESTSCRIPT) LICENSE README Makefile NEWS +MERGED = lualibs-basic-merged.lua lualibs-extended-merged.lua # Files grouped by installation location RUNFILES = $(UNPACKED) $(MODULES) DOCFILES = $(DOC_DTX) LICENSE README NEWS -SRCFILES = $(DTX) $(SRC_TEX) Makefile +SRCFILES = $(DTX) $(SRC_TEX) Makefile $(TESTSCRIPT) # The following definitions should be equivalent # ALL_FILES = $(RUNFILES) $(DOCFILES) $(SRCFILES) -ALL_FILES = $(GENERATED) $(SOURCE) $(MERGED) +ALL_FILES = $(GENERATED) $(SOURCE) # Installation locations FORMAT = luatex @@ -37,13 +38,16 @@ DO_PDFLATEX = latexmk -pdf -e '$$pdflatex = q(lualatex %O %S)' -silent $< >/dev DO_MAKEINDEX = makeindex -s gind.ist $(subst .dtx,,$<) >/dev/null 2>&1 DO_PACKAGE = mtxrun --script package --merge $< >/dev/null -all: $(GENERATED) $(DOC_TEX) $(MERGED) +all: $(GENERATED) $(DOC_TEX) doc: $(COMPILED) unpack: $(UNPACKED) -ctan: $(CTAN_ZIP) +ctan: check $(CTAN_ZIP) tds: $(TDS_ZIP) world: all ctan +check: $(TESTSCRIPT) + @texlua $(TESTSCRIPT) + .PHONY: all doc unpack ctan tds world %.pdf: %.dtx diff --git a/README b/README index affefe2..499ceb8 100644 --- a/README +++ b/README @@ -72,6 +72,7 @@ Source files: Makefile source/luatex/lualibs/Makefile NEWS doc/luatex/lualibs/NEWS README doc/luatex/lualibs/README + test-lualibs.lua source/luatex/lualibs/test-lualibs.lua Derived files: lualibs.lua tex/luatex/lualibs/lualibs.lua diff --git a/lualibs.dtx b/lualibs.dtx index b8fe169..b8c74c0 100644 --- a/lualibs.dtx +++ b/lualibs.dtx @@ -450,13 +450,9 @@ lualibs.module_info = { config = config or { } config.lualibs = config.lualibs or { } -if config.lualibs.prefer_merged == nil then - lualibs.prefer_merged = true -end -if config.lualibs.load_extended == nil then - lualibs.load_extended = true -end -config.lualibs.verbose = config.lualibs.verbose == false +lualibs.prefer_merged = config.lualibs.prefer_merged or true +lualibs.load_extended = config.lualibs.load_extended or true +config.lualibs.verbose = config.lualibs.verbose or false % \end{macrocode} % The lualibs may be loaded in scripts. @@ -526,13 +522,17 @@ lualibs.loadmodule = loadmodule % % \begin{macrocode} -if lualibs.basic_loaded ~= true then +if lualibs.basic_loaded ~= true +or config.lualibs.force_reload == true +then loadmodule"lualibs-basic.lua" loadmodule"lualibs-compat.lua" --- restore stuff gone since v1.* end -if lualibs.load_extended == true -and lualibs.extended_loaded ~= true then +if lualibs.load_extended == true +and lualibs.extended_loaded ~= true +or config.lualibs.force_reload == true +then loadmodule"lualibs-extended.lua" end diff --git a/test-lualibs.lua b/test-lualibs.lua new file mode 100644 index 0000000..b74fde1 --- /dev/null +++ b/test-lualibs.lua @@ -0,0 +1,81 @@ +#!/usr/bin/env texlua + +local luafiles = { + "lualibs-boolean.lua", "lualibs-compat.lua", + "lualibs-dir.lua", "lualibs-file.lua", + "lualibs-function.lua", "lualibs-io.lua", + "lualibs-lpeg.lua", "lualibs-lua.lua", + "lualibs-math.lua", "lualibs-md5.lua", + "lualibs-number.lua", "lualibs-os.lua", + "lualibs-package.lua", "lualibs-set.lua", + "lualibs-string.lua", "lualibs-table.lua", + "lualibs-trac-inf.lua", "lualibs-unicode.lua", + "lualibs-url.lua", "lualibs-util-deb.lua", + "lualibs-util-dim.lua", "lualibs-util-env.lua", + "lualibs-util-jsn.lua", "lualibs-util-lua.lua", + "lualibs-util-prs.lua", "lualibs-util-sta.lua", + "lualibs-util-sto.lua", "lualibs-util-str.lua", + "lualibs-util-tab.lua", "lualibs-util-fmt.lua", + "lualibs-util-tpl.lua", "lualibs.lua", + "lualibs-basic.lua", "lualibs-basic-merged.lua", + "lualibs-extended.lua", "lualibs-extended-merged.lua", +} + +local test_cmd = "texluac -p %s &> /dev/null" + +local check_wellformed = function (file) + io.write"testing " + io.write(file) + io.write" ... " + local exit_status = os.execute(string.format(test_cmd, file)) + if exit_status == 0 then + io.write"SUCCESS!\n" + return true + end + io.write"FAIL :-/\n" + return false +end + +local check_files check_files = function (lst, n) + if n == nil then + return check_files(lst, 1) + end + local this = lst[n] + if this then + if check_wellformed(this) then + return check_files(lst, n+1) + else + return false + end + end + return true +end + +config = { lualibs = { force_reload = true } } + +local load_all = function ( ) + + io.write"testing merged packages ... " + config.lualibs.prefer_merged = true + if not pcall(function () dofile"lualibs.lua"end) then + io.write"FAIL :-/\n" + end + io.write"SUCCESS\n" + + io.write"testing files ... " + config.lualibs.prefer_merged = false + if not pcall(function () dofile"lualibs.lua"end) then + io.write"FAIL :-/\n" + end + io.write"SUCCESS\n" + return true +end + +local main = function ( ) + local retval = 0 + retval = check_files(luafiles) and retval or 1 + retval = load_all() and retval or 1 + os.exit(retval) +end + +return main() -- cgit v1.2.3