Just skip the test if we don't have Capture::Tiny
[gitmo/MooseX-Getopt.git] / t / 011_version_options.t
CommitLineData
a7474a4d 1use strict;
2use warnings;
a7474a4d 3use File::Spec::Functions 'catfile';
4use Test::More;
5
153352c3 6BEGIN {
7 eval "use Capture::Tiny 'capture'";
8 plan skip_all => "Capture::Tiny unavailable" if $@;
9}
10
a7474a4d 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
65559489 27 SKIP: {
28 if ($test eq 'version_with_simpleconfig.pl' && !$HAVE_SIMPLECONFIG) {
29 skip('MooseX::SimpleConfig unavailable', 3);
30 }
a7474a4d 31
65559489 32 my ($v, undef) = capture { system $^X, $script, '-v' };
33 like($v, qr/^SUCCESS/, "Option -v is correct");
a7474a4d 34
65559489 35 my ($version, undef) = capture { system $^X, $script, '--version' };
36 like($version, qr/^SUCCESS/, "Option --version is correct");
a7474a4d 37
65559489 38 my (undef, $V) = capture { system $^X, $script, '-V' };
39 like($V, qr/^Unknown option/, "Option -V is unknown");
40 }
a7474a4d 41}
42
43done_testing();