summaryrefslogtreecommitdiff
path: root/t/048lwp.t
blob: 5749ff524a7456e18e3ffd4e2407bb80003d3163 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
###########################################
# Test Suite for LWP debugging with Log4perl
# Mike Schilli, 2004 (m@perlmeister.com)
###########################################

BEGIN { 
    if($ENV{INTERNAL_DEBUG}) {
        require Log::Log4perl::InternalDebug;
        Log::Log4perl::InternalDebug->enable();
    }
}

use warnings;
use strict;

use Test::More;

BEGIN {
    eval {
        require LWP::UserAgent;
        die "Skip tests" if $LWP::UserAgent::VERSION <  2.0;
        die "Skip tests" if $LWP::UserAgent::VERSION >= 5.822;
    };

    if($@) {
        plan skip_all => "Only with 2.0 < LWP::UserAgent < 5.822 ";
    } else {
        plan tests => 3;
    }
}

use Log::Log4perl qw(:easy);
use Log::Log4perl::Util;

Log::Log4perl->easy_init(
    { level    => $DEBUG,
      category => "LWP::UserAgent",
      file     => 'lwpout.txt'
    });

Log::Log4perl->infiltrate_lwp();

my $ua = LWP::UserAgent->new();

my $tmpfile = Log::Log4perl::Util::tmpfile_name();
END { unlink $tmpfile };
$ua->get("file:$tmpfile");

open LOG, "<lwpout.txt" or die "Cannot open lwpout.txt";
my $data = join('', <LOG>);
close LOG;

like($data, qr#\QGET file:$tmpfile\E#);

END { unlink "lwpout.txt" }

####################################
# Check different category
####################################
Log::Log4perl->reset();
Log::Log4perl->easy_init(
    { level    => $DEBUG,
      category => "LWP::SchmoozeAgent",
      file     => '>lwpout.txt'
    });

Log::Log4perl->infiltrate_lwp();

$ua = LWP::UserAgent->new();
$ua->get("file:$tmpfile");

open LOG, "<lwpout.txt" or die "Cannot open lwpout.txt";
$data = join('', <LOG>);
close LOG;

is($data, '');

####################################
# Check layout
####################################
Log::Log4perl->reset();
Log::Log4perl->easy_init(
    { level    => $DEBUG,
      category => "LWP::UserAgent",
      file     => '>lwpout.txt',
      layout   => '%F-%L: %m%n',
    });

Log::Log4perl->infiltrate_lwp();

$ua = LWP::UserAgent->new();
$ua->get("file:$tmpfile");

open LOG, "<lwpout.txt" or die "Cannot open lwpout.txt";
$data = join('', <LOG>);
close LOG;

like($data, qr#LWP/UserAgent.pm-\d+#);