test harness: improve catching of usage errors in script 'test-driver'
[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
24 fatal () { echo "$me: $*" >&2; exit 1; }
25
26 case $# in
27   0) input=$(cat);;
28   1) input=$(cat -- "$1");;
29   *) fatal "too many arguments";;
30 esac
31
32 AWK=${AWK-awk}
33 SED=${SED-sed}
34
35 [[ -f bin/automake.in && -d lib/Automake ]] \
36   || fatal "can only be run from the top-level of the Automake source tree"
37
38 $SED --version 2>&1 | grep GNU >/dev/null 2>&1 \
39   || fatal "GNU sed is required by this script"
40
41 # Input validation and cleanup.
42 input=$(
43   $AWK -v me="$me" '
44     /^#/ { next; }
45     (NF == 0) { next; }
46     (NF != 2) { print me ": wrong number of fields at line " NR;
47                 exit(1); }
48     { printf ("t/%s t/%s\n", $1, $2); }
49   ' <<<"$input"
50 ) || exit $?
51
52 # Prepare git commit message.
53 exec 5>"$msg_file"
54 echo "tests: more significant names for some tests" >&5
55 echo >&5
56 $AWK >&5 <<<"$input" \
57   '{ printf ("* %s: Rename...\n* %s: ... like this.\n", $1, $2) }'
58 exec 5>&-
59
60 # Rename tests.
61 eval "$($AWK '{ printf ("git mv %s %s\n", $1, $2) }' <<<"$input")"
62
63 # Adjust the list of tests (do this conditionally, since such a
64 # list is not required nor used in Automake-NG).
65 if test -f t/list-of-tests.mk; then
66   $SED -e "$($AWK '{ printf ("s|^%s |%s |\n", $1, $2) }' <<<"$input")" \
67        -i t/list-of-tests.mk
68   git add t/list-of-tests.mk
69 fi
70
71 git status
72 echo
73 echo "NOTICE: pre-filled commit message is in file '$msg_file'"
74
75 exit 0