Just skip the test if we don't have Capture::Tiny
[gitmo/MooseX-Getopt.git] / t / 011_version_options.t
1 use strict;
2 use warnings;
3 use File::Spec::Functions 'catfile';
4 use Test::More;
5
6 BEGIN {
7     eval "use Capture::Tiny 'capture'";
8     plan skip_all => "Capture::Tiny unavailable" if $@;
9 }
10
11 my $HAVE_SIMPLECONFIG = eval {
12     require MooseX::SimpleConfig;
13     return 1;
14 };
15
16 # none of the options should be known
17 for my $opt (qw(-v --version -V)) {
18     my $script = catfile('t', 'version_no_options.pl');
19     my (undef, $stderr) = capture { system $^X, $script, $opt };
20     like($stderr, qr/^Unknown option/, "Option $opt is unknown");
21 }
22
23 # only -V should be unknown, the other two should return our custom string
24 for my $test (qw(version_with_options.pl version_with_simpleconfig.pl)) {
25     my $script = catfile('t', $test);
26
27     SKIP: {
28         if ($test eq 'version_with_simpleconfig.pl' && !$HAVE_SIMPLECONFIG) {
29             skip('MooseX::SimpleConfig unavailable', 3);
30         }
31
32         my ($v, undef) = capture { system $^X, $script, '-v' };
33         like($v, qr/^SUCCESS/, "Option -v is correct");
34
35         my ($version, undef) = capture { system $^X, $script, '--version' };
36         like($version, qr/^SUCCESS/, "Option --version is correct");
37
38         my (undef, $V) = capture { system $^X, $script, '-V' };
39         like($V, qr/^Unknown option/, "Option -V is unknown");
40     }
41 }
42
43 done_testing();