aboutsummaryrefslogtreecommitdiffstats
path: root/res/test-ck
blob: 647f43dc431b9bc9585a5a186bf4bbb31da7e234 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash

BIN=$(realpath @CMAKE_BINARY_DIR@) # solve symlink problems
TEST_LOCATION=$(realpath @PROJECT_TESTING_GROUNDS@)

# used in regression tests
function running {
    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 > /dev/null &
    wait $!

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

function clear_tests {
    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 {
    echo -e "Regression Tests:"
    echo -e "~~~~~~~~~~~~~~~~~"
    DIR=@BIN_TEST_DIR@
    COUNT=1
    TOTAL=$(ls $DIR | wc -l)
    for i in $(ls $DIR); do
        ERROR="TEST "$i" FAILED:"
        PASS="=> $i passed\n"
        source $DIR/$i
        wait $!
    done
}

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

function run {
    unit_tests
    regression_tests
}

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 "  -c, --clear\t\tremove test files"
    echo -e "             \t\t use if the tests crush unexpectedly"
    echo -e "  -h, --help, *\t\tprint this"
    exit
}

if [[ $# -gt 1 ]]; then
    print_help
fi

while [[ $# -gt 0 ]]
do
    key="$1"
    case $key in
        -h | --help)
            print_help
            ;;
        -c | --clear)
            clear_tests
            exit
            ;;
	-u | --unit)
	    unit_tests
	    exit
	    ;;
	-r | --regression)
	    regression_tests
	    exit
	    ;;
        *)    # unknown option
            print_help
            exit
            ;;
    esac
done

run