1#!/usr/bin/perl -w 2 3use strict; 4use warnings; 5 6BEGIN { 7 unshift @INC, 't/lib'; 8} 9 10chdir 't'; 11 12use Config; 13use MakeMaker::Test::Utils; 14use Test::More tests => 16; 15use File::Spec; 16 17my $TB = Test::More->builder; 18my $perl = which_perl; 19 20BEGIN { use_ok('ExtUtils::MM') } 21 22my $mm = bless { NAME => "Foo", MAKE => $Config{make} }, 'MM'; 23isa_ok($mm, 'ExtUtils::MakeMaker'); 24isa_ok($mm, 'ExtUtils::MM_Any'); 25 26 27sub try_oneliner { 28 my($code, $switches, $expect, $name) = @_; 29 my $cmd = $mm->oneliner($code, $switches); 30 $cmd =~ s{\$\(ABSPERLRUN\)}{$perl}; 31 32 # VMS likes to put newlines at the end of commands if there isn't 33 # one already. 34 $expect =~ s/([^\n])\z/$1\n/ if $^O eq 'VMS'; 35 36 $TB->is_eq(scalar `$cmd`, $expect, $name) || $TB->diag("oneliner:\n$cmd"); 37} 38 39# Lets see how it deals with quotes. 40try_oneliner(q{print "foo'o", ' bar"ar'}, [], q{foo'o bar"ar}, 'quotes'); 41 42# How about dollar signs? 43try_oneliner(q{$PATH = 'foo'; print $PATH},[], q{foo}, 'dollar signs' ); 44 45# switches? 46try_oneliner(q{print 'foo'}, ['-l'], "foo\n", 'switches' ); 47 48# some DOS-specific things 49try_oneliner(q{print " \" "}, [], q{ " }, 'single quote' ); 50try_oneliner(q{print " < \" "}, [], q{ < " }, 'bracket, then quote' ); 51try_oneliner(q{print " \" < "}, [], q{ " < }, 'quote, then bracket' ); 52try_oneliner(q{print " < \"\" < \" < \" < "}, [], q{ < "" < " < " < }, 'quotes and brackets mixed' ); 53try_oneliner(q{print " < \" | \" < | \" < \" < "}, [], q{ < " | " < | " < " < }, 'brackets, pipes and quotes' ); 54 55# some examples from http://www.autohotkey.net/~deleyd/parameters/parameters.htm#CPP 56try_oneliner(q{print q[ &<>^|()@ ! ]}, [], q{ &<>^|()@ ! }, 'example 8.1' ); 57try_oneliner(q{print q[ &<>^|@()!"&<>^|@()! ]}, [], q{ &<>^|@()!"&<>^|@()! }, 'example 8.2' ); 58try_oneliner(q{print q[ "&<>^|@() !"&<>^|@() !" ]}, [], q{ "&<>^|@() !"&<>^|@() !" }, 'example 8.3' ); 59try_oneliner(q{print q[ "C:\TEST A\" ]}, [], q{ "C:\TEST A\" }, 'example 8.4' ); 60try_oneliner(q{print q[ "C:\TEST %&^ A\" ]}, [], q{ "C:\TEST %&^ A\" }, 'example 8.5' ); 61 62# XXX gotta rethink the newline test. The Makefile does newline 63# escaping, then the shell. 64 65