]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Suppressions.pm
800a7c79bc94c5ed87a68f2d997e7e50307c5edc
[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 =head1 SEE ALSO
92
93 L<Test::Valgrind>, L<Test::Valgrind::Command>, L<Test::Valgrind::Tool>, L<Test::Valgrind::Action::Suppressions>.
94
95 =head1 AUTHOR
96
97 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
98
99 You can contact me by mail or on C<irc.perl.org> (vincent).
100
101 =head1 BUGS
102
103 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>.
104 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
105
106 =head1 SUPPORT
107
108 You can find documentation for this module with the perldoc command.
109
110     perldoc Test::Valgrind::Suppressions
111
112 =head1 COPYRIGHT & LICENSE
113
114 Copyright 2008-2009 Vincent Pit, all rights reserved.
115
116 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
117
118 =cut
119
120 1; # End of Test::Valgrind::Suppressions