automake-patches
[Top][All Lists]
Advanced

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

[FYI] {ylwrap-refactor} ylwrap: make less general and more "expert"


From: Stefano Lattarini
Subject: [FYI] {ylwrap-refactor} ylwrap: make less general and more "expert"
Date: Thu, 5 May 2011 17:07:31 +0200
User-agent: KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; )

Related to automake bug#7648 and PR automake/491.

Using the fact that ylwrap is called only in specific ways from
the Automake-generated Makefiles, we rewrote parts of it to let
it have and use more knowledge of the building process.
This decreases the generality of the script, but increases its
clarity and, more important for us, the possibility for future
optimizations and extensions.

* lib/ylwrap: Partial rewrite to take advantage of the knowledge
about the possible ways this script is called, and the fact that
it deals only with Yacc/Lex and not with generic preprocessors
or generators of C source and header files.  Also improved error
messages and checks about invalid usage.
* lib/am/yacc.am (?GENERIC?%EXT%%DERIVED-EXT%, ?!GENERIC?%OBJ%):
Adjust to the new simplified ylwrap calling convention.
(am__yacc_c2h): Remove, it's not needed anymore.
* lib/am/yacc.am (?GENERIC?%EXT%%DERIVED-EXT%, ?!GENERIC?%OBJ%):
Adjust to the new simplified ylwrap calling convention.
* automake.in (lang_yacc_target_hook): Adjust comment.
* tests/yacclex-line.test: New test.
* tests/ylwrap-extra-args.test: Likewise.
* tests/ylwrap-fail.test: Likewise.
* tests/ylwrap-lex-parallel.test: Likewise.
* tests/ylwrap-output-rename.test: Likewise.
* tests/ylwrap-path-handling.test: Likewise.
* tests/ylwrap-signals.test: Likewise.
* tests/ylwrap-yacc-dos.test: Likewise.
* tests/ylwrap-yacc-ext.test: Likewise.
* tests/ylwrap-yacc-parallel.test: Likewise.
* tests/Makefile.am (TESTS): Update.
---
 ChangeLog                       |   33 ++++++++
 automake.in                     |    2 +-
 lib/am/lex.am                   |    7 +-
 lib/am/yacc.am                  |   10 +-
 lib/ylwrap                      |  167 +++++++++++++++++++++++++--------------
 tests/Makefile.am               |   10 +++
 tests/Makefile.in               |   10 +++
 tests/yacclex-line.test         |   95 ++++++++++++++++++++++
 tests/ylwrap-extra-args.test    |   53 ++++++++++++
 tests/ylwrap-fail.test          |  141 +++++++++++++++++++++++++++++++++
 tests/ylwrap-lex-parallel.test  |   64 +++++++++++++++
 tests/ylwrap-output-rename.test |  135 +++++++++++++++++++++++++++++++
 tests/ylwrap-path-handling.test |   91 +++++++++++++++++++++
 tests/ylwrap-signals.test       |   68 ++++++++++++++++
 tests/ylwrap-yacc-dos.test      |   59 ++++++++++++++
 tests/ylwrap-yacc-ext.test      |   54 +++++++++++++
 tests/ylwrap-yacc-parallel.test |   72 +++++++++++++++++
 17 files changed, 1002 insertions(+), 69 deletions(-)
 create mode 100755 tests/yacclex-line.test
 create mode 100755 tests/ylwrap-extra-args.test
 create mode 100755 tests/ylwrap-fail.test
 create mode 100755 tests/ylwrap-lex-parallel.test
 create mode 100755 tests/ylwrap-output-rename.test
 create mode 100755 tests/ylwrap-path-handling.test
 create mode 100755 tests/ylwrap-signals.test
 create mode 100755 tests/ylwrap-yacc-dos.test
 create mode 100755 tests/ylwrap-yacc-ext.test
 create mode 100755 tests/ylwrap-yacc-parallel.test

diff --git a/ChangeLog b/ChangeLog
index 903a49a..1634f9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2011-05-05  Stefano Lattarini  <address@hidden>
+
+       ylwrap: make less general and more "expert"
+       Related to automake bug#7648 and PR automake/491.
+       Using the fact that ylwrap is called only in specific ways from
+       the Automake-generated Makefiles, we rewrote parts of it to let
+       it have and use more knowledge of the building process.
+       This decreases the generality of the script, but increases its
+       clarity and, more important for us, the possibility for future
+       optimizations and extensions.
+       * lib/ylwrap: Partial rewrite to take advantage of the knowledge
+       about the possible ways this script is called, and the fact that
+       it deals only with Yacc/Lex and not with generic preprocessors
+       or generators of C source and header files.  Also improved error
+       messages and checks about invalid usage.
+       * lib/am/yacc.am (?GENERIC?%EXT%%DERIVED-EXT%, ?!GENERIC?%OBJ%):
+       Adjust to the new simplified ylwrap calling convention.
+       (am__yacc_c2h): Remove, it's not needed anymore.
+       * lib/am/yacc.am (?GENERIC?%EXT%%DERIVED-EXT%, ?!GENERIC?%OBJ%):
+       Adjust to the new simplified ylwrap calling convention.
+       * automake.in (lang_yacc_target_hook): Adjust comment.
+       * tests/yacclex-line.test: New test.
+       * tests/ylwrap-extra-args.test: Likewise.
+       * tests/ylwrap-fail.test: Likewise.
+       * tests/ylwrap-lex-parallel.test: Likewise.
+       * tests/ylwrap-output-rename.test: Likewise.
+       * tests/ylwrap-path-handling.test: Likewise.
+       * tests/ylwrap-signals.test: Likewise.
+       * tests/ylwrap-yacc-dos.test: Likewise.
+       * tests/ylwrap-yacc-ext.test: Likewise.
+       * tests/ylwrap-yacc-parallel.test: Likewise.
+       * tests/Makefile.am (TESTS): Update.
+
 2011-05-04  Stefano Lattarini  <address@hidden>
 
        tests: add a couple of inter-tests reference
