automake-patches
[Top][All Lists]
Advanced

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

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


From: Stefano Lattarini
Subject: Re: [PATCH] test defs: add subroutine for input unindenting
Date: Wed, 16 Feb 2011 13:21:00 +0100
User-agent: KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; )

On Wednesday 16 February 2011, Ralf Wildenhues wrote:
> * Stefano Lattarini wrote on Wed, Feb 16, 2011 at 12:29:02AM CET:
> > On Tuesday 15 February 2011, Ralf Wildenhues wrote:
> > > The space after : is not portable.  The sed script could be shortened to
> > >   sed -n "/[^ $tab].*$/{
> > >             s///p
> > >             d
> > >           }"
> > >
> > Did you mean 'q' instead of 'd' here, right?
> 
> Yes.  Sorry about that.
>
OK, fixed.

> > > It's a bit of a shame this uses a temp file though.  awk should be able
> > > to cope without
> > >
> > Yes, if I could assume "new" awk.  But traditional awk lacks the 'sub()'
> > and 'gsub()' builtins, so I really really don't want to go down that road.
> > Moreover, the use of a tempfile is not a big issue here, because we can
> > already assume the existence of a temporary working directory (i.e., the
> > one the test runs in) and of a cleanup trap (installed by `tests/defs').
> 
> True.  One would assume that it's not common to use more than one
> function invocation in parallel:
>   deindent foo | deindent > ...
>
Which should be a no-op, BTW.

> or:
>   deindent foo > ... & deindent bar ...
> 
> > But if you truly truly dislike the use of the tempfile, I could try to
> > use perl instead...  WDYT?
> 
> That'll slow things down more than using a temp file, so I'm reasonably
> happy with sed+sed right now.
>
OK.  Attached is what I pushed to maint, and the result of the merge to
master (which I pushed too).

Thanks,
   Stefano
From a118732d1138b169e3c41759b8e3e03945994172 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.
---
 ChangeLog     |    6 ++++++
 tests/defs.in |   18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fa53707..4563585 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-02-16  Stefano Lattarini  <address@hidden>
+           Ralf Wildenhues  <address@hidden>
+
+       test defs: add subroutine for input unindenting
+       * tests/defs.in (unindent): New subroutine.
+
 2011-02-15  Stefano Lattarini  <address@hidden>
 
        python: report the 'PYTHON' influential environment variable
diff --git a/tests/defs.in b/tests/defs.in
index eb92caa..ffe21e1 100644
--- a/tests/defs.in
+++ b/tests/defs.in
@@ -440,6 +440,24 @@ 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].*$/{
+      s///p
+      q
+  }"`
+  sed "s/^$indentation//" deindent.tmp
+  rm -f deindent.tmp
+}
+
 # Turn on shell traces.
 set -x
 
-- 
1.7.2.3

commit 95ce684f09a47df6fc165311c5372066e0e28f9f (from 
95b717e8bd43406afc81bc5f6ebeef8b81da970c)
Merge: 95b717e a118732
Author:     Stefano Lattarini <address@hidden>
AuthorDate: Wed Feb 16 13:00:59 2011 +0100
Commit:     Stefano Lattarini <address@hidden>
CommitDate: Wed Feb 16 13:00:59 2011 +0100

    Merge branch 'maint'

diff --git a/ChangeLog b/ChangeLog
index c3ff53b..12b8e9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-02-16  Stefano Lattarini  <address@hidden>
+           Ralf Wildenhues  <address@hidden>
+
+       test defs: add subroutine for input unindenting
+       * tests/defs.in (unindent): New subroutine.
+       * tests/instspc-tests.sh: Use it.
+
 2011-02-15  Stefano Lattarini  <address@hidden>
 
        python: report the 'PYTHON' influential environment variable
diff --git a/tests/defs b/tests/defs
index 4e27788..a32ef15 100644
--- a/tests/defs
+++ b/tests/defs
@@ -146,6 +146,24 @@ 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].*$/{
+      s///p
+      q
+  }"`
+  sed "s/^$indentation//" deindent.tmp
+  rm -f deindent.tmp
+}
+
 
 ## ----------------------------------------------------------- ##
 ##  Checks for required tools, and additional setups (if any)  ##
diff --git a/tests/instspc-tests.sh b/tests/instspc-tests.sh
index 981365f..2c4089f 100755
--- a/tests/instspc-tests.sh
+++ b/tests/instspc-tests.sh
@@ -101,11 +101,6 @@ define_problematic_string ()
 
 # Helper subroutines for creation of input data files.
 
-unindent ()
-{
-  sed 's/^ *//' # we don't strip leading tabs -- this is deliberate!
-}
-
 create_input_data ()
 {
   mkdir sub

reply via email to

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