File: fail.t

package info (click to toggle)
libcss-inliner-perl 4024-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 412 kB
  • sloc: perl: 882; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,088 bytes parent folder | download
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
use strict;
use warnings;
use lib qw( ./lib ../lib );

use Data::Dumper;

use Test::More;
plan(tests => 5);

use_ok('CSS::Inliner::Parser');

#aggregate all our warnings, this test is specifically to determine how errors/warns are handled
my @warnings = ();
BEGIN { $SIG{'__WARN__'} = sub { push @warnings, $_[0] } }

my $css = <<END;
.foo {
	color?: red;
}
END

#test to ensure that fatal errors are in fact fatal
my $fatal = CSS::Inliner::Parser->new({ warns_as_errors => 1 });

eval {
  $fatal->read({ css => $css });
};

ok($@ =~ /^Invalid or unexpected property/);

@warnings = (); # clear all preceding warnings and start over

#test to ensure that when fatals are disabled that we only get warnings
my $suppressed = CSS::Inliner::Parser->new();

eval {
  $suppressed->read({ css => $css });
};

@warnings = @{$suppressed->content_warnings()};

ok(scalar @warnings == 1);
ok($warnings[0] =~ /^Invalid or unexpected property/);

#test to ensure that errors are not thrown by default
my $fatal = CSS::Inliner::Parser->new();

eval {
  $fatal->read({ css => $css });
};

ok($@ eq '');