1use strict; 2use Test::More; 3use File::Spec; 4use HTTP::Proxy; 5 6my $errfile = File::Spec->catfile( 't', 'stderr.out' ); 7my @deprecated = ( 8 [ maxchild => qr/^maxchild is deprecated, please use max_clients/ ], 9 [ maxconn => qr/^maxconn is deprecated, please use max_connections/ ], 10 [ 11 maxserve => 12 qr/^maxserve is deprecated, please use max_keep_alive_requests/ 13 ], 14); 15 16plan tests => 4 * @deprecated; 17 18# check the warnings 19open my $olderr, ">&STDERR" or die "Can't dup STDERR: $!"; 20open STDERR, '>', $errfile or die "Can't redirect STDERR: $!"; 21select STDERR; 22$| = 1; # make unbuffered 23 24# call the deprecated methods 25my $p1 = HTTP::Proxy->new( 26 maxchild => 1, 27 maxconn => 3, 28 maxserve => 5, 29); 30 31my $p2 = HTTP::Proxy->new(); 32$p2->maxchild(9); 33$p2->maxconn(8); 34$p2->maxserve(7); 35 36# get the old STDERR back 37open STDERR, ">&", $olderr or die "Can't dup \$olderr: $!"; 38 39# read the stderr log 40open my $fh, $errfile or die "Can't open $errfile: $!"; 41my @err = sort <$fh>; 42close $fh or diag "Can't close $errfile: $!"; 43 44# run the tests 45for (@deprecated) { 46 like( shift @err, $_->[1], "$_->[0] is deprecated" ); 47 like( shift @err, $_->[1], "$_->[0] is deprecated" ); 48} 49diag $_ for @err; 50 51unlink $errfile or diag "Can't unlink $errfile: $!"; 52 53# check that the real method was called 54is( $p1->max_clients, 1, "max_clients called for maxchild" ); 55is( $p1->max_connections, 3, "max_connections called for maxconn" ); 56is( $p1->max_keep_alive_requests, 5, "max_keep_alive_requests called for maxserve" ); 57 58is( $p2->max_clients, 9, "max_clients called for maxchild" ); 59is( $p2->max_connections, 8, "max_connections called for maxconn" ); 60is( $p2->max_keep_alive_requests, 7, "max_keep_alive_requests called for maxserve" ); 61