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