File: export.test

package info (click to toggle)
lepton-eda 1.9.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,024 kB
  • sloc: ansic: 66,688; lisp: 29,508; sh: 6,792; makefile: 3,111; perl: 1,404; pascal: 1,161; lex: 887; sed: 16; cpp: 8
file content (837 lines) | stat: -rw-r--r-- 26,788 bytes parent folder | download | duplicates (2)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
(use-modules (ice-9 receive))

(load-from-path "env.scm")

(define file (getenv "FILE"))
(define skip-file-tests (string-null? file))
(define compare (getenv "COMPARE"))
(define skip-compare-tests (string-null? compare))
(define identify (getenv "IDENTIFY"))
(define skip-identify-tests (string-null? identify))
(define convert (getenv "CONVERT"))
(define skip-convert-tests (string-null? convert))

(define cwd (getcwd))
(define *testdir* (build-filename (getcwd) "export-tmp"))

;;; Setup/teardown directories/files needed by tests.
(define (test-setup)
  (mkdir *testdir*)
  (chdir *testdir*))

(define (test-teardown)
  (chdir cwd)
  (system* "rm" "-rf" *testdir*))


(test-begin "lepton-cli export")

(receive (<status> <stdout> <stderr>)
    (command-values lepton-cli "export")
  (test-eq EXIT_FAILURE <status>)
  (test-assert (string-contains <stderr> "ERROR: You must specify at least one input filename."))
  (test-assert (string-contains <stderr> "Run `lepton-cli export --help' for more information.")))

(test-end "lepton-cli export")

(define help-string
  "Export Lepton EDA files in various image formats.")

(test-begin "export -h")

(receive (<status> <stdout> <stderr>)
    (command-values lepton-cli "export" "-h")
  (test-eq EXIT_SUCCESS <status>)
  (test-assert (string-contains <stdout> help-string)))

(test-end "export -h")


(test-begin "export --help")

(receive (<status> <stdout> <stderr>)
    (command-values lepton-cli "export" "--help")
  (test-eq EXIT_SUCCESS <status>)
  (test-assert (string-contains <stdout> help-string)))

(test-end "export --help")


(test-begin "export -P")

(receive (<status> <stdout> <stderr>)
    (command-values lepton-cli "export" "-P")
  (test-eq EXIT_SUCCESS <status>)
  (test-assert (string-contains <stdout> "iso_a4"))
  (test-assert (string-contains <stdout> "na_letter")))

(test-end "export -P")


(test-begin "export --paper-names")

(receive (<status> <stdout> <stderr>)
    (command-values lepton-cli "export" "--paper-names")
  (test-eq EXIT_SUCCESS <status>)
  (test-assert (string-contains <stdout> "iso_a4"))
  (test-assert (string-contains <stdout> "na_letter")))

(test-end "export --paper-names")


(define schematic
  (build-filename *abs-top-srcdir*
                  "libleptongui"
                  "tests"
                  "embedded_1.sch"))

(define (file-size-about? filename size)
  (define delta .2)
  (false-if-exception
   (< (* size (- 1 delta))
      (stat:size (stat filename))
      (* size (+ 1 delta)))))


(test-begin "export -o")

(test-group-with-cleanup "export -o"
  (test-setup)

  (let ((cli-png (basename (string-append schematic ".cli.png")))
        (export-png (basename (string-append schematic ".export.png"))))
    ;; Test 'lepton-cli export'.

    ;; This command hangs up due to weird things when running
    ;; lepton-cli using pipes defined in command-values().
    ;;   (receive (<status> <stdout> <stderr>)
    ;;       (command-values lepton-cli "export" "-o" cli-png schematic)
    ;;     (test-eq EXIT_SUCCESS <status>))

    (test-run-success lepton-cli "export" "-o" cli-png schematic)
    (test-assert (file-exists? cli-png))
    (file-size-about? cli-png 360000)

    (test-run-success lepton-export "-o" export-png schematic)
    (test-assert (file-exists? export-png))
    (file-size-about? export-png 360000)

    ;; Test long option version.
    (test-run-success lepton-cli "export" "--output=cli.pdf" schematic)
    (test-assert (file-exists? "cli.pdf"))

    (test-run-success lepton-export "export" "--output=export.pdf" schematic)
    (test-assert (file-exists? "export.pdf"))
    )

  ;; Clean up.
  (test-teardown))

(test-end "export -o")


