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