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