File: print_errors.t

package info (click to toggle)
libpkgconfig-perl 0.26026-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,912 kB
  • sloc: ansic: 6,120; perl: 1,922; makefile: 4; sh: 3
file content (71 lines) | stat: -rw-r--r-- 1,706 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use strict;
use warnings;
use lib 't/lib';
use PkgConfig::Capture;
use Test::More;
use PkgConfig;

note "DEFAULT_SEARCH_PATH = $_" for @PkgConfig::DEFAULT_SEARCH_PATH;

# adjust to test with real pkg-config
my @pkg_config = ( $^X, $INC{'PkgConfig.pm'} );
#my @pkg_config = ( 'pkg-config' );

#  assuming nobody will create a library named after an extinct
#  crocodile from the Miocene Riversleigh fauna.  
my $nonexistent_lib = 'libtrilophosuchus-rackhami';

my $re_error_message = qr/^Can't find $nonexistent_lib.pc in any of /m;

my %test_data = (
  'no-arg' => {
    stdout => 'unlike',
    stderr => 'unlike',
  },
  '--print-errors' => {
    stdout => 'unlike',
    stderr => 'like',
  },
  '--silence-errors' => {
    stdout => 'unlike',
    stderr => 'unlike',
  },
  '--errors-to-stdout' => {
    stdout => 'like',
    stderr => 'unlike',
  },
  
);


foreach my $test_name (sort keys %test_data) {
  my @command
    = grep {$_ ne 'no-arg'}
      ( @pkg_config, $test_name, $nonexistent_lib );

  note "% @command";
  my($out, $err, $ret) = capture {
    system @command;
    $?;
  };

  is $ret, 256, "error code correct";
  if ($test_data{$test_name}{stdout} eq 'like') {
    like $out, $re_error_message, "stdout for $test_name contains error string";
  }
  else {
    unlike $out, $re_error_message, "stdout for $test_name does not contain error string";
  }
  if ($test_data{$test_name}{stderr} eq 'like') {
    like $err, $re_error_message, "stderr for $test_name contains error string";
  }
  else {
    unlike $err, $re_error_message, "stderr for $test_name does not contain error string";
  }
  note "out: $out" if defined $out;
  note "err: $err" if defined $err;
  
}


done_testing();