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
|
#!perl
use strict;
use warnings;
use Test::More 0.88;
use HTTP::Tiny;
# blank slate for testing
delete $ENV{no_proxy};
{
my $c = HTTP::Tiny->new();
is_deeply( $c->no_proxy, [], "no no_proxy given" );
}
my @cases = (
#<<< No perltidy
{
no_proxy => [
undef,
[],
],
expect => [],
},
{
no_proxy => [
"localhost",
["localhost"],
],
expect => ["localhost"],
},
{
no_proxy => [
"localhost,example.com",
"localhost, example.com",
[qw/localhost example.com/]
],
expect => [ "localhost", "example.com" ],
},
#>>>
);
for my $c (@cases) {
for my $no_proxy ( @{ $c->{no_proxy} } ) {
my $label =
!defined $no_proxy ? 'undef'
: ref $no_proxy ? "[qw/@$no_proxy/]"
: "'$no_proxy'";
# Can't test environment with array ref (ENV stringifies in new perls)
if ( ref $no_proxy ) {
my $ht = HTTP::Tiny->new( no_proxy => $no_proxy );
is_deeply( $ht->no_proxy, $c->{expect}, "new(no_proxy => $label)" );
}
else {
{
local $ENV{no_proxy} = $no_proxy;
my $ht = HTTP::Tiny->new();
is_deeply( $ht->no_proxy, $c->{expect}, "\$ENV{no_proxy} = $label" );
}
{
local $ENV{no_proxy} = "Shouldnt,see,this";
my $ht = HTTP::Tiny->new( no_proxy => $no_proxy );
is_deeply( $ht->no_proxy, $c->{expect},
"new(no_proxy => $label) versus other \$ENV{no_proxy}" );
}
}
}
}
done_testing();
|