automake-patches
[Top][All Lists]
Advanced

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

[PATCH] test defs: add subroutine for input unindenting (was: Re: [Ping


From: Stefano Lattarini
Subject: [PATCH] test defs: add subroutine for input unindenting (was: Re: [Ping PATCHES] {master} Optimize tests `instspc-*.test' for speed.)
Date: Tue, 15 Feb 2011 13:36:16 +0100
User-agent: KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; )

On Tuesday 15 February 2011, Stefano Lattarini wrote:
> On Monday 14 February 2011, Ralf Wildenhues wrote:
> > Hi Stefano,
> > 
> > a while ago ...
> > 
> > * Stefano Lattarini wrote on Tue, Jan 25, 2011 at 06:38:50PM CET:
> > >   
> > > <http://lists.gnu.org/archive/html/automake-patches/2010-11/msg00152.html>
> > >   
> > > <http://lists.gnu.org/archive/html/automake-patches/2010-12/msg00006.html>
> > 
> > [BIG CUT]
> > 
> > > --- a/tests/instspc-tests.sh
> > > +++ b/tests/instspc-tests.sh
> > 
> > > @@ -94,6 +99,91 @@ define_problematic_string ()
> > >    esac
> > >  }
> > >  
> > > +# Helper subroutines for creation of input data files.
> > > +
> > > +deindent ()
> > 
> > "unindent"?  Hmm.  Both sound weird, but maybe unindent is easier to
> > read.
> >
> They're both fine with me, so I went for `unindent'.
> 
> > Might wanna have it in tests/defs?
> >
> Hmmm... maybe in a follow-up patch.  But then, IMHO, we would want
> a smarter implementation, that doesn't undiscriminately strip away
> any leading whitespace from every line.  Maybe it should look at
> the first non-blank line to determine which amount of whitespace
> to remove.  I.e., something like:
> 
> deindent > main.c <<EOF
>   main()
>     {
>       return 0;
>     }
> EOF
> 
> should result in main.c containing:
> 
> main()
>   {
>     return 0;
>   }
> 
> WDYT?
> 
OK, here's my shot at it.  The implementation might be suboptimal,
but since it wasn't completely obvious to get right, I'd rather not
tweak it anymore, until there's a real need at least.

(By the way, I think that we should really start testing non-obvious
subroutines and pieces of code defined in tests/defs.  But that's
for another thread).

OK for maint?

Regards,
  Stefano
From a67a4db5ce9b090979867ecc3bc4803254a406c5 Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <address@hidden>
Date: Tue, 15 Feb 2011 12:45:28 +0100
Subject: [PATCH] test defs: add subroutine for input unindenting

* tests/defs.in (unindent): New subroutine.

Suggestion by Ralf Wildenhues.
---
 ChangeLog     |    6 ++++++
 tests/defs.in |   25 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fa53707..9e0ad00 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2011-02-15  Stefano Lattarini  <address@hidden>
 
+       test defs: add subroutine for input unindenting
+       * tests/defs.in (unindent): New subroutine.
+       Suggestion by Ralf Wildenhues.
+
+2011-02-15  Stefano Lattarini  <address@hidden>
+
        python: report the 'PYTHON' influential environment variable
        * m4/python.m4 (AM_PATH_PYTHON): Call AC_ARG_VAR on PYTHON.
        * doc/automake.texi (Python): Update and extend.
diff --git a/tests/defs.in b/tests/defs.in
index eb92caa..0246aff 100644
--- a/tests/defs.in
+++ b/tests/defs.in
@@ -440,6 +440,31 @@ AUTOMAKE_fails ()
   AUTOMAKE_run 1 ${1+"$@"}
 }
 
+# unindent [input files...]
+# -------------------------
+# Remove the "proper" amount of leading whitespace from the given files,
+# and output the result on stdout.  That amount is determined by looking
+# at the leading whitespace of the first non-blank line in the input
+# files.  If no input file is specified, standard input is implied.
+unindent ()
+{
+  cat ${1+"$@"} > deindent.tmp
+  indentation=`sed <deindent.tmp -n "
+    /^[ $tab]*$/n
+    s/[^ $tab].*$//
+    t end
+    b
+: end
+    p
+    q
+  "`
+  case $indentation in
+    '') cat deindent.tmp;;
+     *) sed "s/^$indentation//" deindent.tmp;;
+  esac
+  rm -f deindent.tmp
+}
+
 # Turn on shell traces.
 set -x
 
-- 
1.7.2.3


reply via email to

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