File: 030-output-file.t

package info (click to toggle)
liblog-handler-perl 0.45-1%2Blenny1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 392 kB
  • ctags: 145
  • sloc: perl: 2,017; makefile: 39
file content (43 lines) | stat: -rw-r--r-- 951 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use strict;
use warnings;
use Test::More tests => 5;
use File::Spec;
use Log::Handler::Output::File;

my $rand_num = int(rand(999999));
my $logfile  = File::Spec->catfile('t', "Log-Handler-$rand_num.log");
my $log      = Log::Handler::Output::File->new(
    filename     => [ 't', "Log-Handler-$rand_num.log" ],
    permissions  => '0664',
    mode         => 'append',
    autoflush    => 0,
    fileopen     => 0,
    filelock     => 0,
    reopen       => 0,
);

ok(1, 'new');

# write a string to the file
$log->log(message => "test\n") or die $!;
ok(1, "checking log()");

# checking if the file is readable
open(my $fh, '<', $logfile) or do {
   ok(0, "open logfile ($logfile)");
   exit(1);
};

ok(1, "open logfile ($logfile)");

my $line = <$fh>;
chomp($line);
close $fh;

ok($line =~ /^test\z/, "checking logfile ($line)");

if ( unlink($logfile) ) {
    ok(1, "unlink logfile ($logfile)");
} else {
    ok(0, "unlink logfile ($logfile)");
}