Rename 'maint/' -> 'maintainer/', for Git's sake
[platform/upstream/automake.git] / maintainer / rename-tests
1 #!/usr/bin/env bash
2 # Convenience script to rename test cases in Automake.
3
4 set -e -u
5
6 me=${0##*/}
7 fatal () { echo "$me: $*" >&2; exit 1; }
8
9 case $# in
10   0) input=$(cat);;
11   1) input=$(cat -- "$1");;
12   *) fatal "too many arguments";;
13 esac
14
15 AWK=${AWK-awk}
16 SED=${SED-sed}
17
18 [[ -f automake.in && -d lib/Automake ]] \
19   || fatal "can only be run from the top-level of the Automake source tree"
20
21 $SED --version 2>&1 | grep GNU >/dev/null 2>&1 \
22   || fatal "GNU sed is required by this script"
23
24 # Validate and cleanup input.
25 input=$(
26   $AWK -v me="$me" "
27     /^#/ { next; }
28     (NF == 0) { next; }
29     (NF != 2) { print me \": wrong number of fields at line \" NR;
30                 exit(1); }
31     { printf (\"t/%s t/%s\\n\", \$1, \$2); }
32   " <<<"$input")
33
34 # Prepare git commit message.
35 exec 5>$me.git-msg
36 echo "tests: more significant names for some tests" >&5
37 echo >&5
38 $AWK >&5 <<<"$input" \
39   '{ printf ("* %s: Rename...\n* %s: ... like this.\n", $1, $2) }'
40 exec 5>&-
41
42 # Rename tests.
43 eval "$($AWK '{ printf ("git mv %s %s\n", $1, $2) }' <<<"$input")"
44
45 # Adjust the list of tests (do this conditionally, since such a
46 # list is not required nor used in Automake-NG.
47 if test -f t/list-of-tests.mk; then
48   $SED -e "$($AWK '{ printf ("s|^%s |%s |\n", $1, $2) }' <<<"$input")" \
49        -i t/list-of-tests.mk
50 fi
51
52 git status