1(use-modules (ice-9 receive))
2
3(load-from-path "env.scm")
4
5(define file (getenv "FILE"))
6(define skip-file-tests (string-null? file))
7(define compare (getenv "COMPARE"))
8(define skip-compare-tests (string-null? compare))
9(define identify (getenv "IDENTIFY"))
10(define skip-identify-tests (string-null? identify))
11(define convert (getenv "CONVERT"))
12(define skip-convert-tests (string-null? convert))
13
14(define cwd (getcwd))
15(define *testdir* (build-filename (getcwd) "export-tmp"))
16
17;;; Setup/teardown directories/files needed by tests.
18(define (test-setup)
19  (mkdir *testdir*)
20  (chdir *testdir*))
21
22(define (test-teardown)
23  (chdir cwd)
24  (system* "rm" "-rf" *testdir*))
25
26
27(test-begin "lepton-cli export")
28
29(receive (<status> <stdout> <stderr>)
30    (command-values lepton-cli "export")
31  (test-eq EXIT_FAILURE <status>)
32  (test-assert (string-contains <stderr> "ERROR: You must specify at least one input filename."))
33  (test-assert (string-contains <stderr> "Run `lepton-cli export --help' for more information.")))
34
35(test-end "lepton-cli export")
36
37(define help-string
38  "Export Lepton EDA files in various image formats.")
39
40(test-begin "export -h")
41
42(receive (<status> <stdout> <stderr>)
43    (command-values lepton-cli "export" "-h")
44  (test-eq EXIT_SUCCESS <status>)
45  (test-assert (string-contains <stdout> help-string)))
46
47(test-end "export -h")
48
49
50(test-begin "export --help")
51
52(receive (<status> <stdout> <stderr>)
53    (command-values lepton-cli "export" "--help")
54  (test-eq EXIT_SUCCESS <status>)
55  (test-assert (string-contains <stdout> help-string)))
56
57(test-end "export --help")
58
59
60(test-begin "export -P")
61
62(receive (<status> <stdout> <stderr>)
63    (command-values lepton-cli "export" "-P")
64  (test-eq EXIT_SUCCESS <status>)
65  (test-assert (string-contains <stdout> "iso_a4"))
66  (test-assert (string-contains <stdout> "na_letter")))
67
68(test-end "export -P")
69
70
71(test-begin "export --paper-names")
72
73(receive (<status> <stdout> <stderr>)
74    (command-values lepton-cli "export" "--paper-names")
75  (test-eq EXIT_SUCCESS <status>)
76  (test-assert (string-contains <stdout> "iso_a4"))
77  (test-assert (string-contains <stdout> "na_letter")))
78
79(test-end "export --paper-names")
80
81
82(define schematic
83  (build-filename *abs-top-srcdir*
84                  "libleptongui"
85                  "tests"
86                  "embedded_1.sch"))
87
88(define (file-size-about? filename size)
89  (define delta .2)
90  (false-if-exception
91   (< (* size (- 1 delta))
92      (stat:size (stat filename))
93      (* size (+ 1 delta)))))
94
95
96(test-begin "export -o")
97
98(test-group-with-cleanup "export -o"
99  (test-setup)
100
101  (let ((cli-png (basename (string-append schematic ".cli.png")))
102        (export-png (basename (string-append schematic ".export.png"))))
103    ;; Test 'lepton-cli export'.
104
105    ;; This command hangs up due to weird things when running
106    ;; lepton-cli using pipes defined in command-values().
107    ;;   (receive (<status> <stdout> <stderr>)
108    ;;       (command-values lepton-cli "export" "-o" cli-png schematic)
109    ;;     (test-eq EXIT_SUCCESS <status>))
110
111    (test-run-success lepton-cli "export" "-o" cli-png schematic)
112    (test-assert (file-exists? cli-png))
113    (file-size-about? cli-png 360000)
114
115    (test-run-success lepton-export "-o" export-png schematic)
116    (test-assert (file-exists? export-png))
117    (file-size-about? export-png 360000)
118
119    ;; Test long option version.
120    (test-run-success lepton-cli "export" "--output=cli.pdf" schematic)
121    (test-assert (file-exists? "cli.pdf"))
122
123    (test-run-success lepton-export "export" "--output=export.pdf" schematic)
124    (test-assert (file-exists? "export.pdf"))
125    )
126
127  ;; Clean up.
128  (test-teardown))
129
130(test-end "export -o")
131
132
133(define (make-test-filename name)
134  (build-filename *abs-top-srcdir*
135                  "utils"
136                  "cli"
137                  "tests"
138                  name))
139
140
141
142(when (or skip-compare-tests
143          skip-identify-tests)
144  (test-skip "export -c"))
145
146(test-begin "export -c")
147
148(test-group-with-cleanup "export -c"
149  (test-setup)
150
151  (let ((input (make-test-filename "box.sch"))
152        (output "box.png")
153        (output-c "box-c.png")
154        (output-color "box-color.png")
155        (output-no-color "box-no-color.png"))
156
157    (test-run-success lepton-cli "export"
158                      "-k" "100px"
159                      "-m" "10px"
160                      "-o" output
161                      input)
162    (test-assert (file-exists? output))
163    (receive (<status> <stdout> <stderr>)
164        (command-values identify output)
165      (test-eq EXIT_SUCCESS <status>)
166      (test-assert
167          (string-contains <stdout> "130x130")))
168    (test-run-success lepton-cli "export"
169                      "-c"
170                      "-k" "100px"
171                      "-m" "10px"
172                      "-o" output-c
173                      input)
174    (test-assert (file-exists? output-c))
175    (receive (<status> <stdout> <stderr>)
176        (command-values identify output-c)
177      (test-eq EXIT_SUCCESS <status>)
178      (test-assert
179          (string-contains <stdout> "130x130")))
180    ;; Compare files.  It is enough to test that they are
181    ;; different for now.
182    (test-run-failure compare "-metric" "MAE" output output-c "diff.png")
183
184    ;; Test long option version.
185    (test-run-success lepton-cli "export"
186                      "-c"
187                      "-k" "100px"
188                      "-m" "10px"
189                      "-o" output-color
190                      input)
191    ;; Colored files should not differ.
192    (test-run-success compare "-metric" "MAE" output-c output-color "diff.png")
193
194    ;; Test --no-color.
195    (test-run-success lepton-cli "export"
196                      "--no-color"
197                      "-k" "100px"
198                      "-m" "10px"
199                      "-o" output-no-color
200                      input)
201    ;; Colored files should not differ.
202    (test-run-success compare "-metric" "MAE" output output-no-color "diff.png")
203    )
204  ;; Clean up.
205  (test-teardown))
206
207(test-end "export -c")
208
209
210(when skip-file-tests
211  (test-skip "export -f"))
212
213(test-begin "export -f")
214(test-group-with-cleanup "export -f"
215  (test-setup)
216
217  (let ((input (make-test-filename "box.sch"))
218        (output "box.x"))
219
220    (test-run-success lepton-cli "export" "-f" "png" "-o" output input)
221    (test-grep-stdout "PNG" file output)
222
223    (test-run-success lepton-cli "export" "-f" "svg" "-o" output input)
224    (test-grep-stdout "SVG" file output)
225
226    (test-run-success lepton-cli "export" "-f" "pdf" "-o" output input)
227    (test-grep-stdout "PDF" file output)
228
229    (test-run-success lepton-cli "export" "-f" "ps" "-o" output input)
230    (test-grep-stdout "PostScript" file output)
231
232    ;; Test long option version.
233    (test-run-success lepton-cli "export" "--format=eps" "-o" output input)
234    (test-grep-stdout "PostScript" file output)
235    (test-grep-stdout "EPS" file output)
236
237    (receive (<status> <stdout> <stderr>)
238      (command-values lepton-cli "export" "-f" "x" "-o" output input)
239    (test-eq EXIT_FAILURE <status>)
240    (test-assert
241        (string-contains <stderr> "ERROR: Unsupported output format"))))
242
243  ;; Clean up.
244  (test-teardown))
245
246(test-end "export -f")
247
248(when skip-file-tests
249  (test-skip "export format"))
250
251(test-begin "export format")
252(test-group-with-cleanup "export format"
253  (test-setup)
254
255  (let ((input (make-test-filename "box.sch")))
256
257    (test-run-success lepton-cli "export" "-o" "output.png" input)
258    (test-grep-stdout "PNG" file "output.png")
259
260    (test-run-success lepton-cli "export" "-o" "output.svg" input)
261    (test-grep-stdout "SVG" file "output.svg")
262
263    (test-run-success lepton-cli "export" "-o" "output.pdf" input)
264    (test-grep-stdout "PDF" file "output.pdf")
265
266    (test-run-success lepton-cli "export" "-o" "output.ps" input)
267    (test-grep-stdout "PostScript" file "output.ps")
268
269    (test-run-success lepton-cli "export" "-o" "output.eps" input)
270    (test-grep-stdout "PostScript" file "output.eps")
271    (test-grep-stdout "EPS" file "output.eps")
272
273    (receive (<status> <stdout> <stderr>)
274      (command-values lepton-cli "export" "-o" "output.x" input)
275    (test-eq EXIT_FAILURE <status>)
276    (test-assert
277        (string-contains <stderr> "ERROR: Cannot find supported format for filename"))))
278
279  ;; Clean up.
280  (test-teardown))
281
282(test-end "export format")
283
284(when skip-identify-tests
285  (test-skip "export -p"))
286
287(test-begin "export -p")
288(test-group-with-cleanup "export -p"
289  (test-setup)
290
291  (let ((input-box (make-test-filename "box.sch"))
292        (input-horiz (make-test-filename "box-horiz.sch"))
293        (input-vert (make-test-filename "box-vert.sch"))
294        (output-box "box.png")
295        (output-horiz "box-horiz.png")
296        (output-vert "box-vert.png"))
297
298    (test-run-success lepton-cli "export" "-o" output-box "-p" "iso_a4" input-box)
299    (test-assert (file-exists? output-box))
300    (test-run-success lepton-cli "export" "-o" output-horiz "-p" "iso_a4" input-horiz)
301    (test-assert (file-exists? output-horiz))
302    ;; Test long option version.
303    (test-run-success lepton-cli "export" "-o" output-vert "--paper=iso_a4" input-vert)
304    (test-assert (file-exists? output-vert))
305
306    (receive (<status> <stdout> <stderr>)
307        (command-values identify output-box)
308      (test-eq EXIT_SUCCESS <status>)
309      (test-assert
310          (string-contains <stdout> "794x1123")))
311
312    (receive (<status> <stdout> <stderr>)
313        (command-values identify output-horiz)
314      (test-eq EXIT_SUCCESS <status>)
315      (test-assert
316          (string-contains <stdout> "1123x794")))
317
318    (receive (<status> <stdout> <stderr>)
319        (command-values identify output-vert)
320      (test-eq EXIT_SUCCESS <status>)
321      (test-assert
322          (string-contains <stdout> "794x1123"))))
323
324  ;; Clean up.
325  (test-teardown))
326
327(test-end "export -p")
328
329
330(when skip-identify-tests
331  (test-skip "export -s"))
332
333;;; Some tests here output glitches as white 1px lines on two
334;;; edges of boxes.  This should be addressed some day.
335
336(test-begin "export -s")
337(test-group-with-cleanup "export -s"
338  (test-setup)
339
340  (let ((input (make-test-filename "box.sch"))
341        (output "box.png"))
342
343    ;; Export without margins.
344    ;; Default unit is 'pt' so '100:100' means '100pt:100pt'.
345    (test-run-success lepton-cli "export" "-m" "0" "-s" "100:100" "-o" output input)
346    (test-assert (file-exists? output))
347    (receive (<status> <stdout> <stderr>)
348        (command-values identify output)
349      (test-eq EXIT_SUCCESS <status>)
350      (test-assert
351          (string-contains <stdout> "134x134")))
352
353    (test-run-success lepton-cli "export" "-m" "0" "-s" "100pt:100pt" "-o" output input)
354    (test-assert (file-exists? output))
355    (receive (<status> <stdout> <stderr>)
356        (command-values identify output)
357      (test-eq EXIT_SUCCESS <status>)
358      (test-assert
359          (string-contains <stdout> "134x134")))
360
361    (test-run-success lepton-cli "export" "-m" "0" "-s" "100px:100px" "-o" output input)
362    (test-assert (file-exists? output))
363    (receive (<status> <stdout> <stderr>)
364        (command-values identify output)
365      (test-eq EXIT_SUCCESS <status>)
366      (test-assert
367          (string-contains <stdout> "100x100")))
368
369    (test-run-success lepton-cli "export" "-m" "0" "-s" "1cm:1cm" "-o" output input)
370    (test-assert (file-exists? output))
371    (receive (<status> <stdout> <stderr>)
372        (command-values identify output)
373      (test-eq EXIT_SUCCESS <status>)
374      (test-assert
375          (string-contains <stdout> "38x38")))
376
377    (test-run-success lepton-cli "export" "-m" "0" "-s" "10mm:10mm" "-o" output input)
378    (test-assert (file-exists? output))
379    (receive (<status> <stdout> <stderr>)
380        (command-values identify output)
381      (test-eq EXIT_SUCCESS <status>)
382      (test-assert
383          (string-contains <stdout> "38x38")))
384
385    (test-run-success lepton-cli "export" "-m" "0" "-s" "1in:1in" "-o" output input)
386    (test-assert (file-exists? output))
387    (receive (<status> <stdout> <stderr>)
388        (command-values identify output)
389      (test-eq EXIT_SUCCESS <status>)
390      (test-assert
391          (string-contains <stdout> "96x96")))
392
393    ;; Test long option version.
394    (test-run-success lepton-cli "export" "-m" "0" "--size=10pc:10pc" "-o" output input)
395    (test-assert (file-exists? output))
396    (receive (<status> <stdout> <stderr>)
397        (command-values identify output)
398      (test-eq EXIT_SUCCESS <status>)
399      (test-assert
400          (string-contains <stdout> "160x160")))
401    )
402
403  ;; Clean up.
404  (test-teardown))
405
406(test-end "export -s")
407
408
409(when skip-identify-tests
410  (test-skip "export -k"))
411
412(test-begin "export -k")
413(test-group-with-cleanup "export -k"
414  (test-setup)
415
416  (let ((input (make-test-filename "box.sch"))
417        (output "box.png"))
418
419    ;; Export without margins.
420    (test-run-success lepton-cli "export" "-m" "0" "-k" "5mm" "-o" output input)
421    (test-assert (file-exists? output))
422    (receive (<status> <stdout> <stderr>)
423        (command-values identify output)
424      (test-eq EXIT_SUCCESS <status>)
425      (test-assert
426          (string-contains <stdout> "21x21")))
427
428    ;; Test long option version.
429    (test-run-success lepton-cli "export" "-m" "0" "--scale=1cm" "-o" output input)
430    (test-assert (file-exists? output))
431    (receive (<status> <stdout> <stderr>)
432        (command-values identify output)
433      (test-eq EXIT_SUCCESS <status>)
434      (test-assert
435          (string-contains <stdout> "42x42")))
436    )
437
438  ;; Clean up.
439  (test-teardown))
440
441(test-end "export -k")
442
443
444(when skip-identify-tests
445  (test-skip "export -d"))
446
447(test-begin "export -d")
448(test-group-with-cleanup "export -d"
449  (test-setup)
450
451  (let ((input (make-test-filename "box.sch"))
452        (output "box.png"))
453
454    ;; Export a4 without margins.
455    (test-run-success lepton-cli "export" "-p" "iso_a4" "-m" "0" "-d" "100" "-o" output input)
456    (test-assert (file-exists? output))
457    (receive (<status> <stdout> <stderr>)
458        (command-values identify output)
459      (test-eq EXIT_SUCCESS <status>)
460      (test-assert
461          (string-contains <stdout> "827x1170")))
462
463    ;; Test long option version.
464    (test-run-success lepton-cli "export" "-p" "iso_a4" "-m" "0" "--dpi=200" "-o" output input)
465    (test-assert (file-exists? output))
466    (receive (<status> <stdout> <stderr>)
467        (command-values identify output)
468      (test-eq EXIT_SUCCESS <status>)
469      (test-assert
470          (string-contains <stdout> "1654x2339")))
471    )
472
473  ;; Clean up.
474  (test-teardown))
475
476(test-end "export -d")
477
478
479(test-begin "export --")
480
481(receive (<status> <stdout> <stderr>)
482    (command-values lepton-cli "export" "--" "-o" "x.png" "x.sch")
483  (test-eq EXIT_FAILURE <status>)
484  (test-assert
485      (string-contains <stderr> "ERROR: You must specify an output filename.")))
486
487(test-end "export --")
488
489
490(test-begin "export -F")
491(test-group-with-cleanup "export -F"
492  (test-setup)
493
494  (let ((input (make-test-filename "text.sch"))
495        (output-sans "text-sans.ps")
496        (output-serif "text-serif.ps"))
497
498    ;; Export to PostScript using different fonts and check that
499    ;; output files differ.
500    (test-run-success lepton-cli "export" "-F" "Sans" "-o" output-sans input)
501    (test-assert (file-exists? output-sans))
502    ;; Test long option version.
503    (test-run-success lepton-cli "export" "--font=Serif" "-o" output-serif input)
504    (test-assert (file-exists? output-serif))
505
506    (let ((font-sans #f)
507          (font-serif #f))
508      (receive (<status> <stdout> <stderr>)
509          (command-values "grep" "FontName" output-sans)
510        (test-eq EXIT_SUCCESS <status>)
511        (set! font-sans <stdout>))
512
513      (receive (<status> <stdout> <stderr>)
514          (command-values "grep" "FontName" output-serif)
515        (test-eq EXIT_SUCCESS <status>)
516        (set! font-serif <stdout>))
517
518      (test-assert (not (string= font-sans font-serif)))))
519
520  ;; Clean up.
521  (test-teardown))
522
523(test-end "export -F")
524
525
526(when skip-identify-tests
527  (test-skip "export -l"))
528
529(test-begin "export -l")
530
531(test-group-with-cleanup "export -l"
532  (test-setup)
533
534  (let ((input-horiz (make-test-filename "box-horiz.sch"))
535        (input-vert (make-test-filename "box-vert.sch"))
536        (output-plain "plain.png")
537        (output-auto "auto.png")
538        (output-portrait "portrait.png")
539        (output-landscape "landscape.png"))
540
541    (test-run-success lepton-cli "export" "-p" "iso_a4" "-o" output-plain input-horiz)
542    (test-assert (file-exists? output-plain))
543    (test-run-success lepton-cli "export" "-p" "iso_a4" "-l" "auto" "-o" output-auto input-horiz)
544    (test-assert (file-exists? output-auto))
545    (test-run-success lepton-cli "export" "-p" "iso_a4" "-l" "portrait" "-o" output-portrait input-horiz)
546    (test-assert (file-exists? output-portrait))
547    (test-run-success lepton-cli "export" "-p" "iso_a4" "-l" "landscape" "-o" output-landscape input-horiz)
548    (test-assert (file-exists? output-landscape))
549
550    (receive (<status> <stdout> <stderr>)
551        (command-values identify output-plain)
552      (test-eq EXIT_SUCCESS <status>)
553      (test-assert
554          (string-contains <stdout> "1123x794")))
555
556    (receive (<status> <stdout> <stderr>)
557        (command-values identify output-auto)
558      (test-eq EXIT_SUCCESS <status>)
559      (test-assert
560          (string-contains <stdout> "1123x794")))
561
562    (receive (<status> <stdout> <stderr>)
563        (command-values identify output-portrait)
564      (test-eq EXIT_SUCCESS <status>)
565      (test-assert
566          (string-contains <stdout> "794x1123")))
567
568    (receive (<status> <stdout> <stderr>)
569        (command-values identify output-landscape)
570      (test-eq EXIT_SUCCESS <status>)
571      (test-assert
572          (string-contains <stdout> "1123x794")))
573
574    ;; Test long option version.
575    (test-run-success lepton-cli "export" "-p" "iso_a4" "-o" output-plain input-vert)
576    (test-assert (file-exists? output-plain))
577    (test-run-success lepton-cli "export" "-p" "iso_a4" "--layout=auto" "-o" output-auto input-vert)
578    (test-assert (file-exists? output-auto))
579    (test-run-success lepton-cli "export" "-p" "iso_a4" "--layout=portrait" "-o" output-portrait input-vert)
580    (test-assert (file-exists? output-portrait))
581    (test-run-success lepton-cli "export" "-p" "iso_a4" "--layout=landscape" "-o" output-landscape input-vert)
582    (test-assert (file-exists? output-landscape))
583
584    (receive (<status> <stdout> <stderr>)
585        (command-values identify output-plain)
586      (test-eq EXIT_SUCCESS <status>)
587      (test-assert
588          (string-contains <stdout> "794x1123")))
589
590    (receive (<status> <stdout> <stderr>)
591        (command-values identify output-auto)
592      (test-eq EXIT_SUCCESS <status>)
593      (test-assert
594          (string-contains <stdout> "794x1123")))
595
596    (receive (<status> <stdout> <stderr>)
597        (command-values identify output-portrait)
598      (test-eq EXIT_SUCCESS <status>)
599      (test-assert
600          (string-contains <stdout> "794x1123")))
601
602    (receive (<status> <stdout> <stderr>)
603        (command-values identify output-landscape)
604      (test-eq EXIT_SUCCESS <status>)
605      (test-assert
606          (string-contains <stdout> "1123x794")))
607    )
608
609  ;; Clean up.
610  (test-teardown))
611
612(test-end "export -l")
613
614
615(when (or skip-compare-tests
616          skip-convert-tests
617          skip-identify-tests)
618  (test-skip "export -m"))
619
620(test-begin "export -m")
621(test-group-with-cleanup "export -m"
622  (test-setup)
623
624  (let ((input (make-test-filename "box.sch"))
625        (output-no-margins "box-no-margins.png")
626        (output-margins "box-with-margins.png")
627        (output-crop "box-with-margins-crop.png"))
628
629    ;; Create first file without margins.
630    (test-run-success lepton-cli "export"
631                      "-k" "100px"
632                      "-m" "0"
633                      "-o" output-no-margins
634                      input)
635    (test-assert (file-exists? output-no-margins))
636    (receive (<status> <stdout> <stderr>)
637        (command-values identify output-no-margins)
638      (test-eq EXIT_SUCCESS <status>)
639      (test-assert
640          (string-contains <stdout> "110x110")))
641
642    ;; Create second file with margins.
643    ;; Test long option version.
644    (test-run-success lepton-cli "export"
645                      "-k" "100px"
646                      "--margins=10px:20px:30px:40px"
647                      "-o" output-margins
648                      input)
649    (test-assert (file-exists? output-margins))
650    (receive (<status> <stdout> <stderr>)
651        (command-values identify output-margins)
652      (test-eq EXIT_SUCCESS <status>)
653      (test-assert
654          (string-contains <stdout> "170x150")))
655
656    ;; Now use ImageMagic tools to crop margins and compare the
657    ;; result with the first file.
658    (test-run-success convert output-margins
659                      "-gravity" "North" "-chop" "0x10"
660                      "-gravity" "West" "-chop" "20x0"
661                      "-gravity" "South" "-chop" "0x30"
662                      "-gravity" "East" "-chop" "40x0"
663                      output-crop)
664    (test-assert (file-exists? output-crop))
665    ;; Check size of cropped file.
666    (receive (<status> <stdout> <stderr>)
667        (command-values identify output-crop)
668      (test-eq EXIT_SUCCESS <status>)
669      (test-assert
670          (string-contains <stdout> "110x110")))
671
672    ;; Compare files.
673    (test-run-success compare "-metric" "MAE" output-no-margins output-crop "diff.png"))
674
675  ;; Clean up.
676  (test-teardown))
677
678(test-end "export -m")
679
680
681(when (or skip-compare-tests
682          skip-convert-tests
683          skip-identify-tests)
684  (test-skip "export -a"))
685
686(test-begin "export -a")
687(test-group-with-cleanup "export -a"
688  (test-setup)
689
690  (let ((input (make-test-filename "box.sch"))
691        (golden-output "box-golden.png")
692        (output "box.png")
693        (cropped-output "box-cropped.png"))
694
695    ;; Create a golden image.
696    (test-run-success lepton-cli "export"
697                      "-s" "50px:50px"
698                      "-m" "0"
699                      "-o" golden-output
700                      input)
701    (test-assert (file-exists? golden-output))
702
703    ;; Note that the argument of the option '-a' has locale
704    ;; dependent floating point separator (dot or comma).  We use
705    ;; it without any one, just in case. "auto" means "0.5:0.5".
706
707    ;; Horizontal auto alignment.
708    (test-run-success lepton-cli "export"
709                      "-s" "100px:50px"
710                      "-m" "0"
711                      "-a" "auto"
712                      "-o" output
713                      input)
714    (test-assert (file-exists? output))
715    (receive (<status> <stdout> <stderr>)
716        (command-values identify output)
717      (test-eq EXIT_SUCCESS <status>)
718      (test-assert
719          (string-contains <stdout> "100x50")))
720    ;; Crop image.
721    (test-run-success convert output
722                      "-gravity" "West" "-chop" "25x0"
723                      "-gravity" "East" "-chop" "25x0"
724                      cropped-output)
725    ;; Compare files.
726    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")
727
728
729    ;; Horizontal left alignment.
730    (test-run-success lepton-cli "export"
731                      "-s" "100px:50px"
732                      "-m" "0"
733                      "-a" "0:0"
734                      "-o" output
735                      input)
736    (test-assert (file-exists? output))
737    (receive (<status> <stdout> <stderr>)
738        (command-values identify output)
739      (test-eq EXIT_SUCCESS <status>)
740      (test-assert
741          (string-contains <stdout> "100x50")))
742    ;; Crop image.
743    (test-run-success convert output
744                      "-gravity" "East" "-chop" "50x0"
745                      cropped-output)
746    ;; Compare files.
747    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")
748
749    ;; Horizontal right alignment.
750    (test-run-success lepton-cli "export"
751                      "-s" "100px:50px"
752                      "-m" "0"
753                      "-a" "1:1"
754                      "-o" output
755                      input)
756    (test-assert (file-exists? output))
757    (receive (<status> <stdout> <stderr>)
758        (command-values identify output)
759      (test-eq EXIT_SUCCESS <status>)
760      (test-assert
761          (string-contains <stdout> "100x50")))
762    ;; Crop image.
763    (test-run-success convert output
764                      "-gravity" "West" "-chop" "50x0"
765                      cropped-output)
766    ;; Compare files.
767    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")
768
769    ;; Test long option version below.
770
771    ;; Vertical auto alignment.
772    (test-run-success lepton-cli "export"
773                      "-s" "50px:100px"
774                      "-m" "0"
775                      "--align=auto"
776                      "-o" output
777                      input)
778    (test-assert (file-exists? output))
779    (receive (<status> <stdout> <stderr>)
780        (command-values identify output)
781      (test-eq EXIT_SUCCESS <status>)
782      (test-assert
783          (string-contains <stdout> "50x100")))
784    ;; Crop image.
785    (test-run-success convert output
786                      "-gravity" "South" "-chop" "0x25"
787                      "-gravity" "North" "-chop" "0x25"
788                      cropped-output)
789    ;; Compare files.
790    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")
791
792
793    ;; Vertical top alignment.
794    (test-run-success lepton-cli "export"
795                      "-s" "50px:100px"
796                      "-m" "0"
797                      "--align=0:0"
798                      "-o" output
799                      input)
800    (test-assert (file-exists? output))
801    (receive (<status> <stdout> <stderr>)
802        (command-values identify output)
803      (test-eq EXIT_SUCCESS <status>)
804      (test-assert
805          (string-contains <stdout> "50x100")))
806    ;; Crop image.
807    (test-run-success convert output
808                      "-gravity" "South" "-chop" "0x50"
809                      cropped-output)
810    ;; Compare files.
811    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")
812
813    ;; Vertical bottom alignment.
814    (test-run-success lepton-cli "export"
815                      "-s" "50px:100px"
816                      "-m" "0"
817                      "--align=1:1"
818                      "-o" output
819                      input)
820    (test-assert (file-exists? output))
821    (receive (<status> <stdout> <stderr>)
822        (command-values identify output)
823      (test-eq EXIT_SUCCESS <status>)
824      (test-assert
825          (string-contains <stdout> "50x100")))
826    ;; Crop image.
827    (test-run-success convert output
828                      "-gravity" "North" "-chop" "0x50"
829                      cropped-output)
830    ;; Compare files.
831    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")
832    )
833
834  ;; Clean up.
835  (test-teardown))
836
837(test-end "export -a")
838