xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/ExtUtils/t/oneliner.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/usr/bin/perl -w
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateBEGIN {
4*0Sstevel@tonic-gate    if( $ENV{PERL_CORE} ) {
5*0Sstevel@tonic-gate        chdir 't' if -d 't';
6*0Sstevel@tonic-gate        @INC = ('../lib', 'lib');
7*0Sstevel@tonic-gate    }
8*0Sstevel@tonic-gate    else {
9*0Sstevel@tonic-gate        unshift @INC, 't/lib';
10*0Sstevel@tonic-gate    }
11*0Sstevel@tonic-gate}
12*0Sstevel@tonic-gate
13*0Sstevel@tonic-gatechdir 't';
14*0Sstevel@tonic-gate
15*0Sstevel@tonic-gateuse MakeMaker::Test::Utils;
16*0Sstevel@tonic-gateuse Test::More tests => 6;
17*0Sstevel@tonic-gateuse File::Spec;
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gatemy $TB = Test::More->builder;
20*0Sstevel@tonic-gate
21*0Sstevel@tonic-gateBEGIN { use_ok('ExtUtils::MM') }
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gatemy $mm = bless { NAME => "Foo" }, 'MM';
24*0Sstevel@tonic-gateisa_ok($mm, 'ExtUtils::MakeMaker');
25*0Sstevel@tonic-gateisa_ok($mm, 'ExtUtils::MM_Any');
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gatesub try_oneliner {
29*0Sstevel@tonic-gate    my($code, $switches, $expect, $name) = @_;
30*0Sstevel@tonic-gate    my $cmd = $mm->oneliner($code, $switches);
31*0Sstevel@tonic-gate    $cmd =~ s{\$\(PERLRUN\)}{$^X};
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate    # VMS likes to put newlines at the end of commands if there isn't
34*0Sstevel@tonic-gate    # one already.
35*0Sstevel@tonic-gate    $expect =~ s/([^\n])\z/$1\n/ if $^O eq 'VMS';
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate    $TB->is_eq(scalar `$cmd`, $expect, $name) || $TB->diag("oneliner:\n$cmd");
38*0Sstevel@tonic-gate}
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate# Lets see how it deals with quotes.
41*0Sstevel@tonic-gatetry_oneliner(q{print "foo'o", ' bar"ar'}, [],  q{foo'o bar"ar},  'quotes');
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate# How about dollar signs?
44*0Sstevel@tonic-gatetry_oneliner(q{$PATH = 'foo'; print $PATH},[], q{foo},   'dollar signs' );
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate# switches?
47*0Sstevel@tonic-gatetry_oneliner(q{print 'foo'}, ['-l'],           "foo\n",       'switches' );
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate# XXX gotta rethink the newline test.  The Makefile does newline
50*0Sstevel@tonic-gate# escaping, then the shell.
51*0Sstevel@tonic-gate
52