Skip to content

Commit

Permalink
Test oneliner without double escaping dollar sign
Browse files Browse the repository at this point in the history
Fix #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.
  • Loading branch information
atoomic committed Jul 22, 2020
1 parent 570413d commit 8eda217
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions t/oneliner.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ chdir 't';

use Config;
use MakeMaker::Test::Utils;
use Test::More tests => 16;
use Test::More tests => 17;
use File::Spec;

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

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

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

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

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

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

0 comments on commit 8eda217

Please sign in to comment.