diff --git a/automake.in b/automake.in
index de0833c..e07fb22 100755
--- a/automake.in
+++ b/automake.in
@@ -6109,7 +6109,7 @@ sub lang_yacc_target_hook
        (my $output_ext = basename ($output)) =~ s/.*(\.[^.]+)$/$1/;
 
        # We know that a yacc input should be turned into either a C or
-       # C++ output file.  We depend on this fact (here and in yacc.am),
+       # C++ output file.  We depend on this fact (here and in ylwrap),
        # so check that it really holds.
        my $lang = $languages{$extension_map{$output_ext}};
        prog_error "invalid output name `$output' for yacc file `$input'"
diff --git a/lib/am/lex.am b/lib/am/lex.am
index fb4077d..8f8300b 100644
--- a/lib/am/lex.am
+++ b/lib/am/lex.am
@@ -24,8 +24,11 @@ endif %?MAINTAINER-MODE%
 
 ?GENERIC?%EXT%%DERIVED-EXT%:
 ?!GENERIC?%OBJ%: %SOURCE%
-?GENERIC?      %VERBOSE%$(am__skiplex) $(SHELL) $(YLWRAP) %SOURCE% 
$(LEX_OUTPUT_ROOT).c %OBJ% -- %COMPILE%
+?GENERIC?      %VERBOSE%$(am__skiplex) \
 ?!GENERIC?     %VERBOSE% \
 ?!GENERIC??DIST_SOURCE?        $(am__skiplex) \
+       $(SHELL) $(YLWRAP) --lex $(LEX_OUTPUT_ROOT) \
+?GENERIC?      %SOURCE% \
 ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%.
-?!GENERIC?     $(SHELL) $(YLWRAP) `test -f '%SOURCE%' || echo 
'$(srcdir)/'`%SOURCE% $(LEX_OUTPUT_ROOT).c %OBJ% -- %COMPILE%
+?!GENERIC?     `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% \
+       %OBJ% -- %COMPILE%
diff --git a/lib/am/yacc.am b/lib/am/yacc.am
index 8ad4074..a255fb2 100644
--- a/lib/am/yacc.am
+++ b/lib/am/yacc.am
@@ -37,15 +37,15 @@ if %?FIRST%
 if %?MAINTAINER-MODE%
 @address@hidden = test -f $@ ||
 endif %?MAINTAINER-MODE%
-## The 's/c$/h/' substitution *must* be the last one.
-am__yacc_c2h = sed -e s/cc$$/hh/ -e s/cpp$$/hpp/ -e s/cxx$$/hxx/ \
-                  -e s/c++$$/h++/ -e s/c$$/h/
 endif %?FIRST%
 
 ?GENERIC?%EXT%%DERIVED-EXT%:
 ?!GENERIC?%OBJ%: %SOURCE%
-?GENERIC?      %VERBOSE%$(am__skipyacc) $(SHELL) $(YLWRAP) %SOURCE% y.tab.c 
%OBJ% y.tab.h `echo %OBJ% | $(am__yacc_c2h)` y.output %BASE%.output -- %COMPILE%
+?GENERIC?      %VERBOSE%$(am__skipyacc) \
 ?!GENERIC?     %VERBOSE% \
 ?!GENERIC??DIST_SOURCE?        $(am__skipyacc) \
+        $(SHELL) $(YLWRAP) --yacc %EXT% \
+?GENERIC?      %SOURCE% \
 ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%.
-?!GENERIC?     $(SHELL) $(YLWRAP) `test -f '%SOURCE%' || echo 
'$(srcdir)/'`%SOURCE% y.tab.c %OBJ% y.tab.h `echo %OBJ% | $(am__yacc_c2h)` 
y.output %BASE%.output -- %COMPILE%
+?!GENERIC?     `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% \
+       %OBJ% -- %COMPILE%
diff --git a/lib/ylwrap b/lib/ylwrap
index 92b2011..9dd3b89 100755
--- a/lib/ylwrap
+++ b/lib/ylwrap
@@ -1,12 +1,12 @@
 #! /bin/sh
 # ylwrap - wrapper for lex/yacc invocations.
 
-scriptversion=2010-02-06.18; # UTC
+scriptversion=2011-05-05.09; # UTC
 
 # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
-# 2007, 2009, 2010 Free Software Foundation, Inc.
+# 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
 #
-# Written by Tom Tromey <address@hidden>.
+# Originally written by Tom Tromey <address@hidden>.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -30,28 +30,30 @@ scriptversion=2010-02-06.18; # UTC
 # bugs to <address@hidden> or send patches to
 # <address@hidden>.
 
