verify: new macro 'assume'
[gnulib.git] / lib / t-idcache
1 #!/bin/sh
2 # Compare the two halves (user and group) of idcache.c.
3 # Once xformed, they'd better be the same:
4
5 pwd=`pwd`
6 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
7 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
8 trap '(exit $?); exit $?' 1 2 13 15
9
10 srcdir=../..
11 framework_failure=0
12 mkdir -p $tmp || framework_failure=1
13 cd $tmp || framework_failure=1
14
15 if test $framework_failure = 1; then
16   echo "$0: failure in testing framework" 1>&2
17   (exit 1); exit 1
18 fi
19
20 # Extract user-oriented functions.
21 perl -ne \
22   'print if /^static struct.*user_alist/ .. /^static struct.*group_alist/' \
23   $srcdir/idcache.c | head -n -3 > u
24 # Extract group-oriented functions.
25 perl -ne 'print if /^static struct.*group_alist/ .. eof' $srcdir/idcache.c > g
26
27 # Convert user-specific strings of "u" into corresponding group-specific strings
28 subst='
29 s/user_/group_/g;
30 s/\buser\b/group/g;
31 s/USER/GROUP/g;
32 s/\bu\b/g/g;
33 s/passwd/group/g;
34 s/pw_uid/gr_gid/g;
35 s/pwnam/grnam/g;
36 s/pwent/grent/g;
37 s/getpw/getgr/g;
38 s/pw_/gr_/g;
39 s/UID/GID/g;
40 s/uid/gid/g;
41 s/getuser/getgroup/;
42 s/login name/group name/;
43 s/to be the/to belong to/;
44 s/pwd fun/grp fun/;
45 '
46
47 fail=0
48 # Ensure that the transformed "u" is the same as g.
49 # Any differences here constitute an error.
50 perl -pe "$subst" u | diff -u - g || fail=1
51
52 exit $fail