(define (make-test-filename name)
  (build-filename *abs-top-srcdir*
                  "utils"
                  "cli"
                  "tests"
                  name))



(when (or skip-compare-tests
          skip-identify-tests)
  (test-skip "export -c"))

(test-begin "export -c")

(test-group-with-cleanup "export -c"
  (test-setup)

  (let ((input (make-test-filename "box.sch"))
        (output "box.png")
        (output-c "box-c.png")
        (output-color "box-color.png")
        (output-no-color "box-no-color.png"))

    (test-run-success lepton-cli "export"
                      "-k" "100px"
                      "-m" "10px"
                      "-o" output
                      input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "130x130")))
    (test-run-success lepton-cli "export"
                      "-c"
                      "-k" "100px"
                      "-m" "10px"
                      "-o" output-c
                      input)
    (test-assert (file-exists? output-c))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output-c)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "130x130")))
    ;; Compare files.  It is enough to test that they are
    ;; different for now.
    (test-run-failure compare "-metric" "MAE" output output-c "diff.png")

    ;; Test long option version.
    (test-run-success lepton-cli "export"
                      "-c"
                      "-k" "100px"
                      "-m" "10px"
                      "-o" output-color
                      input)
    ;; Colored files should not differ.
    (test-run-success compare "-metric" "MAE" output-c output-color "diff.png")

    ;; Test --no-color.
    (test-run-success lepton-cli "export"
                      "--no-color"
                      "-k" "100px"
                      "-m" "10px"
                      "-o" output-no-color
                      input)
    ;; Colored files should not differ.
    (test-run-success compare "-metric" "MAE" output output-no-color "diff.png")
    )
  ;; Clean up.
  (test-teardown))

(test-end "export -c")


(when skip-file-tests
  (test-skip "export -f"))

(test-begin "export -f")
(test-group-with-cleanup "export -f"
  (test-setup)

  (let ((input (make-test-filename "box.sch"))
        (output "box.x"))

    (test-run-success lepton-cli "export" "-f" "png" "-o" output input)
    (test-grep-stdout "PNG" file output)

    (test-run-success lepton-cli "export" "-f" "svg" "-o" output input)
    (test-grep-stdout "SVG" file output)

    (test-run-success lepton-cli "export" "-f" "pdf" "-o" output input)
    (test-grep-stdout "PDF" file output)

    (test-run-success lepton-cli "export" "-f" "ps" "-o" output input)
    (test-grep-stdout "PostScript" file output)

    ;; Test long option version.
    (test-run-success lepton-cli "export" "--format=eps" "-o" output input)
    (test-grep-stdout "PostScript" file output)
    (test-grep-stdout "EPS" file output)

    (receive (<status> <stdout> <stderr>)
      (command-values lepton-cli "export" "-f" "x" "-o" output input)
    (test-eq EXIT_FAILURE <status>)
    (test-assert
        (string-contains <stderr> "ERROR: Unsupported output format"))))

  ;; Clean up.
  (test-teardown))

(test-end "export -f")

(when skip-file-tests
  (test-skip "export format"))

(test-begin "export format")
(test-group-with-cleanup "export format"
  (test-setup)

  (let ((input (make-test-filename "box.sch")))

    (test-run-success lepton-cli "export" "-o" "output.png" input)
    (test-grep-stdout "PNG" file "output.png")

    (test-run-success lepton-cli "export" "-o" "output.svg" input)
    (test-grep-stdout "SVG" file "output.svg")

    (test-run-success lepton-cli "export" "-o" "output.pdf" input)
    (test-grep-stdout "PDF" file "output.pdf")

    (test-run-success lepton-cli "export" "-o" "output.ps" input)
    (test-grep-stdout "PostScript" file "output.ps")

    (test-run-success lepton-cli "export" "-o" "output.eps" input)
    (test-grep-stdout "PostScript" file "output.eps")
    (test-grep-stdout "EPS" file "output.eps")

    (receive (<status> <stdout> <stderr>)
      (command-values lepton-cli "export" "-o" "output.x" input)
    (test-eq EXIT_FAILURE <status>)
    (test-assert
        (string-contains <stderr> "ERROR: Cannot find supported format for filename"))))

  ;; Clean up.
  (test-teardown))

(test-end "export format")

(when skip-identify-tests
  (test-skip "export -p"))

