Add ARM files
[dh-make-perl] / dev / arm / libmodule-build-perl / libmodule-build-perl-0.2808.01 / t / ext.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest;
6
7 my @unix_splits = 
8   (
9    { q{one t'wo th'ree f"o\"ur " "five" } => [ 'one', 'two three', 'fo"ur ', 'five' ] },
10    { q{ foo bar }                         => [ 'foo', 'bar'                         ] },
11   );
12
13 my @win_splits = 
14   (
15    { 'a" "b\\c" "d'         => [ 'a b\c d'       ] },
16    { '"a b\\c d"'           => [ 'a b\c d'       ] },
17    { '"a b"\\"c d"'         => [ 'a b"c', 'd'    ] },
18    { '"a b"\\\\"c d"'       => [ 'a b\c d'       ] },
19    { '"a"\\"b" "a\\"b"'     => [ 'a"b a"b'       ] },
20    { '"a"\\\\"b" "a\\\\"b"' => [ 'a\b', 'a\b'    ] },
21    { '"a"\\"b a\\"b"'       => [ 'a"b', 'a"b'    ] },
22    { 'a"\\"b" "a\\"b'       => [ 'a"b', 'a"b'    ] },
23    { 'a"\\"b"  "a\\"b'      => [ 'a"b', 'a"b'    ] },
24    { 'a           b'        => [ 'a', 'b'        ] },
25    { 'a"\\"b a\\"b'         => [ 'a"b a"b'       ] },
26    { '"a""b" "a"b"'         => [ 'a"b ab'        ] },
27    { '\\"a\\"'              => [ '"a"'           ] },
28    { '"a"" "b"'             => [ 'a"', 'b'       ] },
29    { 'a"b'                  => [ 'ab'            ] },
30    { 'a""b'                 => [ 'ab'            ] },
31    { 'a"""b'                => [ 'a"b'           ] },
32    { 'a""""b'               => [ 'a"b'           ] },
33    { 'a"""""b'              => [ 'a"b'           ] },
34    { 'a""""""b'             => [ 'a""b'          ] },
35    { '"a"b"'                => [ 'ab'            ] },
36    { '"a""b"'               => [ 'a"b'           ] },
37    { '"a"""b"'              => [ 'a"b'           ] },
38    { '"a""""b"'             => [ 'a"b'           ] },
39    { '"a"""""b"'            => [ 'a""b'          ] },
40    { '"a""""""b"'           => [ 'a""b'          ] },
41    { ''                     => [                 ] },
42    { ' '                    => [                 ] },
43    { '""'                   => [ ''              ] },
44    { '" "'                  => [ ' '             ] },
45    { '""a'                  => [ 'a'             ] },
46    { '""a b'                => [ 'a', 'b'        ] },
47    { 'a""'                  => [ 'a'             ] },
48    { 'a"" b'                => [ 'a', 'b'        ] },
49    { '"" a'                 => [ '', 'a'         ] },
50    { 'a ""'                 => [ 'a', ''         ] },
51    { 'a "" b'               => [ 'a', '', 'b'    ] },
52    { 'a " " b'              => [ 'a', ' ', 'b'   ] },
53    { 'a " b " c'            => [ 'a', ' b ', 'c' ] },
54 );
55
56 plan tests => 10 + 2*@unix_splits + 2*@win_splits;
57
58 #########################
59
60 use Module::Build;
61 ok(1);
62
63 # Should always return an array unscathed
64 foreach my $platform ('', '::Platform::Unix', '::Platform::Windows') {
65   my $pkg = "Module::Build$platform";
66   my @result = $pkg->split_like_shell(['foo', 'bar', 'baz']);
67   is @result, 3, "Split using $pkg";
68   is "@result", "foo bar baz", "Split using $pkg";
69 }
70
71 use Module::Build::Platform::Unix;
72 foreach my $test (@unix_splits) {
73   do_split_tests('Module::Build::Platform::Unix', $test);
74 }
75
76 use Module::Build::Platform::Windows;
77 foreach my $test (@win_splits) {
78   do_split_tests('Module::Build::Platform::Windows', $test);
79 }
80
81
82 {
83   # Make sure read_args() functions properly as a class method
84   my @args = qw(foo=bar --food bard --foods=bards);
85   my ($args) = Module::Build->read_args(@args);
86   is_deeply($args, {foo => 'bar', food => 'bard', foods => 'bards', ARGV => []});
87 }
88
89 {
90   # Make sure data can make a round-trip through unparse_args() and read_args()
91   my %args = (foo => 'bar', food => 'bard', config => {a => 1, b => 2}, ARGV => []);
92   my ($args) = Module::Build->read_args( Module::Build->unparse_args(\%args) );
93   is_deeply($args, \%args);
94 }
95
96 {
97   # Make sure run_perl_script() propagates @INC
98   my $dir = 'whosiewhatzit';
99   mkdir $dir, 0777;
100   local @INC = ($dir, @INC);
101   my $output = stdout_of( sub { Module::Build->run_perl_script('', ['-le', 'print for @INC']) } );
102   like $output, qr{^$dir}m;
103   rmdir $dir;
104 }
105
106 ##################################################################
107 sub do_split_tests {
108   my ($package, $test) = @_;
109
110   my ($string, $expected) = %$test;
111   my @result = $package->split_like_shell($string);
112   is( 0 + grep( !defined(), @result ), # all defined
113       0,
114       "'$string' result all defined" );
115   is_deeply(\@result, $expected);
116 }