File: 020-error.t

package info (click to toggle)
libimager-perl 1.005%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,308 kB
  • ctags: 4,067
  • sloc: perl: 30,915; ansic: 27,680; makefile: 55; cpp: 4
file content (43 lines) | stat: -rw-r--r-- 1,040 bytes parent folder | download | duplicates (7)
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
#!perl -w
use strict;
use Test::More tests => 7;
BEGIN { use_ok("Imager", ":all") }

-d "testout" or mkdir "testout";

Imager->open_log(log => "testout/t05error.log");

# try to read an invalid pnm file
open FH, "< testimg/junk.ppm"
  or die "Cannot open testin/junk: $!";
binmode(FH);
my $IO = Imager::io_new_fd(fileno(FH));
my $im = i_readpnm_wiol($IO, -1);
SKIP:{
  ok(!$im, "read of junk.ppm should have failed")
    or skip("read didn't fail!", 5);

  my @errors = Imager::i_errors();

  is(scalar @errors, 1, "got the errors")
    or skip("no errors to check", 4);

 SKIP:
  {
    my $error0 = $errors[0];
    is(ref $error0, "ARRAY", "entry 0 is an array ref")
      or skip("entry 0 not an array", 3);

    is(scalar @$error0, 2, "entry 0 has 2 elements")
      or skip("entry 0 doesn't have enough elements", 2);

    is($error0->[0], "while skipping to height", "check message");
    is($error0->[1], "0", "error code should be 0");
  }
}

Imager->close_log;

unless ($ENV{IMAGER_KEEP_FILES}) {
  unlink "testout/t05error.log";
}