(test-begin "export -p")
(test-group-with-cleanup "export -p"
  (test-setup)

  (let ((input-box (make-test-filename "box.sch"))
        (input-horiz (make-test-filename "box-horiz.sch"))
        (input-vert (make-test-filename "box-vert.sch"))
        (output-box "box.png")
        (output-horiz "box-horiz.png")
        (output-vert "box-vert.png"))

    (test-run-success lepton-cli "export" "-o" output-box "-p" "iso_a4" input-box)
    (test-assert (file-exists? output-box))
    (test-run-success lepton-cli "export" "-o" output-horiz "-p" "iso_a4" input-horiz)
    (test-assert (file-exists? output-horiz))
    ;; Test long option version.
    (test-run-success lepton-cli "export" "-o" output-vert "--paper=iso_a4" input-vert)
    (test-assert (file-exists? output-vert))

    (receive (<status> <stdout> <stderr>)
        (command-values identify output-box)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "794x1123")))

    (receive (<status> <stdout> <stderr>)
        (command-values identify output-horiz)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "1123x794")))

    (receive (<status> <stdout> <stderr>)
        (command-values identify output-vert)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "794x1123"))))

  ;; Clean up.
  (test-teardown))

(test-end "export -p")


(when skip-identify-tests
  (test-skip "export -s"))

;;; Some tests here output glitches as white 1px lines on two
;;; edges of boxes.  This should be addressed some day.

(test-begin "export -s")
(test-group-with-cleanup "export -s"
  (test-setup)

  (let ((input (make-test-filename "box.sch"))
        (output "box.png"))

    ;; Export without margins.
    ;; Default unit is 'pt' so '100:100' means '100pt:100pt'.
    (test-run-success lepton-cli "export" "-m" "0" "-s" "100:100" "-o" output input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "134x134")))

    (test-run-success lepton-cli "export" "-m" "0" "-s" "100pt:100pt" "-o" output input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "134x134")))

    (test-run-success lepton-cli "export" "-m" "0" "-s" "100px:100px" "-o" output input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "100x100")))

    (test-run-success lepton-cli "export" "-m" "0" "-s" "1cm:1cm" "-o" output input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "38x38")))

    (test-run-success lepton-cli "export" "-m" "0" "-s" "10mm:10mm" "-o" output input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "38x38")))

    (test-run-success lepton-cli "export" "-m" "0" "-s" "1in:1in" "-o" output input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "96x96")))

    ;; Test long option version.
    (test-run-success lepton-cli "export" "-m" "0" "--size=10pc:10pc" "-o" output input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "160x160")))
    )

  ;; Clean up.
  (test-teardown))

(test-end "export -s")


(when skip-identify-tests
  (test-skip "export -k"))

(test-begin "export -k")
(test-group-with-cleanup "export -k"
  (test-setup)

  (let ((input (make-test-filename "box.sch"))
        (output "box.png"))

    ;; Export without margins.
    (test-run-success lepton-cli "export" "-m" "0" "-k" "5mm" "-o" output input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "21x21")))

    ;; Test long option version.
    (test-run-success lepton-cli "export" "-m" "0" "--scale=1cm" "-o" output input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "42x42")))
    )

  ;; Clean up.
  (test-teardown))

(test-end "export -k")


(when skip-identify-tests
  (test-skip "export -d"))

(test-begin "export -d")
(test-group-with-cleanup "export -d"
  (test-setup)

  (let ((input (make-test-filename "box.sch"))
        (output "box.png"))

    ;; Export a4 without margins.
    (test-run-success lepton-cli "export" "-p" "iso_a4" "-m" "0" "-d" "100" "-o" output input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "827x1170")))

    ;; Test long option version.
    (test-run-success lepton-cli "export" "-p" "iso_a4" "-m" "0" "--dpi=200" "-o" output input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "1654x2339")))
    )

  ;; Clean up.
  (test-teardown))

(test-end "export -d")


(test-begin "export --")

(receive (<status> <stdout> <stderr>)
    (command-values lepton-cli "export" "--" "-o" "x.png" "x.sch")
  (test-eq EXIT_FAILURE <status>)
  (test-assert
      (string-contains <stderr> "ERROR: You must specify an output filename.")))

(test-end "export --")


