]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - t/80-suppressions.t
b6f22c7d6b1dfcb61b4e178fe0b1d773d90daa5e
[perl/modules/Test-Valgrind.git] / t / 80-suppressions.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use Test::Valgrind::Command;
9 use Test::Valgrind::Tool;
10 use Test::Valgrind::Session;
11
12 my $cmd = Test::Valgrind::Command->new(
13  command => 'Perl',
14  args    => [ ],
15 );
16
17 my $tool = Test::Valgrind::Tool->new(
18  tool => 'memcheck',
19 );
20
21 my $sess = eval { Test::Valgrind::Session->new(
22  min_version => $tool->requires_version,
23 ) };
24
25 if ($@) {
26  plan skip_all => $@;
27 } else {
28  plan tests => 4;
29 }
30
31 $sess->command($cmd);
32 $sess->tool($tool);
33
34 my $file = $sess->def_supp_file;
35
36 like($file, qr!\Q$Test::Valgrind::Session::VERSION\E/memcheck-\d+(?:\.\d+)*-[0-9a-f]{32}\.supp$!, 'suppression file is correctly named');
37 ok(-e $file, 'suppression file exists');
38 ok(-r $file, 'suppression file is readable');
39
40 if (not open my $supp, '<', $file) {
41  fail("Couldn't open the suppression file at $file: $!");
42 } else {
43  pass("Could open the suppression file");
44  my ($in, $count, $true, $line) = (0, 0, 0, 0);
45  while (<$supp>) {
46   ++$line;
47   chomp;
48   s/^\s*//;
49   s/\s*$//;
50   if (!$in && $_ eq '{') {
51    $in = $line;
52   } elsif ($in && $_ eq '}') {
53    ++$count;
54    ++$true if $line - $in >= 2;
55    $in = 0;
56   }
57  }
58  diag "$count suppressions, of which $true are not empty";
59  close $supp;
60 }