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