Imported Upstream version 1.09

This commit is contained in:
Mario Fetka
2017-01-16 14:36:11 +01:00
commit 4b555c3e4d
16 changed files with 969 additions and 0 deletions

17
t/1.t Executable file
View File

@@ -0,0 +1,17 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test;
BEGIN { plan tests => 1 };
use Log::Dispatch::File::Rolling;
ok(1); # If we made it this far, we're ok.
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

18
t/2.t Executable file
View File

@@ -0,0 +1,18 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test;
BEGIN { plan tests => 1 };
use Log::Dispatch;
use Log::Dispatch::File::Rolling;
ok(1); # If we made it this far, we're ok.
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

70
t/3.t Executable file
View File

@@ -0,0 +1,70 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test;
BEGIN { plan tests => 8 };
use Log::Dispatch;
use Log::Dispatch::File::Rolling;
ok(1); # If we made it this far, we're ok.
#########################1
my $dispatcher = Log::Dispatch->new;
ok($dispatcher);
#########################2
my %params = (
name => 'file',
min_level => 'debug',
filename => 'logfile.txt',
);
my $Rolling = Log::Dispatch::File::Rolling->new(%params);
ok($Rolling);
#########################3
$dispatcher->add($Rolling);
ok(1);
#########################4
my $message = 'logtest id ' . int(rand(9999));
$dispatcher->log( level => 'info', message => $message );
ok(1);
#########################5
$dispatcher = $Rolling = undef;
ok(1);
#########################6
my @logfiles = glob('logfile*.txt');
ok(scalar(@logfiles) == 1 or scalar(@logfiles) == 2);
#########################7
my $content = '';
foreach my $file (@logfiles) {
open F, '<', $file;
local $/ = undef;
$content .= <F>;
close F;
unlink $file;
}
ok($content =~ /$message/);
#########################8

70
t/4.t Executable file
View File

@@ -0,0 +1,70 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test;
BEGIN { plan tests => 8 };
use Log::Dispatch;
use Log::Dispatch::File::Rolling;
ok(1); # If we made it this far, we're ok.
#########################1
my $dispatcher = Log::Dispatch->new;
ok($dispatcher);
#########################2
my %params = (
name => 'file',
min_level => 'debug',
filename => 'logfile%d{$$}.txt',
);
my $Rolling = Log::Dispatch::File::Rolling->new(%params);
ok($Rolling);
#########################3
$dispatcher->add($Rolling);
ok(1);
#########################4
my $message = 'logtest id ' . int(rand(9999));
$dispatcher->log( level => 'info', message => $message );
ok(1);
#########################5
$dispatcher = $Rolling = undef;
ok(1);
#########################6
my @logfiles = glob("logfile$$.txt");
ok(scalar(@logfiles) == 1);
#########################7
my $content = '';
foreach my $file (@logfiles) {
open F, '<', $file;
local $/ = undef;
$content .= <F>;
close F;
unlink $file;
}
ok($content =~ /$message/);
#########################8

70
t/5.t Executable file
View File

@@ -0,0 +1,70 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test;
BEGIN { plan tests => 8 };
use Log::Dispatch;
use Log::Dispatch::File::Rolling;
ok(1); # If we made it this far, we're ok.
#########################1
my $dispatcher = Log::Dispatch->new;
ok($dispatcher);
#########################2
my %params = (
name => 'file',
min_level => 'debug',
filename => 'logfile',
);
my $Rolling = Log::Dispatch::File::Rolling->new(%params);
ok($Rolling);
#########################3
$dispatcher->add($Rolling);
ok(1);
#########################4
my $message = 'logtest id ' . int(rand(9999));
$dispatcher->log( level => 'info', message => $message );
ok(1);
#########################5
$dispatcher = $Rolling = undef;
ok(1);
#########################6
my @logfiles = glob("logfile.2*");
ok(scalar(@logfiles) == 1 or scalar(@logfiles) == 2);
#########################7
my $content = '';
foreach my $file (@logfiles) {
open F, '<', $file;
local $/ = undef;
$content .= <F>;
close F;
unlink $file;
}
ok($content =~ /$message/);
#########################8

