]> git.donarmstrong.com Git - biopieces.git/blob - bp_test/lib/test.sh
68b83defc2beef6543b6ee6d2977c6ecd80ffb18
[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_ruby
121 {
122     echo -n "Testing Ruby version ... "
123
124     if error=$( ruby -e 'raise "Ruby version 1.9 reqauired--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then
125         echo_green "OK"
126     else
127         echo $error | sed "s/.*: //"
128         echo_red "FAIL"
129         exit
130     fi  
131 }