+usage_error ()
+{
+    echo "$0: $*" >&2
+    echo "Try \`$0 --help' for more information." >&2
+    exit 2
+}
+
+test $# -gt 0 || usage_error "missing argument"
+
 case "$1" in
-  '')
-    echo "$0: No files given.  Try \`$0 --help' for more information." 1>&2
-    exit 1
-    ;;
   --basedir)
     basedir=$2
     shift 2
     ;;
   -h|--h*)
     cat <<\EOF
-Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
-
-Wrapper for lex/yacc invocations, renaming files as desired.
-
-  INPUT is the input file
-  OUTPUT is one file PROG generates
-  DESIRED is the file we actually want instead of OUTPUT
-  PROGRAM is program to run
-  ARGS are passed to PROG
+ylwrap: Wrapper for lex/yacc invocations, renaming files as desired.
 
-Any number of OUTPUT,DESIRED pairs may be used.
+Usage:
+  ylwrap {--help|--version}
+or:
+  ylwrap --yacc YACC-EXTENSION INPUT [--] PROGRAM [ARGS]...
+or:
+  ylwrap --lex LEX-OUTPUT-ROOT INPUT OUTPUT [--] PROGRAM [ARGS]...
 
 Report bugs to <address@hidden>.
 EOF
@@ -61,12 +63,70 @@ EOF
     echo "ylwrap $scriptversion"
     exit $?
     ;;
+  --yacc)
+    wrapped=yacc
+    shift
+    case $# in
+      0) usage_error "missing yacc extension";;
+      1) usage_error "missing input file";;
+      2) usage_error "missing output file";;
+    esac
+    y_ext=`expr x"$1" : x'\.\(.*\)'`
+    input=$2
+    output=$3
+    shift 3
+    ;;
+  --lex)
+    wrapped=lex
+    shift
+    case $# in
+      0) usage_error "missing lex output root";;
+      1) usage_error "missing input file";;
+      2) usage_error "missing output file";;
+    esac
+    lex_output_root=$1
+    input=$2
+    output=$3
+    shift 3
+    ;;
+  -*)
+    usage_error "invalid option '$1'"
+    ;;
+  *)
+    break
+    ;;
 esac
 
+case $wrapped in
+  yacc)
+    c_ext=`echo $y_ext | tr 'y' 'c'`
+    h_ext=`echo $y_ext | tr 'y' 'h'`
+    output_stem=`echo "$output" | sed "s/\\\\.$c_ext$//"`
+    pairlist="
+      y.tab.c  $output_stem.$c_ext
+      y.tab.h  $output_stem.$h_ext
+      y.output $output_stem.output"
+    ;;
+  lex)
+    pairlist="$lex_output_root.c $output"
+    ;;
+  '')
+    usage_error "no operation mode specified"
+    ;;
+  *)
+    exit 255 # not reached
+    ;;
+esac
 
-# The input.
-input="$1"
+if test x"$1" = x"--"; then
+  shift
+fi
+
+# The program to run.
+test $# -gt 0 || usage_error "missing program to run"
+prog="$1"
 shift
+
 case "$input" in
   [\\/]* | ?:[\\/]*)
     # Absolute path; do nothing.
@@ -77,19 +137,6 @@ case "$input" in
     ;;
 esac
 
-pairlist=
-while test "$#" -ne 0; do
-  if test "$1" = "--"; then
-    shift
-    break
-  fi
-  pairlist="$pairlist $1"
-  shift
-done
-
-# The program to run.
-prog="$1"
-shift
 # Make any relative path in $prog absolute.
 case "$prog" in
   [\\/]* | ?:[\\/]*) ;;
@@ -100,6 +147,8 @@ esac
 # other machines.  But that might take us over the 14-char limit.
 dirname=ylwrap$$
 do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit 
$ret'
+# The only signals which are portably trappable are 1 (SIGHUP),
+# 2 (SIGINT), 13 (SIGPIPE) and 15 (SIGTERM).
 trap "ret=129; $do_exit" 1
 trap "ret=130; $do_exit" 2
 trap "ret=141; $do_exit" 13
@@ -115,15 +164,18 @@ esac
 ret=$?
 
 if test $ret -eq 0; then
+
   set X $pairlist
   shift
-  first=yes
-  # Since DOS filename conventions don't allow two dots,
-  # the DOS version of Bison writes out y_tab.c instead of y.tab.c
-  # and y_tab.h instead of y.tab.h. Test to see if this is the case.
-  y_tab_nodot="no"
-  if test -f y_tab.c || test -f y_tab.h; then
-    y_tab_nodot="yes"
+
+  if test $wrapped = yacc; then
+    # Since DOS filename conventions don't allow two dots,
+    # the DOS version of Bison writes out y_tab.c instead of y.tab.c
+    # and y_tab.h instead of y.tab.h. Test to see if this is the case.
+    y_tab_nodot="no"
+    if test -f y_tab.c || test -f y_tab.h; then
+      y_tab_nodot="yes"
+    fi
   fi
 
   # The directory holding the input.
@@ -134,15 +186,11 @@ if test $ret -eq 0; then
 
   while test "$#" -ne 0; do
     from="$1"
