~ubuntu-branches/ubuntu/precise/liblwp-online-perl/precise

« back to all changes in this revision

Viewing changes to t/02_main.t

  • Committer: Bazaar Package Importer
  • Author(s): Antonio Radici
  • Date: 2009-02-10 21:48:54 UTC
  • Revision ID: james.westby@ubuntu.com-20090210214854-jzfatwqkg605tzrp
Tags: upstream-1.07
ImportĀ upstreamĀ versionĀ 1.07

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# Main testing for LWP-Online
 
4
 
 
5
use strict;
 
6
BEGIN {
 
7
        $|  = 1;
 
8
        $^W = 1;
 
9
}
 
10
 
 
11
use Test::More tests => 6;
 
12
use LWP::Online 'online', 'offline';
 
13
 
 
14
ok( defined &online,  'LWP::Online exports the online function'  );
 
15
ok( defined &offline, 'LWP::Online exports the offline function' );
 
16
 
 
17
# We can't actually be sure if we are online or not currently.
 
18
# So as long as calling online never crashes, and returns EITHER
 
19
# 1 or '', then it is a success.
 
20
diag("\nLooking for the internet, this may take a few minutes if you are offline...");
 
21
 
 
22
my $rv = eval { online() };
 
23
is( $@, '', 'Call to online() does not crash' );
 
24
ok( ($rv eq '1' or $rv eq ''), "online() returns a valid result '$rv'" );
 
25
if ( $rv ) {
 
26
        diag("You are online");
 
27
} else {
 
28
        diag("You are not online");
 
29
}
 
30
my $off = eval { offline() };
 
31
is( $@, '', 'Call to offline() does not crash' );
 
32
is( $off, ! $rv, 'online() and offline() return opposite results' );