1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 24);
12 use_ok('Bio::Root::Root');
16 ok my $obj = Bio::Root::Root->new();
17 isa_ok($obj, 'Bio::Root::RootI');
19 eval { $obj->throw('Testing throw') };
20 ok $@ =~ /Testing throw/;# 'throw failed';
22 # doesn't work in perl 5.00405
25 # my ($tfh,$tfile) = $obj->tempfile();
26 # local * STDERR = $tfh;
27 # $obj->warn('Testing warn');
29 # open(IN, $tfile) or die("cannot open $tfile");
30 # $val = join("", <IN>) ;
34 #ok $val =~ /Testing warn/;
35 #'verbose(0) warn did not work properly' . $val;
38 eval { $obj->throw('Testing throw') };
39 ok $@=~ /Testing throw/;# 'verbose(-1) throw did not work properly' . $@;
41 eval { $obj->warn('Testing warn') };
45 eval { $obj->throw('Testing throw') };
46 ok $@ =~ /Testing throw/;# 'verbose(1) throw did not work properly' . $@;
48 # doesn't work in perl 5.00405
51 # my ($tfh,$tfile) = $obj->tempfile();
52 # local * STDERR = $tfh;
53 # $obj->warn('Testing warn');
55 # open(IN, $tfile) or die("cannot open $tfile");
56 # $val = join("", <IN>);
60 #ok $val =~ /Testing warn/;# 'verbose(1) warn did not work properly' . $val;
62 my @stack = $obj->stack_trace();
65 my $verbobj = Bio::Root::Root->new(-verbose=>1,-strict=>1);
66 is $verbobj->verbose(), 1;
68 $Bio::Root::Root::DEBUG = 1;
69 my $seq = Bio::Seq->new();
73 my @vals = Bio::Root::RootI->_rearrange([qw(apples pears)],
76 eval { $obj->throw_not_implemented() };
77 ok $@ =~ /Bio::Root::NotImplemented/;
79 is shift @vals, 'up the';
80 is shift @vals, 'stairs';
82 # tests for _set_from_args()
84 no warnings 'redefine';
87 local *Bio::Root::Root::new = sub {
90 bless $self, ref($class) || $class;
92 $self->_set_from_args(\@_);
97 $obj = Bio::Root::Root->new(-verbose => 1, t1 => 1, '--Test-2' => 2);
98 ok ! $obj->can('t1'), 'arg not callable';
100 # with method creation
101 local *Bio::Root::Root::new = sub {
104 bless $self, ref($class) || $class;
106 $self->_set_from_args(\@_, -create => 1);
111 $obj = Bio::Root::Root->new(-verbose => 1, t3 => 1, '--Test-4' => 2);
112 ok $obj->can('t3'), 'arg callable since method was created';
113 ok $obj->can('test_4'), 'mal-formed arg callable since method was created with good name';
115 # with method creation, but limited to certain methods
116 local *Bio::Root::Root::new = sub {
119 bless $self, ref($class) || $class;
121 $self->_set_from_args(\@_, -methods => ['verbose', 't5'], -create => 1);
126 $obj = Bio::Root::Root->new(-verbose => 1, t5 => 1, '--Test-6' => 2);
127 ok $obj->can('t5'), 'arg callable since method was created';
128 ok ! $obj->can('test_6'), 'arg not in method list not created';
131 local *Bio::Root::Root::new = sub {
134 bless $self, ref($class) || $class;
138 $self->_set_from_args(\%args, -methods => {(verbose => 'v',
146 $obj = Bio::Root::Root->new(-verbose => 1, t7 => 1, '--Test-8' => 2);
147 is $obj->verbose, 1, 'verbose was set correctly';
148 is $obj->t7, 1, 'synonym was set correctly';
149 is $obj->test7, 1, 'real method of synonym was set correctly';
150 is $obj->test_8, 2, 'mal-formed arg correctly resolved to created method';
151 is $obj->t8, 2, 'synonym of set method was set correctly';