]> git.donarmstrong.com Git - biopieces.git/blob - bp_test/lib/test.sh
shortened messages in test suite
[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     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     else
117         echo $error | sed "s/, stopped.*//"
118         echo_red "FAIL"
119         exit
120     fi  
121 }
122
123 function test_perl_module
124 {
125     local module=$1
126
127     echo -n "Checking required Perl module - \"$module\": "
128
129     if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then
130         echo_red "FAIL"
131         echo "   Try: perl -MCPAN -e 'install $module'"
132         exit
133     else
134         echo_green "OK"
135     fi
136 }
137
138 function test_ruby
139 {
140     echo -n "Testing Ruby version ... "
141
142     if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then
143         echo_green "OK"
144     else
145         echo $error | sed "s/.*: //"
146         echo_red "FAIL"
147         exit
148     fi  
149 }
150
151 function test_ruby_gem
152 {
153     local gem=$1
154
155     echo -n "Checking required Ruby gem - \"$gem\": "
156
157     if error=$( gem list --local | grep $gem ); then
158         echo_green "OK"
159     else
160         echo_red "FAIL"
161         echo "   Try: gem install $gem"
162         exit
163     fi
164 }
165