dslinux/user/perl/ext/File/Glob/t basic.t case.t global.t taint.t
cayenne
dslinux_cayenne at user.in-berlin.de
Mon Dec 4 17:59:24 CET 2006
Update of /cvsroot/dslinux/dslinux/user/perl/ext/File/Glob/t
In directory antilope:/tmp/cvs-serv17422/ext/File/Glob/t
Added Files:
basic.t case.t global.t taint.t
Log Message:
Adding fresh perl source to HEAD to branch from
--- NEW FILE: taint.t ---
#!./perl -T
BEGIN {
chdir 't' if -d 't';
if ($^O eq 'MacOS') {
@INC = qw(: ::lib ::macos:lib);
} else {
@INC = '.';
push @INC, '../lib';
}
require Config; import Config;
if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) {
print "1..0\n";
exit 0;
}
print "1..2\n";
}
END {
print "not ok 1\n" unless $loaded;
}
use File::Glob;
$loaded = 1;
print "ok 1\n";
# all filenames should be tainted
@a = File::Glob::bsd_glob("*");
eval { $a = join("", at a), kill 0; 1 };
unless ($@ =~ /Insecure dependency/) {
print "not ";
}
print "ok 2\n";
--- NEW FILE: basic.t ---
#!./perl
BEGIN {
chdir 't' if -d 't';
if ($^O eq 'MacOS') {
@INC = qw(: ::lib ::macos:lib);
} else {
@INC = '.';
push @INC, '../lib';
}
require Config; import Config;
if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) {
print "1..0\n";
exit 0;
}
print "1..12\n";
}
END {
print "not ok 1\n" unless $loaded;
}
use File::Glob ':glob';
use Cwd ();
$loaded = 1;
print "ok 1\n";
sub array {
return '(', join(", ", map {defined $_ ? "\"$_\"" : "undef"} @a), ")\n";
}
# look for the contents of the current directory
$ENV{PATH} = "/bin";
delete @ENV{BASH_ENV, CDPATH, ENV, IFS};
@correct = ();
if (opendir(D, $^O eq "MacOS" ? ":" : ".")) {
@correct = grep { !/^\./ } sort readdir(D);
closedir D;
}
@a = File::Glob::glob("*", 0);
@a = sort @a;
if ("@a" ne "@correct" || GLOB_ERROR) {
print "# |@a| ne |@correct|\nnot ";
}
print "ok 2\n";
# look up the user's home directory
# should return a list with one item, and not set ERROR
if ($^O ne 'MSWin32' && $^O ne 'NetWare' && $^O ne 'VMS' && $^O ne 'os2'
&& $^O ne 'beos') {
eval {
($name, $home) = (getpwuid($>))[0,7];
1;
} and do {
if (defined $home && defined $name && -d $home) {
@a = bsd_glob("~$name", GLOB_TILDE);
if ((scalar(@a) != 1 || $a[0] ne $home || GLOB_ERROR)) {
print "not ";
}
}
};
}
print "ok 3\n";
# check backslashing
# should return a list with one item, and not set ERROR
@a = bsd_glob('TEST', GLOB_QUOTE);
if (scalar @a != 1 || $a[0] ne 'TEST' || GLOB_ERROR) {
local $/ = "][";
print "# [@a]\n";
print "not ";
}
print "ok 4\n";
# check nonexistent checks
# should return an empty list
# XXX since errfunc is NULL on win32, this test is not valid there
@a = bsd_glob("asdfasdf", 0);
if (($^O ne 'MSWin32' && $^O ne 'NetWare') and scalar @a != 0) {
print "# |@a|\nnot ";
}
print "ok 5\n";
# check bad protections
# should return an empty list, and set ERROR
if ($^O eq 'mpeix' or $^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'os2' or $^O eq 'VMS'
or $^O eq 'cygwin' or Cwd::cwd() =~ m#^$Config{'afsroot'}#s or not $>)
{
print "ok 6 # skipped\n";
}
else {
$dir = "pteerslo";
mkdir $dir, 0;
@a = bsd_glob("$dir/*", GLOB_ERR);
#print "\@a = ", array(@a);
rmdir $dir;
if (scalar(@a) != 0 || GLOB_ERROR == 0) {
if ($^O eq 'vos') {
print "not ok 6 # TODO hit VOS bug posix-956\n";
} else {
print "not ok 6\n";
}
}
else {
print "ok 6\n";
}
}
# check for csh style globbing
@a = bsd_glob('{a,b}', GLOB_BRACE | GLOB_NOMAGIC);
unless (@a == 2 and $a[0] eq 'a' and $a[1] eq 'b') {
print "not ";
}
print "ok 7\n";
@a = bsd_glob(
'{TES*,doesntexist*,a,b}',
GLOB_BRACE | GLOB_NOMAGIC | ($^O eq 'VMS' ? GLOB_NOCASE : 0)
);
# Working on t/TEST often causes this test to fail because it sees Emacs temp
# and RCS files. Filter them out, and .pm files too, and patch temp files.
@a = grep !/(,v$|~$|\.(pm|ori?g|rej)$)/, @a;
@a = (grep !/test.pl/, @a) if $^O eq 'VMS';
print "# @a\n";
unless (@a == 3
and $a[0] eq ($^O eq 'VMS'? 'test.' : 'TEST')
and $a[1] eq 'a'
and $a[2] eq 'b')
{
print "not ok 8 # @a\n";
} else {
print "ok 8\n";
}
# "~" should expand to $ENV{HOME}
$ENV{HOME} = "sweet home";
@a = bsd_glob('~', GLOB_TILDE | GLOB_NOMAGIC);
unless ($^O eq "MacOS" || (@a == 1 and $a[0] eq $ENV{HOME})) {
print "not ";
}
print "ok 9\n";
# GLOB_ALPHASORT (default) should sort alphabetically regardless of case
mkdir "pteerslo", 0777;
chdir "pteerslo";
@f_names = qw(Ax.pl Bx.pl Cx.pl aY.pl bY.pl cY.pl);
@f_alpha = qw(Ax.pl aY.pl Bx.pl bY.pl Cx.pl cY.pl);
if ('a' lt 'A') { # EBCDIC char sets sort lower case before UPPER
@f_names = sort(@f_names);
}
if ($^O eq 'VMS') { # VMS is happily caseignorant
@f_alpha = qw(ax.pl ay.pl bx.pl by.pl cx.pl cy.pl);
@f_names = @f_alpha;
}
for (@f_names) {
open T, "> $_";
close T;
}
$pat = "*.pl";
$ok = 1;
@g_names = bsd_glob($pat, 0);
print "# f_names = @f_names\n";
print "# g_names = @g_names\n";
for (@f_names) {
$ok = 0 unless $_ eq shift @g_names;
}
print $ok ? "ok 10\n" : "not ok 10\n";
$ok = 1;
@g_alpha = bsd_glob($pat);
print "# f_alpha = @f_alpha\n";
print "# g_alpha = @g_alpha\n";
for (@f_alpha) {
$ok = 0 unless $_ eq shift @g_alpha;
}
print $ok ? "ok 11\n" : "not ok 11\n";
unlink @f_names;
chdir "..";
rmdir "pteerslo";
# this can panic if PL_glob_index gets passed as flags to bsd_glob
<*>; <*>;
print "ok 12\n";
--- NEW FILE: case.t ---
#!./perl
BEGIN {
chdir 't' if -d 't';
if ($^O eq 'MacOS') {
@INC = qw(: ::lib ::macos:lib);
} else {
@INC = '.';
push @INC, '../lib';
}
require Config; import Config;
if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) {
print "1..0\n";
exit 0;
}
print "1..7\n";
}
END {
print "not ok 1\n" unless $loaded;
}
use File::Glob qw(:glob csh_glob);
$loaded = 1;
print "ok 1\n";
my $pat = $^O eq "MacOS" ? ":op:G*.t" : "op/G*.t";
# Test the actual use of the case sensitivity tags, via csh_glob()
import File::Glob ':nocase';
@a = csh_glob($pat);
print "not " unless @a >= 8;
print "ok 2\n";
# This may fail on systems which are not case-PRESERVING
import File::Glob ':case';
@a = csh_glob($pat); # None should be uppercase
print "not " unless @a == 0;
print "ok 3\n";
# Test the explicit use of the GLOB_NOCASE flag
@a = bsd_glob($pat, GLOB_NOCASE);
print "not " unless @a >= 3;
print "ok 4\n";
# Test Win32 backslash nastiness...
if ($^O ne 'MSWin32' && $^O ne 'NetWare') {
print "ok 5\nok 6\nok 7\n";
}
else {
@a = File::Glob::glob("op\\g*.t");
print "not " unless @a >= 8;
print "ok 5\n";
mkdir "[]", 0;
@a = File::Glob::glob("\\[\\]", GLOB_QUOTE);
rmdir "[]";
print "# returned @a\nnot " unless @a == 1;
print "ok 6\n";
@a = bsd_glob("op\\*", GLOB_QUOTE);
print "not " if @a == 0;
print "ok 7\n";
}
--- NEW FILE: global.t ---
#!./perl
BEGIN {
chdir 't' if -d 't';
if ($^O eq 'MacOS') {
@INC = qw(: ::lib ::macos:lib);
} else {
@INC = '.';
push @INC, '../lib';
}
require Config; import Config;
if ($Config{'extensions'} !~ /\bFile\/Glob\b/i) {
print "1..0\n";
exit 0;
}
print "1..10\n";
}
END {
print "not ok 1\n" unless $loaded;
}
BEGIN {
*CORE::GLOBAL::glob = sub { "Just another Perl hacker," };
}
BEGIN {
if ("Just another Perl hacker," ne (<*>)[0]) {
die <<EOMessage;
Your version of perl ($]) doesn't seem to allow extensions to override
the core glob operator.
EOMessage
}
}
use File::Glob ':globally';
$loaded = 1;
print "ok 1\n";
$_ = $^O eq "MacOS" ? ":op:*.t" : "op/*.t";
my @r = glob;
print "not " if $_ ne ($^O eq "MacOS" ? ":op:*.t" : "op/*.t");
print "ok 2\n";
print "# |@r|\nnot " if @r < 3;
print "ok 3\n";
# check if <*/*> works
if ($^O eq "MacOS") {
@r = <:*:*.t>;
} else {
@r = <*/*.t>;
}
# at least t/global.t t/basic.t, t/taint.t
print "not " if @r < 3;
print "ok 4\n";
my $r = scalar @r;
# check if scalar context works
@r = ();
if ($^O eq "MacOS") {
while (defined($_ = <:*:*.t>)) {
#print "# $_\n";
push @r, $_;
}
} else {
while (defined($_ = <*/*.t>)) {
#print "# $_\n";
push @r, $_;
}
}
print "not " if @r != $r;
print "ok 5\n";
# check if list context works
@r = ();
if ($^O eq "MacOS") {
for (<:*:*.t>) {
#print "# $_\n";
push @r, $_;
}
} else {
for (<*/*.t>) {
#print "# $_\n";
push @r, $_;
}
}
print "not " if @r != $r;
print "ok 6\n";
# test if implicit assign to $_ in while() works
@r = ();
if ($^O eq "MacOS") {
while (<:*:*.t>) {
#print "# $_\n";
push @r, $_;
}
} else {
while (<*/*.t>) {
#print "# $_\n";
push @r, $_;
}
}
print "not " if @r != $r;
print "ok 7\n";
# test if explicit glob() gets assign magic too
my @s = ();
while (glob($^O eq 'MacOS' ? ':*:*.t' : '*/*.t')) {
#print "# $_\n";
push @s, $_;
}
print "not " if "@r" ne "@s";
print "ok 8\n";
# how about in a different package, like?
package Foo;
use File::Glob ':globally';
@s = ();
while (glob($^O eq 'MacOS' ? ':*:*.t' : '*/*.t')) {
#print "# $_\n";
push @s, $_;
}
print "not " if "@r" ne "@s";
print "ok 9\n";
# test if different glob ops maintain independent contexts
@s = ();
my $i = 0;
if ($^O eq "MacOS") {
while (<:*:*.t>) {
#print "# $_ <";
push @s, $_;
while (<:bas*:*.t>) {
#print " $_";
$i++;
}
#print " >\n";
}
} else {
while (<*/*.t>) {
#print "# $_ <";
push @s, $_;
while (<bas*/*.t>) {
#print " $_";
$i++;
}
#print " >\n";
}
}
print "not " if "@r" ne "@s" or not $i;
print "ok 10\n";
More information about the dslinux-commit
mailing list