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