File: check_checkmk

package info (click to toggle)
check 0.15.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,404 kB
  • sloc: ansic: 11,759; sh: 5,258; makefile: 334
file content (143 lines) | stat: -rwxr-xr-x 3,327 bytes parent folder | download | duplicates (3)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env sh

TESTS_RUN=0
TESTS_PASSED=0
TESTS_FAILED=0

TEST_DIRS='empty_input pass_thru single_test_line basic_complete'
TEST_DIRS="$TEST_DIRS multiple_everything between_the_lines"
TEST_DIRS="$TEST_DIRS repeated_suites repeated_tcases repeated_tests"
TEST_DIRS="$TEST_DIRS not_really_repeated tcase_implied_repeat"
TEST_DIRS="$TEST_DIRS case_insensitive_pp trailing_ws non_word_chars"
TEST_DIRS="$TEST_DIRS test_chars num_start_test_name"
TEST_DIRS="$TEST_DIRS no_args clean_mode declarations test_after_main_pre"
TEST_DIRS="$TEST_DIRS main_pre_multiple main_post main_pre_after_post"
TEST_DIRS="$TEST_DIRS test_after_main_post main_post_multiple ucn"
TEST_DIRS="$TEST_DIRS invalid_ucn argument_ws repeated_argument_tests"

check_dir() {
    status=0

    checkmkdir=$PWD
    outdir="test.out/$1"
    testdir="$srcdir/test/$1"

    if ! mkdir -p "$outdir"
    then
        echo "Couldn't make path \"$outdir\"!"
    fi
    outdir=$(cd "$outdir" && pwd)

    if ! cd "$testdir"
    then
        echo "Couldn't chdir to \"$testdir\"!"
    fi

    # set up expected input/output file names
    infname=in
    outfname="$outdir/output"
    errfname="$outdir/err"
    diffname="$outdir/diff"
    errdiffname="$outdir/err-diff"
    CHECKMK="$checkmkdir/checkmk"
    checkmk_cmd='"$CHECKMK" "$infname" > "$outfname" 2>"$errfname"'

    rm -f "$outfname" "$errfname" "$diffname" "$errdiffname"

    # source local versions, if available.
    [ -r ./cmd ] && . ./cmd

    # Check output.
    eval "$checkmk_cmd"
    ckstat=$?

    if ! diff -c "x_output" "$outfname" > "$diffname"
    then
        echo "Unexpected output differences:"
        cat "$diffname"
        status=1
    fi

    # Check stderr.
    if [ -s x_err ]
    then
        if ! diff -c "x_err" "$errfname" > "$errdiffname"
        then
            echo "Unexpected error differences:"
            cat "$errdiffname"
            status=1
        fi
    elif [ -s err ]
    then
        echo "Unexpected text from standard error:"
        echo "------------------------------------"
        cat "$errfname"
        echo "------------------------------------"
        status=1
    fi

    # Check status.
    xstat=0
    if [ -e "x_exit" ]
    then
        xstat=`cat x_exit`
    elif [ -s "x_err" ]
    then
        xstat=1
    fi

    if [ $xstat != $ckstat ]
    then
        echo "Expected exit status of $xstat, but got $ckstat."
        status=1
    fi

    return $status
}

pass_dir() {
    echo "Test $1 passed."
    TESTS_PASSED=$(($TESTS_PASSED+1))
}

fail_dir() {
    echo "Test $1 FAILED."
    TESTS_FAILED=$(($TESTS_FAILED+1))
}

echo "These are the tests for the checkmk program."
echo
echo "===================="
echo "   Test Run Start"
echo "===================="
echo

for dir in $TEST_DIRS
do
    echo "Running test $dir..."
    if ( check_dir $dir )
    then
        pass_dir $dir
    else
        fail_dir $dir
    fi
    TESTS_RUN=$(($TESTS_RUN+1))
    echo
done

echo "===================="
echo " Test Run Complete"
echo "===================="
echo "Total:  $TESTS_RUN"
echo "Passed: $TESTS_PASSED"
echo "Failed: $TESTS_FAILED"

if [ "$TESTS_FAILED" -gt 0 ]
then
    echo
    echo "****************************************"
    echo "          TEST RUN FAILED!!!!"
    echo "****************************************"
    exit 1;
fi
echo