1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
%--------------------------------------------------
% Provides a feature for fully automated regression testing of PGF or derived works.
%
% DEPRECATED.
% The idea might be interesting, but it is simply did not work and is
% too complicated. Don't use it.
%
% Idea:
% - it is based on the 'external' lib of pgf (which automatically exports each tikzpicture to pdf).
% - modification: in addition to the pdf export, call imagemagick's convert
% tool to export to png as well and compare the png to a reference image.
% - pgfregressiontest.sty provides two modes:
% 1) the REFERENCE GENERATION mode
% - each image knows a reference revision tag (or the system default)
% - the 'system call' makes a "checkout" of the desired revision,
% generates the image and returns to the original revision
% - the images are stored with a unique prefix.
% 2) the COMPARISON mode
% - each tikzpicture is compared to its reference image. If there
% is none, it should be generated.
% - if the comparison fails, a protocol is generated and the user
% is alerted.
%--------------------------------------------------
%
\ProvidesPackage{pgfregressiontest}[2010/10/31 Version 0.1]
\RequirePackage{tikz}
\usetikzlibrary{external}
\def\pgfregression@invokecmdkey#1#2{%
\pgfkeysvalueof{/pgf/regression/#1/.@cmd}#2\pgfeov
}%
\newif\ifpgfregressionpreamble
\pgfregressionpreambletrue
\def\pgfregressiontestset{\pgfqkeys{/pgf/regression}}%
\pgfqkeys{/pgf/regression}{%
% will be set in \begin{document}
system call original/.initial=<not yet set>,
%
% 'rev checkout' can be used to manually change the environment
% state before actually generating the image.
% Example:
% 'rev checkout=cd ~/code/tex/pgfplots ; git checkout 1.3'
% or something like this.
%
% Use 'rev restore' to immediately undo the effects. All that
% stuff is executed in one shell environment, i.e. you can define
% and use shell variables.
rev checkout/.code=\def\pgfregression@revcheckout{#1},
rev checkout={},
rev restore/.code=\def\pgfregression@revrestore{#1},
rev restore={},
reference prefix/.initial=reference_images/,
protocol file/.initial=\jobname.protocol.sh,
convert to png/.initial={convert "\image.pdf" "\image.png"},%
reference mode/.code={
\def\pgfregr@replacement@syscall{%
\ifx\pgfregression@revcheckout\pgfutil@empty
\else
\pgfregression@revcheckout;^^J%
@echo "'rev checkout' was successful, generating pdf...";^^J%
\fi
mkdir -p \pgfkeysvalueof{/pgf/regression/reference prefix};^^J%
\pgfkeysvalueof{/pgf/regression/system call original}; EXITCODE=$$?; \\^^J%
\ifx\pgfregression@revrestore\pgfutil@empty
\else
\pgfregression@revrestore; \\^^J%
echo "'rev restore' was successful.";^^J%
\fi
@if [ "$$EXITCODE" != "0" ]; then echo "pdf generation failed; Abort"; false; fi;^^J%
\pgfkeysvalueof{/pgf/regression/convert to png};^^J%
}%
\def\pgfregr@style{%
\message{^^Jpgfregressiontest: Running in REFERENCE GENERATION mode.^^J}%
\pgfqkeys{/pgf/regression}{%
/tikz/external/prefix=\pgfkeysvalueof{/pgf/regression/reference prefix},
}%
}%
\ifpgfregressionpreamble
\else
\pgfkeyslet{/tikz/external/system call}\pgfregr@replacement@syscall
\pgfregr@style
\fi
},
comparison mode/.code={
\def\pgfregr@replacement@syscall{%
\pgfkeysvalueof{/pgf/regression/system call original};^^J%
\pgfkeysvalueof{/pgf/regression/convert to png};^^J%
diff "\image.png" "\expandafter\expandafter\expandafter\pgfregr@get@reference@image@for\image\relax.png";^^J%
if [ ! $? -eq 0 ]; then ^^J
echo 'echo "file \image.pdf differs from \expandafter\expandafter\expandafter\pgfregr@get@reference@image@for\image\relax.pdf (displaying differences now)".' >> \pgfkeysvalueof{/pgf/regression/protocol file};^^J
echo 'convert "\image.png" "\expandafter\expandafter\expandafter\pgfregr@get@reference@image@for\image\relax.png" -compose difference -composite -colorspace gray miff:- | display' >>\pgfkeysvalueof{/pgf/regression/protocol file};^^J%
else^^J
rm -f "\image.png";^^J%
fi;^^J%
}%
\def\pgfregr@style{%
\message{^^Jpgfregressiontest: Running in COMPARISON mode.^^J}%
\expandafter\def\expandafter\pgfregr@get@reference@image@for\tikzexternal@filenameprefix####1\relax{%
\pgfkeysvalueof{/pgf/regression/reference prefix}####1%
}%
}%
\ifpgfregressionpreamble
\else
\pgfkeyslet{/tikz/external/system call}\pgfregr@replacement@syscall
\pgfregr@style
\fi
},
comparison mode,
}
% Check for "command line arguments".
% if 'pdflatex '\def\referencemode{1}\input{filename}' has been used,
% the 'reference mode' will be enabled. Otherwise we are in
% 'comparison mode'.
\expandafter\ifx\csname referencemode\endcsname\relax
\pgfregressiontestset{comparison mode}%
\message{^^Jpgfregressiontest: use pdflatex '\string\def\string\referencemode{1}\string\input{\jobname}' to enable reference generation.^^J}%
\else
\pgfregressiontestset{reference mode}%
\fi
\AtBeginDocument{%
\tikzifexternalizehasbeencalled{}{%
\PackageError{pgfregressiontest}{%
Please call \string\tikzexternalize\space somewhere in your preamble. I can only perform my tests together with image externalization}{}%
}%
\pgfkeysgetvalue{/tikz/external/system call}\pgfregression@temp
\pgfkeyslet{/pgf/regression/system call original}\pgfregression@temp
%
\pgfkeyslet{/tikz/external/system call}\pgfregr@replacement@syscall
\pgfregr@style
%
\immediate\openout\w@pgf@writea=\pgfkeysvalueof{/pgf/regression/protocol file} %
\immediate\closeout\w@pgf@writea
%
\global\pgfregressionpreamblefalse
}
\AtEndDocument{%
\openin\r@pgf@reada=\pgfkeysvalueof{/pgf/regression/protocol file} %
\ifeof\r@pgf@reada
\else
\message{
^^J%
======================================^^J%
There have been regression errors.^^J%
Use^^J%
>> bash \pgfkeysvalueof{/pgf/regression/protocol file}^^J%
to visualize them.^^J%
======================================^^J%
}%
\fi
}%
|