1#!/usr/bin/perl -w 2 3BEGIN { 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 13chdir 't'; 14 15use ExtUtils::MM; 16use MakeMaker::Test::Utils; 17 18my $Is_VMS = $^O eq 'VMS'; 19my $Is_Win32 = $^O eq 'MSWin32'; 20 21use Test::More tests => 7; 22 23my $perl = which_perl; 24my $mm = bless { NAME => "Foo" }, "MM"; 25 26# I don't expect anything to have a length shorter than 256 chars. 27cmp_ok( $mm->max_exec_len, '>=', 256, 'max_exec_len' ); 28 29my $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; 33is( $mm->max_exec_len, $mm->{_MAX_EXEC_LEN}, ' forced a short max_exec_len' ); 34 35my @test_args = qw(foo bar baz yar car har ackapicklerootyjamboree); 36my @cmds = $mm->split_command($echo, @test_args); 37isnt( @cmds, 0 ); 38 39@results = _run(@cmds); 40is( join('', @results), join('', @test_args)); 41 42 43my %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); 46isnt( @cmds, 0 ); 47 48@results = _run(@cmds); 49like( join('', @results ), qr/^1+$/, 'pairs preserved' ); 50 51is( $mm->split_command($echo), 0, 'no args means no commands' ); 52 53 54sub _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} 67