1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 50);
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';
85 warning_like{ Bio::Root::Root->deprecated('Test1') } qr/Test1/, 'simple';
86 warning_like{ Bio::Root::Root->deprecated(-message => 'Test2') } qr/Test2/, 'simple';
87 warning_like{ Bio::Root::Root->deprecated('Test3', 999.999) } qr/Test3/,
88 'warns for versions below current version '.$Bio::Root::Version::VERSION;
89 warning_like{ Bio::Root::Root->deprecated(-message => 'Test4',
90 -version => 999.999) } qr/Test4/,
91 'warns for versions below current version '.$Bio::Root::Version::VERSION;
92 throws_ok{ Bio::Root::Root->deprecated('Test5', 0.001) } qr/Test5/,
93 'throws for versions above '.$Bio::Root::Version::VERSION;
94 throws_ok{ Bio::Root::Root->deprecated(-message => 'Test6',
95 -version => 0.001) } qr/Test6/,
96 'throws for versions above '.$Bio::Root::Version::VERSION;
97 throws_ok{ Bio::Root::Root->deprecated(-message => 'Test6',
98 -version => $Bio::Root::Version::VERSION) } qr/Test6/,
99 'throws for versions equal to '.$Bio::Root::Version::VERSION;
102 my $root = Bio::Root::Root->new();
103 warning_like{ $root->deprecated('Test1') } qr/Test1/, 'simple';
104 warning_like{ $root->deprecated(-message => 'Test2') } qr/Test2/, 'simple';
105 warning_like{ $root->deprecated('Test3', 999.999) } qr/Test3/,
106 'warns for versions below current version '.$Bio::Root::Version::VERSION;
107 warning_like{ $root->deprecated(-message => 'Test4',
108 -version => 999.999) } qr/Test4/,
109 'warns for versions below current version '.$Bio::Root::Version::VERSION;
110 throws_ok{ $root->deprecated('Test5', 0.001) } qr/Test5/,
111 'throws for versions above '.$Bio::Root::Version::VERSION;
112 throws_ok{ $root->deprecated(-message => 'Test6',
113 -version => 0.001) } qr/Test6/,
114 'throws for versions above '.$Bio::Root::Version::VERSION;
116 # tests for _set_from_args()
117 # Let's not pollute Bio::Root::Root namespace if possible
118 # Create temp classes instead which inherit Bio::Root::Root, then test
121 use base qw(Bio::Root::Root);
125 bless $self, ref($class) || $class;
127 $self->_set_from_args(\@_);
134 $obj = Bio::Foo1->new(-verbose => 1, t1 => 1, '--Test-2' => 2);
135 #ok ! $obj->can('t1'), 'arg not callable';
138 use base qw(Bio::Root::Root);
142 bless $self, ref($class) || $class;
144 $self->_set_from_args(\@_, -create => 1);
151 $obj = Bio::Foo2->new(-verbose => 1, t3 => 1, '--Test-4' => 2);
152 ok $obj->can('t3'), 'arg callable since method was created';
153 ok $obj->can('test_4'), 'mal-formed arg callable since method was created with good name';
154 for my $m (qw(t3 test_4)) {
155 can_ok('Bio::Foo2',$m);
156 ok (!UNIVERSAL::can('Bio::Root::Root',$m), "Methods don't pollute original Bio::Root::Root namespace");
160 use base qw(Bio::Root::Root);
164 bless $self, ref($class) || $class;
166 $self->_set_from_args(\@_, -methods => ['verbose', 't5'], -create => 1);
173 $obj = Bio::Foo3->new(-verbose => 1, t5 => 1, '--Test-6' => 2);
175 ok ! $obj->can('test_6'), 'arg not in method list not created';
177 can_ok ('Bio::Foo3','t5');
178 ok (!UNIVERSAL::can('Bio::Root::Root','t5'), "Methods don't pollute original Bio::Root::Root namespace");
181 use base qw(Bio::Root::Root);
185 bless $self, ref($class) || $class;
189 $self->_set_from_args(\%args, -methods => {(verbose => 'v',
200 $obj = Bio::Foo4->new(-verbose => 1, t7 => 1, '--Test-8' => 2);
201 is $obj->verbose, 1, 'verbose was set correctly';
202 is $obj->t7, 1, 'synonym was set correctly';
203 is $obj->test7, 1, 'real method of synonym was set correctly';
204 is $obj->test_8, 2, 'mal-formed arg correctly resolved to created method';
205 is $obj->t8, 2, 'synonym of set method was set correctly';
207 for my $m (qw(t7 test7 test_8 t8)) {
208 can_ok('Bio::Foo4',$m);
209 ok(!UNIVERSAL::can('Bio::Root::Root','t7'), "Methods don't pollute original Bio::Root::Root namespace");