mc-test 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. #!/bin/sh
  2. # Midnight Commander Test Suite
  3. #
  4. # (c) 2005 Roland Illig <roland.illig@gmx.de>
  5. #
  6. # Licensed under the GPL 2.0
  7. set -efu
  8. ### initialize environment ###
  9. LC_CTYPE="C"; export LC_ALL
  10. LC_COLLATE="C"; export LC_COLLATE
  11. LC_MONETARY="C"; export LC_MONETARY
  12. LC_NUMERIC="C"; export LC_NUMERIC
  13. LC_TIME="C"; export LC_TIME
  14. LC_MESSAGES="C"; export LC_MESSAGES
  15. LC_ALL="C"; export LC_ALL
  16. ### set default configuration ###
  17. mc_nice_value="19"
  18. mc_maxlines="10"
  19. mc_basedir="/tmp/mc-current-build"
  20. mc_srcdir="" # default: ${mc_basedir}/src
  21. mc_builddir="" # default: ${mc_basedir}/build
  22. mc_prefixdir="" # default: ${mc_basedir}/installed
  23. mc_logdir="" # default: ${mc_basedir}/logs
  24. mc_cvs_rsh="ssh"
  25. mc_cvs_repository=":pserver:anonymous:@cvs.savannah.gnu.org:/sources/mc"
  26. mc_cvs_module="mc"
  27. mc_cvs_tag="HEAD"
  28. mc_configure_args_pre="--enable-maintainer-mode"
  29. mc_configure_args_post=""
  30. mc_make="make"
  31. mc_make_flags=""
  32. mc_cpp="" # default: ${mc_cc} -E
  33. mc_cppflags=""
  34. mc_cc="cc"
  35. mc_cflags=""
  36. mc_ldflags=""
  37. mc_tests="plain glib12 charset no_charset vfs no_vfs mcfs no_mcfs samba "\
  38. "no_samba ext2undel no_ext2undel slang ncurses maintainer "\
  39. "no_maintainer i18n no_i18n no_features all_features"
  40. do_clean_basedir=no
  41. do_download=auto
  42. do_autoconf=auto
  43. do_clean_workdir=no
  44. do_configure=auto
  45. do_make_clean=no
  46. do_make_all=yes
  47. do_make_check=yes
  48. do_make_install=yes
  49. ### command line parsing ###
  50. usage() {
  51. cat >&2 <<EOF
  52. usage: `basename $0` [options ...] [var=value...] [<testname ...>]
  53. -config <file> load the configuration from <file>
  54. -basedir <dir> set the base directory
  55. -srcdir <dir> select the directory where the source code is
  56. read from or will be downloaded to from CVS
  57. -[dont-]download checkout or update from CVS (default: ${do_download})
  58. -[dont-]autoconf generate the configure script (default: ${do_autoconf})
  59. -[dont-]cleanwork recreate the build directory (default: ${do_clean_workdir})
  60. -[dont-]configure run configure (default: ${do_configure})
  61. -[dont-]clean make clean (default: ${do_make_clean})
  62. -[dont-]build make all (default: ${do_make_all})
  63. -[dont-]check make check (default: ${do_make_check})
  64. -[dont-]install make install (default: ${do_make_install})
  65. -fast only do what's necessary
  66. -nice <n> set the nice(1) value (default: ${mc_nice_value})
  67. -maxlines <n> the maximum number of lines for each phase (default: ${mc_maxlines})
  68. -quiet disable most status messages (default: ${quiet:-"no"}${quiet+"yes"})
  69. EOF
  70. exit 1
  71. }
  72. eval_arg() {
  73. _shquote_var=`echo x"$1" | sed -e '1s,^x\([^=]*\)=.*,\1,' -e '1q'`
  74. _shquote_val=`echo x"$1" | sed '1s,^x[^=]*=\(.*\),\1,'`
  75. _shquote_qval=`echo x"${_shquote_val}" | sed -e '1s,.,,' -e s,\',\'\\\\\\\\\'\',g`
  76. eval "${_shquote_var}='${_shquote_qval}'"
  77. }
  78. while test $# -ne 0; do
  79. case "$1" in
  80. -config) shift; case "$1" in /*) . "$1";; *) . "./$1";; esac; shift;;
  81. -basedir) shift; mc_basedir="$1"; shift;;
  82. -cvs-repository) shift; mc_cvs_repository="$1"; shift;;
  83. -cvs-module) shift; mc_cvs_module="$1"; shift;;
  84. -srcdir) shift; mc_srcdir="$1"; shift;;
  85. -cleanup) shift; do_clean_basedir=yes;;
  86. -download) shift; do_download=yes;;
  87. -dont-download) shift; do_download=no;;
  88. -autoconf) shift; do_autoconf=yes;;
  89. -dont-autoconf) shift; do_autoconf=no;;
  90. -cleanwork) shift; do_clean_workdir=yes;;
  91. -dont-cleanwork) shift; do_clean_workdir=no;;
  92. -configure) shift; do_configure=yes;;
  93. -dont-configure) shift; do_configure=no;;
  94. -clean) shift; do_make_clean=yes;;
  95. -dont-clean) shift; do_make_clean=no;;
  96. -build) shift; do_make_all=yes;;
  97. -dont-build) shift; do_make_all=no;;
  98. -check) shift; do_make_check=yes;;
  99. -dont-check) shift; do_make_check=no;;
  100. -install) shift; do_make_install=yes;;
  101. -dont-install) shift; do_make_install=no;;
  102. -fast) shift; do_clean_workdir=no
  103. do_autoconf=no
  104. do_configure=no
  105. do_make_clean=no
  106. do_make_all=yes;;
  107. -nice) shift; mc_nice_value="$1"; shift;;
  108. -maxlines) shift; mc_maxlines="$1"; shift;;
  109. -quiet) shift; quiet="yes";;
  110. mc_*=*) eval_arg "$1"; shift;;
  111. --) shift; break;;
  112. -) shift; break;;
  113. -*) usage;;
  114. *) break;;
  115. esac
  116. done
  117. ### Initialization ###
  118. renice ${mc_nice_value} $$ 1>/dev/null 2>&1 || true
  119. ### Tools ###
  120. configure_args_enable_all="--enable-largefile --enable-nls "\
  121. "--enable-netcode --enable-background --enable-charset "\
  122. "--with-mmap --with-included-gettext --with-x "\
  123. "--with-vfs --with-mcfs --with-samba --with-ext2undel "\
  124. "--with-gpm-mouse --with-subshell --with-edit"
  125. configure_args_disable_all="--disable-largefile --disable-nls "\
  126. "--disable-netcode --disable-background --disable-charset "\
  127. "--without-mmap --without-included-gettext --without-x "\
  128. "--without-vfs --without-mcfs --without-samba --without-ext2undel "\
  129. "--without-gpm-mouse --without-subshell --without-edit"
  130. errors=0
  131. warnings=0
  132. # feature tests
  133. if test x"`echo -n`" = x"-n"; then
  134. echo_n="echo"
  135. echo_cont=" " # a tab character
  136. else
  137. echo_n="echo -n"
  138. echo_cont=" "
  139. fi
  140. show_file() {
  141. if test -f "$1"; then
  142. echo ""
  143. sed -e "${mc_maxlines}s,.*,(more lines follow ...)," -e "${mc_maxlines}q" "$1"
  144. echo ""
  145. fi
  146. return 0
  147. }
  148. phase_start() {
  149. ${echo_n} "[`date`] $1"
  150. return 0
  151. }
  152. phase_ok() {
  153. echo "${echo_cont}ok"
  154. return 0
  155. }
  156. phase_warnings() {
  157. echo "${echo_cont}WARNINGS"
  158. warnings=`expr $warnings + 1`
  159. if test $# -gt 0; then show_file "$1"; fi
  160. return 0
  161. }
  162. phase_ok_or_warnings() {
  163. fsize=`wc -c < "$1"`
  164. { test -n "${fsize}" && test ${fsize} -eq 0
  165. } && phase_ok || phase_warnings "$1"
  166. return 0
  167. }
  168. phase_failed() {
  169. echo "${echo_cont}FAILED"
  170. failed=yes
  171. errors=`expr $errors + 1`
  172. if test $# -gt 0; then show_file "$1"; fi
  173. return 0
  174. }
  175. setup_preconf_env=\
  176. "out=\"\${mc_logdir}/\${test_phase}.out\";"\
  177. "err=\"\${mc_logdir}/\${test_phase}.err\";"
  178. preconf_download() {
  179. test_phase="download"
  180. eval "${setup_preconf_env}"
  181. if test ${do_download} = no && test -d "${mc_srcdir}/CVS"; then
  182. return 0
  183. fi
  184. mkdir -p "${mc_logdir}"
  185. if test -d "${mc_srcdir}/CVS"; then
  186. phase_start "updating CVS copy ..."
  187. ( cd "${mc_srcdir}" \
  188. && env CVS_RSH=${mc_cvs_rsh} cvs update -r "${mc_cvs_tag}" -dP
  189. ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
  190. else
  191. phase_start "getting fresh CVS copy ..."
  192. ( mkdir -p "${mc_srcdir}" \
  193. && cd "${mc_srcdir}/.." \
  194. && env CVS_RSH=${mc_cvs_rsh} cvs -d "${mc_cvs_repository}" checkout -P -r "${mc_cvs_tag}" -d "`basename "${mc_srcdir}"`" "${mc_cvs_module}"
  195. ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
  196. fi
  197. }
  198. preconf_autoconf() {
  199. test_phase="autoconf"
  200. eval "${setup_preconf_env}"
  201. if test ${do_autoconf} != yes && test -f "${mc_srcdir}/configure"; then
  202. return 0
  203. fi
  204. mkdir -p "${mc_logdir}"
  205. phase_start "creating ./configure script ..."
  206. { cd "${mc_srcdir}" \
  207. && echo "#!/bin/sh" > ./configure.mc \
  208. && chmod +x ./configure.mc \
  209. && ${SHELL-"/bin/sh"} ./autogen.sh
  210. } 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
  211. }
  212. setup_testenv=\
  213. "test_srcdir=\"\${mc_srcdir}\";"\
  214. "test_workdir=\"\${mc_builddir}/\${testname}\";"\
  215. "test_prefix=\"\${mc_prefixdir}/\${testname}\";"\
  216. "test_logdir=\"\${mc_logdir}/\${testname}\";"\
  217. "out=\"\${test_logdir}/\${test_phase}.out\";"\
  218. "err=\"\${test_logdir}/\${test_phase}.err\";"
  219. confbuild_cleanwork() {
  220. test_phase="cleanwork"
  221. eval "${setup_testenv}"
  222. if test ${do_clean_workdir} = no || test ! -d "${test_workdir}"; then
  223. return 0
  224. fi
  225. mkdir -p "${test_logdir}"
  226. phase_start "cleaning directory for ${testname} ..."
  227. { rm -rf "${test_workdir}"
  228. } 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
  229. }
  230. confbuild_configure() {
  231. test_phase="configure"
  232. eval "${setup_testenv}"
  233. if test ${do_configure} != yes && test -f "${test_workdir}/Makefile"; then
  234. return 0
  235. fi
  236. mkdir -p "${test_logdir}"
  237. phase_start "configuring for ${testname} ..."
  238. ( set -e
  239. mkdir -p "${test_workdir}"
  240. cd "${test_workdir}"
  241. cmd="${test_srcdir}/configure"
  242. cmd="${cmd} --prefix=\"${test_prefix}\""
  243. cmd="${cmd} MAKE=\"${mc_make}\""
  244. cmd="${cmd} CPP=\"${mc_cpp}\""
  245. cmd="${cmd} CPPFLAGS=\"${mc_cppflags}\""
  246. cmd="${cmd} CC=\"${mc_cc}\""
  247. cmd="${cmd} CFLAGS=\"${mc_cflags}\""
  248. cmd="${cmd} LDFLAGS=\"${mc_ldflags}\""
  249. cmd="${cmd} ${mc_configure_args_pre}"
  250. cmd="${cmd} ${configure_args}"
  251. cmd="${cmd} ${mc_configure_args_post}"
  252. echo "running $cmd"
  253. eval "$cmd"
  254. ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
  255. }
  256. confbuild_make() {
  257. make_target="$1"
  258. test_phase="make_${make_target}"
  259. eval "${setup_testenv}"
  260. if eval "test \${do_make_${make_target}} = no"; then
  261. return 0
  262. fi
  263. mkdir -p "${test_logdir}"
  264. phase_start "running \"make ${make_target}\" for ${testname} ..."
  265. ( cd "${test_workdir}" \
  266. && eval "${mc_make} ${mc_make_flags} ${make_target}"
  267. ) 1>"${out}" 2>"${err}" && phase_ok_or_warnings "${err}" || phase_failed "${err}"
  268. }
  269. confbuild() {
  270. failed=no
  271. confbuild_cleanwork
  272. if test ${failed} = yes; then return 0; fi
  273. confbuild_configure
  274. if test ${failed} = yes; then return 0; fi
  275. confbuild_make "clean"
  276. if test ${failed} = yes; then return 0; fi
  277. confbuild_make "all"
  278. if test ${failed} = yes; then return 0; fi
  279. confbuild_make "check"
  280. if test ${failed} = yes; then return 0; fi
  281. confbuild_make "install"
  282. if test ${failed} = yes; then return 0; fi
  283. }
  284. test_plain() {
  285. testname="plain"
  286. configure_args=""
  287. confbuild
  288. }
  289. test_glib12() {
  290. testname="glib12"
  291. configure_args="--with-glib12"
  292. confbuild
  293. }
  294. test_charset() {
  295. testname="charset"
  296. configure_args="--enable-charset"
  297. confbuild
  298. }
  299. test_no_charset() {
  300. testname="no_charset"
  301. configure_args="--disable-charset"
  302. confbuild
  303. }
  304. test_X11() {
  305. testname="X11"
  306. configure_args="--with-x"
  307. confbuild
  308. }
  309. test_no_X11() {
  310. testname="no_X11"
  311. configure_args="--without-x"
  312. confbuild
  313. }
  314. test_vfs() {
  315. testname="vfs"
  316. configure_args="--with-vfs"
  317. confbuild
  318. }
  319. test_no_vfs() {
  320. testname="no_vfs"
  321. configure_args="--without-vfs"
  322. confbuild
  323. }
  324. test_mcfs() {
  325. testname="mcfs"
  326. configure_args="--with-mcfs"
  327. confbuild
  328. }
  329. test_no_mcfs() {
  330. testname="no_mcfs"
  331. configure_args="--without-mcfs"
  332. confbuild
  333. }
  334. test_samba() {
  335. testname="samba"
  336. configure_args="--with-samba"
  337. confbuild
  338. }
  339. test_no_samba() {
  340. testname="no_samba"
  341. configure_args="--without-samba"
  342. confbuild
  343. }
  344. test_ext2undel() {
  345. testname="ext2undel"
  346. configure_args="--with-ext2undel"
  347. confbuild
  348. }
  349. test_no_ext2undel() {
  350. testname="no_ext2undel"
  351. configure_args="--without-ext2undel"
  352. confbuild
  353. }
  354. test_slang() {
  355. testname="slang"
  356. configure_args="--with-screen=slang"
  357. confbuild
  358. }
  359. test_ncurses() {
  360. testname="ncurses"
  361. configure_args="--with-screen=ncurses"
  362. confbuild
  363. }
  364. test_maintainer() {
  365. testname="maintainer"
  366. configure_args="--enable-maintainer-mode"
  367. confbuild
  368. }
  369. test_no_maintainer() {
  370. testname="no_maintainer"
  371. configure_args="--disable-maintainer-mode"
  372. confbuild
  373. }
  374. test_i18n() {
  375. testname="i18n"
  376. configure_args="--enable-nls"
  377. confbuild
  378. }
  379. test_no_i18n() {
  380. testname="no_i18n"
  381. configure_args="--disable-nls"
  382. confbuild
  383. }
  384. test_no_features() {
  385. testname="no_features"
  386. configure_args="${configure_args_disable_all}"
  387. confbuild
  388. }
  389. test_all_features() {
  390. testname="all_features"
  391. configure_args="${configure_args_enable_all}"
  392. confbuild
  393. }
  394. run_tests() {
  395. failed=no
  396. preconf_download
  397. if test ${failed} = yes; then return 0; fi
  398. preconf_autoconf
  399. if test ${failed} = yes; then return 0; fi
  400. for i in "$@"; do
  401. if type test_"${i}" 2>/dev/null \
  402. | grep "function" 1>/dev/null 2>&1; then
  403. eval "test_${i}"
  404. else
  405. echo "[`date`] test \"$i\" not found." 1>&2
  406. errors=`expr $errors + 1`
  407. fi
  408. done
  409. }
  410. if test -z "${mc_srcdir}"; then mc_srcdir="${mc_basedir}/src"; fi
  411. if test -z "${mc_prefixdir}"; then mc_prefixdir="${mc_basedir}/installed"; fi
  412. if test -z "${mc_builddir}"; then mc_builddir="${mc_basedir}/build"; fi
  413. if test -z "${mc_logdir}"; then mc_logdir="${mc_basedir}/logs"; fi
  414. if test -z "${mc_cpp}"; then mc_cpp="${mc_cc} -E"; fi
  415. if test ${do_clean_basedir} = yes; then
  416. phase_start "cleaning up everything ..."
  417. { rm -rf "${mc_basedir}"
  418. } && phase_ok || phase_failed
  419. else
  420. if test $# -gt 0; then
  421. mc_tests="$@"
  422. fi
  423. run_tests $mc_tests
  424. fi
  425. if test ${errors} -ne 0 || test ${warnings} -ne 0; then
  426. echo "[`date`] finished with ${errors} errors and ${warnings} warnings."
  427. else
  428. echo "[`date`] finished successfully."
  429. fi
  430. exit ${errors}