mc-test 12 KB

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