#!./perl
print
"1..41\n"
;
$test_count
= 1;
$teststring
=
"1\n12\n123\n1234\n1234\n12345\n\n123456\n1234567\n"
;
$teststring2
=
"1234567890123456789012345678901234567890"
;
1
while
unlink
'foo'
;
rmdir
'foo'
;
open
TESTFILE,
">./foo"
or
die
"error $! $^E opening"
;
binmode
TESTFILE;
print
TESTFILE
$teststring
;
close
TESTFILE or
die
"error $! $^E closing"
;
$test_count_start
=
$test_count
;
open
TESTFILE,
"<./foo"
;
binmode
TESTFILE;
test_string(
*TESTFILE
);
close
TESTFILE;
unlink
"./foo"
;
open
TESTFILE,
">./foo"
;
print
TESTFILE
$teststring2
;
binmode
TESTFILE;
close
TESTFILE;
open
TESTFILE,
"<./foo"
;
binmode
TESTFILE;
test_record(
*TESTFILE
);
close
TESTFILE;
$test_count_end
=
$test_count
;
$/ =
"\n"
;
my
$note
=
"\$/ preserved when set to bad value"
;
test_bad_setting();
print
+($/ ne
"\n"
?
"not "
:
""
) .
"ok $test_count # \$/ preserved when set to bad value\n"
;
++
$test_count
;
if
($^O eq
'VMS'
) {
open
FDLFILE,
"> ./foo.fdl"
;
print
FDLFILE
"RECORD\n FORMAT VARIABLE\n"
;
close
FDLFILE;
open
CREATEFILE,
"> ./foo.com"
;
print
CREATEFILE
'$ DEFINE/USER SYS$INPUT NL:'
,
"\n"
;
print
CREATEFILE
'$ DEFINE/USER SYS$OUTPUT NL:'
,
"\n"
;
print
CREATEFILE
'$ OPEN YOW []FOO.BAR/WRITE'
,
"\n"
;
print
CREATEFILE
'$ CLOSE YOW'
,
"\n"
;
print
CREATEFILE
"\$EXIT\n"
;
close
CREATEFILE;
$throwaway
= `\@\[\]foo`,
"\n"
;
open
(TEMPFILE,
">./foo.bar"
) or
print
"# open failed $! $^E\n"
;
print
TEMPFILE
"foo\nfoobar\nbaz\n"
;
close
TEMPFILE;
open
TESTFILE,
"<./foo.bar"
;
$/ = \10;
$bar
= <TESTFILE>;
if
(
$bar
eq
"foo\n"
) {
print
"ok $test_count\n"
;}
else
{
print
"not ok $test_count\n"
;}
$test_count
++;
$bar
= <TESTFILE>;
if
(
$bar
eq
"foobar\n"
) {
print
"ok $test_count\n"
;}
else
{
print
"not ok $test_count\n"
;}
$test_count
++;
$/ = \2;
$bar
= <TESTFILE>;
if
(
$bar
eq
"ba"
) {
print
"ok $test_count\n"
;}
else
{
print
"not ok $test_count\n"
;}
$test_count
++;
$bar
= <TESTFILE>;
if
(
$bar
eq
"z\n"
) {
print
"ok $test_count\n"
;}
else
{
print
"not ok $test_count\n"
;}
$test_count
++;
close
TESTFILE;
1
while
unlink
qw(foo.bar foo.com foo.fdl)
;
}
else
{
foreach
$test
(
$test_count
..
$test_count
+ 3) {
print
"ok $test # skipped on non-VMS system\n"
;
$test_count
++;
}
}
$/ =
"\n"
;
{
if
(
open
our
$T
,
"./foo"
) {
my
$line
= <
$T
>;
print
"# $line\n"
;
length
(
$line
) == 40 or
print
"not "
;
close
$T
or
print
"not "
;
}
else
{
print
"not "
;
}
print
"ok $test_count # open/readline/close on our variable\n"
;
$test_count
++;
}
{
if
(
open
my
$T
,
"./foo"
) {
my
$line
= <
$T
>;
print
"# $line\n"
;
length
(
$line
) == 40 or
print
"not "
;
close
$T
or
print
"not "
;
}
else
{
print
"not "
;
}
print
"ok $test_count # open/readline/close on my variable\n"
;
$test_count
++;
}
{
local
@INC
= (
"../lib"
,
"lib"
,
@INC
);
open
TESTFILE,
"<"
, \
$teststring
;
test_string(
*TESTFILE
);
close
TESTFILE;
open
TESTFILE,
"<"
, \
$teststring2
;
test_record(
*TESTFILE
);
close
TESTFILE;
}
END {
unlink
"./foo"
; }
sub
test_string {
*FH
=
shift
;
$bar
= <FH>;
if
(
$bar
ne
"1\n"
) {
print
"not "
;}
print
"ok $test_count # default \$/\n"
;
$test_count
++;
$/ =
"\n"
;
$bar
= <FH>;
if
(
$bar
ne
"12\n"
) {
print
"not "
;}
print
"ok $test_count # \$/ = \"\\n\"\n"
;
$test_count
++;
$/ = 3;
$bar
= <FH>;
if
(
$bar
ne
"123"
) {
print
"not "
;}
print
"ok $test_count # \$/ = 3\n"
;
$test_count
++;
$/ =
"\n"
;
$bar
= <FH>;
$/ =
"34"
;
$bar
= <FH>;
if
(
$bar
ne
"1234"
) {
print
"not "
;}
print
"ok $test_count # \$/ = \"34\"\n"
;
$test_count
++;
$/ =
"\n"
;
$bar
= <FH>;
$/ =
''
;
$bar
= <FH>;
if
(
$bar
ne
"1234\n12345\n\n"
) {
print
"not "
;}
print
"ok $test_count # \$/ = ''\n"
;
$test_count
++;
$/ =
undef
;
$bar
= <FH>;
if
(
$bar
ne
"123456\n1234567\n"
) {
print
"not "
;}
print
"ok $test_count # \$/ = undef\n"
;
$test_count
++;
}
sub
test_record {
*FH
=
shift
;
$/ = \2;
$bar
= <FH>;
if
(
$bar
ne
"12"
) {
print
"not "
;}
print
"ok $test_count # \$/ = \\2\n"
;
$test_count
++;
$/ = \
"2"
;
$bar
= <FH>;
if
(
$bar
ne
"34"
) {
print
"not "
;}
print
"ok $test_count # \$/ = \"2\"\n"
;
$test_count
++;
$foo
= 2;
$/ = \
$foo
;
$bar
= <FH>;
if
(
$bar
ne
"56"
) {
print
"not "
;}
print
"ok $test_count # \$/ = \\\$foo (\$foo = 2)\n"
;
$test_count
++;
$foo
=
"2"
;
$/ = \
$foo
;
$bar
= <FH>;
if
(
$bar
ne
"78"
) {
print
"not "
;}
print
"ok $test_count # \$/ = \\\$foo (\$foo = \"2\")\n"
;
$test_count
++;
}
sub
test_bad_setting {
if
(
eval
{$/ = \0; 1}) {
print
"not ok "
,
$test_count
++,
" # \$/ = \\0; should die\n"
;
print
"not ok "
,
$test_count
++,
" # \$/ = \\0; produced expected error message\n"
;
}
else
{
my
$msg
= $@ ||
"Zombie Error"
;
print
"ok "
,
$test_count
++,
" # \$/ = \\0; should die\n"
;
if
(
$msg
!~m!Setting \$\/ to a reference to zero is forbidden!) {
print
"not "
;
}
print
"ok "
,
$test_count
++,
" # \$/ = \\0; produced expected error message\n"
;
}
if
(
eval
{$/ = \-1; 1}) {
print
"not ok "
,
$test_count
++,
" # \$/ = \\-1; should die\n"
;
print
"not ok "
,
$test_count
++,
" # \$/ = \\-1; produced expected error message\n"
;
}
else
{
my
$msg
= $@ ||
"Zombie Error"
;
print
"ok "
,
$test_count
++,
" # \$/ = \\-1; should die\n"
;
if
(
$msg
!~m!Setting \$\/ to a reference to a negative integer is forbidden!) {
print
"not "
;
}
print
"ok "
,
$test_count
++,
" # \$/ = \\-1; produced expected error message\n"
;
}
if
(
eval
{$/ = []; 1}) {
print
"not ok "
,
$test_count
++,
" # \$/ = []; should die\n"
;
print
"not ok "
,
$test_count
++,
" # \$/ = []; produced expected error message\n"
;
}
else
{
my
$msg
= $@ ||
"Zombie Error"
;
print
"ok "
,
$test_count
++,
" # \$/ = []; should die\n"
;
if
(
$msg
!~m!Setting \$\/ to an ARRAY reference is forbidden!) {
print
"not "
;
}
print
"ok "
,
$test_count
++,
" # \$/ = []; produced expected error message\n"
;
}
if
(
eval
{$/ = {}; 1}) {
print
"not ok "
,
$test_count
++,
" # \$/ = {}; should die\n"
;
print
"not ok "
,
$test_count
++,
" # \$/ = {}; produced expected error message\n"
;
}
else
{
my
$msg
= $@ ||
"Zombie Error"
;
print
"ok "
,
$test_count
++,
" # \$/ = {}; should die\n"
;
if
(
$msg
!~m!Setting \$\/ to a HASH reference is forbidden!) {
print
"not "
;}
print
"ok "
,
$test_count
++,
" # \$/ = {}; produced expected error message\n"
;
}
if
(
eval
{$/ = \\1; 1}) {
print
"not ok "
,
$test_count
++,
" # \$/ = \\\\1; should die\n"
;
print
"not ok "
,
$test_count
++,
" # \$/ = \\\\1; produced expected error message\n"
;
}
else
{
my
$msg
= $@ ||
"Zombie Error"
;
print
"ok "
,
$test_count
++,
" # \$/ = \\\\1; should die\n"
;
if
(
$msg
!~m!Setting \$\/ to a REF reference is forbidden!) {
print
"not "
;}
print
"ok "
,
$test_count
++,
" # \$/ = \\\\1; produced expected error message\n"
;
}
if
(
eval
{$/ =
qr/foo/
; 1}) {
print
"not ok "
,
$test_count
++,
" # \$/ = qr/foo/; should die\n"
;
print
"not ok "
,
$test_count
++,
" # \$/ = qr/foo/; produced expected error message\n"
;
}
else
{
my
$msg
= $@ ||
"Zombie Error"
;
print
"ok "
,
$test_count
++,
" # \$/ = qr/foo/; should die\n"
;
if
(
$msg
!~m!Setting \$\/ to a REGEXP reference is forbidden!) {
print
"not "
;}
print
"ok "
,
$test_count
++,
" # \$/ = qr/foo/; produced expected error message\n"
;
}
if
(
eval
{$/ = \
*STDOUT
; 1}) {
print
"not ok "
,
$test_count
++,
" # \$/ = \\*STDOUT; should die\n"
;
print
"not ok "
,
$test_count
++,
" # \$/ = \\*STDOUT; produced expected error message\n"
;
}
else
{
my
$msg
= $@ ||
"Zombie Error"
;
print
"ok "
,
$test_count
++,
" # \$/ = \\*STDOUT; should die\n"
;
if
(
$msg
!~m!Setting \$\/ to a GLOB reference is forbidden!) {
print
"not "
;}
print
"ok "
,
$test_count
++,
" # \$/ = \\*STDOUT; produced expected error message\n"
;
}
}