Skip to content

Commit 8eda217

Browse files
committed
Test oneliner without double escaping dollar sign
Fix Perl-Toolchain-Gang#355 Double escaping '$' for Makefile usage is fine, but we should not use such a syntax while testing and trying to run the oneliner output. This change is 'unescaping' the '$$' to '$' so we can perform some extra checks while using oneliner. Otherwise as shown in this example a simple 'my $foo' test will fail. Note we also have to unescape braces '{{' and '}}' used in dmake... A better solution would be to produce a Makefile and run it directly.
1 parent 570413d commit 8eda217

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

t/oneliner.t

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ chdir 't';
88

99
use Config;
1010
use MakeMaker::Test::Utils;
11-
use Test::More tests => 16;
11+
use Test::More tests => 17;
1212
use File::Spec;
1313

1414
my $TB = Test::More->builder;
@@ -24,20 +24,26 @@ isa_ok($mm, 'ExtUtils::MM_Any');
2424
sub try_oneliner {
2525
my($code, $switches, $expect, $name) = @_;
2626
my $cmd = $mm->oneliner($code, $switches);
27+
# unescape Makefile syntax
28+
$cmd =~ s{\$\$}{\$}g;
29+
$cmd =~ s|\{\{|\{|g; # for dmake
30+
$cmd =~ s|\}\}|\}|g;
2731
$cmd =~ s{\$\(ABSPERLRUN\)}{$perl};
2832

2933
# VMS likes to put newlines at the end of commands if there isn't
3034
# one already.
3135
$expect =~ s/([^\n])\z/$1\n/ if $^O eq 'VMS';
3236

37+
# a better idea would be to create Makefile and run them
3338
$TB->is_eq(scalar `$cmd`, $expect, $name) || $TB->diag("oneliner:\n$cmd");
3439
}
3540

3641
# Lets see how it deals with quotes.
3742
try_oneliner(q{print "foo'o", ' bar"ar'}, [], q{foo'o bar"ar}, 'quotes');
3843

3944
# How about dollar signs?
40-
try_oneliner(q{$PATH = 'foo'; print $PATH},[], q{foo}, 'dollar signs' );
45+
try_oneliner(q{my $PATH = 'foo'; print $PATH},[], q{foo}, 'dollar signs' );
46+
try_oneliner(q{my %h = (1, 2); print $h{1}},[], q{2}, '%h and $h' );
4147

4248
# switches?
4349
try_oneliner(q{print 'foo'}, ['-l'], "foo\n", 'switches' );

0 commit comments

Comments
 (0)