PCRE_CFLAGS are CPPFLAGS, actually.
[midnight-commander.git] / maint / mc-test
blob7cf40a1c1a429eea22340a5957265bbae6953804
1 #!/bin/sh
3 # Midnight Commander Test Suite
5 # (c) 2005 Roland Illig <roland.illig@gmx.de>
7 # The Midnight Commander is free software: you can redistribute it
8 # and/or modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation, either version 3 of the License,
10 # or (at your option) any later version.
12 # The Midnight Commander is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 set -efu
22 ### initialize environment ###
24 LC_CTYPE="C"; export LC_ALL
25 LC_COLLATE="C"; export LC_COLLATE
26 LC_MONETARY="C"; export LC_MONETARY
27 LC_NUMERIC="C"; export LC_NUMERIC
28 LC_TIME="C"; export LC_TIME
29 LC_MESSAGES="C"; export LC_MESSAGES
30 LC_ALL="C"; export LC_ALL
32 ### set default configuration ###
34 mc_nice_value="19"
35 mc_maxlines="10"
37 mc_basedir="/tmp/mc-current-build"
38 mc_srcdir="" # default: ${mc_basedir}/src
39 mc_builddir="" # default: ${mc_basedir}/build
40 mc_prefixdir="" # default: ${mc_basedir}/installed
41 mc_logdir="" # default: ${mc_basedir}/logs
43 mc_cvs_rsh="ssh"
44 mc_cvs_repository=":pserver:anonymous:@cvs.savannah.gnu.org:/sources/mc"
45 mc_cvs_module="mc"
46 mc_cvs_tag="HEAD"
48 mc_configure_args_pre="--enable-maintainer-mode"
49 mc_configure_args_post=""
51 mc_make="make"
52 mc_make_flags=""
54 mc_cpp="" # default: ${mc_cc} -E
55 mc_cppflags=""
57 mc_cc="cc"
58 mc_cflags=""
60 mc_ldflags=""
62 mc_tests="plain charset no_charset vfs no_vfs samba "\
63 "no_samba ext2undel no_ext2undel slang ncurses maintainer "\
64 "no_maintainer i18n no_i18n no_features all_features"
66 do_clean_basedir=no
67 do_download=auto
68 do_autoconf=auto
69 do_clean_workdir=no
70 do_configure=auto
71 do_make_clean=no
72 do_make_all=yes
73 do_make_check=yes
74 do_make_install=yes
76 ### command line parsing ###
78 usage() {
79 cat >&2 <<EOF
80 usage: `basename $0` [options ...] [var=value...] [<testname ...>]
82 -config <file> load the configuration from <file>
83 -basedir <dir> set the base directory
84 -srcdir <dir> select the directory where the source code is
85 read from or will be downloaded to from CVS
87 -[dont-]download checkout or update from CVS (default: ${do_download})
88 -[dont-]autoconf generate the configure script (default: ${do_autoconf})
89 -[dont-]cleanwork recreate the build directory (default: ${do_clean_workdir})
90 -[dont-]configure run configure (default: ${do_configure})
91 -[dont-]clean make clean (default: ${do_make_clean})
92 -[dont-]build make all (default: ${do_make_all})
93 -[dont-]check make check (default: ${do_make_check})
94 -[dont-]install make install (default: ${do_make_install})
96 -fast only do what's necessary
97 -nice <n> set the nice(1) value (default: ${mc_nice_value})
98 -maxlines <n> the maximum number of lines for each phase (default: ${mc_maxlines})
99 -quiet disable most status messages (default: ${quiet:-"no"}${quiet+"yes"})
101 exit 1
104 eval_arg() {
105 _shquote_var=`echo x"$1" | sed -e '1s,^x\([^=]*\)=.*,\1,' -e '1q'`
106 _shquote_val=`echo x"$1" | sed '1s,^x[^=]*=\(.*\),\1,'`
107 _shquote_qval=`echo x"${_shquote_val}" | sed -e '1s,.,,' -e s,\',\'\\\\\\\\\'\',g`
108 eval "${_shquote_var}='${_shquote_qval}'"
111 while test $# -ne 0; do
112 case "$1" in
113 -config) shift; case "$1" in /*) . "$1";; *) . "./$1";; esac; shift;;
114 -basedir) shift; mc_basedir="$1"; shift;;
115 -cvs-repository) shift; mc_cvs_repository="$1"; shift;;
116 -cvs-module) shift; mc_cvs_module="$1"; shift;;
117 -srcdir) shift; mc_srcdir="$1"; shift;;
119 -cleanup) shift; do_clean_basedir=yes;;
121 -download) shift; do_download=yes;;
122 -dont-download) shift; do_download=no;;
123 -autoconf) shift; do_autoconf=yes;;
124 -dont-autoconf) shift; do_autoconf=no;;
125 -cleanwork) shift; do_clean_workdir=yes;;
126 -dont-cleanwork) shift; do_clean_workdir=no;;
127 -configure) shift; do_configure=yes;;
128 -dont-configure) shift; do_configure=no;;
129 -clean) shift; do_make_clean=yes;;
130 -dont-clean) shift; do_make_clean=no;;
131 -build) shift; do_make_all=yes;;
132 -dont-build) shift; do_make_all=no;;
133 -check) shift; do_make_check=yes;;
134 -dont-check) shift; do_make_check=no;;
135 -install) shift; do_make_install=yes;;
136 -dont-install) shift; do_make_install=no;;
138 -fast) shift; do_clean_workdir=no
139 do_autoconf=no
140 do_configure=no
141 do_make_clean=no
142 do_make_all=yes;;
143 -nice) shift; mc_nice_value="$1"; shift;;
144 -maxlines) shift; mc_maxlines="$1"; shift;;
145 -quiet) shift; quiet="yes";;
146 mc_*=*) eval_arg "$1"; shift;;
148 --) shift; break;;
149 -) shift; break;;
150 -*) usage;;
151 *) break;;
152 esac
153 done
156 ### Initialization ###
158 renice ${mc_nice_value} $$ 1>/dev/null 2>&1 || true
160 ### Tools ###
162 configure_args_enable_all="--enable-largefile --enable-nls "\
163 "--enable-background --enable-charset "\
164 "--with-mmap --with-included-gettext --with-x "\
165 "--enable-vfs --enable-vfs-smb --enable-vfs-undelfs "\
166 "--with-gpm-mouse --with-subshell --with-edit"
167 configure_args_disable_all="--disable-largefile --disable-nls "\
168 "--disable-background --disable-charset "\
169 "--without-mmap --without-included-gettext --without-x "\
170 "--disable-vfs --disable-vfs-smb --disable-vfs-undelfs "\
171 "--without-gpm-mouse --without-subshell --without-edit"
173 errors=0
174 warnings=0
176 # feature tests
177 if test x"`echo -n`" = x"-n"; then
178 echo_n="echo"
179 echo_cont=" " # a tab character
180 else
181 echo_n="echo -n"
182 echo_cont=" "
186 show_file() {
187 if test -f "$1"; then
188 echo ""
189 sed -e "${mc_maxlines}s,.*,(more lines follow ...)," -e "${mc_maxlines}q" "$1"
190 echo ""
192 return 0
195 phase_start() {
196 ${echo_n} "[`date`] $1"
197 return 0
200 phase_ok() {
201 echo "${echo_cont}ok"
202 return 0
205 phase_warnings() {
206 echo "${echo_cont}WARNINGS"
207 warnings=`expr $warnings + 1`
208 if test $# -gt 0; then show_file "$1"; fi
209 return 0
212 phase_ok_or_warnings() {
213 fsize=`wc -c < "$1"`
215 { test -n "${fsize}" && test ${fsize} -eq 0
216 } && phase_ok || phase_warnings "$1"
217 return 0
220 phase_failed() {
221 echo "${echo_cont}FAILED"
222 failed=yes
223 errors=`expr $errors + 1`
224 if test $# -gt 0; then show_file "$1"; fi
225 return 0
228 setup_preconf_env=\
229 "out=\"\${mc_logdir}/\${test_phase}.out\";"\
230 "err=\"\${mc_logdir}/\${test_phase}.err\";"
232 preconf_download() {
233 test_phase="download"
234 eval "${setup_preconf_env}"
236 if test ${do_download} = no && test -d "${mc_srcdir}/CVS"; then
237 return 0
240 mkdir -p "${mc_logdir}"
242 if test -d "${mc_srcdir}/CVS"; then
243 phase_start "updating CVS copy ..."
244 ( cd "${mc_srcdir}" \
245 && env CVS_RSH=${mc_cvs_rsh} cvs update -r "${mc_cvs_tag}" -dP
246 ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
247 else
248 phase_start "getting fresh CVS copy ..."
249 ( mkdir -p "${mc_srcdir}" \
250 && cd "${mc_srcdir}/.." \
251 && env CVS_RSH=${mc_cvs_rsh} cvs -d "${mc_cvs_repository}" checkout -P -r "${mc_cvs_tag}" -d "`basename "${mc_srcdir}"`" "${mc_cvs_module}"
252 ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
256 preconf_autoconf() {
257 test_phase="autoconf"
258 eval "${setup_preconf_env}"
260 if test ${do_autoconf} != yes && test -f "${mc_srcdir}/configure"; then
261 return 0
264 mkdir -p "${mc_logdir}"
266 phase_start "creating ./configure script ..."
267 { cd "${mc_srcdir}" \
268 && echo "#!/bin/sh" > ./configure.mc \
269 && chmod +x ./configure.mc \
270 && ${SHELL-"/bin/sh"} ./autogen.sh
271 } 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
274 setup_testenv=\
275 "test_srcdir=\"\${mc_srcdir}\";"\
276 "test_workdir=\"\${mc_builddir}/\${testname}\";"\
277 "test_prefix=\"\${mc_prefixdir}/\${testname}\";"\
278 "test_logdir=\"\${mc_logdir}/\${testname}\";"\
279 "out=\"\${test_logdir}/\${test_phase}.out\";"\
280 "err=\"\${test_logdir}/\${test_phase}.err\";"
282 confbuild_cleanwork() {
283 test_phase="cleanwork"
284 eval "${setup_testenv}"
286 if test ${do_clean_workdir} = no || test ! -d "${test_workdir}"; then
287 return 0
290 mkdir -p "${test_logdir}"
292 phase_start "cleaning directory for ${testname} ..."
293 { rm -rf "${test_workdir}"
294 } 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
297 confbuild_configure() {
298 test_phase="configure"
299 eval "${setup_testenv}"
301 if test ${do_configure} != yes && test -f "${test_workdir}/Makefile"; then
302 return 0
305 mkdir -p "${test_logdir}"
307 phase_start "configuring for ${testname} ..."
308 ( set -e
309 mkdir -p "${test_workdir}"
310 cd "${test_workdir}"
311 cmd="${test_srcdir}/configure"
312 cmd="${cmd} --prefix=\"${test_prefix}\""
313 cmd="${cmd} MAKE=\"${mc_make}\""
314 cmd="${cmd} CPP=\"${mc_cpp}\""
315 cmd="${cmd} CPPFLAGS=\"${mc_cppflags}\""
316 cmd="${cmd} CC=\"${mc_cc}\""
317 cmd="${cmd} CFLAGS=\"${mc_cflags}\""
318 cmd="${cmd} LDFLAGS=\"${mc_ldflags}\""
319 cmd="${cmd} ${mc_configure_args_pre}"
320 cmd="${cmd} ${configure_args}"
321 cmd="${cmd} ${mc_configure_args_post}"
322 echo "running $cmd"
323 eval "$cmd"
324 ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
327 confbuild_make() {
328 make_target="$1"
329 test_phase="make_${make_target}"
330 eval "${setup_testenv}"
332 if eval "test \${do_make_${make_target}} = no"; then
333 return 0
336 mkdir -p "${test_logdir}"
338 phase_start "running \"make ${make_target}\" for ${testname} ..."
339 ( cd "${test_workdir}" \
340 && eval "${mc_make} ${mc_make_flags} ${make_target}"
341 ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
344 confbuild() {
345 failed=no
347 confbuild_cleanwork
348 if test ${failed} = yes; then return 0; fi
350 confbuild_configure
351 if test ${failed} = yes; then return 0; fi
353 confbuild_make "clean"
354 if test ${failed} = yes; then return 0; fi
356 confbuild_make "all"
357 if test ${failed} = yes; then return 0; fi
359 confbuild_make "check"
360 if test ${failed} = yes; then return 0; fi
362 confbuild_make "install"
363 if test ${failed} = yes; then return 0; fi
367 test_plain() {
368 testname="plain"
369 configure_args=""
370 confbuild
373 test_charset() {
374 testname="charset"
375 configure_args="--enable-charset"
376 confbuild
379 test_no_charset() {
380 testname="no_charset"
381 configure_args="--disable-charset"
382 confbuild
385 test_X11() {
386 testname="X11"
387 configure_args="--with-x"
388 confbuild
391 test_no_X11() {
392 testname="no_X11"
393 configure_args="--without-x"
394 confbuild
397 test_vfs() {
398 testname="vfs"
399 configure_args="--enable-vfs"
400 confbuild
403 test_no_vfs() {
404 testname="no_vfs"
405 configure_args="--disable-vfs"
406 confbuild
409 test_samba() {
410 testname="samba"
411 configure_args="--enable-vfs-smb"
412 confbuild
415 test_no_samba() {
416 testname="no_samba"
417 configure_args="--disable-vfs-smb"
418 confbuild
421 test_ext2undel() {
422 testname="ext2undel"
423 configure_args="--enable-vfs-undelfs"
424 confbuild
427 test_no_ext2undel() {
428 testname="no_ext2undel"
429 configure_args="--disable-vfs-undelfs"
430 confbuild
433 test_slang() {
434 testname="slang"
435 configure_args="--with-screen=slang"
436 confbuild
439 test_ncurses() {
440 testname="ncurses"
441 configure_args="--with-screen=ncurses"
442 confbuild
445 test_maintainer() {
446 testname="maintainer"
447 configure_args="--enable-maintainer-mode"
448 confbuild
451 test_no_maintainer() {
452 testname="no_maintainer"
453 configure_args="--disable-maintainer-mode"
454 confbuild
457 test_i18n() {
458 testname="i18n"
459 configure_args="--enable-nls"
460 confbuild
463 test_no_i18n() {
464 testname="no_i18n"
465 configure_args="--disable-nls"
466 confbuild
469 test_no_features() {
470 testname="no_features"
471 configure_args="${configure_args_disable_all}"
472 confbuild
475 test_all_features() {
476 testname="all_features"
477 configure_args="${configure_args_enable_all}"
478 confbuild
481 run_tests() {
482 failed=no
484 preconf_download
485 if test ${failed} = yes; then return 0; fi
487 preconf_autoconf
488 if test ${failed} = yes; then return 0; fi
490 for i in "$@"; do
491 if type test_"${i}" 2>/dev/null \
492 | grep "function" 1>/dev/null 2>&1; then
493 eval "test_${i}"
494 else
495 echo "[`date`] test \"$i\" not found." 1>&2
496 errors=`expr $errors + 1`
498 done
501 if test -z "${mc_srcdir}"; then mc_srcdir="${mc_basedir}/src"; fi
502 if test -z "${mc_prefixdir}"; then mc_prefixdir="${mc_basedir}/installed"; fi
503 if test -z "${mc_builddir}"; then mc_builddir="${mc_basedir}/build"; fi
504 if test -z "${mc_logdir}"; then mc_logdir="${mc_basedir}/logs"; fi
505 if test -z "${mc_cpp}"; then mc_cpp="${mc_cc} -E"; fi
507 if test ${do_clean_basedir} = yes; then
508 phase_start "cleaning up everything ..."
509 { rm -rf "${mc_basedir}"
510 } && phase_ok || phase_failed
511 else
512 if test $# -gt 0; then
513 mc_tests="$@"
515 run_tests $mc_tests
518 if test ${errors} -ne 0 || test ${warnings} -ne 0; then
519 echo "[`date`] finished with ${errors} errors and ${warnings} warnings."
520 else
521 echo "[`date`] finished successfully."
523 exit ${errors}