1[= autogen5 template sh=check.sh =]
2[=
3#
4#  This file contains the shell template to run tests on the fixes
5#
6=]#!/bin/sh
7
8set -e
9TESTDIR=tests
10TESTBASE=`cd $1;${PWDCMD-pwd}`
11
12[ -d ${TESTDIR} ] || mkdir ${TESTDIR}
13cd ${TESTDIR}
14TESTDIR=`${PWDCMD-pwd}`
15
16TARGET_MACHINE='*'
17DESTDIR=`${PWDCMD-pwd}`/res
18SRCDIR=`${PWDCMD-pwd}`/inc
19FIND_BASE='.'
20VERBOSE=[=` echo ${VERBOSE-1} `=]
21INPUT=`${PWDCMD-pwd}`
22ORIGDIR=${INPUT}
23
24export TARGET_MACHINE DESTDIR SRCDIR FIND_BASE VERBOSE INPUT ORIGDIR
25
26rm -rf ${DESTDIR} ${SRCDIR}
27mkdir ${DESTDIR} ${SRCDIR}
28(
29[=
30  (shellf
31    "for f in %s
32     do case $f in
33        */* ) echo $f | sed 's;/[^/]*$;;' ;;
34        esac
35     done | sort -u | \
36     while read g
37     do echo \"  mkdir \\${SRCDIR}/$g || mkdir -p \\${SRCDIR}/$g || exit 1\"
38     done" (join " " (stack "fix.files"))  ) =]
39) 2> /dev/null[= # suppress 'No such file or directory' messages =]
40cd inc
41[=
42(define sfile "")
43(define HACK  "")
44(define dfile "")              =][=
45
46FOR fix                        =][=
47
48  IF (> (count "test_text") 1) =][=
49    (set! HACK (string-upcase! (get "hackname")))
50    (set! sfile (if (exist? "files") (get "files[]") "testing.h"))
51    (set! dfile (string-append
52          (if (*==* sfile "/")
53              (shellf "echo \"%s\"|sed 's,/[^/]*,/,'" sfile )
54              "" )
55          (string-tr! (get "hackname") "_A-Z" "-a-z")
56    )           )              =][=
57
58    FOR test_text (for-from 1) =]
59cat >> [=(. sfile)=] <<_HACK_EOF_
60
61
62#if defined( [=(. HACK)=]_CHECK_[=(for-index)=] )
63[=test_text=]
64#endif  /* [=(. HACK)=]_CHECK_[=(for-index)=] */
65_HACK_EOF_
66echo [=(. sfile)=] | ../../fixincl
67mv -f [=(. sfile)=] [=(. dfile)=]-[=(for-index)=].h
68[ -f ${DESTDIR}/[=(. sfile)=] ] && [=#
69   =]mv ${DESTDIR}/[=(. sfile)=] ${DESTDIR}/[=(. dfile)=]-[=(for-index)=].h[=
70
71    ENDFOR  test_text =][=
72
73  ENDIF  multi-test   =][=
74
75ENDFOR  fix
76
77=][=
78
79FOR fix  =][=
80  (set! HACK (string-upcase! (get "hackname")))  =][=
81
82  IF (not (exist? "test_text")) =][=
83    (if (not (exist? "replace"))
84        (error (sprintf "include fix '%s' has no test text"
85                        (get "hackname") )) )
86         =][=
87  ELSE   =]
88cat >> [= (raw-shell-str (if (exist? "files") (get "files[0]") "testing.h"))
89         =] <<_HACK_EOF_
90
91
92#if defined( [=(. HACK)=]_CHECK )
93[=test_text=]
94#endif  /* [=(. HACK)=]_CHECK */
95_HACK_EOF_
96[=ENDIF =][=
97
98ENDFOR  fix
99
100=]
101
102export TEST_MODE=true
103find . -type f | sed 's;^\./;;' | sort | ../../fixincl
104cd ${DESTDIR}
105
106exitok=true
107
108find * -type f -print > ${TESTDIR}/LIST
109
110#  Special hack for sys/types.h:  the #define-d types for size_t,
111#  ptrdiff_t and wchar_t are different for each port.  Therefore,
112#  strip off the defined-to type so that the test results are the
113#  same for all platforms.
114#
115sed 's/\(#define __[A-Z_]*_TYPE__\).*/\1/' sys/types.h > XX
116mv -f XX sys/types.h
117
118#  The following subshell weirdness is for saving an exit
119#  status from within a while loop that reads input.  If you can
120#  think of a cleaner way, suggest away, please...
121#
122exitok=`
123exec < ${TESTDIR}/LIST
124while read f
125do
126  if [ ! -f ${TESTBASE}/$f ]
127  then
128    echo "Newly fixed header:  $f" >&2
129    exitok=false
130
131  elif cmp $f ${TESTBASE}/$f >&2
132  then
133    :
134
135  else
136    ${DIFF:-diff} -c $f ${TESTBASE}/$f >&2 || :
137    exitok=false
138  fi
139done
140echo $exitok`
141
142cd $TESTBASE
143
144find * -type f ! -name .DS_Store ! -name CVS ! -name .svn -print \
145> ${TESTDIR}/LIST
146
147exitok=`
148exec < ${TESTDIR}/LIST
149while read f
150do
151  if [ -s $f ] && [ ! -f ${DESTDIR}/$f ]
152  then
153    echo "Missing header fix:  $f" >&2
154    exitok=false
155  fi
156done
157echo $exitok`
158
159echo
160if $exitok
161then
162  cd ${TESTDIR}
163  rm -rf inc res LIST
164  cd ..
165  rmdir ${TESTDIR} > /dev/null 2>&1 || :
166  echo All fixinclude tests pass >&2
167else
168  echo There were fixinclude test FAILURES  >&2
169fi
170$exitok[=
171
172(if (defined? 'set-writable) (set-writable))
173
174=]
175