X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_test%2Flib%2Ftest.sh;h=7ce41900d12068649fdf92320f6110f779c17398;hb=9bd8d05f53c3908907b379025ed64b90d26ddd5e;hp=54ded2a7f1cb34aa8fcfbd184dffa96653bba30f;hpb=b519aaee3bd06edaee19afe101f6f1a489927e1f;p=biopieces.git diff --git a/bp_test/lib/test.sh b/bp_test/lib/test.sh index 54ded2a..7ce4190 100755 --- a/bp_test/lib/test.sh +++ b/bp_test/lib/test.sh @@ -3,21 +3,24 @@ bp=`basename $0 | sed s/^test_//` in="$BP_DIR/bp_test/in/$bp.in" out="$BP_DIR/bp_test/out/$bp.out" -tmp="$BP_TMP/$bp.out" -tmp_dir="$BP_TMP/test_tmp" -log_file="$BP_TMP/test.log" +tmp="$BP_TMP/$USER.$bp.out" +tmp_dir="$BP_TMP/$USER.test_tmp" +log_file="$BP_TMP/$USER.test.log" +# Function to run a given command (verbose). function run { local command=$1 msg="${command/$BP_DIR/\$BP_DIR}" msg="${msg//$BP_TMP/\$BP_TMP}" + msg="${msg/$BP_DIR/\$BP_DIR}" echo -n "Testing $msg ... " eval $command > /dev/null 2>&1 } +# Function to run a given command (quiet). function run_quiet { local command=$1 @@ -25,6 +28,8 @@ function run_quiet eval $command > /dev/null 2>&1 } +# Function to assert no difference between +# two given files. function assert_no_diff { local src=$1 @@ -53,6 +58,38 @@ function assert_no_diff fi } +# Function to assert no difference between the content +# of two given direcories (recursive). +function assert_no_diff_dir +{ + local src_dir=$1 + local dst_dir=$2 + + if [ ! -d $src_dir ]; then + echo_red "FAIL" + log "FAIL" + return + fi + + if [ ! -d $dst_dir ]; then + echo_red "FAIL" + log "FAIL" + return + fi + + local src_cksum=`find $src_dir -type f | grep -v "\.svn" | sort | xargs cat | cksum` + local dst_cksum=`find $dst_dir -type f | grep -v "\.svn" | sort | xargs cat | cksum` + + if [ "$src_cksum" == "$dst_cksum" ]; then + echo_green "OK" + log "OK" + else + echo_red "FAIL" + log "FAIL" + fi +} + +# Function to assert that all given files do exists. function assert_files_exists { error=0 @@ -72,6 +109,7 @@ function assert_files_exists fi } +# Function to output a given message to the log file. function log { local msg=$1 @@ -79,6 +117,7 @@ function log echo "$msg" >> $log_file } +# Function that renders a given message in ASCII green. function echo_green { local msg=$1 @@ -86,6 +125,7 @@ function echo_green echo -e "\033[32;38m$msg\033[0m" } +# Function that renders a given message in ASCII yellow. function echo_yellow { local msg=$1 @@ -93,6 +133,7 @@ function echo_yellow echo -e "\033[33;38m$msg\033[0m" } +# Function that renders a given message in ASCII red. function echo_red { local msg=$1 @@ -100,6 +141,7 @@ function echo_red echo -e "\033[31;38m$msg\033[0m" } +# Function to clean the temporary file. function clean { if [ -f "$tmp" ]; then @@ -107,12 +149,14 @@ function clean fi } +# Function to test if the required version of Perl is installed. function test_perl { echo -n "Testing Perl version ... " if error=$( perl -e 'use 5.8.0;' 2>&1 ); then echo_green "OK" + log "OK" else echo $error | sed "s/, stopped.*//" echo_red "FAIL" @@ -120,11 +164,12 @@ function test_perl fi } +# Function to test if a given Perl module is installed. function test_perl_module { local module=$1 - echo -n "Checking required Perl module - \"$module\": " + echo -n "Testing required Perl module - \"$module\": " if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then echo_red "FAIL" @@ -132,15 +177,18 @@ function test_perl_module exit else echo_green "OK" + log "OK" fi } +# Function to test if the required version of Ruby is installed. function test_ruby { echo -n "Testing Ruby version ... " if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then echo_green "OK" + log "OK" else echo $error | sed "s/.*: //" echo_red "FAIL" @@ -148,14 +196,16 @@ function test_ruby fi } +# Function to test if a given Ruby gem is installed. function test_ruby_gem { local gem=$1 - echo -n "Checking required Ruby gem - \"$gem\": " + echo -n "Testing required Ruby gem - \"$gem\": " if error=$( gem list --local | grep $gem ); then echo_green "OK" + log "OK" else echo_red "FAIL" echo " Try: gem install $gem" @@ -163,3 +213,18 @@ function test_ruby_gem fi } +# Function to test is a given auxillary program is in $PATH. +function test_aux_program +{ + local program=$1 + + echo -n "Testing auxiliary program - \"$program\": " + + if command -v $program >/dev/null; then + echo_green "OK" + log "OK" + else + echo_yellow "WARNING" + log "WARNING" + fi +}