BEGIN { $| = 1;
print
"1..6\n"
; }
END {
print
"not ok 1\n"
unless
$loaded
;}
$loaded
= 1;
print
"ok 1\n"
;
$debug
=0;
$testname
=
"./test$$"
;
open
(TEST,
">$testname"
);
select
TEST;
$|=1;
select
STDOUT;
$|=1;
$file
=File::Tail->new(
name
=>
$testname
,
debug
=>
$debug
,
interval
=>1,
maxinterval
=>5,
adjustafter
=>5,
errmode
=>
"return"
) or
print
"not ok 2\n"
;
print
"ok 2\n"
if
defined
(
$file
);
$teststring
=
"This is a test string\n"
;
print
TEST
$teststring
;
$t
=
$file
->
read
;
if
(
$t
eq
$teststring
) {
print
"ok 3\n"
;
}
else
{
print
"not ok 3\n"
;
}
print
TEST
"0\n1\n2\n3\n4\n"
;
@t
=
$file
->
read
;
foreach
(0..4) {
unless
(
$t
[
$_
] eq
"$_\n"
) {
print
"not ok 4\n - <$t[$_]> at $_"
;
last
;
}
}
print
"ok 4\n"
;
close
(TEST);
open
(TEST,
">$testname"
);
$teststring
=
"This is another test string\n"
;
print
TEST
$teststring
;
$t
=
$file
->
read
;
if
(
$t
eq
$teststring
) {
print
"ok 5\n"
;
}
else
{
print
"not ok 5\n"
;
}
system
(
"mv $testname $testname-tmp"
);
open
(TEST,
">$testname"
);
$teststring
=
"This is yet another test string\n"
;
print
TEST
$teststring
;
$t
=
$file
->
read
;
if
(
$t
eq
$teststring
) {
print
"ok 6\n"
;
}
else
{
print
"not ok 6\n"
;
}
unlink
"$testname"
;
unlink
"$testname-tmp"
;