rename-tests 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env bash
  2. # Convenience script to rename test cases in Automake.
  3. # Copyright (C) 2013-2017 Free Software Foundation, Inc.
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. set -e -u
  15. me=${0##*/}
  16. msg_file=$me.git-msg
  17. fatal () { echo "$me: $*" >&2; exit 1; }
  18. case $# in
  19. 0) input=$(cat);;
  20. 1) input=$(cat -- "$1");;
  21. *) fatal "too many arguments";;
  22. esac
  23. AWK=${AWK-awk}
  24. SED=${SED-sed}
  25. [[ -f bin/automake.in && -d lib/Automake ]] \
  26. || fatal "can only be run from the top-level of the Automake source tree"
  27. $SED --version 2>&1 | grep GNU >/dev/null 2>&1 \
  28. || fatal "GNU sed is required by this script"
  29. # Input validation and cleanup.
  30. input=$(
  31. $AWK -v me="$me" '
  32. /^#/ { next; }
  33. (NF == 0) { next; }
  34. (NF != 2) { print me ": wrong number of fields at line " NR;
  35. exit(1); }
  36. { printf ("t/%s t/%s\n", $1, $2); }
  37. ' <<<"$input"
  38. ) || exit $?
  39. # Prepare git commit message.
  40. exec 5>"$msg_file"
  41. echo "tests: more significant names for some tests" >&5
  42. echo >&5
  43. $AWK >&5 <<<"$input" \
  44. '{ printf ("* %s: Rename...\n* %s: ... like this.\n", $1, $2) }'
  45. exec 5>&-
  46. # Rename tests.
  47. eval "$($AWK '{ printf ("git mv %s %s\n", $1, $2) }' <<<"$input")"
  48. # Adjust the list of tests (do this conditionally, since such a
  49. # list is not required nor used in Automake-NG).
  50. if test -f t/list-of-tests.mk; then
  51. $SED -e "$($AWK '{ printf ("s|^%s |%s |\n", $1, $2) }' <<<"$input")" \
  52. -i t/list-of-tests.mk
  53. git add t/list-of-tests.mk
  54. fi
  55. git status
  56. echo
  57. echo "NOTICE: pre-filled commit message is in file '$msg_file'"
  58. exit 0