1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 31);
12 use_ok('Bio::Root::IO');
15 my $obj = Bio::Root::IO->new();
16 ok defined($obj) && $obj->isa('Bio::Root::IO');
18 #############################################
19 # tests for exceptions/debugging/verbosity
20 #############################################
22 eval { $obj->throw('Testing throw') };
23 like $@, qr/Testing throw/, 'throw()'; # 'throw failed';
26 eval { $obj->throw('Testing throw') };
27 like $@, qr/Testing throw/, 'throw() verbose(-1)'; # 'verbose(-1) throw did not work properly' . $@;
29 eval { $obj->warn('Testing warn') };
33 eval { $obj->throw('Testing throw') };
34 like $@, qr/Testing throw/, 'throw() verbose(1)'; # 'verbose(1) throw did not work properly' . $@;
36 my @stack = $obj->stack_trace();
37 is scalar @stack, 2, 'stack_trace()';
39 my $verbobj = Bio::Root::IO->new(-verbose=>1,-strict=>1);
40 is $verbobj->verbose(), 1, 'set verbosity to 1';
44 #############################################
45 # tests for handle read and write abilities
46 #############################################
48 ok my $TESTINFILE = Bio::Root::IO->catfile(qw(t data test.waba));
50 my($handle,$file) = $obj->tempfile;
56 ok my $rio = Bio::Root::IO->new(-file=>$TESTINFILE);
57 is $rio->mode, 'r', 'filename, read';
59 ok my $wio = Bio::Root::IO->new(-file=>">$file");
60 is $wio->mode, 'w', 'filename, write';
64 ok open(my $I, $TESTINFILE);
65 ok open(my $O, '>', $file);
67 ok $rio = Bio::Root::IO->new(-fh=>$I);
68 is $rio->mode, 'r', 'handle, read';
70 ok $wio = Bio::Root::IO->new(-fh=>$O);
71 is $wio->mode, 'w', 'handle, write';
73 ##############################################
74 # tests _pushback for multi-line buffering
75 ##############################################
77 my $line1 = $rio->_readline;
78 my $line2 = $rio->_readline;
80 ok $rio->_pushback($line1);
81 ok $rio->_pushback($line2);
83 my $line3 = $rio->_readline;
84 my $line4 = $rio->_readline;
85 my $line5 = $rio->_readline;
94 ##############################################
95 # tests http retrieval
96 ##############################################
99 test_skip(-tests => 2, -requires_networking => 1);
101 my $TESTURL = 'http://www.google.com/index.html';
103 ok $rio = Bio::Root::IO->new(-url=>$TESTURL), 'default -url method';
105 if ($Bio::Root::IO::HAS_LWP) {
106 $Bio::Root::IO::HAS_LWP = 0;
107 ok $rio = Bio::Root::IO->new(-url=>$TESTURL), 'non-LWP -url method';
110 ok 1, 'non-LWP -url method not needed as non-LWP was default';