From a7b9f6008110a82f56aee6ea0ce8bfcb61bb6f1d Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 5 Oct 2001 16:12:22 +0000 Subject: [PATCH] * tests/m4sh.at (LINENO): New. * lib/m4sugar/m4sh.m4 (AS_SHELL_SANITIZE): Be sure to set PATH_SEPARATOR before using it. Fix the absolute path case/esac pattern. Provide $0 as fallback for as_myself. Reported by Raja R Harinath. --- ChangeLog | 9 ++++++ lib/m4sugar/m4sh.m4 | 19 ++++++++----- tests/m4sh.at | 67 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 740c6139..ad29cc08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2001-10-05 Akim Demaille + + * tests/m4sh.at (LINENO): New. + * lib/m4sugar/m4sh.m4 (AS_SHELL_SANITIZE): Be sure to set + PATH_SEPARATOR before using it. + Fix the absolute path case/esac pattern. + Provide $0 as fallback for as_myself. + Reported by Raja R Harinath. + 2001-10-05 Akim Demaille * Makefile.am, config/Makefile.am, lib/emacs/Makefile.am, diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index 6a0c7349..c5c2e1f2 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -113,14 +113,14 @@ fi # Name of the executable. as_me=`AS_BASENAME($[0])` -# Rewrite early. +# Rewrite early, but we need PATH_SEPARATOR. +_AS_PATH_SEPARATOR_PREPARE _AS_LINENO_PREPARE _AS_CR_PREPARE _AS_ECHO_N_PREPARE _AS_EXPR_PREPARE _AS_LN_S_PREPARE -_AS_PATH_SEPARATOR_PREPARE _AS_TEST_PREPARE _AS_TR_CPP_PREPARE _AS_TR_SH_PREPARE @@ -428,17 +428,22 @@ if test "x$as_lineno_1" = "x$as_lineno_2" || then # Find who we are. case $[0] in - *[[\\/]]* | ?:[[\\/]]* ) as_myself=$[0] ;; + [[\\/]]* | ?:[[\\/]]* ) as_myself=$[0] ;; *) _AS_PATH_WALK([], [test -r "$as_dir/$[0]" && as_myself=$as_dir/$[0] && break]) ;; esac - if test ! -f $as_myself; then + # We did not find ourselves, most probably we were run as `sh COMMAND' + # in which case we are not to be found in the path. + if test "x$as_myself" = x; then + as_myself=$[0] + fi + if test ! -f "$as_myself"; then AS_ERROR([cannot find myself; rerun with an absolute path]) fi - if test ! -f $as_me.lineno || - test x`ls -1dt $as_me.lineno $as_myself 2>/dev/null | sed 1q` \ - != x$as_me.lineno; then + if test ! -f "$as_me.lineno" || + test x`ls -1dt "$as_me.lineno" "$as_myself" 2>/dev/null | sed 1q` \ + != x"$as_me.lineno"; then # Be sure to write the pattern so that it doesn't replace itself: # it must not match itself. awk <$as_myself ' diff --git a/tests/m4sh.at b/tests/m4sh.at index 2dc78f74..39bf90d2 100644 --- a/tests/m4sh.at +++ b/tests/m4sh.at @@ -22,6 +22,73 @@ AT_BANNER([M4sh.]) # Used in many tests. m4_pattern_allow([^AS_EXIT$]) +## ---------------- ## +## LINENO support. ## +## ---------------- ## + +AT_SETUP([LINENO]) + +# AT_DATA_LINENO(FILENAME, +# UNSET-LINENO = true | false, COUNTER, COUNTER-RE) +# ---------------------------------------------------------------- +# Produce FILENAME which uses the COUNTER LINENO or _oline_, which +# we can recognized via COUNTER-RE. Unset LINENO is UNSET-LINENO. +# +# Use COUNTER, COUNTER-RE = [$@&t@LINENO], [LINENO] +# or = [__@&t@oline__], [_oline__] +# to make sure we are not replace in the test suite itself and to avoid +# seeing the COUNTER-RE being replaced. +# +# UNSET-LINENO is a shell condition to make sure the scripts have the +# same number of lines in the output, so that their outputs be identical. +m4_define([AT_DATA_LINENO], +[AT_DATA([$1], +[[AS@&t@_INIT +m4@&t@_divert_push([0])d@&t@nl +m4@&t@_wrap([m4@&t@_divert_pop([0])[]])d@&t@nl +#! /bin/sh +if $2; then + AS@&t@_UNSET([LINENO]) +fi +AS@&t@_SHELL_SANITIZE +echo "Line: $3" +grep 'Line: .*$4' $[0] >/dev/null || + AS@&t@_ERROR([cannot find original script]) +exit 0 +]]) +])# AT_DATA_LINENO + +# `_oline_', once processed and ran, produces our reference. +# We check that we find ourself by looking at a string which is +# available only in the original script: `_oline_'. +AT_DATA_LINENO([reference.as], [false], [__@&t@oline__], [_oline__]) +AT_CHECK([autom4te -l m4sh reference.as -o reference]) +AT_CHECK([./reference], 0, [stdout]) + +# The reference: +mv stdout expout + +# Now using a maybe-functioning LINENO, with different call conventions. +# Be sure to be out of the PATH. +AT_CHECK([mkdir test || exit 77]) + +AT_DATA_LINENO([test/test-1.as], [false], [$@&t@LINENO], [LINENO]) +AT_CHECK([autom4te -l m4sh test/test-1.as -o test/test-1]) +AT_CHECK([test/test-1], 0, [expout]) +AT_CHECK([PATH=test$PATH_SEPARATOR$PATH test-1], 0, [expout]) +AT_CHECK([sh test/test-1], 0, [expout]) + +# Now using a disabled LINENO, with different call conventions. +AT_DATA_LINENO([test/test-2.as], [true], [$@&t@LINENO], [LINENO]) +AT_CHECK([autom4te -l m4sh test/test-2.as -o test/test-2]) +AT_CHECK([test/test-2], 0, [expout]) +AT_CHECK([PATH=test$PATH_SEPARATOR$PATH test-2], 0, [expout]) +AT_CHECK([sh test/test-2], 0, [expout]) + +# Beware that *.lineno scripts can be *here* while the masters are in test/. +AT_CLEANUP(reference test test-1.lineno test-2.lineno) + + ## ----------------------------- ## ## AS_DIRNAME & AS_DIRNAME_SED. ## ## ----------------------------- ##