Skip to content

Commit 3966577

Browse files
committed
test, fix split_command with multi-line oneliner
1 parent fe21e89 commit 3966577

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lib/ExtUtils/MM_Any.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ the args. Collectively they will process all the arguments. Each
287287
individual line in @cmds will not be longer than the
288288
$self->max_exec_len being careful to take into account macro expansion.
289289
290-
$cmd should include any switches and repeated initial arguments.
290+
$cmd should include any switches and repeated initial arguments. If it
291+
has newlines, they should be already escaped.
291292
292293
If no @args are given, no @cmds will be returned.
293294
@@ -334,7 +335,7 @@ sub split_command {
334335
}
335336
chop $arg_str;
336337

337-
push @cmds, $self->escape_newlines("$cmd \n$arg_str");
338+
push @cmds, $cmd . $self->escape_newlines(" \n$arg_str");
338339
} while @args;
339340

340341
return @cmds;

t/split_command.t

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use MakeMaker::Test::Utils;
1515
my $Is_VMS = $^O eq 'VMS';
1616
my $Is_Win32 = $^O eq 'MSWin32';
1717

18-
use Test::More tests => 7;
18+
use Test::More tests => 9;
1919

2020
my $perl = which_perl;
2121
my $mm = bless { NAME => "Foo", MAKE => $Config{make} }, "MM";
@@ -36,28 +36,31 @@ isnt( @cmds, 0 );
3636
my @results = _run(@cmds);
3737
is( join('', @results), join('', @test_args));
3838

39-
4039
my %test_args = ( foo => 42, bar => 23, car => 'har' );
4140
my $even_args = $mm->oneliner(q{print !(@ARGV % 2)});
4241
@cmds = $mm->split_command($even_args, %test_args);
4342
isnt( @cmds, 0 );
44-
4543
@results = _run(@cmds);
4644
like( join('', @results ), qr/^1+$/, 'pairs preserved' );
4745

48-
is( $mm->split_command($echo), 0, 'no args means no commands' );
46+
%test_args = ( foo => 42, bar => 23, car => 'har' );
47+
$even_args = $mm->oneliner(qq{\$x="";\n}.q{print !(@ARGV % 2)});
48+
my @save = @cmds = $mm->split_command($even_args, %test_args);
49+
isnt @cmds, 0 or diag explain \@cmds;
50+
@results = _run(@cmds);
51+
like join('', @results), qr/^1+$/, 'pairs preserved'
52+
or diag explain [$even_args, \@save, \@cmds, \@results];
4953

54+
is( $mm->split_command($echo), 0, 'no args means no commands' );
5055

5156
sub _run {
5257
my @cmds = @_;
53-
5458
s{\$\(ABSPERLRUN\)}{$perl} foreach @cmds;
5559
if( $Is_VMS ) {
56-
s{-\n}{} foreach @cmds
60+
s{-\n}{}g foreach @cmds
5761
}
5862
elsif( $Is_Win32 ) {
59-
s{\\\n}{} foreach @cmds;
63+
s{\\\n}{}g foreach @cmds;
6064
}
61-
62-
return map { s/\n+$//; $_ } map { `$_` } @cmds
65+
map { s/\n+$//; $_ } map { `$_` } @cmds
6366
}

0 commit comments

Comments
 (0)