]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blobdiff - lib/Test/Valgrind/Session.pm
Add support for ->parser_class() in tools
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Session.pm
index f47e4759228e608a636756884a1584eb1ef9a0f3..fe521a0e0907ef8edc18d36c253c538131b4af83 100644 (file)
@@ -34,8 +34,6 @@ BEGIN {
 
 use base qw/Test::Valgrind::Carp/;
 
-use Test::Valgrind::Report;
-
 =head1 METHODS
 
 =head2 C<< new search_dirs => \@search_dirs, valgrind => [ $valgrind | \@valgrind ], min_version => $min_version, no_def_supp => $no_def_supp, extra_supps => \@extra_supps >>
@@ -201,7 +199,7 @@ sub _run {
 
  $self->command($cmd);
 
- $self->report(Test::Valgrind::Report->new_diag(
+ $self->report($self->report_class->new_diag(
   'Using valgrind ' . $self->version . ' located at ' . $self->valgrind
  ));
 
@@ -210,25 +208,22 @@ sub _run {
  my @supp_args;
  if ($self->do_suppressions) {
   push @supp_args, '--gen-suppressions=all';
- } else {
-  my @supps;
-  if (not $self->no_def_supp) {
-   my $def_supp = $self->def_supp_file;
-   if (defined $def_supp and not -e $def_supp) {
-    $self->report(Test::Valgrind::Report->new_diag(
-     "Generating suppressions..."
-    ));
-    require Test::Valgrind::Suppressions;
-    Test::Valgrind::Suppressions->generate(
-     tool    => $self->tool,
-     command => $self->command,
-     target  => $def_supp,
-    );
-    $self->_croak('Couldn\'t generate suppressions') unless -e $def_supp;
-    $self->report(Test::Valgrind::Report->new_diag(
-     "Suppressions for this perl stored in $def_supp"
-    ));
-   }
+ } elsif (not $self->no_def_supp) {
+  my $def_supp = $self->def_supp_file;
+  if (defined $def_supp and not -e $def_supp) {
+   $self->report($self->report_class->new_diag(
+    "Generating suppressions..."
+   ));
+   require Test::Valgrind::Suppressions;
+   Test::Valgrind::Suppressions->generate(
+    tool    => $self->tool,
+    command => $self->command,
+    target  => $def_supp,
+   );
+   $self->_croak('Couldn\'t generate suppressions') unless -e $def_supp;
+   $self->report($self->report_class->new_diag(
+    "Suppressions for this perl stored in $def_supp"
+   ));
   }
   push @supp_args, '--suppressions=' . $_ for $self->suppressions;
  }
@@ -251,13 +246,13 @@ sub _run {
 
   my @args = (
    $self->valgrind,
-   '--log-fd=' . fileno($vwtr),
    $self->tool->args($self),
    @supp_args,
+   $self->parser->args($self, $vwtr),
    $self->command->args($self),
   );
 
-#  $self->report(Test::Valgrind::Report->new_diag("@args"));
+#  $self->report($self->report_class->new_diag("@args"));
 
   exec { $args[0] } @args or $self->_croak("exec @args: $!");
  }
@@ -270,7 +265,7 @@ sub _run {
 
  close $vwtr or $self->_croak("close(\$vwtr): $!");
 
- $self->tool->parse($self, $vrdr);
+ $self->parser->parse($self, $vrdr);
 
  $self->{exit_code} = (waitpid($pid, 0) == $pid) ? $? >> 8 : 255;
 
@@ -297,7 +292,7 @@ Read-only accessor for the C<command> associated to the current run.
 
 my @members;
 BEGIN {
- @members = qw/action tool command/;
+ @members = qw/action tool command parser/;
  for (@members) {
   eval "sub $_ { \@_ <= 1 ? \$_[0]->{$_} : (\$_[0]->{$_} = \$_[1]) }";
   die if $@;
@@ -382,7 +377,7 @@ sub start {
 
  my %args = @_;
 
- for (@members) {
+ for (qw/action tool command/) {
   my $base = 'Test::Valgrind::' . ucfirst;
   my $value = $args{$_};
   $self->_croak("Invalid $_") unless Scalar::Util::blessed($value)
@@ -393,6 +388,7 @@ sub start {
  delete @{$self}{qw/last_status exit_code/};
 
  $self->tool->start($self);
+ $self->parser($self->tool->parser_class($self)->new)->start($self);
  $self->action->start($self);
 
  return;
@@ -406,6 +402,7 @@ Forwards to C<< ->action->abort >> after unshifting the session object to the ar
 
 sub abort {
  my $self = shift;
+
  $self->action->abort($self, @_);
 }
 
@@ -420,8 +417,10 @@ sub report {
 
  return unless defined $report;
 
- $report = $self->command->filter($self, $report);
- return unless defined $report;
+ for my $handler (qw/tool command/) {
+  $report = $self->$handler->filter($self, $report);
+  return unless defined $report;
+ }
 
  $self->action->report($self, $report);
 }
@@ -437,7 +436,9 @@ sub finish {
  my ($self) = @_;
 
  my $action = $self->action;
+
  $action->finish($self);
+ $self->parser->finish($self);
  $self->tool->finish($self);
 
  my $status = $action->status($self);
@@ -458,7 +459,7 @@ sub status { $_[0]->{last_status} }
 
 =head1 SEE ALSO
 
-L<Test::Valgrind>, L<Test::Valgrind::Action>, L<Test::Valgrind::Tool>, L<Test::Valgrind::Command>.
+L<Test::Valgrind>, L<Test::Valgrind::Action>, L<Test::Valgrind::Command>, L<Test::Valgrind::Tool>, L<Test::Valgrind::Parser>.
 
 L<version>, L<File::HomeDir>.