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