]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/img.t
add unittests for img
[git.ikiwiki.info.git] / t / img.t
1 #!/usr/bin/perl
2 #
3 # unit test that creates test images (png, svg, multi-page pdf), runs ikiwiki
4 # on them, checks the resulting images for plausibility based on their image
5 # sizes, and checks if they vanish when not required in the build process any
6 # more
7 #
8 package IkiWiki;
10 use warnings;
11 use strict;
12 use Test::More;
14 BEGIN { use_ok("IkiWiki"); }
16 ok(! system("rm -rf t/tmp; mkdir -p t/tmp/in"));
18 ok(! system("convert canvas:red -scale 20x20 t/tmp/in/simple.png"));
19 ok(! system("convert t/tmp/in/simple.png -extent 20x10 t/tmp/in/long.png"));
20 ok(! system("convert t/tmp/in/simple.png t/tmp/in/simple-svg.svg"));
21 # using different image sizes for different pages, so the pagenumber selection can be tested easily
22 ok(! system("convert t/tmp/in/simple.png t/tmp/in/long.png t/tmp/in/simple-pdf.pdf"));
24 writefile("imgconversions.mdwn", "t/tmp/in", <<EOF
25 [[!img simple.png]]
26 [[!img simple.png size=10x]]
27 [[!img simple-svg.svg size=10x]]
28 [[!img simple-pdf.pdf size=10x]]
29 [[!img simple-pdf.pdf size=10x pagenumber=1]]
30 EOF
31 );
33 ok(! system("make -s ikiwiki.out"));
35 my $command = "perl -I. ./ikiwiki.out -set usedirs=0 -plugin img t/tmp/in t/tmp/out -verbose";
37 ok(! system($command));
39 my $outpath = "t/tmp/out/imgconversions";
40 ok(`identify $outpath/10x-simple.png` =~ "PNG 10x10 ");
41 ok(`identify $outpath/10x-simple-svg.png` =~ "PNG 10x10 ");
42 ok(`identify $outpath/10x-simple-pdf.png` =~ "PNG 10x10 ");
43 ok(`identify $outpath/10x-p1-simple-pdf.png` =~ "PNG 10x5 ");
45 # now let's remove them again
47 writefile("imgconversions.mdwn", "t/tmp/in", "nothing to see here");
49 ok(! system("$command --refresh"));
51 ok(! -e "$outpath/10x-simple.png");
52 ok(! -e "$outpath/10x-simple-svg.png");
53 ok(! -e "$outpath/10x-simple-pdf.png");
54 ok(! -e "$outpath/10x-p1-simple-pdf.png");
56 # cleanup
57 ok(! system("rm -rf t/tmp"));
58 done_testing;
60 1;