- error messages when writing TIFF images were always
[imager.git] / t / t104ppm.t
index da4eb38f22893899c2c204423a007a928c6ecf57..fa942cc5ecfb524c11b88ef501956f643b7768a9 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use Imager ':all';
 use lib 't';
-use Test::More tests => 60;
+use Test::More tests => 64;
 use strict;
 
 init_log("testout/t104ppm.log",1);
@@ -195,6 +195,18 @@ check_gray(Imager::i_get_pixel($ooim->{IMG}, 1, 1), 255);
   Imager->set_file_limits(reset=>1);
 }
 
+{ # check error messages set correctly
+  my $im = Imager->new(xsize=>100, ysize=>100, channels=>4);
+  ok(!$im->write(file=>"testout/t104_fail.ppm", type=>'pnm'),
+     "should fail to write 4 channel image");
+  is($im->errstr, 'can only save 1 or 3 channel images to pnm',
+     "check error message");
+  ok(!$im->read(file=>'t/t104ppm.t', type=>'pnm'),
+     'should fail to read script as an image file');
+  is($im->errstr, 'unable to read pnm image: bad header magic, not a PNM file',
+     "check error message");
+}
+
 sub openimage {
   my $fname = shift;
   local(*FH);