1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 27);
12 use_ok('Bio::Tools::Run::WrapperBase');
15 my @params = qw(test1 test_2);
16 my @switches = qw(Test3 test_4);
17 *Bio::Tools::Run::WrapperBase::new = sub {
18 my ($class, @args) = @_;
19 my $self = $class->Bio::Tools::Run::WrapperBase::SUPER::new(@args);
21 $self->_set_from_args(\@args, -methods => [@params, @switches],
26 my $new = *Bio::Tools::Run::WrapperBase::new; # just to avoid warning
27 my $obj = Bio::Tools::Run::WrapperBase->new(-test_2 => 2, -test3 => 1, -test_4 => 0);
28 isa_ok($obj, 'Bio::Tools::Run::WrapperBase');
30 # it is interface-like with throw_not_implemented methods; check their
32 foreach my $method (qw(run program_dir program_name version)) {
33 ok $obj->can($method), "$method() exists";
36 ## most methods are defined; check their function
39 foreach my $method (qw(error_string arguments no_param_checks save_tempfiles
40 outfile_name quiet)) {
42 is $obj->$method(), 1, "$method could be set";
47 $obj->save_tempfiles(0);
48 my $tmpdir = $obj->tempdir();
49 ok -d $tmpdir, 'tempdir created a directory';
50 ok open(my $test, '>', File::Spec->catfile($tmpdir, 'test')), 'could create file in tempdir';
57 ok ! -d $tmpdir, 'following cleanup() with save_tempfiles unset, tempdir was deleted';
62 isa_ok($io1, 'Bio::Root::IO');
63 is $io1, $io2, 'io() always returns the same instance of IO';
65 # program_dir and program_name need to be defined for program_path and
68 no warnings 'redefine';
69 *Bio::Tools::Run::WrapperBase::program_dir = sub {
71 if (@_) { $self->{pdir} = shift }
72 return $self->{pdir} || '';
74 *Bio::Tools::Run::WrapperBase::program_name = sub {
76 if (@_) { $self->{pname} = shift }
77 return $self->{pname} || '';
80 $obj->program_dir('test_dir');
81 $obj->program_name('test_name');
84 is $obj->program_path, File::Spec->catfile('test_dir', 'test_name'.($^O =~ /mswin/i ?'.exe':'')), 'program_path was correct';
87 ok ! $obj->executable, 'pretend program name not found as executable';
88 $obj->program_name('perl');
89 ok $obj->executable, 'perl found as exectuable';
92 my $params = $obj->_setparams(-params => \@params,
93 -switches => \@switches);
94 is $params, ' test_2 2 Test3', 'params string correct';
95 $params = $obj->_setparams(-params => \@params,
96 -switches => \@switches,
98 is $params, ' test_2=2 Test3', 'params string correct';
99 $params = $obj->_setparams(-params => \@params,
100 -switches => \@switches,
103 is $params, ' test_2=2 test3', 'params string correct';
104 $params = $obj->_setparams(-params => \@params,
105 -switches => \@switches,
109 is $params, ' -test_2=2 -test3', 'params string correct';
110 $params = $obj->_setparams(-params => \@params,
111 -switches => \@switches,
115 is $params, ' --test_2=2 --test3', 'params string correct';
116 $params = $obj->_setparams(-params => \@params,
117 -switches => \@switches,
121 -underscore_to_dash => 1);
122 is $params, ' --test-2=2 --test3', 'params string correct';
123 $params = $obj->_setparams(-params => {(test1 => 't1', test_2 => 't_2')},
124 -switches => {(Test3 => 'T3', test_4 => 't4')},
128 -underscore_to_dash => 1);
129 is $params, ' --t-2=2 --t3', 'params string correct';