summaryrefslogtreecommitdiff
path: root/maintainer/rename-tests
blob: 8c643872bc75446733510b47fe5b92e156a2751f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
# Convenience script to rename test cases in Automake.

# Copyright (C) 2013-2017 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

set -e -u

me=${0##*/}
msg_file=$me.git-msg

fatal () { echo "$me: $*" >&2; exit 1; }

case $# in
  0) input=$(cat);;
  1) input=$(cat -- "$1");;
  *) fatal "too many arguments";;
esac

AWK=${AWK-awk}
SED=${SED-sed}

[[ -f bin/automake.in && -d lib/Automake ]] \
  || fatal "can only be run from the top-level of the Automake source tree"

$SED --version 2>&1 | grep GNU >/dev/null 2>&1 \
  || fatal "GNU sed is required by this script"

# Input validation and cleanup.
input=$(
  $AWK -v me="$me" '
    /^#/ { next; }
    (NF == 0) { next; }
    (NF != 2) { print me ": wrong number of fields at line " NR;
                exit(1); }
    { printf ("t/%s t/%s\n", $1, $2); }
  ' <<<"$input"
) || exit $?

# Prepare git commit message.
exec 5>"$msg_file"
echo "tests: more significant names for some tests" >&5
echo >&5
$AWK >&5 <<<"$input" \
  '{ printf ("* %s: Rename...\n* %s: ... like this.\n", $1, $2) }'
exec 5>&-

# Rename tests.
eval "$($AWK '{ printf ("git mv %s %s\n", $1, $2) }' <<<"$input")"

# Adjust the list of tests (do this conditionally, since such a
# list is not required nor used in Automake-NG).
if test -f t/list-of-tests.mk; then
  $SED -e "$($AWK '{ printf ("s|^%s |%s |\n", $1, $2) }' <<<"$input")" \
       -i t/list-of-tests.mk
  git add t/list-of-tests.mk
fi

git status
echo
echo "NOTICE: pre-filled commit message is in file '$msg_file'"

exit 0