src/tests.sh

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
#!/bin/sh

showfiles()
{
    if ! darcs show files > /dev/null 2>&1; then
	ls *.$1 2> /dev/null | sed 's/\(.*\)/	\1 \\/g'
    else
	ROOT=`darcs show repo | grep Root | awk '{print $2}'`
	DIR=`echo $PWD | sed "s|$ROOT|.|"`
	darcs show files | grep $DIR'/[^/]*\.'$1'$' | \
	    sed 's|'$DIR'/\(.*\)|	\1 \\|g'
    fi
}

# join lines delimited by \\n characters
singleline()
{
    sed -e ':a
N
$!ba
s/\\\n//g
'
}

echo "updating Makefile.tests"
# create symbolic links between pages and sources if necessary
for f in `showfiles '[ch]\.page'` \\; do
    if test "$f" != "\\"; then
	short=`echo $f | sed 's/\.\([ch]\)\.page/\.\1/'`
	if test ! -f $short; then
	    ln -s $f $short
	fi
    fi
done
(
    echo "# Automatically generated using 'make Makefile.tests'"
    echo "# DO NOT EDIT, edit 'Makefile' instead"
    DIR=`basename $PWD`
    echo "ALLTESTS = \\"
    (showfiles c
     showfiles 'c\.page' | sed 's/\.page / /g'
     grep '^[a-zA-Z_0-9-]*\.*tst[ ]*:' Makefile | \
	 sed -n 's/\(^[a-zA-Z_0-9-]*\)\.*tst[ ]*:.*/	\1.c \\/p'
    ) | sort | uniq
    echo ""
    echo "plots: \\"
    showfiles plot | sed 's/\(.*\)\.plot/\1\/plot.png/g'
    echo ""
    echo "TESTS = \\"
    singleline < Makefile | 		                   \
	grep '^check:' | tr ' ' '\n' |                     \
	sed -n 's/[ 	]*\([a-zA-Z_0-9-]*\..tst\)[ 	]*/\1/p' |  \
	sed 's/\(.*\)\..tst/	\1.c \\/g'
    singleline < Makefile | 		                   \
	grep -v '^check:' | grep '^[^.]*:.*' | tr ' ' '\n' |     \
	sed -n 's/[ 	]*\([a-zA-Z_0-9-]*\.tst\)[ 	]*/\1/p' |    \
	sed 's/\(.*\)\.tst/	\1.c \\/g'
    echo ""
    echo "SPECIAL_TESTS = \\"
    sed -n 's/.*:[ 	]*\([a-zA-Z_0-9-]*\.ctst\)/\1/p' Makefile | \
	sort | uniq | sed 's/\(.*\)/	\1 \\/g'
    echo ""
    echo "ALLPAGES = \\"
    showfiles '[ch]\.page'
    echo ""
) > Makefile.tests

rm -f Makefile.deps