From dd89951ce8d22cbce567bf3db99f3f6b00c15c7e Mon Sep 17 00:00:00 2001 From: muzimuzhi Date: Fri, 24 Dec 2021 18:50:25 +0800 Subject: [PATCH] test(gd)!: New test set and its first test The gd test set only runs on LuaTeX. `pgfgd-debug.lua` adds debugging code to `InterfaceToDisplay` functions which helps in checking tests based on states of display layer (Lua), rather than box content. Signed-off-by: muzimuzhi --- build.lua | 3 + config-gd.lua | 5 ++ testfiles-gd/support/pgfgd-debug.lua | 39 +++++++++++ .../support/pgfgd-regression-test.tex | 18 ++++++ testfiles-gd/tikz-gd-gh1087.lvt | 64 +++++++++++++++++++ testfiles-gd/tikz-gd-gh1087.tlg | 57 +++++++++++++++++ 6 files changed, 186 insertions(+) create mode 100644 config-gd.lua create mode 100644 testfiles-gd/support/pgfgd-debug.lua create mode 100644 testfiles-gd/support/pgfgd-regression-test.tex create mode 100644 testfiles-gd/tikz-gd-gh1087.lvt create mode 100644 testfiles-gd/tikz-gd-gh1087.tlg diff --git a/build.lua b/build.lua index 4951ccf59..cffe654b9 100644 --- a/build.lua +++ b/build.lua @@ -40,6 +40,9 @@ specialformats["latex"] = specialformats["latex"] or } checkengines = {"pdftex", "latexdvips", "latexdvisvgm", "luatex", "xetex"} +-- Use multiple sets of tests +checkconfigs = { "build", "config-gd" } + --- Keep all \special data (may one day be the l3build default) maxprintline = 9999 diff --git a/config-gd.lua b/config-gd.lua new file mode 100644 index 000000000..2b11da78a --- /dev/null +++ b/config-gd.lua @@ -0,0 +1,5 @@ +-- Tests for graph drawing (gd) library + +stdengine = "luatex" +checkengines = {"luatex"} +testfiledir = "testfiles-gd" diff --git a/testfiles-gd/support/pgfgd-debug.lua b/testfiles-gd/support/pgfgd-debug.lua new file mode 100644 index 000000000..139db5ef0 --- /dev/null +++ b/testfiles-gd/support/pgfgd-debug.lua @@ -0,0 +1,39 @@ +local InterfaceToDisplay = pgf.gd.interface.InterfaceToDisplay + +--- Wrap InterfaceToDisplay functions to prepend debugging code +local createVertex = InterfaceToDisplay.createVertex +-- here `...` is a vararg expression, +-- see https://www.lua.org/manual/5.3/manual.html#3.4.11 +function InterfaceToDisplay.createVertex(...) + local name = ... + debug("Create vertex '%s'", name) + createVertex(...) +end + +local createEdge = InterfaceToDisplay.createEdge +function InterfaceToDisplay.createEdge(...) + local tail, head, direction = ... + debug("Create edge '%s' from '%s' to '%s'", direction, tail, head) + createEdge(...) +end + +-- this generates too many debugging lines +-- local createEvent = InterfaceToDisplay.createEvent +-- function InterfaceToDisplay.createEvent(...) +-- local kind = ... +-- debug("Create event '%s'", kind) +-- return createEvent(...) +-- end + +local addToVertexOptions = InterfaceToDisplay.addToVertexOptions +function InterfaceToDisplay.addToVertexOptions(...) + local name = ... + debug("Add options to vertex '%s'", name) + addToVertexOptions(...) +end + + +-- helper +function debug(format_str, ...) + tex.sprint(string.format("\\pgfgdluainfo{" .. format_str .. "}", ...)) +end diff --git a/testfiles-gd/support/pgfgd-regression-test.tex b/testfiles-gd/support/pgfgd-regression-test.tex new file mode 100644 index 000000000..16ad5bd81 --- /dev/null +++ b/testfiles-gd/support/pgfgd-regression-test.tex @@ -0,0 +1,18 @@ +\input regression-test.tex + +\catcode`\@=11 % \makeatletter + +% this macro should be used _after_ graphdrawing library is loaded +\def\pgfgdBeforeBeginDocument{ + % redirect error + \def\pgfutil@packageerror#1#2#3{\immediate\write17{Package #1 Error: #2.}} + + % new message type "info" + \def\pgftest@genericinfo#1#2{\immediate\write17{#1 Info: #2.}} + \def\pgfgdluainfo{\pgftest@genericinfo{Gd Lua layer}} + + % insert debugging code + \directlua{dofile('pgfgd-debug.lua')} +} + +\catcode`\@=12 % \makeatother diff --git a/testfiles-gd/tikz-gd-gh1087.lvt b/testfiles-gd/tikz-gd-gh1087.lvt new file mode 100644 index 000000000..0cace3e7f --- /dev/null +++ b/testfiles-gd/tikz-gd-gh1087.lvt @@ -0,0 +1,64 @@ +\documentclass{minimal} +\input{pgfgd-regression-test} + +\RequirePackage{tikz} +\usetikzlibrary{graphs, graphdrawing} +\usegdlibrary{layered} + +\pgfgdBeforeBeginDocument +\begin{document} + +\START + +% use all five edge kinds +% make node names variable, to prevent false negative results +\def\testgraph#1{ a#1 -> {b#1, c#1 <-> d#1} -- e#1 <- f#1; a#1 -!- f#1; } +\SEPARATOR +\TYPE{Base graph: \testgraph{}} +\SEPARATOR + +\BEGINTEST{Empty `name prefix`} +\tikzpicture + \graph[layered layout] { [parse/.expand once=\testgraph{1}] }; + \path (b1); + \path[name prefix=z-] (b1); +\endtikzpicture +\ENDTEST + +\BEGINTEST{Non-empty `name prefix`} +\tikzpicture[name prefix=x-] + \graph[layered layout] { [parse/.expand once=\testgraph{2}] }; + + % works + \path (b2) (x-b2); + \path[name prefix=] (x-b2); + \path[name prefix=y-] (x-b2); + + % should throw errors + \path[name prefix=] (b2); +\endtikzpicture +\ENDTEST + +\BEGINTEST{Simple non-gd graph + Empty `name suffix`} +\tikzpicture + \graph { [parse/.expand once=\testgraph{3}] }; + \path (b3); + \path[name suffix=-z] (b3); +\endtikzpicture +\ENDTEST + +\BEGINTEST{Simple non-gd graph + Non-empty `name suffix`} +\tikzpicture[name suffix=-x] + \graph { [parse/.expand once=\testgraph{4}] }; + + % works + \path (b4) (b4-x); + \path[name suffix=] (b4-x); + \path[name suffix=-y] (b4-x); + + % throws errors + \path[name suffix=] (b4); +\endtikzpicture +\ENDTEST + +\END diff --git a/testfiles-gd/tikz-gd-gh1087.tlg b/testfiles-gd/tikz-gd-gh1087.tlg new file mode 100644 index 000000000..9e86129b5 --- /dev/null +++ b/testfiles-gd/tikz-gd-gh1087.tlg @@ -0,0 +1,57 @@ +This is a generated file for the l3build validation system. +Don't change this file in any respect. +============================================================ +Base graph: a -> {b, c <-> d} -- e <- f; a -!- f; +============================================================ +============================================================ +TEST 1: Empty `name prefix` +============================================================ +Gd Lua layer Info: Create vertex 'a1'. +Gd Lua layer Info: Create vertex 'b1'. +Gd Lua layer Info: Create vertex 'c1'. +Gd Lua layer Info: Create vertex 'd1'. +Gd Lua layer Info: Create edge '<->' from 'c1' to 'd1'. +Gd Lua layer Info: Create edge '->' from 'a1' to 'b1'. +Gd Lua layer Info: Create edge '->' from 'a1' to 'c1'. +Gd Lua layer Info: Create vertex 'e1'. +Gd Lua layer Info: Create edge '--' from 'b1' to 'e1'. +Gd Lua layer Info: Create edge '--' from 'd1' to 'e1'. +Gd Lua layer Info: Create vertex 'f1'. +Gd Lua layer Info: Create edge '<-' from 'e1' to 'f1'. +Gd Lua layer Info: Add options to vertex 'a1'. +Gd Lua layer Info: Add options to vertex 'a1'. +Gd Lua layer Info: Add options to vertex 'f1'. +Gd Lua layer Info: Add options to vertex 'f1'. +Gd Lua layer Info: Create edge '-!-' from 'a1' to 'f1'. +============================================================ +============================================================ +TEST 2: Non-empty `name prefix` +============================================================ +Gd Lua layer Info: Create vertex 'x-a2'. +Gd Lua layer Info: Create vertex 'x-b2'. +Gd Lua layer Info: Create vertex 'x-c2'. +Gd Lua layer Info: Create vertex 'x-d2'. +Gd Lua layer Info: Create edge '<->' from 'x-c2' to 'x-d2'. +Gd Lua layer Info: Create edge '->' from 'x-a2' to 'x-b2'. +Gd Lua layer Info: Create edge '->' from 'x-a2' to 'x-c2'. +Gd Lua layer Info: Create vertex 'x-e2'. +Gd Lua layer Info: Create edge '--' from 'x-b2' to 'x-e2'. +Gd Lua layer Info: Create edge '--' from 'x-d2' to 'x-e2'. +Gd Lua layer Info: Create vertex 'x-f2'. +Gd Lua layer Info: Create edge '<-' from 'x-e2' to 'x-f2'. +Gd Lua layer Info: Add options to vertex 'x-a2'. +Gd Lua layer Info: Add options to vertex 'x-a2'. +Gd Lua layer Info: Add options to vertex 'x-f2'. +Gd Lua layer Info: Add options to vertex 'x-f2'. +Gd Lua layer Info: Create edge '-!-' from 'x-a2' to 'x-f2'. +Package pgf Error: No shape named `b2' is known. +============================================================ +============================================================ +TEST 3: Simple non-gd graph + Empty `name suffix` +============================================================ +============================================================ +============================================================ +TEST 4: Simple non-gd graph + Non-empty `name suffix` +============================================================ +Package pgf Error: No shape named `b4' is known. +============================================================