bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: "make check" for gnulib/lib


From: Jim Meyering
Subject: FYI: "make check" for gnulib/lib
Date: Mon, 20 Nov 2006 16:14:32 +0100

This rule would have helped avoid a problem in idcache.c.
I expect to add something similar (though in modules/) that will
run check-module once I've found the time to clean up the existing
violations.

I chose to put it in lib/ only slightly arbitrarily.
Eventually we may divide things by functionality, and
to that end, keeping tests alongside tested code might
be nicer.  I won't object if someone moves it to another
directory.

Why didn't I bother with autoconf/automake/etc?
My intent is to minimize the maintainer (e.g., my) effort, yet to
provide a way to add more tests like this.  We need many more.
True, if you don't have a usable version of "perl" installed,
this test will fail.  If that happens, maybe you'll take the
hint and install perl :-)

If someone wants to add an autoconf test for perl, and to
change lib/Makefile into lib/Makefile.am, I'm sure we won't
mind having to run "configure" once in a while, and an
automake-derived "make check" framework *would* be better.
Though, perhaps an autotest-based framework would be better still.


2006-11-20  Jim Meyering  <address@hidden>

        The beginnings of syntax-related checks for gnulib.
        * lib/Makefile: New file.
        * lib/t-idcache: New script.  Ensure that the two halves of
        idcache.c stay in sync.

Index: lib/Makefile
===================================================================
RCS file: lib/Makefile
diff -N lib/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/Makefile        20 Nov 2006 15:03:43 -0000
@@ -0,0 +1,6 @@
+# Run "make check" to ensure that the code passes some simple tests,
+# usually (always?) not involving compilation.
+all:
+
+check:
+       ./t-idcache
Index: lib/t-idcache
===================================================================
RCS file: lib/t-idcache
diff -N lib/t-idcache
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/t-idcache       20 Nov 2006 15:03:43 -0000
@@ -0,0 +1,52 @@
+#!/bin/sh
+# Compare the two halves (user and group) of idcache.c.
+# Once xformed, they'd better be the same:
+
+pwd=`pwd`
+t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
+trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit 
$status' 0
+trap '(exit $?); exit $?' 1 2 13 15
+
+srcdir=../..
+framework_failure=0
+mkdir -p $tmp || framework_failure=1
+cd $tmp || framework_failure=1
+
+if test $framework_failure = 1; then
+  echo "$0: failure in testing framework" 1>&2
+  (exit 1); exit 1
+fi
+
+# Extract user-oriented functions.
+perl -ne \
+  'print if /^static struct.*user_alist/ .. /^static struct.*group_alist/' \
+  $srcdir/idcache.c | head -n -3 > u
+# Extract group-oriented functions.
+perl -ne 'print if /^static struct.*group_alist/ .. eof' $srcdir/idcache.c > g
+
+# Convert user-specific strings of "u" into corresponding group-specific 
strings
+subst='
+s/user_/group_/g;
+s/\buser\b/group/g;
+s/USER/GROUP/g;
+s/\bu\b/g/g;
+s/passwd/group/g;
+s/pw_uid/gr_gid/g;
+s/pwnam/grnam/g;
+s/pwent/grent/g;
+s/getpw/getgr/g;
+s/pw_/gr_/g;
+s/UID/GID/g;
+s/uid/gid/g;
+s/getuser/getgroup/;
+s/login name/group name/;
+s/to be the/to belong to/;
+s/pwd fun/grp fun/;
+'
+
+fail=0
+# Ensure that the transformed "u" is the same as g.
+# Any differences here constitute an error.
+perl -pe "$subst" u | diff -u - g || fail=1
+
+exit $fail




reply via email to

[Prev in Thread] Current Thread [Next in Thread]