-    # Handle y_tab.c and y_tab.h output by DOS
-    if test $y_tab_nodot = "yes"; then
-      if test $from = "y.tab.c"; then
-       from="y_tab.c"
-      else
-       if test $from = "y.tab.h"; then
-         from="y_tab.h"
-       fi
-      fi
+    ofrom="$from"
+    if test $wrapped = "yacc" && test $y_tab_nodot = "yes"; then
+      # Handle y_tab.c and y_tab.h output by DOS
+      test $from = "y.tab.c" && from="y_tab.c"
+      test $from = "y.tab.h" && from="y_tab.h"
     fi
     if test -f "$from"; then
       # If $2 is an absolute path name, then just use that,
@@ -158,7 +206,7 @@ if test $ret -eq 0; then
       # because it is the destination of the .y.c rule in the
       # Makefile.  Divert the output of all other files to a temporary
       # file so we can compare them to existing versions.
-      if test $first = no; then
+      if test $wrapped = yacc && test $ofrom = "y.tab.h"; then
        realtarget="$target"
        target="tmp-`echo $target | sed s/.*[\\/]//g`"
       fi
@@ -183,7 +231,7 @@ if test $ret -eq 0; then
           -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
 
       # Check whether header files must be updated.
-      if test $first = no; then
+      if test $wrapped = "yacc" && test $ofrom = "y.tab.h"; then
        if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
          echo "$2" is unchanged
          rm -f "$target"
@@ -192,21 +240,18 @@ if test $ret -eq 0; then
           mv -f "$target" "$realtarget"
         fi
       fi
-    else
-      # A missing file is only an error for the first file.  This
-      # is a blatant hack to let us support using "yacc -d".  If -d
-      # is not specified, we don't want an error when the header
-      # file is "missing".
-      if test $first = yes; then
-        ret=1
-      fi
+    else # ! -f $from
+      # When using yacc, if the `-d' option is not used, we don't want an
+      # error when the header file is "missing".  Similarly, if `-v' is not
+      # used, we don't want an error when the `y.output' file is "missing".
+      case $wrapped:$ofrom in
+        yacc:y.tab.h|yacc:y.output) ;;
+        *) ret=1;;
+      esac
     fi
     shift
     shift
-    first=no
   done
-else
-  ret=$?
 fi
 
 # Remove the directory.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1f3e83f..0c0968b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -868,6 +868,16 @@ yflags-d-false-positives.test \
 yflags-force-override.test \
 yflags-force-conditional.test \
 yflags-var-expand.test \
+yacclex-line.test \
+ylwrap-extra-args.test \
+ylwrap-fail.test \
+ylwrap-lex-parallel.test \
+ylwrap-output-rename.test \
+ylwrap-path-handling.test \
+ylwrap-signals.test \
+ylwrap-yacc-dos.test \
+ylwrap-yacc-ext.test \
+ylwrap-yacc-parallel.test \
 $(parallel_tests)
 
 EXTRA_DIST = ChangeLog-old gen-parallel-tests $(TESTS)
diff --git a/tests/Makefile.in b/tests/Makefile.in
index c06637e..0aa6af5 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -1139,6 +1139,16 @@ yflags-d-false-positives.test \
 yflags-force-override.test \
 yflags-force-conditional.test \
 yflags-var-expand.test \
+yacclex-line.test \
+ylwrap-extra-args.test \
+ylwrap-fail.test \
+ylwrap-lex-parallel.test \
+ylwrap-output-rename.test \
+ylwrap-path-handling.test \
+ylwrap-signals.test \
+ylwrap-yacc-dos.test \
+ylwrap-yacc-ext.test \
+ylwrap-yacc-parallel.test \
 $(parallel_tests)
 
 EXTRA_DIST = ChangeLog-old gen-parallel-tests $(TESTS)
