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