(test-begin "export -F")
(test-group-with-cleanup "export -F"
  (test-setup)

  (let ((input (make-test-filename "text.sch"))
        (output-sans "text-sans.ps")
        (output-serif "text-serif.ps"))

    ;; Export to PostScript using different fonts and check that
    ;; output files differ.
    (test-run-success lepton-cli "export" "-F" "Sans" "-o" output-sans input)
    (test-assert (file-exists? output-sans))
    ;; Test long option version.
    (test-run-success lepton-cli "export" "--font=Serif" "-o" output-serif input)
    (test-assert (file-exists? output-serif))

    (let ((font-sans #f)
          (font-serif #f))
      (receive (<status> <stdout> <stderr>)
          (command-values "grep" "FontName" output-sans)
        (test-eq EXIT_SUCCESS <status>)
        (set! font-sans <stdout>))

      (receive (<status> <stdout> <stderr>)
          (command-values "grep" "FontName" output-serif)
        (test-eq EXIT_SUCCESS <status>)
        (set! font-serif <stdout>))

      (test-assert (not (string= font-sans font-serif)))))

  ;; Clean up.
  (test-teardown))

(test-end "export -F")


(when skip-identify-tests
  (test-skip "export -l"))

(test-begin "export -l")

(test-group-with-cleanup "export -l"
  (test-setup)

  (let ((input-horiz (make-test-filename "box-horiz.sch"))
        (input-vert (make-test-filename "box-vert.sch"))
        (output-plain "plain.png")
        (output-auto "auto.png")
        (output-portrait "portrait.png")
        (output-landscape "landscape.png"))

    (test-run-success lepton-cli "export" "-p" "iso_a4" "-o" output-plain input-horiz)
    (test-assert (file-exists? output-plain))
    (test-run-success lepton-cli "export" "-p" "iso_a4" "-l" "auto" "-o" output-auto input-horiz)
    (test-assert (file-exists? output-auto))
    (test-run-success lepton-cli "export" "-p" "iso_a4" "-l" "portrait" "-o" output-portrait input-horiz)
    (test-assert (file-exists? output-portrait))
    (test-run-success lepton-cli "export" "-p" "iso_a4" "-l" "landscape" "-o" output-landscape input-horiz)
    (test-assert (file-exists? output-landscape))

    (receive (<status> <stdout> <stderr>)
        (command-values identify output-plain)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "1123x794")))

    (receive (<status> <stdout> <stderr>)
        (command-values identify output-auto)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "1123x794")))

    (receive (<status> <stdout> <stderr>)
        (command-values identify output-portrait)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "794x1123")))

    (receive (<status> <stdout> <stderr>)
        (command-values identify output-landscape)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "1123x794")))

    ;; Test long option version.
    (test-run-success lepton-cli "export" "-p" "iso_a4" "-o" output-plain input-vert)
    (test-assert (file-exists? output-plain))
    (test-run-success lepton-cli "export" "-p" "iso_a4" "--layout=auto" "-o" output-auto input-vert)
    (test-assert (file-exists? output-auto))
    (test-run-success lepton-cli "export" "-p" "iso_a4" "--layout=portrait" "-o" output-portrait input-vert)
    (test-assert (file-exists? output-portrait))
    (test-run-success lepton-cli "export" "-p" "iso_a4" "--layout=landscape" "-o" output-landscape input-vert)
    (test-assert (file-exists? output-landscape))

    (receive (<status> <stdout> <stderr>)
        (command-values identify output-plain)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "794x1123")))

    (receive (<status> <stdout> <stderr>)
        (command-values identify output-auto)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "794x1123")))

    (receive (<status> <stdout> <stderr>)
        (command-values identify output-portrait)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "794x1123")))

    (receive (<status> <stdout> <stderr>)
        (command-values identify output-landscape)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "1123x794")))
    )

  ;; Clean up.
  (test-teardown))

(test-end "export -l")


(when (or skip-compare-tests
          skip-convert-tests
          skip-identify-tests)
  (test-skip "export -m"))