diff --git a/tests/yacclex-line.test b/tests/yacclex-line.test
new file mode 100755
index 0000000..2f8765a
--- /dev/null
+++ b/tests/yacclex-line.test
@@ -0,0 +1,95 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test how ylwrap adjusts "#line" directives.
+
+required='lex yacc'
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AC_PROG_YACC
+AC_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = maude
+maude_SOURCES = main.c foobar.l zardoz.y
+AM_YFLAGS = -d
+BUILT_SOURCES = zardoz.h
+LDADD = @LEXLIB@
+## Avoid spurious faulures with Solaris make.
address@hidden@: foobar.c
address@hidden@: zardoz.c
+END
+
+cat > foobar.l << 'END'
+%%
+"END" return EOF;
+.
+%%
+END
+
+cat > zardoz.y << 'END'
+%{
+int yylex ();
+void yyerror (char *s) { return; }
+%}
+%token TOKEN
+%%
+x : 'x' {};
+END
+
+cat > main.c << 'END'
+#include "zardoz.h"
+int main (void)
+{
+  return yyparse ();
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+for vpath in : false; do
+  if $vpath; then
+    srcdir=..
+    mkdir build
+    cd build
+  else
+    srcdir=.
+  fi
+  $srcdir/configure
+  $MAKE
+  # Sanity check.
+  test -f foobar.c
+  test -f zardoz.c
+  test -f zardoz.h
+  # For debugging.
+  grep '#.*line' foobar.c zardoz.c zardoz.h
+  # Do checks.
+  ws="[$sp$tab]"
+  $EGREP '#.*(y\.tab|lex\.yy)' foobar.c zardoz.c zardoz.h && Exit 1
+  grep "^$ws*#.*line$ws.*foobar\\.l" foobar.c
+  grep "^$ws*#.*line$ws.*zardoz\\.y" zardoz.c
+  cd $srcdir
+done
+
+:
diff --git a/tests/ylwrap-extra-args.test b/tests/ylwrap-extra-args.test
new file mode 100755
index 0000000..465de64
--- /dev/null
+++ b/tests/ylwrap-extra-args.test
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test that one can pass arguments to the program run by ylwrap.
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir"/../lib/ylwrap .
+
+mkdir bin
+cat > bin/fake-yacc <<'END'
+#!/bin/sh
+echo " $* " > y.tab.c
+END
+cat > bin/fake-lex <<'END'
+#!/bin/sh
+echo " $* " > lex.yy.c
+END
+chmod a+x bin/fake-yacc bin/fake-lex
+PATH=`pwd`/bin$PATH_SEPARATOR$PATH; export PATH
+
+manyargs='0 1 2 3 4 5 6 7 8 9 @ : foo bar zardoz asd-asd-asd-asd-asd-asd'
+
+mkdir yacc
+cd yacc
+$SHELL -x ../ylwrap --yacc .y foo.y foo.c fake-yacc GrepMe
+cat foo.c
+$FGREP " GrepMe " foo.c
+cd ..
+
+mkdir lex
+cd lex
+$SHELL -x ../ylwrap --lex lex.yy bar.l bar.c fake-lex $manyargs
+cat bar.c
+$FGREP " $manyargs " bar.c
+cd ..
+
+:
diff --git a/tests/ylwrap-fail.test b/tests/ylwrap-fail.test
new file mode 100755
index 0000000..8c5f424
--- /dev/null
+++ b/tests/ylwrap-fail.test
@@ -0,0 +1,141 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check how ylwrap handles runtime failures and/or incorrect usages.
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir"/../lib/ylwrap .
+
+#
+# Check usage errors.
+#
+
+$SHELL ./ylwrap 2>stderr && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'ylwrap:.*missing argument' stderr
+grep 'Try.*ylwrap --help' stderr
+
+$SHELL ./ylwrap foo 2>stderr && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'ylwrap:.*no operation mode specified' stderr
+grep 'Try.*ylwrap --help' stderr
+
+for opt in -x --foo -df --bar=qux -- -; do
+  $SHELL ./ylwrap $opt 2>stderr && { cat stderr >&2; Exit 1; }
+  cat stderr >&2
+  grep "ylwrap:.*invalid option.*$opt" stderr
+  grep 'Try.*ylwrap --help' stderr
+done
+
+$SHELL ./ylwrap --yacc 2>stderr && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'ylwrap:.*missing yacc extension' stderr
+grep 'Try.*ylwrap --help' stderr
+
+$SHELL ./ylwrap --lex 2>stderr && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'ylwrap:.*missing lex output root' stderr
+grep 'Try.*ylwrap --help' stderr
+
+$SHELL ./ylwrap --yacc .y 2>stderr && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'ylwrap:.*missing input file' stderr
+grep 'Try.*ylwrap --help' stderr
+
+$SHELL ./ylwrap 2>stderr --lex foo.yy && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'ylwrap:.*missing input file' stderr
+grep 'Try.*ylwrap --help' stderr
+
+$SHELL ./ylwrap 2>stderr --lex foo.yy bar.l && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'ylwrap:.*missing output file' stderr
+grep 'Try.*ylwrap --help' stderr
+
+for preamble in '--yacc .y foo.y foo.c' '--lex lex.yy bar.l bar.c'; do
+  for separator in '' '--'; do
+    $SHELL ./ylwrap $preamble $separator 2>stderr \
+      && { cat stderr >&2; Exit 1; }
+    cat stderr >&2
+    grep 'ylwrap:.*missing program to run' stderr
+    grep 'Try.*ylwrap --help' stderr
+  done
+done
+
+#
+# Now check runtime failures.
+#
+
+# Check that temporary files/directories are not left lying around.
+check_emptydir ()
+{
+  ls -a ${1-.} | $EGREP -v '^\.\.?$' && { ls -l; Exit 1; }
+  :
+}
+
+mkdir bin
+cat > bin/fail.sh <<'END'
+echo o:FAIL
+echo e:FAIL >&2
+: > bad-file
+(exit 1); exit 1
+END
+cat > bin/exit13.sh <<'END'
+#!/bin/sh
+: > bad-file
+(exit 13); exit 13
+END
+chmod a+x bin/fail.sh bin/exit13.sh
+PATH=`pwd`/bin$PATH_SEPARATOR$PATH; export PATH
+
+mkdir foo
+cd foo
+$SHELL ../ylwrap --yacc .y foo.y foo.c -- fail.sh >../stdout 2>../stderr \
+  && { cat ../stdout; cat ../stderr >&2; Exit 1; }
+cat ../stdout
+cat ../stderr >&2
+check_emptydir
+# ylwrap should pass messages through.
+grep '^o:FAIL$' ../stdout
+grep '^e:FAIL$' ../stderr
+cd ..
+
+mkdir bar
+cd bar
+if $SHELL -x ../ylwrap --lex x.yy foo.l foo.c -- exit13.sh; then
+  Exit 1
+else
+  # Return the same failure of the invoked program.
+  test $? -eq 13 || Exit 1
+fi
+check_emptydir
+cd ..
+
+mkdir baz
+cd baz
+if $SHELL -x ../ylwrap --yacc .yxx foo.yxx foo.cxx -- _NoSuchCommand_; then
+  Exit 1
+else
+  # If ylwrap fails to found the given program, it must exit with 127.
+  test $? -eq 127 || Exit 1
+fi
+check_emptydir
+cd ..
+
+:
diff --git a/tests/ylwrap-lex-parallel.test b/tests/ylwrap-lex-parallel.test
new file mode 100755
index 0000000..1233b4f
--- /dev/null
+++ b/tests/ylwrap-lex-parallel.test
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that ylwrap can handle multiple instances of yacc running
+# in parallel.
+# Keep this in sync with sister test `ylwrap-yacc-parallel.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir"/../lib/ylwrap .
+
+mkdir bin
+cat > bin/fake-lex <<'END'
+#!/bin/sh -e
+printf 'l:%s-' "$1" > lex.yy.c
+sleep $time
+printf '%s:l\n' "$1" >> lex.yy.c
+chmod a-w lex.yy.c
+END
+chmod a+x bin/fake-lex
+PATH=`pwd`/bin$PATH_SEPARATOR$PATH; export PATH
+
+args='a b foo zardoz bar x'
+
+# The possible errors are time-dependent race conditions, so try a few
+# times in order to to maximize the possibility of hitting such races (if
+# they exist).
+for try in 1 2 3 4; do
+    mkdir $try
+    cd $try
+    for arg in $args; do \
+      time=`printf %s $arg | wc -c`; export time
+      $SHELL ../ylwrap --lex lex.yy $arg.l $arg.c fake-lex $arg \
+        >stdout.$arg 2>stderr.$arg &
+      unset time
+    done
+    wait
+    for arg in $args; do
+      cat $arg.c
+      cat stdout.$arg
+      cat stderr.$arg >&2
+      test "`cat $arg.c`" = "l:$arg-$arg:l"
+      test ! -s stdout.$arg
+      test ! -s stderr.$arg
+    done
+    cd ..
+done
+
+:
diff --git a/tests/ylwrap-output-rename.test b/tests/ylwrap-output-rename.test
new file mode 100755
index 0000000..3b75499
--- /dev/null
+++ b/tests/ylwrap-output-rename.test
@@ -0,0 +1,135 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that ylwrap can rename output files to names that are unrelated
+# to the name of input files.  Also check for unusual or "pathological"
+# output names.
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir"/../lib/ylwrap .
+
+mkdir bin
+cat > bin/fake-yacc <<'END'
+#!/bin/sh -e
+: > y.tab.c
+case " $* " in *" -d "*) : > y.tab.h  ;; *) : ;; esac
+case " $* " in *" -v "*) : > y.output ;; *) : ;; esac
+END
+cat > bin/fake-lex <<'END'
+#!/bin/sh -e
+echo "$*" > lex.yy.c
+END
+chmod a+x bin/fake-yacc bin/fake-lex
+PATH=`pwd`/bin$PATH_SEPARATOR$PATH; export PATH
+
+mkdir yacc
+cd yacc
+$SHELL -x ../ylwrap --yacc .y foo.y zardoz.c fake-yacc
+ls -l
+test   -f zardoz.c
+test ! -f zardoz.h
+test ! -f foo.c
+test ! -f y.tab.c
+cd ..
+
+mkdir yacc-d-subdir
+cd yacc-d-subdir
+mkdir quux
+$SHELL -x ../ylwrap --yacc .y foo.y quux/zardoz.c fake-yacc -d
+ls -l . quux
+test   -f quux/zardoz.c
+test   -f quux/zardoz.h
+test ! -f zardoz.c
+test ! -f zardoz.h
+test ! -f quux/foo.c
+test ! -f quux/foo.h
+test ! -f quux/y.tab.c
+test ! -f quux/y.tab.h
+test ! -f foo.c
+test ! -f foo.h
+test ! -f y.tab.c
+test ! -f y.tab.h
+cd ..
+
+mkdir yacc-cxx
+cd yacc-cxx
+$SHELL -x ../ylwrap --yacc .yxx foo.yxx f-o--o-.cxx fake-yacc
+ls -l
+test   -f f-o--o-.cxx
+test ! -f foo.c
+test ! -f foo.cxx
+test ! -f y.tab.c
+cd ..
+
+mkdir yacc-cxx-d
+cd yacc-cxx-d
+$SHELL -x ../ylwrap --yacc .y++ foo.y++ .quux..c++ fake-yacc -d
+ls -l
+test   -f .quux..c++
+test   -f .quux..h++
+test ! -f foo.c
+test ! -f foo.c++
+test ! -f foo.h
+test ! -f foo.h++
+test ! -f y.tab.c
+test ! -f y.tab.h
+cd ..
+
+mkdir yacc-cxx-d-v
+cd yacc-cxx-d-v
+$SHELL -x ../ylwrap --yacc .yy foo.yy y.tab.cc fake-yacc -d -v
+ls -l
+test   -f y.tab.cc
+test   -f y.tab.hh
+test   -f y.tab.output
+test ! -f foo.cc
+test ! -f foo.hh
+test ! -f foo.c
+test ! -f foo.h
+test ! -f y.tab.c
+test ! -f y.tab.h
+test ! -f y.output
+cd ..
+
+mkdir lex
+cd lex
+$SHELL -x ../ylwrap --lex lex.yy bar.l c.c fake-lex
+test   -f c.c
+test ! -f bar.c
+test ! -f lex.yy.c
+cd ..
+
+mkdir lex-cxx-1
+cd lex-cxx-1
+$SHELL -x ../ylwrap --lex lex.yy bar.ll cxx.cc fake-lex
+test   -f cxx.cc
+test ! -f bar.c
+test ! -f bar.cc
+test ! -f lex.yy.c
+cd ..
+
+mkdir lex-cxx-2
+cd lex-cxx-2
+$SHELL -x ../ylwrap --lex lex.yy bar.lpp y.cpp fake-lex
+test   -f y.cpp
+test ! -f bar.c
+test ! -f bar.cpp
+test ! -f lex.yy.c
+
+:
diff --git a/tests/ylwrap-path-handling.test b/tests/ylwrap-path-handling.test
new file mode 100755
index 0000000..47fd193
--- /dev/null
+++ b/tests/ylwrap-path-handling.test
@@ -0,0 +1,91 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check how ylwrap handle relative and absolute paths/names for input
+# file, output file, and program to run.
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir"/../lib/ylwrap .
+
+cat > fake-yacc <<'END'
+#!/bin/sh -e
+cp "$1" y.tab.c
+cp "$1" y.tab.h
+cp "$1" y.output
+END
+cat > fake-lex <<'END'
+#!/bin/sh -e
+cp "$1" lex.yy.c
+END
+chmod a+x fake-yacc fake-lex
+
+ocwd=`pwd` || Exit 99
+
+mkdir 1
+cd 1
+echo 'blah 1' > foo.y
+$SHELL -x ../ylwrap --yacc .y "$ocwd"/1/foo.y ../1/foo.c ../fake-yacc
+ls -l
+cmp foo.y foo.c
+cmp foo.y foo.h
+cmp foo.y foo.output
+cd ..
+
+mkdir 2
+cd 2
+echo 'blah 2' > foo.yy
+cp ../fake-yacc .
+$SHELL -x ../ylwrap --yacc .yy ./foo.yy "$ocwd"/2/foo.cc -- ./fake-yacc
+ls -l
+cmp foo.yy foo.cc
+cmp foo.yy foo.hh
+cmp foo.yy foo.output
+cd ..
+
+mkdir 3
+cd 3
+mkdir sub1 sub2
+echo 'blah 3' > sub1/foo.yxx
+cp ../fake-yacc .
+$SHELL -x ../ylwrap --yacc .yxx sub1/foo.yxx sub2/foo.cxx -- ../3/fake-yacc
+ls -l
+cmp sub1/foo.yxx sub2/foo.cxx
+cmp sub1/foo.yxx sub2/foo.hxx
+cmp sub1/foo.yxx sub2/foo.output
+cd ..
+
+mkdir 4
+cd 4
+echo 'blah 4' > foo.l
+$SHELL -x ../ylwrap --lex lex.yy ../4/foo.l ./foo.c "$ocwd"/fake-lex
+ls -l
+cmp foo.l foo.c
+cd ..
+
+mkdir 5
+cd 5
+echo 'blah 5' > foo.l++
+mkdir sub
+cp ../fake-lex sub
+$SHELL -x ../ylwrap --lex lex.yy foo.l++ foo.c++ -- sub/fake-lex
+ls -l
+cmp foo.l++ foo.c++
+cd ..
+
+:
diff --git a/tests/ylwrap-signals.test b/tests/ylwrap-signals.test
new file mode 100755
index 0000000..5bc158e
--- /dev/null
+++ b/tests/ylwrap-signals.test
@@ -0,0 +1,68 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check how ylwrap trap signals.
+
+. ./defs || Exit 1
+
+set -e
+
+test `ps -o pid $$ | sed 1d` -eq $$ || skip_ "requires POSIX 'ps' program"
+
+cp "$testsrcdir"/../lib/ylwrap .
+
+mkdir bin
+# This is hacky and ugly, but will avoid pain with background
+# processes and related synchronization issues.
+cat > bin/parricide <<'END'
+#!/bin/sh
+signum=$1
+# We expect ylwrap to clean up these.
+touch y.tab.c y.tab.h lex.yy.c || exit 1
+touch random-file .hidden-file || exit 1
+mkdir random-dir .hidden-dir || exit 1
+pwd
+ls -l
+ppid=`ps -o ppid $$ | sed 1d` && test -n "$$ppid" || exit 1
+ps $ppid $$ || : For debugging.
+kill -$signum $ppid || exit 1
+END
+chmod a+x bin/parricide
+PATH=`pwd`/bin$PATH_SEPARATOR$PATH; export PATH
+
+do_check ()
+{
+  signum=$1; shift
+  ret=0
+  $SHELL -x ../ylwrap $* parricide $signum || ret=$?
+  # Return a proper exit status.
+  test $ret -eq `expr 128 + $signum`
+  # Do not leave temporary files/directories lying around.
+  ls -a | $EGREP -v '^\.\.?$' && { ls -l; Exit 1; }
+  :
+}
+
+mkdir work
+cd work
+
+# The only signals which are portably trappable are 1 (SIGHUP),
+# 2 (SIGINT), 13 (SIGPIPE) and 15 (SIGTERM).
+do_check 1 --yacc .y foo.y foo.c
+do_check 2 --lex .l foo.l foo.c
+do_check 13 --yacc .yy foo.yy foo.cc
+do_check 15 --yacc lex.yy.c foo.l++ foo.c++
+
+:
diff --git a/tests/ylwrap-yacc-dos.test b/tests/ylwrap-yacc-dos.test
new file mode 100755
index 0000000..b065758
--- /dev/null
+++ b/tests/ylwrap-yacc-dos.test
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test that ylwrap behaves well on DOS, where yacc/bison produces file
+# named y_tab.c and y_tab.j instead of y.tab.h and y.tab.c.
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir"/../lib/ylwrap .
+
+mkdir bin
+cat > bin/dos-yacc <<'END'
+#!/bin/sh -e
+echo 'C source' > y_tab.c
+case $1 in -*d*) echo 'C header' > y_tab.h;; esac
+case $1 in -*v*) echo stats > y.output;; esac
+END
+chmod a+x bin/dos-yacc
+
+PATH=`pwd`/bin$PATH_SEPARATOR$PATH; export PATH
+
+for opts in '' d v vd; do
+    dir=foo${opts}.dir
+    mkdir $dir
+    cd $dir
+    $SHELL -x ../ylwrap --yacc .y bar.y bar.c dos-yacc -$opts
+    ls -l # For debugging.
+    ls y[._]* && Exit 1
+    cat bar.c
+    test "`cat bar.c`" = 'C source'
+    case $opts in
+      *d*)
+        cat bar.h
+        test "`cat bar.h`" = 'C header';;
+    esac
+    case $opts in
+      *v*)
+        cat bar.output
+        test "`cat bar.output`" = stats;;
+    esac
+    cd ..
+done
+
+:
diff --git a/tests/ylwrap-yacc-ext.test b/tests/ylwrap-yacc-ext.test
new file mode 100755
index 0000000..0c81968
--- /dev/null
+++ b/tests/ylwrap-yacc-ext.test
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test ylwrap when used as a yacc wrapper for Yacc files with different
+# extensions (.yy, .y++, .yxx, ypp).
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir"/../lib/ylwrap .
+
+mkdir bin
+cat > bin/fake-yacc <<'END'
+#!/bin/sh -e
+: > y.tab.c
+case $1 in -*d*) : > y.tab.h;; esac
+case $1 in -*v*) : > y.output;; esac
+END
+chmod a+x bin/fake-yacc
+PATH=`pwd`/bin:$PATH; export PATH
+
+for mold in _ __ _++ _xx _pp; do
+  for opts in '' d v vd; do
+    dir=${mold}-${opts}.dir
+    mkdir $dir
+    cd $dir
+    y=`echo $mold | sed 's/_/y/g'`
+    c=`echo $mold | sed 's/_/c/g'`
+    h=`echo $mold | sed 's/_/h/g'`
+    $SHELL -x ../ylwrap --yacc .$y x.$y x.$c fake-yacc -$opts
+    ls -l # For debugging.
+    ls y.* && Exit 1
+    test -f x.$c
+    case $opts in *d*) test -f x.$h;; *) :;; esac
+    case $opts in *v*) test -f x.output;; *) :;; esac
+    cd ..
+  done
+done
+
+:
diff --git a/tests/ylwrap-yacc-parallel.test b/tests/ylwrap-yacc-parallel.test
new file mode 100755
index 0000000..fb4c558
--- /dev/null
+++ b/tests/ylwrap-yacc-parallel.test
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that ylwrap can handle multiple instances of yacc running
+# in parallel.
+# Keep this in sync with sister test `ylwrap-lex-parallel.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir"/../lib/ylwrap .
+
+mkdir bin
+cat > bin/fake-yacc <<'END'
+#!/bin/sh -e
+
+printf 'c:%s-' "$1" > y.tab.c
+sleep $time
+printf '%s\n' "$1" >> y.tab.c
+chmod a-w y.tab.c
+
+printf 'h:%s-' "$1" > y.tab.h
+sleep $time
+printf '%s\n' "$1" >> y.tab.h
+chmod a-w y.tab.h
+END
+chmod a+x bin/fake-yacc
+PATH=`pwd`/bin:$PATH; export PATH
+
+args='a b foo zardoz bar x'
+
+# The possible errors are time-dependent race conditions, so try a few
+# times in order to to maximize the possibility of hitting such races (if
+# they exist).
+for try in 1 2 3 4; do
+    mkdir $try
+    cd $try
+    for arg in $args; do \
+      time=`printf %s $arg | wc -c`; export time
+      $SHELL ../ylwrap --yacc .y $arg.y $arg.c fake-yacc $arg \
+        >stdout.$arg 2>stderr.$arg &
+      unset time
+    done
+    wait
+    for arg in $args; do
+      cat $arg.c
+      cat $arg.h
+      cat stdout.$arg
+      cat stderr.$arg >&2
+      test "`cat $arg.c`" = "c:$arg-$arg"
+      test "`cat $arg.h`" = "h:$arg-$arg"
+      test "`cat stdout.$arg`" = "updating $arg.h"
+      test ! -s stderr.$arg
+    done
+    cd ..
+done
+
+:
-- 
1.7.2.3




reply via email to

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