]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Suppressions.pm
Always strip wildcard frames at the end of a suppression
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Suppressions.pm
1 package Test::Valgrind::Suppressions;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 Test::Valgrind::Suppressions - Generate suppressions for given tool and command.
9
10 =head1 VERSION
11
12 Version 1.11
13
14 =cut
15
16 our $VERSION = '1.11';
17
18 =head1 DESCRIPTION
19
20 This module is an helper for generating suppressions.
21
22 =cut
23
24 use base qw/Test::Valgrind::Carp/;
25
26 =head1 METHODS
27
28 =head2 C<< generate tool => $tool, command => $command, target => $target >>
29
30 Generates suppressions for the command C<< $command->new_trainer >> and the tool C<< $tool->new_trainer >>, and writes them in the file specified by C<$target>.
31 The action used behind the scenes is L<Test::Valgrind::Action::Suppressions>.
32
33 Returns the status code.
34
35 =cut
36
37 sub generate {
38  my $self = shift;
39
40  my %args = @_;
41
42  my $cmd = delete $args{command};
43  unless (ref $cmd) {
44   require Test::Valgrind::Command;
45   $cmd = Test::Valgrind::Command->new(
46    command => $cmd,
47    args    => [ ],
48   );
49  }
50  $cmd = $cmd->new_trainer;
51  return unless defined $cmd;
52
53  my $tool = delete $args{tool};
54  unless (ref $tool) {
55   require Test::Valgrind::Tool;
56   $tool = Test::Valgrind::Tool->new(tool => $tool);
57  }
58  $tool = $tool->new_trainer;
59  return unless defined $tool;
60
61  my $target = delete $args{target};
62  $self->_croak('Invalid target') unless $target and not ref $target;
63
64  require Test::Valgrind::Action;
65  my $action = Test::Valgrind::Action->new(
66   action => 'Suppressions',
67   target => $target,
68   name   => 'PerlSuppression',
69  );
70
71  require Test::Valgrind::Session;
72  my $sess = Test::Valgrind::Session->new(
73   min_version => $tool->requires_version,
74  );
75
76  eval {
77   $sess->run(
78    command => $cmd,
79    tool    => $tool,
80    action  => $action,
81   );
82  };
83  $self->_croak($@) if $@;
84
85  my $status = $sess->status;
86  $status = 255 unless defined $status;
87
88  return $status;
89 }
90
91 =head2 C<strip_tail $session, $suppression>
92
93 Removes all wildcard frames at the end of the suppression.
94 Moreover, C<'...'> is appended when C<valgrind> C<3.4.0> or higher is used.
95 Returns the mangled suppression.
96
97 =cut
98
99 sub strip_tail {
100  shift;
101
102  my ($sess, $supp) = @_;
103
104  1 while $supp =~ s/[^\r\n]*:\s*\*\s*$//;
105  # With valgrind 3.4.0, we can replace unknown series of frames by '...'
106  $supp .= "...\n" if $sess->version ge '3.4.0';
107
108  $supp;
109 }
110
111 =head1 SEE ALSO
112
113 L<Test::Valgrind>, L<Test::Valgrind::Command>, L<Test::Valgrind::Tool>, L<Test::Valgrind::Action::Suppressions>.
114
115 =head1 AUTHOR
116
117 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
118
119 You can contact me by mail or on C<irc.perl.org> (vincent).
120
121 =head1 BUGS
122
123 Please report any bugs or feature requests to C<bug-test-valgrind-suppressions at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>.
124 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
125
126 =head1 SUPPORT
127
128 You can find documentation for this module with the perldoc command.
129
130     perldoc Test::Valgrind::Suppressions
131
132 =head1 COPYRIGHT & LICENSE
133
134 Copyright 2008-2009 Vincent Pit, all rights reserved.
135
136 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
137
138 =cut
139
140 1; # End of Test::Valgrind::Suppressions