1 # -*-Perl-*- Test Harness script for Bioperl
11 test_begin(-tests => 56);
13 use_ok('Bio::Root::Utilities');
17 my $u = Bio::Root::Utilities->new();
18 isa_ok($u, 'Bio::Root::Utilities') ;
20 # month2num() and num2month()
22 my @month = qw(XXX Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
24 is $u->month2num($month[$i]), $i;
25 is $u->num2month($i), $month[$i];
30 is $u->untaint(''), '';
31 is $u->untaint('nice string'), 'nice string';
32 is $u->untaint('bad *?&^$! string'), 'bad ';
33 is $u->untaint( q{100% relaxed&;''\"|*?!~<>^()[]{}$}, 1 ), '100% relaxed';
39 ($mu,$sd) = $u->mean_stdev();
43 ($mu,$sd) = $u->mean_stdev(42);
47 ($mu,$sd) = $u->mean_stdev(-1,0,1);
51 # file_date(), file_flavor(), date_format()
53 my $file = test_input_file('test.txt');
54 my $file2 = test_input_file('test 2.txt');
55 my $fdate = $u->file_date($file);
56 like $fdate , qr/\d{4}-\d{2}-\d{2}/, 'file_date()';
57 ok $u->file_flavor($file), 'unix (\n or 012 or ^J)';
59 my $date = $u->date_format();
60 like $date, qr/\d{4}-\d{2}-\d{2}/, 'date format';
61 my $date2 = $u->date_format('yyyy-mmm-dd', $date);
62 like $date2 , qr/\d{4}-[a-z]{3}-\d{2}/i, 'date format';
63 my $date3 = $u->date_format('mdhms');
64 like $date3 , qr/[a-z]{3}\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}/, 'date format';
65 my $date4 = $u->date_format('d-m-y', '11/22/60');
66 like $date4 , qr/\d{1,2}-[a-z]{3}-\d{4}/i, 'date format';
67 my $date5 = $u->date_format('mdy', '1/5/01');
68 like $date5 , qr/[a-z]{3} \d{1,2}, \d{4}/i, 'date format';
70 # External executable-related functions.
72 my $exe = $u->find_exe('some-weird-thing-no-one-will-have');
75 # compress() and uncompress() using gzip.
77 my $gzip = $u->find_exe('gzip');
78 skip "gzip not found, skipping gzip tests", 12 unless $gzip;
81 # test compression/decompression of a simple file
82 my $zfile = $u->compress($file);
84 # In Windows, the folder separator '\' may brake
85 # the following qr{}, so change it to '/'
89 like $zfile, qr/$file.gz|tmp.bioperl.gz/;
91 if ($zfile =~ /tmp.bioperl.gz/) {
97 my $unzfile = $u->uncompress($zfile);
101 # test compression/decompression of a filename with spaces keeping the original intact
102 my $zfile2 = $file2.'.gz';
103 my $return = $u->compress(-file => $file2, -outfile => $zfile2, -tmp => 1);
107 unlink $file2 or die "Problem deleting $file2: $!\n";
108 $return = $u->uncompress(-file => $zfile2, -outfile => $file2, -tmp => 1);
112 unlink $zfile2 or die "Problem deleting $zfile2: $!\n";
117 # $u->send_mail(-to=>'sac@bioperl.org', # <--- your address here!
118 # -subj=>'Root-Utilities.t',
119 # -msg=>'Hey, your send_mail() method works!');