]> git.donarmstrong.com Git - biopieces.git/blob - bp_test/lib/test.sh
added perl module and ruby gem test to bp_test
[biopieces.git] / bp_test / lib / test.sh
1 #!/bin/bash
2
3 bp=`basename $0 | sed s/^test_//`
4 in="$BP_DIR/bp_test/in/$bp.in"
5 out="$BP_DIR/bp_test/out/$bp.out"
6 tmp="$BP_TMP/$bp.out"
7 tmp_dir="$BP_TMP/test_tmp"
8 log_file="$BP_TMP/test.log"
9
10 function run
11 {
12     local command=$1
13
14     echo -n "Testing $command ... "
15     eval $command > /dev/null 2>&1
16 }
17
18 function run_quiet
19 {
20     local command=$1
21
22     eval $command > /dev/null 2>&1
23 }
24
25 function assert_no_diff
26 {
27     local src=$1
28     local dst=$2
29
30     if [ ! -f $src ]; then
31         echo_red "FAIL"
32         log "FAIL"
33         return
34     fi
35
36     if [ ! -f $dst ]; then
37         echo_red "FAIL"
38         log "FAIL"
39         return
40     fi
41
42     local diff=`diff -q $src $dst`
43      
44     if [ "$diff" != "" ]; then
45         echo_red "FAIL"
46         log "FAIL"
47     else     
48         echo_green "OK"
49         log "OK"
50     fi     
51 }
52
53 function assert_files_exists
54 {
55     error=0
56
57     for arg in "$@"; do
58         if [ ! -f $arg ]; then
59             error=1
60         fi
61     done
62
63     if [ $error = 1 ]; then
64         echo_red "FAIL"
65         log "FAIL"
66     else
67         echo_green "OK"
68         log "OK"
69     fi
70 }
71
72 function log
73 {
74     local msg=$1
75
76     echo "$msg" >> $log_file
77 }
78
79 function echo_green
80 {
81     local msg=$1
82
83     echo -e "\033[32;38m$msg\033[0m"
84 }
85
86 function echo_yellow
87 {
88     local msg=$1
89
90     echo -e "\033[33;38m$msg\033[0m"
91 }
92
93 function echo_red
94 {
95     local msg=$1
96
97     echo -e "\033[31;38m$msg\033[0m"
98 }
99
100 function clean
101 {
102     if [ -f "$tmp" ]; then
103         rm "$tmp"
104     fi
105 }
106
107 function test_perl
108 {
109     echo -n "Testing Perl version ... "
110
111     if error=$( perl -e 'use 5.8.0;' 2>&1 ); then
112         echo_green "OK"
113     else
114         echo $error | sed "s/, stopped.*//"
115         echo_red "FAIL"
116         exit
117     fi  
118 }
119
120 function test_perl_module
121 {
122     local module=$1
123
124     echo -n "Checking required Perl module - \"$module\": "
125
126     if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then
127         echo_red "FAIL"
128         echo "   Try: perl -MCPAN -e 'install $module'"
129         exit
130     else
131         echo_green "OK"
132     fi
133 }
134
135 function test_ruby
136 {
137     echo -n "Testing Ruby version ... "
138
139     if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then
140         echo_green "OK"
141     else
142         echo $error | sed "s/.*: //"
143         echo_red "FAIL"
144         exit
145     fi  
146 }
147
148 function test_ruby_gem
149 {
150     local gem=$1
151
152     echo -n "Checking required Ruby gem - \"$gem\": "
153
154     if error=$( gem list --local | grep $gem ); then
155         echo_green "OK"
156     else
157         echo_red "FAIL"
158         echo "   Try: gem install $gem"
159         exit
160     fi
161 }
162