#!./perl -w
# Tests for the command-line switches:
# -0, -c, -l, -s, -m, -M, -V, -v, -h, -z, -i
# Some switches have their own tests, see MANIFEST.
BEGIN {
chdir 't' if -d 't';
}
require "./test.pl";
use Config;
# due to a bug in VMS's piping which makes it impossible for runperl()
# to emulate echo -n (ie. stdin always winds up with a newline), these
# tests almost totally fail.
my $r;
my @tmpfiles = ();
# Tests for -0
$r = runperl(
);
$r = runperl(
);
$r = runperl(
);
$r = runperl(
);
$r = runperl(
);
$r = runperl(
);
$r = runperl(
);
# Tests for -c
SKIP: {
print $f <<'SWTEST';
print "block 4\n";
$r = runperl(
stderr => 1,
);
# Because of the stderr redirection, we can't tell reliably the order
# in which the output is given
ok(
&& $r =~ /\bblock 1\b/
&& $r =~ /\bblock 2\b/
&& $r !~ /\bblock 3\b/
&& $r !~ /\bblock 4\b/
&& $r !~ /\bblock 5\b/,
'-c'
);
}
# Tests for -l
$r = runperl(
);
# Tests for -s
$r = runperl(
);
# Bug ID 20011106.084
SKIP: {
print $f <<'SWTEST';
#!perl -sn
BEGIN { print $x; exit }
$r = runperl(
);
}
# Tests for -m and -M
SKIP: {
print $f <<'SWTESTPM';
1;
$r = runperl(
);
$r = runperl(
);
$r = runperl(
);
{
}
$r = runperl(
);
}
# Tests for -V
{
# basic perl -V should generate significant output.
# we don't test actual format too much since it could change
'-V generates 20+ lines' );
qr/\ASummary of my perl5 .*configuration:/,
'-V looks okay' );
# lookup a known config var
# lookup a nonexistent var
'perl -V:unknown var');
# regexp lookup
# platforms that don't like this quoting can either skip this test
# or fix test.pl _quote_args
# should be unlike( $r, qr/^$|not found|UNKNOWN/ );
# make sure each line we got matches the re
}
# Tests for -v
{
qr/This is perl, v$v built for $Config{archname}.+Copyright.+Larry Wall.+Artistic License.+GNU General Public License/s,
'-v looks okay' );
}
# Tests for -h
{
'-h looks okay' );
}
# Tests for -z (which does not exist)
{
'-z correctly unknown' );
}
# Tests for -i
{
print FILE <<__EOF__;
foo yada dada
bada foo bing
king kong foo
__EOF__
"bar yada dada:bada bar bing:king kong bar",
"-i new file");
"foo yada dada:bada foo bing:king kong foo",
"-i backup file");
}