1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 43);
11 use_ok 'Bio::Root::Root';
14 ok my $obj = Bio::Root::Root->new();
15 isa_ok $obj, 'Bio::Root::RootI';
17 throws_ok { $obj->throw('Testing throw') } qr/Testing throw/;# 'throw failed';
19 # test throw_not_implemented()
20 throws_ok { $obj->throw_not_implemented() } qr/EXCEPTION: Bio::Root::NotImplemented/;
24 use base qw(Bio::Root::RootI);
28 bless $self, ref($class) || $class;
32 $obj = Bio::FooI->new();
33 throws_ok { $obj->throw_not_implemented() } qr/EXCEPTION /;
34 $obj = Bio::Root::Root->new();
36 # doesn't work in perl 5.00405
39 # my ($tfh,$tfile) = $obj->tempfile();
40 # local * STDERR = $tfh;
41 # $obj->warn('Testing warn');
43 # open(IN, $tfile) or die("cannot open $tfile");
44 # $val = join("", <IN>) ;
48 #ok $val =~ /Testing warn/;
49 #'verbose(0) warn did not work properly' . $val;
52 throws_ok { $obj->throw('Testing throw') } qr/Testing throw/;# 'verbose(-1) throw did not work properly' . $@;
54 lives_ok { $obj->warn('Testing warn') };
57 throws_ok { $obj->throw('Testing throw') } qr/Testing throw/;# 'verbose(1) throw did not work properly' . $@;
59 # doesn't work in perl 5.00405
62 # my ($tfh,$tfile) = $obj->tempfile();
63 # local * STDERR = $tfh;
64 # $obj->warn('Testing warn');
66 # open(IN, $tfile) or die("cannot open $tfile");
67 # $val = join("", <IN>);
71 #ok $val =~ /Testing warn/;# 'verbose(1) warn did not work properly' . $val;
73 my @stack = $obj->stack_trace();
76 my $verbobj = Bio::Root::Root->new(-verbose=>1,-strict=>1);
77 is $verbobj->verbose(), 1;
79 $Bio::Root::Root::DEBUG = 1;
80 my $seq = Bio::Root::Root->new();
84 my @vals = Bio::Root::RootI->_rearrange([qw(apples pears)],
87 is shift @vals, 'up the';
88 is shift @vals, 'stairs';
90 # tests for _set_from_args()
91 # Let's not pollute Bio::Root::Root namespace if possible
92 # Create temp classes instead which inherit Bio::Root::Root, then test
97 use base qw(Bio::Root::Root);
98 our $VERSION = '2.00';
102 bless $self, ref($class) || $class;
104 $self->_set_from_args(\@_);
110 $obj = Bio::Foo1->new(-verbose => 1, t1 => 1, '--Test-2' => 2);
111 #ok ! $obj->can('t1'), 'arg not callable';
116 use base qw(Bio::Root::Root);
120 bless $self, ref($class) || $class;
122 $self->_set_from_args(\@_, -create => 1);
129 $obj = Bio::Foo2->new(-verbose => 1, t3 => 1, '--Test-4' => 2);
130 ok $obj->can('t3'), 'arg callable since method was created';
131 ok $obj->can('test_4'), 'mal-formed arg callable since method was created with good name';
132 for my $m (qw(t3 test_4)) {
133 can_ok('Bio::Foo2',$m);
134 ok ! Bio::Root::Root->can($m), "Methods don't pollute original Bio::Root::Root namespace";
139 use base qw(Bio::Root::Root);
143 bless $self, ref($class) || $class;
145 $self->_set_from_args(\@_, -methods => ['verbose', 't5'], -create => 1);
151 $obj = Bio::Foo3->new(-verbose => 1, t5 => 1, '--Test-6' => 2);
153 ok ! $obj->can('test_6'), 'arg not in method list not created';
155 can_ok ('Bio::Foo3','t5');
156 ok ! UNIVERSAL::can('Bio::Root::Root','t5'), "Methods don't pollute original Bio::Root::Root namespace";
160 use base qw(Bio::Root::Root);
164 bless $self, ref($class) || $class;
168 $self->_set_from_args(\%args, -methods => {(verbose => 'v',
179 $obj = Bio::Foo4->new(-verbose => 1, t7 => 1, '--Test-8' => 2);
180 is $obj->verbose, 1, 'verbose was set correctly';
181 is $obj->t7, 1, 'synonym was set correctly';
182 is $obj->test7, 1, 'real method of synonym was set correctly';
183 is $obj->test_8, 2, 'mal-formed arg correctly resolved to created method';
184 is $obj->t8, 2, 'synonym of set method was set correctly';
186 for my $m (qw(t7 test7 test_8 t8)) {
187 can_ok 'Bio::Foo4', $m;
188 ok ! UNIVERSAL::can('Bio::Root::Root','t7'), "Methods don't pollute original Bio::Root::Root namespace";
191 # test basic Root::clone()
193 my $clone = $obj->clone;
195 is $clone->t7, $obj->t7, 'clone';
196 is $clone->test7, $obj->test7, 'clone';
197 is $clone->test_8, $obj->test_8, 'clone';
198 $clone->test_8('xyz');
199 isnt $clone->test_8, $obj->test_8, 'clone changed, original didn\'t';
201 # test Root::clone() with parameter passing, only works for methods
202 # (introspection via can())
204 my $clone2 = $obj->clone(-t7 => 'foo');
206 is $clone2->t7, 'foo', 'parameters passed to clone() modify object';
207 is $obj->t7, 1, 'original is not modified';