aboutsummaryrefslogblamecommitdiffstats
path: root/res/test-ck
blob: 5e33bb94dbaed511e623cffbb58a59ba399f70d4 (plain) (tree)
1
2
3
4
5
6
7
8
9

           

                                                           
   


         
                          
                  

                         

                                     

 
                          




                              
                                                                                


           

                              
                                                  


                         
                         


      



                      
                      

              





                         
                     

                         



                           




                                       
                               
                      
           




                                            



               





                       
              









                                 

 

                           
                                                
                      

                                                               
                                                                       
                                                
                                                                   
                                                    



                                           



                    
                    


                       
                    

                  
              

                      
                   


                 
                          

                   
              




                        
                      
              
         
    

   
#!/bin/bash

BIN=$(realpath @CMAKE_BINARY_DIR@) # solve symlink problems
TEST_LOCATION=$(realpath @PROJECT_TESTING_GROUNDS@)
V=3
FILTER=""
REG=1
UNIT=1
# used in regression tests
function running {
    # open devnul in fd 3
    exec 3<> /dev/null
    echo "[$COUNT/$TOTAL] testing $1"
    ((++COUNT))
}

# used in regression tests
function init {
    running $1
    mkdir -p $TEST_LOCATION/vc
    mkdir $TEST_LOCATION/sec

    exec $BIN/ck -c $BIN init $TEST_LOCATION/vc $TEST_LOCATION/sec > /dev/null &
    wait $!
}

function add_config {
    echo -e "test $2\n$3" > $2
    exec $BIN/ck -c $BIN -a $1 $2 $4 > /dev/null &
    wait $!

    if [ $? -ne 0 ]; then
        err "ck crashed."
    fi
}

function set_verbose {
    V=1;
}

function clear_tests {
    # close fd
    exec 3>&-
    rm $BIN/ckrc
    rm $BIN/ckdb
    rm $BIN/test*.conf
    rm -rf $TEST_LOCATION
}

function unit_tests {
    echo -e "Unit Tests:"
    echo -e "~~~~~~~~~~~"
    ./ck-test
}

function regression_tests {
    FL=""
    if [ "$FILTER" != "" ]; then
        FL=" (Using filter: *$FILTER*)"
    fi
    echo -e "Regression Tests:$FL"
    echo -e "~~~~~~~~~~~~~~~~~"
    DIR=@BIN_TEST_DIR@
    COUNT=1
    TOTAL=$(ls $DIR/*$FILTER* | wc -l)
    for i in $(ls $DIR/*$FILTER*); do
        ERROR="TEST "`basename $i`" FAILED:"
        PASS="=> `basename $i` passed\n"
        source $i
        wait $!
    done
}

function err {
    echo -e "$ERROR $1"
    clear_tests
    exit 1
}

function run {
    if [ $UNIT -eq 1 ]; then
        unit_tests
    fi

    if [ $REG -eq 1 ]; then
        regression_tests
    elif [ $REG -eq $UNIT ]; then
        unit_tests
        regression_tests
    fi
}

function print_help {
    echo -e "ck test suite"
    echo -e "use without flags to run all tests"
    echo -e "\nflags:"
    echo -e "  -u, --unit\t\trun only the unit tests"
    echo -e "  -r, --regression\trun only the regression tests"
    echo -e "  -f, --filter\trun regression test matching the argument"
    echo -e "  -c, --clear\t\tremove test files"
    echo -e "             \t\t use if the tests crush unexpectedly"
    echo -e "  -v, --verbose\t\tverbose test output"
    echo -e "  -h, --help, *\t\tprint this"
    exit
}

while [[ $# -gt 0 ]]
do
    key="$1"
    case $key in
       -c | --clear)
            clear_tests
            exit
            ;;
	-u | --unit)
	    REG=0;
	    shift
	    ;;
        -f | --filter)
            FILTER=$2;
	    UNIT=0;
            shift
            shift
            ;;
	-r | --regression)
	    UNIT=0;
	    shift
	    ;;
        -v | --verbose)
            set_verbose
            shift
            ;;
        -h | --help | *)
            print_help
            ;;
     esac
done

run