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