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 99 100 101 102 103 104 105 106 107
|
# -*-Perl-*-
## Bioperl Test Harness Script for Modules
## $Id: RootIO.t,v 1.5 2002/10/15 17:38:29 allenday Exp $
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.t'
use strict;
BEGIN {
# to handle systems with no installed Test module
# we include the t dir (where a copy of Test.pm is located)
# as a fallback
eval { require Test; };
if( $@ ) {
use lib 't', '.';
}
use Test;
plan tests => 25;
}
$| = 1;
use Bio::Root::IO;
my $obj = new Bio::Root::IO();
ok defined($obj) && $obj->isa('Bio::Root::IO');
eval { $obj->throw('Testing throw') };
ok $@ =~ /Testing throw/;# 'throw failed';
$obj->verbose(-1);
eval { $obj->throw('Testing throw') };
ok $@=~ /Testing throw/;# 'verbose(-1) throw did not work properly' . $@;
eval { $obj->warn('Testing warn') };
ok !$@;
$obj->verbose(1);
eval { $obj->throw('Testing throw') };
ok $@ =~ /Testing throw/;# 'verbose(1) throw did not work properly' . $@;
my @stack = $obj->stack_trace();
ok scalar @stack, 2;
my $verbobj = new Bio::Root::IO(-verbose=>1,-strict=>1);
ok $verbobj->verbose(), 1;
ok $obj->verbose(-1);
#############################################
# <tests for handle read and write abilities>
#############################################
my($handle,$file) = $obj->tempfile;
ok open(I,"t/data/test.waba");
ok open(O,">$file");
my $rio;
my $wio;
#test with files
ok $rio = Bio::Root::IO->new(-file=>"t/data/test.waba");
ok $wio = Bio::Root::IO->new(-file=>">$file");
ok $rio->mode eq 'r';
ok $wio->mode eq 'w';
#test with handles
ok $rio = Bio::Root::IO->new(-fh=>\*I);
ok $wio = Bio::Root::IO->new(-fh=>\*O);
ok $rio->mode eq 'r';
ok $wio->mode eq 'w';
##############################################
# </tests for handle read and write abilities>
##############################################
##############################################
# <tests _pushback for multi-line buffering>
##############################################
my $line1 = $rio->_readline;
my $line2 = $rio->_readline;
ok $rio->_pushback($line1);
ok $rio->_pushback($line2);
my $line3 = $rio->_readline;
my $line4 = $rio->_readline;
my $line5 = $rio->_readline;
ok $line1 eq $line3;
ok $line2 eq $line4;
ok $line5 ne $line4;
##############################################
# </tests _pushback for multi-line buffering>
##############################################
ok close(I);
ok close(O);
1;
|