4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
11 { q{one t'wo th'ree f"o\"ur " "five" } => [ 'one', 'two three', 'fo"ur ', 'five' ] },
12 { q{ foo bar } => [ 'foo', 'bar' ] },
13 { q{ D\'oh f\{g\'h\"i\]\* } => [ "D'oh", "f{g'h\"i]*" ] },
14 { q{ D\$foo } => [ 'D$foo' ] },
15 { qq{one\\\ntwo} => [ "one\ntwo" ] }, # TODO
20 { 'a" "b\\c" "d' => [ 'a b\c d' ] },
21 { '"a b\\c d"' => [ 'a b\c d' ] },
22 { '"a b"\\"c d"' => [ 'a b"c', 'd' ] },
23 { '"a b"\\\\"c d"' => [ 'a b\c d' ] },
24 { '"a"\\"b" "a\\"b"' => [ 'a"b a"b' ] },
25 { '"a"\\\\"b" "a\\\\"b"' => [ 'a\b', 'a\b' ] },
26 { '"a"\\"b a\\"b"' => [ 'a"b', 'a"b' ] },
27 { 'a"\\"b" "a\\"b' => [ 'a"b', 'a"b' ] },
28 { 'a"\\"b" "a\\"b' => [ 'a"b', 'a"b' ] },
29 { 'a b' => [ 'a', 'b' ] },
30 { 'a"\\"b a\\"b' => [ 'a"b a"b' ] },
31 { '"a""b" "a"b"' => [ 'a"b ab' ] },
32 { '\\"a\\"' => [ '"a"' ] },
33 { '"a"" "b"' => [ 'a"', 'b' ] },
34 { 'a"b' => [ 'ab' ] },
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"' => [ 'ab' ] },
41 { '"a""b"' => [ 'a"b' ] },
42 { '"a"""b"' => [ 'a"b' ] },
43 { '"a""""b"' => [ 'a"b' ] },
44 { '"a"""""b"' => [ 'a""b' ] },
45 { '"a""""""b"' => [ 'a""b' ] },
51 { '""a b' => [ 'a', 'b' ] },
53 { 'a"" b' => [ 'a', 'b' ] },
54 { '"" a' => [ '', 'a' ] },
55 { 'a ""' => [ 'a', '' ] },
56 { 'a "" b' => [ 'a', '', 'b' ] },
57 { 'a " " b' => [ 'a', ' ', 'b' ] },
58 { 'a " b " c' => [ 'a', ' b ', 'c' ] },
61 plan tests => 10 + 4*@unix_splits + 4*@win_splits;
63 ensure_blib('Module::Build');
65 #########################
67 # Should always return an array unscathed
68 foreach my $platform ('', '::Platform::Unix', '::Platform::Windows') {
69 my $pkg = "Module::Build$platform";
70 my @result = $pkg->split_like_shell(['foo', 'bar', 'baz']);
71 is @result, 3, "Split using $pkg";
72 is "@result", "foo bar baz", "Split using $pkg";
75 # I think 3.24 isn't actually the majik version, my 3.23 seems to pass...
76 my $low_TPW_version = Text::ParseWords->VERSION < 3.24;
77 use Module::Build::Platform::Unix;
78 foreach my $test (@unix_splits) {
79 # Text::ParseWords bug:
80 local $TODO = $low_TPW_version && ((keys %$test)[0] =~ m{\\\n});
82 do_split_tests('Module::Build::Platform::Unix', $test);
85 use Module::Build::Platform::Windows;
86 foreach my $test (@win_splits) {
87 do_split_tests('Module::Build::Platform::Windows', $test);
92 # Make sure read_args() functions properly as a class method
93 my @args = qw(foo=bar --food bard --foods=bards);
94 my ($args) = Module::Build->read_args(@args);
95 is_deeply($args, {foo => 'bar', food => 'bard', foods => 'bards', ARGV => []});
99 # Make sure data can make a round-trip through unparse_args() and read_args()
100 my %args = (foo => 'bar', food => 'bard', config => {a => 1, b => 2}, ARGV => []);
101 my ($args) = Module::Build->read_args( Module::Build->unparse_args(\%args) );
102 is_deeply($args, \%args);
106 # Make sure data can make a round-trip through an external perl
107 # process, which can involve the shell command line
109 # Holy crap, I can't believe this works:
110 local $Module::Build{properties}{quiet} = 1;
112 my @data = map values(%$_), @unix_splits, @win_splits;
116 Module::Build->run_perl_script('-le', [], ['print join " ", map "{$_}", @ARGV', @$d]);
119 is($out, join(' ', map "{$_}", @$d), "perl round trip for ".join('',map "{$_}", @$d));
124 # Make sure data can make a round-trip through an external backtick
125 # process, which can involve the shell command line
127 local $Module::Build{properties}{quiet} = 1;
128 my @data = map values(%$_), @unix_splits, @win_splits;
130 chomp(my $out = Module::Build->_backticks('perl', '-le', 'print join " ", map "{$_}", @ARGV', @$d));
131 is($out, join(' ', map "{$_}", @$d), "backticks round trip for ".join('',map "{$_}", @$d));
136 # Make sure run_perl_script() propagates @INC
137 my $dir = 'whosiewhatzit';
139 local @INC = ($dir, @INC);
140 my $output = stdout_of( sub { Module::Build->run_perl_script('-le', [], ['print for @INC']) } );
141 like $output, qr{^$dir}m;
145 ##################################################################
147 my ($package, $test) = @_;
149 my ($string, $expected) = %$test;
150 my @result = $package->split_like_shell($string);
151 is( 0 + grep( !defined(), @result ), # all defined
153 "'$string' result all defined" );
154 is_deeply(\@result, $expected) or
155 diag("$package split_like_shell error \n" .
156 ">$string< is not splitting as >" . join("|", @$expected) . '<');