74
t/6.t Executable file
View File

@@ -0,0 +1,74 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test;
BEGIN { plan tests => 9 };
use Log::Dispatch;
use Log::Dispatch::File::Rolling;
ok(1); # If we made it this far, we're ok.
#########################1
my $dispatcher = Log::Dispatch->new;
ok($dispatcher);
#########################2
my %params = (
name => 'file',
min_level => 'debug',
filename => 'logfile.txt',
);
my $Rolling = Log::Dispatch::File::Rolling->new(%params);
ok($Rolling);
#########################3
$dispatcher->add($Rolling);
ok(1);
#########################4
my $message1 = 'logtest id ' . int(rand(9999));
my $message2 = 'logtest id ' . int(rand(9999));
$dispatcher->log( level => 'info', message => $message1 );
close $Rolling->{fh}; # disturb internal bookkeeping, must recover from this
$dispatcher->log( level => 'info', message => $message2 );
ok(1);
#########################5
$dispatcher = $Rolling = undef;
ok(1);
#########################6
my @logfiles = glob('logfile*.txt');
ok(scalar(@logfiles) == 1 or scalar(@logfiles) == 2);
#########################7
my $content = '';
foreach my $file (@logfiles) {
open F, '<', $file;
local $/ = undef;
$content .= <F>;
close F;
unlink $file;
}
ok($content =~ /$message1/);
ok($content =~ /$message2/);
#########################8

5
t/7testpod.t Executable file
View File

@@ -0,0 +1,5 @@
use Test::More;
eval "
use Test::Pod 1.00;";
plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
all_pod_files_ok();

5
t/8coverage.t Executable file
View File

@@ -0,0 +1,5 @@
use Test::More;
eval "
use Test::Pod::Coverage 1.00; ";
plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@;
all_pod_coverage_ok();

75
t/9reopenfh.t Executable file
View File

@@ -0,0 +1,75 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
#########################
use Test::More;
eval "
use Test::Fork; ";
plan skip_all => "Test::Fork required for this test" if $@;
plan tests => 12;
use Log::Dispatch;
use Log::Dispatch::File::Rolling;
ok(1); # If we made it this far, we're ok.
#########################1
my $dispatcher = Log::Dispatch->new;
ok($dispatcher);
#########################2
my %params = (
name => 'file',
min_level => 'debug',
filename => 'logfile.txt',
);
my $Rolling = Log::Dispatch::File::Rolling->new(%params);
ok($Rolling);
#########################3
$dispatcher->add($Rolling);
ok(1);
#########################4
my @message = map {'logtest id ' . int(rand(9999))} 1 .. 3;
my $initial_fileno = fileno $Rolling->{fh};
$dispatcher->log( level => 'info', message => $message[0] );
my $parent_fileno = fileno $Rolling->{fh};
is( $parent_fileno, $initial_fileno, "initial log call doesn't reopen" );
fork_ok( 2, sub {
$dispatcher->log( level => 'info', message => $message[1] );
my $child_fileno = fileno $Rolling->{fh};
isnt( $child_fileno, $parent_fileno, "logging in child reopens" );
$dispatcher = $Rolling = undef;
ok(1);
});
$dispatcher->log( level => 'info', message => $message[2] );
my $_parent_fileno = fileno $Rolling->{fh};
is( $_parent_fileno, $parent_fileno, "logging in parent does not reopen" );
ok(1);
#########################5
$dispatcher = $Rolling = undef;
ok(1);
#########################6
my @logfiles = glob('logfile*.txt');
ok(scalar(@logfiles) == 1 or scalar(@logfiles) == 2);
#########################7
foreach my $file (@logfiles) {
unlink $file;
}