Skip Menu |

This queue is for tickets about the File-Tail CPAN distribution.

Report information
The Basics
Id: 24141
Status: resolved
Worked: 5 min
Priority: 0/
Queue: File-Tail

People
Owner: Nobody in particular
Requestors: cosimo [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.99.3
Fixed in: (no value)



Subject: File::Tail fixes to pass the tests under Win32
Here I attach updated test scripts that pass also on Win32. The main issue is testing strings against "\n", which can be "translated" when writing to file. Using "binmode FILEHANDLE" corrects these problems. Anyway, there's the 6th test of 10open.t that doesn't pass. I added a note of mine to that test, because its failure is pretty weird. Shortening the string to be written to file causes the test to pass...
Subject: 20tail.t
use File::Tail; $| = 1; print "1..7\n"; $debug=0; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): $testname="./test$$"; open(TEST,">$testname"); select TEST; binmode TEST; $|=1; select STDOUT; # # Test 1 - read whole file # 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; binmode TEST; $|=1; select STDOUT; # # Test 2 - start at end of file # $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); # # Test 3-7 read the last 1-5 lines # open(TEST,">$testname"); select TEST; binmode TEST; $|=1; select STDOUT; print TEST "0\n1\n2\n3\n4\n"; TEST: foreach $test (3..7) { undef @t; # print "Test no. $test!\n"; $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; } # my $a=join("",@t);$a=~tr/\n/ /; # print "<$a>"; foreach ((7-$test)..4) { # print "\$t[$test+$_-7]=$t[$test+$_-7], should be $_\n"; unless ($t[$test+$_-7] eq "$_\n") { print "not ok $test\n - <$t[$_]> at $_"; next TEST; } } print "ok $test\n"; $file->CLOSE; } unlink "$testname";
Subject: 10open.t
BEGIN { $| = 1; print "1..6\n"; } END {print "not ok 1\n" unless $loaded;} use File::Tail; use File::Copy; $loaded = 1; print "ok 1\n"; $debug=0; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): # # Test 2 - open an existant file # $testname="./test$$"; open(TEST,">$testname"); select TEST; binmode TEST; $|=1; select STDOUT; binmode 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); # # Test 3 - read a line from the 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"; } # # Test 4 - read an array of lines from file # 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"; # # Test 5 - Read on reopened file # close(TEST); open(TEST,">$testname"); binmode TEST; select TEST; $|=1; select STDOUT; $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"; } # # Test 6 - Read on moved and reopened file # File::Copy::move($testname, "$testname-tmp"); open(TEST,">$testname"); binmode TEST; select TEST; $| = 1; select STDOUT; # # Strangely, setting $teststring to "This is yet another string\n" # (without "test") it works without problems on my Win32 test machine. # Cosimo 2006/12/29 # $teststring="This is yet another test string\n"; print TEST $teststring; $t=$file->read; warn '$t=('.$t.')'; if ($t eq $teststring) { print "ok 6\n"; } else { warn "# <$t><$teststring>\n"; print "not ok 6\n"; } unlink "$testname"; unlink "$testname-tmp";
Subject: 30name_change.t
use File::Tail; $| = 1; print "1..2\n"; $debug=0; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): my $fnbase="./test$$"; open(TESTA,">$fnbase.a"); binmode TESTA; print TESTA "This is test file A\n"; close TESTA; sub newname { return "$fnbase.b"; } my $file=File::Tail->new(name=>"$fnbase.a", name_changes=>\&newname,maxinterval=>10, debug=>$debug, tail=>1, adjustafter=>2); if ($file->read eq "This is test file A\n") { print "ok 1\n"; } else { print "not ok 1\n"; } open(TESTB,">$fnbase.b"); binmode TESTB; print TESTB "This is test file B (yes, B, not A: A was the other file)\n"; close TESTB; print "ok 2\n" if ($file->read eq "This is test file B (yes, B, not A: A was the other file)\n"); unlink "$fnbase.a","$fnbase.b";
Closed because it is a duplicate of #22903. http://rt.cpan.org/Public/Bug/Display.html?id=22903