]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blobdiff - t/80-suppressions.t
Factor the fake valgrind test helper into a separate class
[perl/modules/Test-Valgrind.git] / t / 80-suppressions.t
index b2cfa8a5a25fed2843c58a309eb3ad7d7af956a6..6eae1ab827391b42167034a30152c97ba08e3dfa 100644 (file)
@@ -9,14 +9,31 @@ use Test::Valgrind::Command;
 use Test::Valgrind::Tool;
 use Test::Valgrind::Session;
 
+use lib 't/lib';
+use Test::Valgrind::FakeValgrind;
+
 my $cmd = Test::Valgrind::Command->new(
  command => 'Perl',
  args    => [ '-e1' ],
 );
 
-my $tool = Test::Valgrind::Tool->new(
- tool => 'memcheck',
-);
+{
+ package Test::Valgrind::Parser::Dummy;
+
+ use base 'Test::Valgrind::Parser';
+
+ sub parse { }
+}
+
+{
+ package Test::Valgrind::Tool::Dummy;
+
+ use base 'Test::Valgrind::Tool::memcheck';
+
+ sub parser_class { 'Test::Valgrind::Parser::Dummy' }
+}
+
+my $tool = Test::Valgrind::Tool::Dummy->new();
 
 {
  package Test::Valgrind::Action::Dummy;
@@ -24,6 +41,20 @@ my $tool = Test::Valgrind::Tool->new(
  use base 'Test::Valgrind::Action';
 
  sub do_suppressions { 0 }
+
+ sub report {
+  my ($self, $sess, $report) = @_;
+
+  if ($report->is_diag) {
+   my $contents = $report->data;
+   if ($contents !~ /^(?:Using valgrind |No suppressions used)/) {
+    ::diag($contents);
+   }
+   return;
+  } else {
+   $self->SUPER::report($sess, $report);
+  }
+ }
 }
 
 my $dummy_action = Test::Valgrind::Action::Dummy->new();
@@ -79,24 +110,31 @@ if ($res) {
  close $supp_fh;
 }
 
-$sess = eval { Test::Valgrind::Session->new(
- no_def_supp => 1,
- extra_supp  => [ 't/supp/no_perl' ],
-)->run(
- tool    => $tool,
- command => $cmd,
- action  => $dummy_action,
-) };
-like $@, qr/No compatible suppressions available/,
-         'incompatible suppression file';
-
-$sess = eval { Test::Valgrind::Session->new(
- no_def_supp   => 1,
- allow_no_supp => 1,
- extra_supp    => [ 't/supp/no_perl' ],
-)->run(
- tool    => $tool,
- command => $cmd,
- action  => $dummy_action,
-) };
-is $@, '', 'incompatible suppression file, but forced';
+SKIP: {
+ my $dummy_vg = Test::Valgrind::FakeValgrind->new();
+ skip $dummy_vg => 2 unless ref $dummy_vg;
+
+ $sess = eval { Test::Valgrind::Session->new(
+  valgrind    => $dummy_vg->path,
+  no_def_supp => 1,
+  extra_supp  => [ 't/supp/no_perl' ],
+ )->run(
+  tool    => $tool,
+  command => $cmd,
+  action  => $dummy_action,
+ ) };
+ like $@, qr/No compatible suppressions available/,
+          'incompatible suppression file';
+
+ $sess = eval { Test::Valgrind::Session->new(
+  valgrind      => $dummy_vg->path,
+  no_def_supp   => 1,
+  allow_no_supp => 1,
+  extra_supp    => [ 't/supp/no_perl' ],
+ )->run(
+  tool    => $tool,
+  command => $cmd,
+  action  => $dummy_action,
+ ) };
+ is $@, '', 'incompatible suppression file, but forced';
+}