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