]> git.imager.perl.org - imager.git/blob - t/t05error.t
use $Config{path_sep} instead of working it out on our own
[imager.git] / t / t05error.t
1 BEGIN { $|=1; print "1..2\n"; }
2 END { print "not ok 1\n" unless $loaded; };
3 use Imager qw(:all);
4 ++$loaded;
5 print "ok 1\n";
6 init_log("testout/t05error.log", 1);
7
8 # try to read an invalid pnm file
9 open FH, "< testimg/junk.ppm"
10   or die "Cannot open testin/junk: $!";
11 binmode(FH);
12 my $IO = Imager::io_new_fd(fileno(FH));
13 my $im = i_readpnm_wiol($IO, -1);
14 if ($im) {
15   print "not ok 2 # read of junk.ppm should have failed\n";
16 }
17 else {
18   my @errors = Imager::i_errors();
19   unless (@errors) {
20     print "not ok 2 # no errors from i_errors()\n";
21   }
22   else {
23     # each entry must be an array ref with 2 elements
24     my $bad;
25     for (@errors) {
26       $bad = 1;
27       if (ref ne 'ARRAY') {
28         print "not ok 2 # element not an array ref\n";
29         last;
30       }
31       if (@$_ != 2) {
32         print "not ok 2 # elements array didn't have 2 elements\n";
33         last;
34       }
35       $bad = 0;
36     }
37     unless ($bad) {
38       print "ok 2\n";
39       for (@errors) {
40         print "# $_->[0]/$_->[1]\n";
41       }
42     }
43   }
44 }