doxygen: various warning fixes
[midnight-commander.git] / maint / mc-test
blobd3fea71a0395490c5fd39944d9a012c1bf3f056f
1 #!/bin/sh
3 # Midnight Commander Test Suite
5 # (c) 2005 Roland Illig <roland.illig@gmx.de>
7 # Licensed under the GPL 2.0
9 set -efu
11 ### initialize environment ###
13 LC_CTYPE="C"; export LC_ALL
14 LC_COLLATE="C"; export LC_COLLATE
15 LC_MONETARY="C"; export LC_MONETARY
16 LC_NUMERIC="C"; export LC_NUMERIC
17 LC_TIME="C"; export LC_TIME
18 LC_MESSAGES="C"; export LC_MESSAGES
19 LC_ALL="C"; export LC_ALL
21 ### set default configuration ###
23 mc_nice_value="19"
24 mc_maxlines="10"
26 mc_basedir="/tmp/mc-current-build"
27 mc_srcdir="" # default: ${mc_basedir}/src
28 mc_builddir="" # default: ${mc_basedir}/build
29 mc_prefixdir="" # default: ${mc_basedir}/installed
30 mc_logdir="" # default: ${mc_basedir}/logs
32 mc_cvs_rsh="ssh"
33 mc_cvs_repository=":pserver:anonymous:@cvs.savannah.gnu.org:/sources/mc"
34 mc_cvs_module="mc"
35 mc_cvs_tag="HEAD"
37 mc_configure_args_pre="--enable-maintainer-mode"
38 mc_configure_args_post=""
40 mc_make="make"
41 mc_make_flags=""
43 mc_cpp="" # default: ${mc_cc} -E
44 mc_cppflags=""
46 mc_cc="cc"
47 mc_cflags=""
49 mc_ldflags=""
51 mc_tests="plain glib12 charset no_charset vfs no_vfs mcfs no_mcfs samba "\
52 "no_samba ext2undel no_ext2undel slang ncurses maintainer "\
53 "no_maintainer i18n no_i18n no_features all_features"
55 do_clean_basedir=no
56 do_download=auto
57 do_autoconf=auto
58 do_clean_workdir=no
59 do_configure=auto
60 do_make_clean=no
61 do_make_all=yes
62 do_make_check=yes
63 do_make_install=yes
65 ### command line parsing ###
67 usage() {
68 cat >&2 <<EOF
69 usage: `basename $0` [options ...] [var=value...] [<testname ...>]
71 -config <file> load the configuration from <file>
72 -basedir <dir> set the base directory
73 -srcdir <dir> select the directory where the source code is
74 read from or will be downloaded to from CVS
76 -[dont-]download checkout or update from CVS (default: ${do_download})
77 -[dont-]autoconf generate the configure script (default: ${do_autoconf})
78 -[dont-]cleanwork recreate the build directory (default: ${do_clean_workdir})
79 -[dont-]configure run configure (default: ${do_configure})
80 -[dont-]clean make clean (default: ${do_make_clean})
81 -[dont-]build make all (default: ${do_make_all})
82 -[dont-]check make check (default: ${do_make_check})
83 -[dont-]install make install (default: ${do_make_install})
85 -fast only do what's necessary
86 -nice <n> set the nice(1) value (default: ${mc_nice_value})
87 -maxlines <n> the maximum number of lines for each phase (default: ${mc_maxlines})
88 -quiet disable most status messages (default: ${quiet:-"no"}${quiet+"yes"})
89 EOF
90 exit 1
93 eval_arg() {
94 _shquote_var=`echo x"$1" | sed -e '1s,^x\([^=]*\)=.*,\1,' -e '1q'`
95 _shquote_val=`echo x"$1" | sed '1s,^x[^=]*=\(.*\),\1,'`
96 _shquote_qval=`echo x"${_shquote_val}" | sed -e '1s,.,,' -e s,\',\'\\\\\\\\\'\',g`
97 eval "${_shquote_var}='${_shquote_qval}'"
100 while test $# -ne 0; do
101 case "$1" in
102 -config) shift; case "$1" in /*) . "$1";; *) . "./$1";; esac; shift;;
103 -basedir) shift; mc_basedir="$1"; shift;;
104 -cvs-repository) shift; mc_cvs_repository="$1"; shift;;
105 -cvs-module) shift; mc_cvs_module="$1"; shift;;
106 -srcdir) shift; mc_srcdir="$1"; shift;;
108 -cleanup) shift; do_clean_basedir=yes;;
110 -download) shift; do_download=yes;;
111 -dont-download) shift; do_download=no;;
112 -autoconf) shift; do_autoconf=yes;;
113 -dont-autoconf) shift; do_autoconf=no;;
114 -cleanwork) shift; do_clean_workdir=yes;;
115 -dont-cleanwork) shift; do_clean_workdir=no;;
116 -configure) shift; do_configure=yes;;
117 -dont-configure) shift; do_configure=no;;
118 -clean) shift; do_make_clean=yes;;
119 -dont-clean) shift; do_make_clean=no;;
120 -build) shift; do_make_all=yes;;
121 -dont-build) shift; do_make_all=no;;
122 -check) shift; do_make_check=yes;;
123 -dont-check) shift; do_make_check=no;;
124 -install) shift; do_make_install=yes;;
125 -dont-install) shift; do_make_install=no;;
127 -fast) shift; do_clean_workdir=no
128 do_autoconf=no
129 do_configure=no
130 do_make_clean=no
131 do_make_all=yes;;
132 -nice) shift; mc_nice_value="$1"; shift;;
133 -maxlines) shift; mc_maxlines="$1"; shift;;
134 -quiet) shift; quiet="yes";;
135 mc_*=*) eval_arg "$1"; shift;;
137 --) shift; break;;
138 -) shift; break;;
139 -*) usage;;
140 *) break;;
141 esac
142 done
145 ### Initialization ###
147 renice ${mc_nice_value} $$ 1>/dev/null 2>&1 || true
149 ### Tools ###
151 configure_args_enable_all="--enable-largefile --enable-nls "\
152 "--enable-netcode --enable-background --enable-charset "\
153 "--with-mmap --with-included-gettext --with-x "\
154 "--with-vfs --with-mcfs --with-samba --with-ext2undel "\
155 "--with-gpm-mouse --with-subshell --with-edit"
156 configure_args_disable_all="--disable-largefile --disable-nls "\
157 "--disable-netcode --disable-background --disable-charset "\
158 "--without-mmap --without-included-gettext --without-x "\
159 "--without-vfs --without-mcfs --without-samba --without-ext2undel "\
160 "--without-gpm-mouse --without-subshell --without-edit"
162 errors=0
163 warnings=0
165 # feature tests
166 if test x"`echo -n`" = x"-n"; then
167 echo_n="echo"
168 echo_cont=" " # a tab character
169 else
170 echo_n="echo -n"
171 echo_cont=" "
175 show_file() {
176 if test -f "$1"; then
177 echo ""
178 sed -e "${mc_maxlines}s,.*,(more lines follow ...)," -e "${mc_maxlines}q" "$1"
179 echo ""
181 return 0
184 phase_start() {
185 ${echo_n} "[`date`] $1"
186 return 0
189 phase_ok() {
190 echo "${echo_cont}ok"
191 return 0
194 phase_warnings() {
195 echo "${echo_cont}WARNINGS"
196 warnings=`expr $warnings + 1`
197 if test $# -gt 0; then show_file "$1"; fi
198 return 0
201 phase_ok_or_warnings() {
202 fsize=`wc -c < "$1"`
204 { test -n "${fsize}" && test ${fsize} -eq 0
205 } && phase_ok || phase_warnings "$1"
206 return 0
209 phase_failed() {
210 echo "${echo_cont}FAILED"
211 failed=yes
212 errors=`expr $errors + 1`
213 if test $# -gt 0; then show_file "$1"; fi
214 return 0
217 setup_preconf_env=\
218 "out=\"\${mc_logdir}/\${test_phase}.out\";"\
219 "err=\"\${mc_logdir}/\${test_phase}.err\";"
221 preconf_download() {
222 test_phase="download"
223 eval "${setup_preconf_env}"
225 if test ${do_download} = no && test -d "${mc_srcdir}/CVS"; then
226 return 0
229 mkdir -p "${mc_logdir}"
231 if test -d "${mc_srcdir}/CVS"; then
232 phase_start "updating CVS copy ..."
233 ( cd "${mc_srcdir}" \
234 && env CVS_RSH=${mc_cvs_rsh} cvs update -r "${mc_cvs_tag}" -dP
235 ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
236 else
237 phase_start "getting fresh CVS copy ..."
238 ( mkdir -p "${mc_srcdir}" \
239 && cd "${mc_srcdir}/.." \
240 && env CVS_RSH=${mc_cvs_rsh} cvs -d "${mc_cvs_repository}" checkout -P -r "${mc_cvs_tag}" -d "`basename "${mc_srcdir}"`" "${mc_cvs_module}"
241 ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
245 preconf_autoconf() {
246 test_phase="autoconf"
247 eval "${setup_preconf_env}"
249 if test ${do_autoconf} != yes && test -f "${mc_srcdir}/configure"; then
250 return 0
253 mkdir -p "${mc_logdir}"
255 phase_start "creating ./configure script ..."
256 { cd "${mc_srcdir}" \
257 && echo "#!/bin/sh" > ./configure.mc \
258 && chmod +x ./configure.mc \
259 && ${SHELL-"/bin/sh"} ./autogen.sh
260 } 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
263 setup_testenv=\
264 "test_srcdir=\"\${mc_srcdir}\";"\
265 "test_workdir=\"\${mc_builddir}/\${testname}\";"\
266 "test_prefix=\"\${mc_prefixdir}/\${testname}\";"\
267 "test_logdir=\"\${mc_logdir}/\${testname}\";"\
268 "out=\"\${test_logdir}/\${test_phase}.out\";"\
269 "err=\"\${test_logdir}/\${test_phase}.err\";"
271 confbuild_cleanwork() {
272 test_phase="cleanwork"
273 eval "${setup_testenv}"
275 if test ${do_clean_workdir} = no || test ! -d "${test_workdir}"; then
276 return 0
279 mkdir -p "${test_logdir}"
281 phase_start "cleaning directory for ${testname} ..."
282 { rm -rf "${test_workdir}"
283 } 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
286 confbuild_configure() {
287 test_phase="configure"
288 eval "${setup_testenv}"
290 if test ${do_configure} != yes && test -f "${test_workdir}/Makefile"; then
291 return 0
294 mkdir -p "${test_logdir}"
296 phase_start "configuring for ${testname} ..."
297 ( set -e
298 mkdir -p "${test_workdir}"
299 cd "${test_workdir}"
300 cmd="${test_srcdir}/configure"
301 cmd="${cmd} --prefix=\"${test_prefix}\""
302 cmd="${cmd} MAKE=\"${mc_make}\""
303 cmd="${cmd} CPP=\"${mc_cpp}\""
304 cmd="${cmd} CPPFLAGS=\"${mc_cppflags}\""
305 cmd="${cmd} CC=\"${mc_cc}\""
306 cmd="${cmd} CFLAGS=\"${mc_cflags}\""
307 cmd="${cmd} LDFLAGS=\"${mc_ldflags}\""
308 cmd="${cmd} ${mc_configure_args_pre}"
309 cmd="${cmd} ${configure_args}"
310 cmd="${cmd} ${mc_configure_args_post}"
311 echo "running $cmd"
312 eval "$cmd"
313 ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
316 confbuild_make() {
317 make_target="$1"
318 test_phase="make_${make_target}"
319 eval "${setup_testenv}"
321 if eval "test \${do_make_${make_target}} = no"; then
322 return 0
325 mkdir -p "${test_logdir}"
327 phase_start "running \"make ${make_target}\" for ${testname} ..."
328 ( cd "${test_workdir}" \
329 && eval "${mc_make} ${mc_make_flags} ${make_target}"
330 ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
333 confbuild() {
334 failed=no
336 confbuild_cleanwork
337 if test ${failed} = yes; then return 0; fi
339 confbuild_configure
340 if test ${failed} = yes; then return 0; fi
342 confbuild_make "clean"
343 if test ${failed} = yes; then return 0; fi
345 confbuild_make "all"
346 if test ${failed} = yes; then return 0; fi
348 confbuild_make "check"
349 if test ${failed} = yes; then return 0; fi
351 confbuild_make "install"
352 if test ${failed} = yes; then return 0; fi
356 test_plain() {
357 testname="plain"
358 configure_args=""
359 confbuild
362 test_glib12() {
363 testname="glib12"
364 configure_args="--with-glib12"
365 confbuild
368 test_charset() {
369 testname="charset"
370 configure_args="--enable-charset"
371 confbuild
374 test_no_charset() {
375 testname="no_charset"
376 configure_args="--disable-charset"
377 confbuild
380 test_X11() {
381 testname="X11"
382 configure_args="--with-x"
383 confbuild
386 test_no_X11() {
387 testname="no_X11"
388 configure_args="--without-x"
389 confbuild
392 test_vfs() {
393 testname="vfs"
394 configure_args="--with-vfs"
395 confbuild
398 test_no_vfs() {
399 testname="no_vfs"
400 configure_args="--without-vfs"
401 confbuild
404 test_mcfs() {
405 testname="mcfs"
406 configure_args="--with-mcfs"
407 confbuild
410 test_no_mcfs() {
411 testname="no_mcfs"
412 configure_args="--without-mcfs"
413 confbuild
416 test_samba() {
417 testname="samba"
418 configure_args="--with-samba"
419 confbuild
422 test_no_samba() {
423 testname="no_samba"
424 configure_args="--without-samba"
425 confbuild
428 test_ext2undel() {
429 testname="ext2undel"
430 configure_args="--with-ext2undel"
431 confbuild
434 test_no_ext2undel() {
435 testname="no_ext2undel"
436 configure_args="--without-ext2undel"
437 confbuild
440 test_slang() {
441 testname="slang"
442 configure_args="--with-screen=slang"
443 confbuild
446 test_ncurses() {
447 testname="ncurses"
448 configure_args="--with-screen=ncurses"
449 confbuild
452 test_maintainer() {
453 testname="maintainer"
454 configure_args="--enable-maintainer-mode"
455 confbuild
458 test_no_maintainer() {
459 testname="no_maintainer"
460 configure_args="--disable-maintainer-mode"
461 confbuild
464 test_i18n() {
465 testname="i18n"
466 configure_args="--enable-nls"
467 confbuild
470 test_no_i18n() {
471 testname="no_i18n"
472 configure_args="--disable-nls"
473 confbuild
476 test_no_features() {
477 testname="no_features"
478 configure_args="${configure_args_disable_all}"
479 confbuild
482 test_all_features() {
483 testname="all_features"
484 configure_args="${configure_args_enable_all}"
485 confbuild
488 run_tests() {
489 failed=no
491 preconf_download
492 if test ${failed} = yes; then return 0; fi
494 preconf_autoconf
495 if test ${failed} = yes; then return 0; fi
497 for i in "$@"; do
498 if type test_"${i}" 2>/dev/null \
499 | grep "function" 1>/dev/null 2>&1; then
500 eval "test_${i}"
501 else
502 echo "[`date`] test \"$i\" not found." 1>&2
503 errors=`expr $errors + 1`
505 done
508 if test -z "${mc_srcdir}"; then mc_srcdir="${mc_basedir}/src"; fi
509 if test -z "${mc_prefixdir}"; then mc_prefixdir="${mc_basedir}/installed"; fi
510 if test -z "${mc_builddir}"; then mc_builddir="${mc_basedir}/build"; fi
511 if test -z "${mc_logdir}"; then mc_logdir="${mc_basedir}/logs"; fi
512 if test -z "${mc_cpp}"; then mc_cpp="${mc_cc} -E"; fi
514 if test ${do_clean_basedir} = yes; then
515 phase_start "cleaning up everything ..."
516 { rm -rf "${mc_basedir}"
517 } && phase_ok || phase_failed
518 else
519 if test $# -gt 0; then
520 mc_tests="$@"
522 run_tests $mc_tests
525 if test ${errors} -ne 0 || test ${warnings} -ne 0; then
526 echo "[`date`] finished with ${errors} errors and ${warnings} warnings."
527 else
528 echo "[`date`] finished successfully."
530 exit ${errors}