xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/split_command.t (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1#!/usr/bin/perl -w
2
3BEGIN {
4    unshift @INC, 't/lib';
5}
6
7chdir 't';
8
9use ExtUtils::MM;
10use MakeMaker::Test::Utils;
11
12my $Is_VMS   = $^O eq 'VMS';
13my $Is_Win32 = $^O eq 'MSWin32';
14
15use Test::More tests => 7;
16
17my $perl = which_perl;
18my $mm = bless { NAME => "Foo" }, "MM";
19
20# I don't expect anything to have a length shorter than 256 chars.
21cmp_ok( $mm->max_exec_len, '>=', 256,   'max_exec_len' );
22
23my $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;
27is( $mm->max_exec_len, $mm->{_MAX_EXEC_LEN}, '  forced a short max_exec_len' );
28
29my @test_args = qw(foo bar baz yar car har ackapicklerootyjamboree);
30my @cmds = $mm->split_command($echo, @test_args);
31isnt( @cmds, 0 );
32
33@results = _run(@cmds);
34is( join('', @results), join('', @test_args));
35
36
37my %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);
40isnt( @cmds, 0 );
41
42@results = _run(@cmds);
43like( join('', @results ), qr/^1+$/,         'pairs preserved' );
44
45is( $mm->split_command($echo), 0,  'no args means no commands' );
46
47
48sub _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}
61