/testsuite/check.sh

https://github.com/coliv/ed · Shell · 106 lines · 78 code · 12 blank · 16 comment · 15 complexity · 9d2fac785d22da25535702cac605ac12 MD5 · raw file

  1. #! /bin/sh
  2. # check script for GNU ed - The GNU line editor
  3. # Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
  4. #
  5. # This script is free software; you have unlimited permission
  6. # to copy, distribute and modify it.
  7. LC_ALL=C
  8. export LC_ALL
  9. objdir=`pwd`
  10. testdir=`cd "$1" ; pwd`
  11. ED="${objdir}"/ed
  12. if [ ! -x "${ED}" ] ; then
  13. echo "${ED}: cannot execute"
  14. exit 1
  15. fi
  16. if [ -d tmp ] ; then rm -rf tmp ; fi
  17. mkdir tmp
  18. # Generate ed test scripts, with extensions .ed and .red, from
  19. # .t and .err files, respectively.
  20. printf "building test scripts for ed-%s...\n" "$2"
  21. cd "${testdir}"
  22. for i in *.t ; do
  23. base=`echo "$i" | sed 's/\.t$//'`
  24. (
  25. echo "#! /bin/sh"
  26. echo "${ED} -s <<'EOT'"
  27. echo H
  28. echo "r ${testdir}/${base}.d"
  29. cat "$i"
  30. echo "w ${base}.o"
  31. echo EOT
  32. ) > "${objdir}/tmp/${base}.ed"
  33. chmod u+x "${objdir}/tmp/${base}.ed"
  34. done
  35. for i in *.err ; do
  36. base=`echo "$i" | sed 's/\.err$//'`
  37. (
  38. echo "#! /bin/sh -"
  39. echo "${ED} -s <<'EOT'"
  40. echo H
  41. echo "r ${testdir}/${base}.err"
  42. cat "$i"
  43. echo "w ${base}.ro"
  44. echo EOT
  45. ) > "${objdir}/tmp/${base}.red"
  46. chmod u+x "${objdir}/tmp/${base}.red"
  47. done
  48. # Run the .ed and .red scripts just generated
  49. # and compare their output against the .r and .pr files, which contain
  50. # the correct output.
  51. printf "testing ed-%s...\n" "$2"
  52. cd "${objdir}"/tmp
  53. # Run the *.red scripts first, since these don't generate output;
  54. # they exit with non-zero status
  55. for i in *.red ; do
  56. echo "$i"
  57. if ./"$i" ; then
  58. echo "*** The script $i exited abnormally ***"
  59. fi
  60. done > errs.ck 2>&1
  61. # Run error scripts again as pipes - these should generate output and
  62. # exit with error (>0) status.
  63. for i in *.red ; do
  64. base=`echo "$i" | sed 's/\.red$//'`
  65. if cat ${base}.red | "${ED}" -s ; then
  66. echo "*** The piped script $i exited abnormally ***"
  67. else
  68. if cmp -s ${base}.ro "${testdir}"/${base}.pr ; then
  69. true
  70. else
  71. echo "*** Output ${base}.ro of piped script $i is incorrect ***"
  72. fi
  73. fi
  74. done > pipes.ck 2>&1
  75. # Run the remainding scripts; they exit with zero status
  76. for i in *.ed ; do
  77. base=`echo "$i" | sed 's/\.ed$//'`
  78. if ./${base}.ed ; then
  79. if cmp -s ${base}.o "${testdir}"/${base}.r ; then
  80. true
  81. else
  82. echo "*** Output ${base}.o of script $i is incorrect ***"
  83. fi
  84. else
  85. echo "*** The script $i exited abnormally ***"
  86. fi
  87. done > scripts.ck 2>&1
  88. grep '\*\*\*' *.ck | sed 's/^[^*]*//'
  89. if grep '\*\*\*' *.ck > /dev/null ; then
  90. exit 127
  91. else
  92. echo "tests completed successfully."
  93. cd "${objdir}" && rm -r tmp
  94. fi