[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[FYI] {ylwrap-refactor} ylwrap: new subroutine `handle_renaming'
From: |
Stefano Lattarini |
Subject: |
[FYI] {ylwrap-refactor} ylwrap: new subroutine `handle_renaming' |
Date: |
Thu, 5 May 2011 18:10:38 +0200 |
User-agent: |
KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; ) |
* lib/ylwrap: Move most of the code in the main loop into ...
(handle_renaming): ... this new subroutine.
* tests/ylwrap-fail.test: Extend the checks on "runtime" failures.
Move the checks about bad usages of ylwrap ...
* tests/ylwrap-usage-fail.test: .. into this new test.
* tests/Makefile.am (TESTS): Update.
---
ChangeLog | 10 +++
lib/ylwrap | 128 ++++++++++++++++++++++--------------------
tests/Makefile.am | 1 +
tests/Makefile.in | 1 +
tests/ylwrap-fail.test | 81 +++++++--------------------
tests/ylwrap-usage-fail.test | 77 +++++++++++++++++++++++++
6 files changed, 176 insertions(+), 122 deletions(-)
create mode 100755 tests/ylwrap-usage-fail.test
diff --git a/ChangeLog b/ChangeLog
index 55d0e9b..870d41b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2011-05-05 Stefano Lattarini <address@hidden>
+ ylwrap: new subroutine `handle_renaming'
+ * lib/ylwrap: Move most of the code in the main loop into ...
+ (handle_renaming): ... this new subroutine.
+ * tests/ylwrap-fail.test: Extend the checks on "runtime" failures.
+ Move the checks about bad usages of ylwrap ...
+ * tests/ylwrap-usage-fail.test: .. into this new test.
+ * tests/Makefile.am (TESTS): Update.
+
+2011-05-05 Stefano Lattarini <address@hidden>
+
ylwrap: new subroutine `tr_cpp'
* lib/ylwrap (tr_cpp): New subroutine, turning the given string
into a suitable C preprocessor symbol.
diff --git a/lib/ylwrap b/lib/ylwrap
index 52b6900..0b0c7e8 100755
--- a/lib/ylwrap
+++ b/lib/ylwrap
@@ -81,6 +81,72 @@ dos_fix_yacc_filenames ()
fi
}
+# Usage: handle_renaming FROM TARGET
+handle_renaming ()
+{
+ from=$1
+ ofrom=$from
+ dos_fix_yacc_filenames
+ if test -f "$from"; then
+ # If $2 is an absolute path name, then just use that,
+ # otherwise prepend `../'.
+ case $2 in
+ [\\/]* | ?:[\\/]*) target=$2;;
+ *) target=../$2;;
+ esac
+
+ # We do not want to overwrite a header file if it hasn't
+ # changed. This avoid useless recompilations. However the
+ # parser itself (the first file) should always be updated,
+ # 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 $wrapped = yacc && test $ofrom = y.tab.h; then
+ realtarget=$target
+ target=header.tmp
+ fi
+ # Edit out `#line' or `#' directives.
+ #
+ # We don't want the resulting debug information to point at
+ # an absolute srcdir; it is better for it to just mention the
+ # .y file with no path.
+ #
+ # We want to use the real output file name, not yy.lex.c for
+ # instance.
+ #
+ # We want the include guards to be adjusted too.
+ # TODO: This include guards seems not to be generated anymore
+ # by newer bison versions (at least starting from 1.875; they
+ # were still generated in version 1.75, though). Also, BSD and
+ # Solaris yacc seems not to generate such include guards either.
+ # So, how much is this code still relevant today?
+ FROM=`tr_cpp "$from"`
+ TARGET=`tr_cpp "$2"`
+
+ sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
+ -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
+
+ # Check whether header files must be updated.
+ 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"
+ else
+ echo updating "$2"
+ mv -f "$target" "$realtarget"
+ fi
+ 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
+}
+
test $# -gt 0 || usage_error "missing argument"
case "$1" in
@@ -212,67 +278,7 @@ if test $ret -eq 0; then
input_rx=`quote_for_sed "$input_dir"`
while test $# -ne 0; do
- from=$1
- ofrom=$from
- dos_fix_yacc_filenames
- if test -f "$from"; then
- # If $2 is an absolute path name, then just use that,
- # otherwise prepend `../'.
- case $2 in
- [\\/]* | ?:[\\/]*) target=$2;;
- *) target=../$2;;
- esac
-
- # We do not want to overwrite a header file if it hasn't
- # changed. This avoid useless recompilations. However the
- # parser itself (the first file) should always be updated,
- # 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 $wrapped = yacc && test $ofrom = y.tab.h; then
- realtarget=$target
- target=header.tmp
- fi
- # Edit out `#line' or `#' directives.
- #
- # We don't want the resulting debug information to point at
- # an absolute srcdir; it is better for it to just mention the
- # .y file with no path.
- #
- # We want to use the real output file name, not yy.lex.c for
- # instance.
- #
- # We want the include guards to be adjusted too.
- # TODO: This include guards seems not to be generated anymore
- # by newer bison versions (at least starting from 1.875; they
- # were still generated in version 1.75, though). Also, BSD and
- # Solaris yacc seems not to generate such include guards either.
- # So, how much is this code still relevant today?
- FROM=`tr_cpp "$from"`
- TARGET=`tr_cpp "$2"`
-
- sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
- -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
-
- # Check whether header files must be updated.
- 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"
- else
- echo updating "$2"
- mv -f "$target" "$realtarget"
- fi
- 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
+ handle_renaming "$1" "$2"
shift
shift
done
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 69e75d6..fc84450 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -873,6 +873,7 @@ ylwrap-chdir-back-fail.test \
ylwrap-cleanup-fail.test \
ylwrap-extra-args.test \
ylwrap-fail.test \
+ylwrap-usage-fail.test \
ylwrap-lex-parallel.test \
ylwrap-output-rename.test \
ylwrap-path-handling.test \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 66b0ca3..108e26d 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -1144,6 +1144,7 @@ ylwrap-chdir-back-fail.test \
ylwrap-cleanup-fail.test \
ylwrap-extra-args.test \
ylwrap-fail.test \
+ylwrap-usage-fail.test \
ylwrap-lex-parallel.test \
ylwrap-output-rename.test \
ylwrap-path-handling.test \
diff --git a/tests/ylwrap-fail.test b/tests/ylwrap-fail.test
index 8c5f424..149fa0f 100755
--- a/tests/ylwrap-fail.test
+++ b/tests/ylwrap-fail.test
@@ -14,7 +14,7 @@
# 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.
+# Check how ylwrap handles runtime failures.
. ./defs || Exit 1
@@ -22,66 +22,6 @@ 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 ()
{
@@ -138,4 +78,23 @@ fi
check_emptydir
cd ..
+# And what about programs that doesn't fail but doesn't produce expected
+# output files either?
+
+mkdir dummy1
+cd dummy1
+$SHELL ../ylwrap --yacc .y foo.y foo.c -- true 2>../stderr \
+ && { cat ../stderr >&2; Exit 1; }
+cat ../stderr >&2
+check_emptydir
+cd ..
+
+mkdir dummy2
+cd dummy2
+$SHELL ../ylwrap --lex lex.yy foo.l foo.c -- true 2>../stderr \
+ && { cat ../stderr >&2; Exit 1; }
+cat ../stderr >&2
+check_emptydir
+cd ..
+
:
diff --git a/tests/ylwrap-usage-fail.test b/tests/ylwrap-usage-fail.test
new file mode 100755
index 0000000..c863a23
--- /dev/null
+++ b/tests/ylwrap-usage-fail.test
@@ -0,0 +1,77 @@
+#! /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 incorrect usages.
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir"/../lib/ylwrap .
+
+$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
+
+:
--
1.7.2.3
- [FYI] {ylwrap-refactor} Refactoring (eventual rewriting) of the `ylwrap' script., Stefano Lattarini, 2011/05/05
- [FYI] {ylwrap-refactor} ylwrap: various refactorings, few improvements, Stefano Lattarini, 2011/05/05
- [FYI] {ylwrap-refactor} ylwrap: fixlets in option parsing, Stefano Lattarini, 2011/05/05
- [FYI] {ylwrap-refactor} ylwrap: make less general and more "expert", Stefano Lattarini, 2011/05/05
- [FYI] {ylwrap-refactor} ylwrap: new subroutine `tr_cpp', Stefano Lattarini, 2011/05/05
- [FYI] {ylwrap-refactor} ylwrap: new subroutine `handle_renaming',
Stefano Lattarini <=
- [FYI] {ylwrap-refactor} ylwrap: warn when expected output files are missing, Stefano Lattarini, 2011/05/05
- [FYI] {ylwrap-refactor} ylwrap: cleanup refactoring (no semantic change), Stefano Lattarini, 2011/05/05
- [FYI] {ylwrap-refactor} ylwrap: another cleanup refactoring (no semantic change), Stefano Lattarini, 2011/05/05
- [FYI] {ylwrap-refactor} ylwrap: get rid of the loop on "FROM TARGET" couples, Stefano Lattarini, 2011/05/05
- FYI] {ylwrap-refactor} ylwrap: go into tempdir only when running wrapped program, Stefano Lattarini, 2011/05/05
- [FYI] {ylwrap-refactor} ylwrap: pull `dos_fix_yacc_filenames' out of `handle_renaming', Stefano Lattarini, 2011/05/05
- [FYI] {ylwrap-refactor} ylwrap: move "update if changed" logic out of `handle_renaming', Stefano Lattarini, 2011/05/05
- [FYI] {ylwrap-refactor} ylwrap: some renaming of variables and subroutines, Stefano Lattarini, 2011/05/06
- [FYI] {ylwrap-refactor} ylwrap: fix indentation, Stefano Lattarini, 2011/05/06
- [FYI] {ylwrap-refactor} ylwrap: rename 'handle_renaming' to 'tempfile_deploy', Stefano Lattarini, 2011/05/06