summaryrefslogtreecommitdiffabout
path: root/t/testsuite
blob: bd870ce16e0c247845d0d243b11e33a0a6ee755a (plain)
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
#! /bin/sh
# testsuite for runcap - run program and capture its output
# Copyright (C) 2017 Sergey Poznyakoff
#
# Runcap is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# Runcap is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Runcap. If not, see <http://www.gnu.org/licenses/>.

testdir=$(cd $(dirname $0); pwd)
progname=$(basename $0)

topworkdir=$(pwd)
workdir=$topworkdir/testsuite.dir
if [ ! -d $workdir ]; then
    mkdir $workdir
fi

cd $testdir
numfiles=$(ls -1 *.t 2>/dev/null| sed -n '$=')

if [ ${numfiles:-0} -eq 0 ]; then
    echo >&2 "$progname: no test files in $testdir"
    exit 2
fi    

printheader() {
    awk -v P=$numfiles 'NR==1 { num=$1; next }
                        NR==2 { printf("%0d: %s", num, $1); next }
                        { if (NF!=0) printf(" - %s", $0);
                          printf(": "); }' <<EOF
$1
$2
$3
EOF
}

PATH=$topworkdir:$PATH
echo $PATH
TC_EXPECT() {
    cat > exp$1
}
TC_TITLE() {
    :
}

numtests=0
numfail=0
cd $testdir
exec 3>$topworkdir/testsuite.log

if [ $# -gt 0 ]; then
    testlist=$(ls $*) || exit 1
else
    testlist=$(ls *.t)
fi    

for tc in $testlist
do
    cd $testdir
    tc=$(echo $tc|sed 's|\./||')
    # Skip if invalid name
    echo "$tc" | grep -q '[^a-zA-Z0-9._-]' && continue
    # Skip if not executable
    test -x $tc || continue

    cd $workdir
    
    dirname=${tc%%.t}
    if [ -d $dirname ]; then
	rm -rf $dirname/*
    else
	mkdir $dirname || continue
    fi
    cd $dirname	

    descr=$(sed -n '/TC_TITLE /s///p' $testdir/$tc)
    printheader $numtests $tc "$descr"
    ( . $testdir/$tc ) >out 2>err
    retcode=$?
    numtests=$(( $numtests + 1 ))
    cd $workdir

    exec 4>templog
    if [ $retcode -eq 77 ]; then
	echo "SKIP"
	continue
    fi
    if [ $retcode -ne 0 ]; then
	echo >&4 "# exit code: $retcode"
    fi
    
    test -r $dirname/expout || > $dirname/expout
    if ! cmp $dirname/expout $dirname/out 2>/dev/null >&2; then
        echo >&4 "# stdout diff"
        diff -pu $dirname/expout $dirname/out >&4
    fi
    test -r $dirname/experr || > $dirname/experr
    if ! cmp $dirname/experr $dirname/err 2>/dev/null >&2; then
        echo >&4 "# stderr diff"
        diff -pu $dirname/experr $dirname/err >&4
    fi

    if [ -s templog ]; then
	echo "FAIL"
	numfail=$(( $numfail + 1 ))
	echo >&3 "# Testcase $tc FAILED"
	cat  >&3 templog
	echo >&3 "# Content:"
	cat  >&3 $testdir/$tc
	echo >&3 "# stdout:"
	cat  >&3 $dirname/out
	echo >&3 "# stderr:"
	cat  >&3 $dirname/err
    else	
	echo "OK"
	rm -rf $dirname
    fi
    rm templog
done    

cd $topworkdir

if [ $numfail -ne 0 ]; then
    echo >&2 "# $numfail out of $numtests tests failed"
    echo >&2 "# See testsuite.log for more info"
    exit 1
else
    rmdir $workdir 2>/dev/null
    rm testsuite.log
fi

Return to:

Send suggestions and report system problems to the System administrator.