]> git.donarmstrong.com Git - biopieces.git/blob - bp_test/lib/test.sh
fd2566d0c029e0f9d1d1189b39b8792f0bd037de
[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_red
87 {
88     local msg=$1
89
90     echo -e "\033[31;38m$msg\033[0m"
91 }
92
93 function clean
94 {
95     if [ -f "$tmp" ]; then
96         rm "$tmp"
97     fi
98 }