Commit | Line | Data |
479d2113 |
1 | #!/usr/bin/perl -w |
2 | |
3 | BEGIN { |
4 | if( $ENV{PERL_CORE} ) { |
5 | chdir 't' if -d 't'; |
6 | @INC = ('../lib', 'lib'); |
7 | } |
8 | else { |
9 | unshift @INC, 't/lib'; |
10 | } |
11 | } |
12 | |
13 | chdir 't'; |
14 | |
15 | use ExtUtils::MM; |
16 | use MakeMaker::Test::Utils; |
17 | |
18 | my $Is_VMS = $^O eq 'VMS'; |
19 | my $Is_Win32 = $^O eq 'MSWin32'; |
20 | |
21 | use Test::More tests => 7; |
22 | |
23 | my $perl = which_perl; |
24 | my $mm = bless { NAME => "Foo" }, "MM"; |
25 | |
26 | # I don't expect anything to have a length shorter than 256 chars. |
27 | cmp_ok( $mm->max_exec_len, '>=', 256, 'max_exec_len' ); |
28 | |
29 | my $echo = $mm->oneliner(q{print @ARGV}, ['-l']); |
30 | |
31 | # Force a short command length to make testing split_command easier. |
32 | $mm->{_MAX_EXEC_LEN} = length($echo) + 15; |
33 | is( $mm->max_exec_len, $mm->{_MAX_EXEC_LEN}, ' forced a short max_exec_len' ); |
34 | |
35 | my @test_args = qw(foo bar baz yar car har ackapicklerootyjamboree); |
36 | my @cmds = $mm->split_command($echo, @test_args); |
37 | isnt( @cmds, 0 ); |
38 | |
39 | @results = _run(@cmds); |
40 | is( join('', @results), join('', @test_args)); |
41 | |
42 | |
43 | my %test_args = ( foo => 42, bar => 23, car => 'har' ); |
44 | $even_args = $mm->oneliner(q{print !(@ARGV % 2)}); |
45 | @cmds = $mm->split_command($even_args, %test_args); |
46 | isnt( @cmds, 0 ); |
47 | |
48 | @results = _run(@cmds); |
49 | like( join('', @results ), qr/^1+$/, 'pairs preserved' ); |
50 | |
51 | is( $mm->split_command($echo), 0, 'no args means no commands' ); |
52 | |
53 | |
54 | sub _run { |
55 | my @cmds = @_; |
56 | |
57 | s{\$\(PERLRUN\)}{$perl} foreach @cmds; |
58 | if( $Is_VMS ) { |
59 | s{-\n}{} foreach @cmds |
60 | } |
61 | elsif( $Is_Win32 ) { |
62 | s{\\\n}{} foreach @cmds; |
63 | } |
64 | |
65 | return map { s/\n+$//; $_ } map { `$_` } @cmds |
66 | } |