(test-begin "export -m")
(test-group-with-cleanup "export -m"
  (test-setup)

  (let ((input (make-test-filename "box.sch"))
        (output-no-margins "box-no-margins.png")
        (output-margins "box-with-margins.png")
        (output-crop "box-with-margins-crop.png"))

    ;; Create first file without margins.
    (test-run-success lepton-cli "export"
                      "-k" "100px"
                      "-m" "0"
                      "-o" output-no-margins
                      input)
    (test-assert (file-exists? output-no-margins))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output-no-margins)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "110x110")))

    ;; Create second file with margins.
    ;; Test long option version.
    (test-run-success lepton-cli "export"
                      "-k" "100px"
                      "--margins=10px:20px:30px:40px"
                      "-o" output-margins
                      input)
    (test-assert (file-exists? output-margins))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output-margins)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "170x150")))

    ;; Now use ImageMagic tools to crop margins and compare the
    ;; result with the first file.
    (test-run-success convert output-margins
                      "-gravity" "North" "-chop" "0x10"
                      "-gravity" "West" "-chop" "20x0"
                      "-gravity" "South" "-chop" "0x30"
                      "-gravity" "East" "-chop" "40x0"
                      output-crop)
    (test-assert (file-exists? output-crop))
    ;; Check size of cropped file.
    (receive (<status> <stdout> <stderr>)
        (command-values identify output-crop)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "110x110")))

    ;; Compare files.
    (test-run-success compare "-metric" "MAE" output-no-margins output-crop "diff.png"))

  ;; Clean up.
  (test-teardown))

(test-end "export -m")


(when (or skip-compare-tests
          skip-convert-tests
          skip-identify-tests)
  (test-skip "export -a"))

(test-begin "export -a")
(test-group-with-cleanup "export -a"
  (test-setup)

  (let ((input (make-test-filename "box.sch"))
        (golden-output "box-golden.png")
        (output "box.png")
        (cropped-output "box-cropped.png"))

    ;; Create a golden image.
    (test-run-success lepton-cli "export"
                      "-s" "50px:50px"
                      "-m" "0"
                      "-o" golden-output
                      input)
    (test-assert (file-exists? golden-output))

    ;; Note that the argument of the option '-a' has locale
    ;; dependent floating point separator (dot or comma).  We use
    ;; it without any one, just in case. "auto" means "0.5:0.5".

    ;; Horizontal auto alignment.
    (test-run-success lepton-cli "export"
                      "-s" "100px:50px"
                      "-m" "0"
                      "-a" "auto"
                      "-o" output
                      input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "100x50")))
    ;; Crop image.
    (test-run-success convert output
                      "-gravity" "West" "-chop" "25x0"
                      "-gravity" "East" "-chop" "25x0"
                      cropped-output)
    ;; Compare files.
    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")


    ;; Horizontal left alignment.
    (test-run-success lepton-cli "export"
                      "-s" "100px:50px"
                      "-m" "0"
                      "-a" "0:0"
                      "-o" output
                      input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "100x50")))
    ;; Crop image.
    (test-run-success convert output
                      "-gravity" "East" "-chop" "50x0"
                      cropped-output)
    ;; Compare files.
    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")

    ;; Horizontal right alignment.
    (test-run-success lepton-cli "export"
                      "-s" "100px:50px"
                      "-m" "0"
                      "-a" "1:1"
                      "-o" output
                      input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "100x50")))
    ;; Crop image.
    (test-run-success convert output
                      "-gravity" "West" "-chop" "50x0"
                      cropped-output)
    ;; Compare files.
    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")

    ;; Test long option version below.

    ;; Vertical auto alignment.
    (test-run-success lepton-cli "export"
                      "-s" "50px:100px"
                      "-m" "0"
                      "--align=auto"
                      "-o" output
                      input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "50x100")))
    ;; Crop image.
    (test-run-success convert output
                      "-gravity" "South" "-chop" "0x25"
                      "-gravity" "North" "-chop" "0x25"
                      cropped-output)
    ;; Compare files.
    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")


    ;; Vertical top alignment.
    (test-run-success lepton-cli "export"
                      "-s" "50px:100px"
                      "-m" "0"
                      "--align=0:0"
                      "-o" output
                      input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "50x100")))
    ;; Crop image.
    (test-run-success convert output
                      "-gravity" "South" "-chop" "0x50"
                      cropped-output)
    ;; Compare files.
    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")

    ;; Vertical bottom alignment.
    (test-run-success lepton-cli "export"
                      "-s" "50px:100px"
                      "-m" "0"
                      "--align=1:1"
                      "-o" output
                      input)
    (test-assert (file-exists? output))
    (receive (<status> <stdout> <stderr>)
        (command-values identify output)
      (test-eq EXIT_SUCCESS <status>)
      (test-assert
          (string-contains <stdout> "50x100")))
    ;; Crop image.
    (test-run-success convert output
                      "-gravity" "North" "-chop" "0x50"
                      cropped-output)
    ;; Compare files.
    (test-run-success compare "-metric" "MAE" golden-output cropped-output "diff.png")
    )

  ;; Clean up.
  (test-teardown))

(test-end "export -a")