t/*: remove "use lib '.'" and t/lib/Error.pm
[bioperl-live.git] / t / Root / Utilities.t
blob0406dc5ee9916fd2c835e5a339ad3486b7239eaf
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
5 use strict;
7 BEGIN {
8     use Bio::Root::Test;
10     test_begin(-tests => 56);
12     use_ok('Bio::Root::Utilities');
15 # Object creation
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);
22 for my $i (1 .. 12) {
23   is $u->month2num($month[$i]), $i;
24   is $u->num2month($i), $month[$i];
27 # untaint()
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';
34 # mean_stdev()
36 my($mu,$sd);
38 ($mu,$sd) = $u->mean_stdev();
39 is $mu, undef;
40 is $sd, undef;
42 ($mu,$sd) = $u->mean_stdev(42);
43 is $mu, 42;
44 is $sd, undef;
46 ($mu,$sd) = $u->mean_stdev(-1,0,1);
47 is $mu, 0;
48 is $sd, 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');
72 ok ! defined $exe ;
74 # compress() and uncompress() using gzip.
75 SKIP: {
76     my $gzip = $u->find_exe('gzip');
77     skip "gzip not found, skipping gzip tests", 12 unless $gzip;
78     ok -x $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 '/'
85     $zfile =~ s'\\'/'g;
86     $file  =~ s'\\'/'g;
88     like $zfile, qr/$file.gz|tmp.bioperl.gz/;
89     ok -s $zfile;
90     if ($zfile =~ /tmp.bioperl.gz/) {
91         ok -e $file;
92     }
93     else {
94         ok ! -e $file;
95     }
96     my $unzfile = $u->uncompress($zfile);
97     ok ! -e $zfile;
98     ok -e $file;
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);
103     is $return, $zfile2;
104     ok -e $zfile2;
105     ok -e $file2;
106     unlink $file2 or die "Problem deleting $file2: $!\n";
107     $return = $u->uncompress(-file => $zfile2, -outfile => $file2, -tmp => 1);
108     is $return, $file2;
109     ok -e $file2;
110     ok -e $zfile2;
111     unlink $zfile2 or die "Problem deleting $zfile2: $!\n";
114 # send_mail()
116 # $u->send_mail(-to=>'sac@bioperl.org',  # <--- your address here!
117 #               -subj=>'Root-Utilities.t',
118 #               -msg=>'Hey, your send_mail() method works!');