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