]> git.sesse.net Git - pgn-extract/blob - test/runtests
Push through a computer/human flag to the binary output.
[pgn-extract] / test / runtests
1 #!/bin/bash
2 # Script to run a battery of tests of the basic functionality of pgn-extract
3 # Copyright (C) David J. Barnes, 2013
4
5 # Location of the file of ECO classifications.
6 ECO_FILE="../eco.pgn"
7 export ECO_FILE
8
9 # Location of the test input files
10 INPUT="infiles"
11
12 # Test template:
13
14 #     + Input file containing games with 
15 #     - Input file(s):
16 #     - Resulting output ...
17 #     - Expected output: ...
18 #     - Command: pgn-extract ...
19
20 # No flags:
21 #     + No input file.
22 #     - Input file(s): N/A
23 #     - Example input:
24 #       f3 e5 g4 Qh4 0-1
25 #     - Resulting output should be that the game input on standard input is
26 #       formatted as PGN on standard output.
27 #     - Expected output: 
28 #       Contents of fools-mate.pgn on standard output.
29 ../pgn-extract < $INPUT/fools-mate.txt
30
31 # No flags:
32 #     + Single input file
33 #     - Input file(s): fools-mate.txt
34 #     - Resulting output should be the input formatted as PGN on standard output.
35 #     - Expected output: Contents of fools-mate.pgn should appear on standard output.
36 ../pgn-extract $INPUT/fools-mate.txt
37
38 # -7 / --seven
39 #     + Input file with games having tags additional to the seven tag roster.
40 #     - Input file(s): test-7.pgn
41 #     - Game output should have only the tags of the seven tag roster.
42 #     - Expected output: test-7-out.pgn
43 ../pgn-extract -7 -otest-7-out.pgn $INPUT/test-7.pgn
44
45 # -a / --append
46 #     + Input file containing games in any accepted format.
47 #     - Input file(s): test-a.txt
48 #     - Resulting output should contain two versions of the input game
49 #       formatted in PGN. The --output command is run first to create
50 #       a new file, then the -a version to append to that file.
51 #     - Expected output: test-a-out.pgn
52 ../pgn-extract --output test-a-out.pgn $INPUT/test-a.txt
53 ../pgn-extract -atest-a-out.pgn $INPUT/test-a.txt
54
55 ../pgn-extract --output test-a-out.pgn $INPUT/test-a.txt
56 ../pgn-extract --append test-a-out.pgn $INPUT/test-a.txt
57
58 # -A
59 #     + Input file containing games and a file of arguments.
60 #     - Input file(s): fischer.pgn, petrosian.pgn, arglist.txt
61 #     - Resulting output should be files separating the unique and
62 #       duplicated games in the input files.
63 #     - Expected output: test-A-unique.pgn, test-A-dupes.pgn
64 ../pgn-extract -A$INPUT/argslist.txt
65
66 # -b
67 #     + Input file containing games of different length.
68 #     - Input file(s): fischer.pgn
69 #     - Resulting output: games whose number of moves is within
70 #       the specified bounds.
71
72 #     - Expected output: 45 moves or more: fischer-bl45-out.pgn
73 ../pgn-extract -bl45 -ofischer-bl45-out.pgn $INPUT/fischer.pgn
74
75 #     - Expected output: 45 moves or less: fischer-bu45-out.pgn
76 ../pgn-extract -bu45 -ofischer-bu45-out.pgn $INPUT/fischer.pgn
77
78 #     - Expected output: exactly 30 moves: fischer-b30-out.pgn
79 ../pgn-extract -b30 -ofischer-b30-out.pgn $INPUT/fischer.pgn
80
81
82 # -c / --checkfile
83 #     + Input files containing games.
84 #     - Input file(s): fischer.pgn, petrosian.pgn
85 #     - Resulting output should contain matched games that do not already occur in
86 #       the check file.
87 #     - Expected output: test-c-out.pgn
88 ../pgn-extract -c$INPUT/petrosian.pgn -D -TpPetrosian -otest-c-out.pgn $INPUT/fischer.pgn
89 ../pgn-extract -c$INPUT/clist.txt -D -TpPetrosian -otest-c-out.pgn $INPUT/fischer.pgn
90
91 # -C / --nocomments
92 #     + Input file containing games with comments
93 #     - Input file(s): test-C.pgn
94 #     - Resulting output should have all comments removed.
95 #     - Expected output: test-C-out.pgn
96 ../pgn-extract -C -otest-C-out.pgn $INPUT/test-C.pgn
97
98 # -d / --duplicates
99 #     + Input file containing games with duplicates and non-duplicates.
100 #     - Input file(s): fischer.pgn, $INPUT/petrosian.pgn
101 #     - Resulting output should be files separating the unique and
102 #       duplicated games in the input files.
103 #     - Expected output: test-d-unique.pgn, test-d-dupes.pgn
104 ../pgn-extract -dtest-d-dupes.pgn -otest-d-unique.pgn $INPUT/fischer.pgn $INPUT/petrosian.pgn
105
106 # -D / --noduplicates
107 #     + Input file containing games with duplicates and non-duplicates.
108 #     - Input file(s): fischer.pgn, $INPUT/petrosian.pgn
109 #     - Resulting output should be a file containing the combined input
110 #       with duplicate games removed.
111 #     - Expected output: test-D-unique.pgn
112 ../pgn-extract -D -otest-D-unique.pgn $INPUT/fischer.pgn $INPUT/petrosian.pgn
113 ../pgn-extract --noduplicates -otest-D-unique.pgn $INPUT/fischer.pgn $INPUT/petrosian.pgn
114
115 # -e
116 #     + Input file containing games without ECO classifications.
117 #     - Input file(s): test-e.pgn and eco.pgn in the test folder.
118 #     - Resulting output should have ECO classification added to the tags.
119 #     - Expected output: test-e-out.pgn
120 ../pgn-extract -e -otest-e-out.pgn $INPUT/test-e.pgn
121 ../pgn-extract -e$ECO_FILE -otest-e-out.pgn $INPUT/test-e.pgn
122
123 # -E
124 #     + Input file containing games.
125 #     - Input file(s): test-E.pgn and eco.pgn if -e flag is used.
126 #     - Resulting output should be separate files for each ECO classification
127 #       at the level of the initial letter (A-E).
128 #     - Expected output: A.pgn, B.pgn, E.pgn
129 ../pgn-extract -e -E1 $INPUT/test-E.pgn
130
131 # -f
132 #     + Input files containing games.
133 #     - Input file(s): test-f1.pgn, test-f2.pgn, files.txt
134 #     - Resulting output should be the combination of the input files.
135 #     - Expected output: test-f-out.pgn
136 ../pgn-extract -f$INPUT/files.txt -otest-f-out.pgn
137
138 # -F:
139 #     + Input file containing games without a trailing FEN comment.
140 #     - Input file(s): test-F.pgn
141 #     - Resulting output should have a comment at the end containing
142 #       the FEN description of the final position.
143 #     - Expected output: test-F-out.pgn
144 ../pgn-extract -F -otest-F-out.pgn $INPUT/test-F.pgn
145
146
147 # -h / -? / --help
148 #     + No input required.
149 #     - Input file(s): N/A
150 #     - Resulting output should be a description of how to use pgn-extract
151 #     - Expected output: N/A
152 ../pgn-extract -h
153 # ../pgn-extract -?
154 # ../pgn-extract --help
155
156 # -l
157 #     + Input file containing games.
158 #     - Input file(s): fischer.pgn
159 #     - Resulting output: List of games parsed written to log.txt
160 #     - Expected output: log.txt
161 ../pgn-extract -llog.txt -otest-l-out.pgn $INPUT/fischer.pgn
162
163 # -L
164 #     + Input file containing games.
165 #     - Input file(s): test-L1.pgn, test-L2.pgn
166 #     - Resulting output should be that log.txt contains the combined
167 #       logs from two runs of pgn-extract.
168 #     - Expected output: log.txt
169 ../pgn-extract -llog.txt -r $INPUT/test-L1.pgn
170 ../pgn-extract -Llog.txt -r $INPUT/test-L2.pgn
171
172 # -M / --checkmate
173 #     + Input file containing games.
174 #     - Input file(s): test-checkmate.pgn
175 #     - Resulting output should contain only those games that end in checkmate.
176 #     - Expected output: test-checkmate-out.pgn
177 ../pgn-extract --checkmate -otest-checkmate-out.pgn $INPUT/test-checkmate.pgn
178
179 # -n
180 #     + Input file containing games.
181 #     - Input file(s): petrosian.pgn
182 #     - Resulting output should be separate files containing matched
183 #       and non-matched games.
184 #     - Expected output: test-n-matched.pgn, test-n-unmatched.pgn
185 ../pgn-extract -TpFischer -otest-n-matched.pgn -ntest-n-unmatched.pgn $INPUT/petrosian.pgn
186
187 # -N / --nonags
188 #     + Input file containing games with NAGs.
189 #     - Input file(s): test-N.pgn
190 #     - Resulting output should have all NAGs removed.
191 #     - Expected output: test-N-out.pgn
192 ../pgn-extract -N -otest-N-out.pgn $INPUT/test-N.pgn
193
194
195 # -o / --output
196 #     + Input file containing games in any accepted format.
197 #     - Input file(s): test-o.txt
198 #     - Resulting output should contain the input game formatted in PGN.
199 #     - Expected output: test-o-out.pgn
200 ../pgn-extract -otest-o-out.pgn $INPUT/test-o.txt
201 ../pgn-extract --output test-o-out.pgn $INPUT/test-o.txt
202
203 # -P
204 #     + Input file containing games with different sequences for the same
205 #       opening.
206 #     - Input file(s): test-P.pgn, Pvars.txt
207 #     - Resulting output should be games whose opening move exactly match
208 #       the sequence specified in Pvars.txt
209 #     - Expected output: test-P-out.pgn
210 ../pgn-extract -P -v$INPUT/Pvars.txt -otest-P-out.pgn $INPUT/test-P.pgn
211
212 # -r
213 #     + Input file containing games in any accepted format.
214 #     - Input file(s): test-r.text
215 #     - Resulting output should contain tag summary lines for the games
216 #       matched and a report of any errors.
217 #     - Expected output: test-r-log.text
218 ../pgn-extract -r -Ltest-r-log.txt $INPUT/test-r.txt
219
220 # -R
221 #     + Input file containing games.
222 #     - Input file(s): test-R.pgn, roster.txt
223 #     - Resulting output should contain games with their tag roster in
224 #       the order specified in roster.txt
225 #     - Expected output: test-R-out.pgn
226 ../pgn-extract -R$INPUT/roster.txt --output test-R-out.pgn $INPUT/test-R.pgn
227
228 # -s
229 #     + Input file containing games.
230 #     - Input file(s): test-s.pgn
231 #     - Resulting output should be silent, with games written to the output file.
232 #     - Expected output: test-s-out.pgn
233 ../pgn-extract -s -o test-s-out.pgn $INPUT/test-s.pgn
234
235 # -S
236 #     + Input file containing games whose players' names have slight
237 #       sound variations from anglesized versions.
238 #     - Input file(s): test-S.pgn
239 #     - Resulting output should be games that match by ignoring slight
240 #       soundex differences.
241 #     - Expected output: test-S-out.pgn
242 ../pgn-extract -S -TpPetrosian -otest-S-out.pgn $INPUT/test-S.pgn
243
244 # -t
245 #     + Input file containing games and a file of tag criteria.
246 #     - Input file(s): test-t.pgn, taglist.txt
247 #     - Resulting output should be only those games whose tags match
248 #       all of the criteria.
249 #     - Expected output: test-t-out.pgn
250 ../pgn-extract -t$INPUT/taglist.txt -otest-t-out.pgn $INPUT/test-t.pgn
251
252 # -T
253 #     + Input file containing games with tag information.
254 #     - Input file(s): fischer.pgn, test-Ta.pgn (and eco.pgn for -Te test.)
255 #     - Resulting output should contain only those games whose tag information
256 #       matches that specified.
257 #     - Expected output: test-Ta-out.pgn, test-Tb-out.pgn, test-Td-out.pgn,
258 #                        test-Te-out.pgn, test-Tp-out.pgn, test-Tw-out.pgn
259 ../pgn-extract -Td1970 -otest-Td-out.pgn $INPUT/fischer.pgn
260 ../pgn-extract -TbPetrosian -otest-Tb-out.pgn $INPUT/fischer.pgn
261 ../pgn-extract -e -TeB14 -otest-Te-out.pgn $INPUT/fischer.pgn
262 ../pgn-extract -TpPetrosian -otest-Tp-out.pgn $INPUT/fischer.pgn
263 ../pgn-extract -Tr0-1 -otest-Tr-out.pgn $INPUT/fischer.pgn
264 ../pgn-extract -TwFischer -otest-Tw-out.pgn $INPUT/fischer.pgn
265 ../pgn-extract -TaBarnes -otest-Ta-out.pgn $INPUT/test-Ta.pgn
266
267 # -U / --nounique
268 #     + Input file containing games with duplicates and non-duplicates.
269 #     - Input file(s): fischer.pgn, petrosian.pgn
270 #     - Resulting output should be a file containing just the duplicate games.
271 #     - Expected output: test-U-unique.pgn
272 ../pgn-extract -U -otest-U-unique.pgn $INPUT/fischer.pgn $INPUT/petrosian.pgn
273 ../pgn-extract --nounique -otest-U-unique.pgn $INPUT/fischer.pgn $INPUT/petrosian.pgn
274
275 # -v
276 #     + Input file containing games.
277 #     - Input file(s): najdorf.pgn, vvars.txt
278 #     - Resulting output should be only those games whose opening moves
279 #       textually match (in any order) the moves in vars.txt.
280 #     - Expected output: test-v-out.pgn
281 ../pgn-extract -v$INPUT/vvars.txt -otest-v-out.pgn $INPUT/najdorf.pgn
282
283 # -V
284 #     + Input file containing games with variations
285 #     - Input file(s): test-V.pgn
286 #     - Resulting output should have all variations removed.
287 #     - Expected output: test-V-out.pgn
288 ../pgn-extract -V -otest-V-out.pgn $INPUT/test-V.pgn
289
290 # -w / --linelength
291 #     + Input file containing games.
292 #     - Input file(s): test-w.pgn
293 #     - Resulting output Games formatted up to the specified line length.
294 #       The default is 75.
295 #     - Expected output: test-w60-out.pgn, test-w75-out.pgn, test-w1000-out.pgn
296 ../pgn-extract -w60 -otest-w60-out.pgn $INPUT/test-w.pgn
297 ../pgn-extract -w75 -otest-w75-out.pgn $INPUT/test-w.pgn
298 ../pgn-extract -w1000 -otest-w1000-out.pgn $INPUT/test-w.pgn
299
300 ../pgn-extract --linelength 60 -otest-w60-out.pgn $INPUT/test-w.pgn
301 ../pgn-extract --linelength 75 -otest-w75-out.pgn $INPUT/test-w.pgn
302 ../pgn-extract --linelength 1000 -otest-w1000-out.pgn $INPUT/test-w.pgn
303
304 # -W
305 #     + Input file containing games.
306 #     - Input file(s): test-W.pgn
307 #     - Resulting output should be games formatted in the specified notation:
308 #       halg (hyphenated long algebraic), lalg (non-hyphenated long algebraic),
309 #       elalg (enhanced long algebraic), uci (UCI-compatible output),
310 #       and alternative piece letters.
311 #     - Expected output: test-Whalg-out.pgn, test-Wlalg-out.pgn,
312 #                        test-elalg-out.pgn, test-Wdeutsch-out.pgn,
313 #                        test-Wuci-out.pgn
314 ../pgn-extract -Whalg -otest-Whalg-out.pgn $INPUT/test-W.pgn
315 ../pgn-extract -Wlalg -otest-Wlalg-out.pgn $INPUT/test-W.pgn
316 ../pgn-extract -Welalg -otest-Welalg-out.pgn $INPUT/test-W.pgn
317 ../pgn-extract -WsanBSLTDK -otest-Wdeutsch-out.pgn $INPUT/test-W.pgn
318 ../pgn-extract -Wuci -otest-Wuci-out.pgn $INPUT/test-W.pgn
319
320 # -x
321 #     + Input file containing games.
322 #     - Input file(s): najdorf.pgn, xvars.txt
323 #     - Resulting output should be only those games which match
324 #       the result of reaching the opening sequence in vars.txt.
325 #     - Expected output: test-x-out.pgn
326 ../pgn-extract -x$INPUT/xvars.txt -otest-x-out.pgn $INPUT/najdorf.pgn
327
328 # -Z
329 #     + Input file containing games with duplicates and non-duplicates.
330 #     - Input file(s): fischer.pgn, petrosian.pgn
331 #     - Resulting output should be files separating the unique and
332 #       duplicated games in the input files.
333 #     - Expected output: test-Z-unique.pgn, test-Z-dupes.pgn
334 ../pgn-extract -Z -dtest-Z-dupes.pgn -otest-Z-unique.pgn $INPUT/fischer.pgn $INPUT/petrosian.pgn
335
336 # -z
337 #     + Input file containing games.
338 #     - Input file(s): petrosian.pgn, zmatch.txt
339 #     - Resulting output should be games whose material balance matches that
340 #       specified in zmatch.txt
341 #     - Expected output: test-z-out.pgn
342 ../pgn-extract -z$INPUT/zmatch.txt -otest-z-out.pgn $INPUT/petrosian.pgn
343
344 # -#
345 #     + Input file containing games.
346 #     - Input file(s): test-hash.pgn
347 #     - Resulting output The input file split in to separate sub-files,
348 #       each containing 10 games, except the last which may contain fewer.
349 #     - Expected output: 1.pgn, 2.pgn
350 ../pgn-extract -#20 $INPUT/test-hash.pgn
351
352 # --evaluation
353 #     + Input file containing games.
354 #     - Input file(s): test-evaluation.pgn
355 #     - Resulting output should include an evaluation value in a comment
356 #       after every move.
357 #     - Expected output: test-evaluation-out.pgn
358 ../pgn-extract --evaluation -otest-evaluation-out.pgn $INPUT/test-evaluation.pgn
359
360 # --fencomments
361 #     + Input file containing games.
362 #     - Input file(s): test-fencomments.pgn
363 #     - Resulting output should have a comment after every move containing a
364 #       FEN description of the position after that move.
365 #     - Expected output: test-fencomments-out.pgn
366 ../pgn-extract --fencomments -otest-fencomments-out.pgn $INPUT/test-fencomments.pgn
367
368 # --markmatches
369 #     + Input file containing games.
370 #     - Input file(s): najdorf.pgn, xvars.txt
371 #     - Resulting output should be only those games which match
372 #       the result of reaching the opening sequence in vars.txt.
373 #       The point of each match is marked with the comment { MATCH }
374 #     - Expected output: test-markmatches-out.pgn
375 ../pgn-extract --markmatches MATCH -x$INPUT/xvars.txt -otest-markmatches-out.pgn $INPUT/najdorf.pgn
376
377 # --nochecks
378 #     + Input file containing games with moves involving moves that give check
379 #       and/or mate.
380 #     - Input file(s): test-nochecks.pgn
381 #     - Resulting output should contain games with no check indicators after moves.
382 #     - Expected output: test-nochecks-out.pgn
383 ../pgn-extract --nochecks -otest-nochecks-out.pgn $INPUT/test-nochecks.pgn
384
385 # --nomovenumbers
386 #     + Input file containing games with move numbers.
387 #     - Input file(s): test-nomovenumbers.pgn
388 #     - Resulting output should contain games with no move numbers.
389 #     - Expected output: test-nomovenumbers-out.pgn
390 ../pgn-extract -otest-no-movenumbers-out.pgn --nomovenumbers $INPUT/test-nomovenumbers.pgn
391
392 # --noresults
393 #     + Input file containing games with results.
394 #     - Input file(s): test-noresults.pgn
395 #     - Resulting output should contain games with no results.
396 #     - Expected output: test-noresults-out.pgn
397 ../pgn-extract -otest-no-results-out.pgn --noresults $INPUT/test-noresults.pgn
398
399 # --notags
400 #     + Input file containing games with tag information.
401 #     - Input file(s): test-notags.pgn
402 #     - Resulting output should contain games with no tag information.
403 #     - Expected output: test-notags-out.pgn
404 ../pgn-extract -otest-no-tags-out.pgn --notags $INPUT/test-notags.pgn
405
406 # --plylimit
407 #     + Input file containing games.
408 #     - Input file(s): test-plylimit.pgn
409 #     - Resulting output should contain games whose number of moves (plies) are
410 #       limited at the specified ply limit.
411 #     - Expected output: test-plylimit-out.pgn
412 ../pgn-extract --plylimit 10 -otest-plylimit-out.pgn $INPUT/test-plylimit.pgn
413
414 # --stalemate
415 #     + Input file containing games.
416 #     - Input file(s): test-stalemate.pgn
417 #     - Resulting output should contain only those games that end in stalemate.
418 #     - Expected output: test-stalemate-out.pgn
419 ../pgn-extract --stalemate -otest-stalemate-out.pgn $INPUT/test-stalemate.pgn
420
421 # Test on a file with a string too long to be output within the
422 # defined line length.
423 #     + Input file containing a game with a very long comment.
424 #     + Input file(s): test-long-line.pgn
425 #     + Resulting output should contain the game properly formatted and
426 #       the log file should contain an error message reporting the problem.
427 #     + Expected output: test-long-line-out.pgn, test-long-line-log.txt
428 ../pgn-extract -otest-long-line-out.pgn -ltest-long-line-log.txt $INPUT/test-long-line.pgn