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