From dc18830f56e88efa2cd92e663d30b9d4f0f27f1b Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Fri, 22 Jun 2012 16:18:28 +0200 Subject: [PATCH] tests: implement is_newest as an auxiliary script, not shell function This will allow to also use it in the makefile recipes used in our test cases. * t/ax/test-init.sh (is_newest): Remove. * t/ax/is_newest: New script. * Makefile.am (EXTRA_DIST): Add it. Signed-off-by: Stefano Lattarini --- Makefile.am | 2 +- t/ax/is_newest | 40 ++++++++++++++++++++++++++++++++++++++++ t/ax/test-init.sh | 10 ---------- 3 files changed, 41 insertions(+), 11 deletions(-) create mode 100755 t/ax/is_newest diff --git a/Makefile.am b/Makefile.am index c464d8bab..76f1cb345 100644 --- a/Makefile.am +++ b/Makefile.am @@ -328,7 +328,7 @@ TAP_LOG_DRIVER = AM_TAP_AWK='$(AWK)' $(SHELL) $(srcdir)/lib/tap-driver.sh AM_TAP_LOG_DRIVER_FLAGS = --merge -EXTRA_DIST += t/README t/ax/is +EXTRA_DIST += t/README t/ax/is t/ax/is_newest TESTS = ## Will be updated later. diff --git a/t/ax/is_newest b/t/ax/is_newest new file mode 100755 index 000000000..f52a1a8e3 --- /dev/null +++ b/t/ax/is_newest @@ -0,0 +1,40 @@ +#! /bin/sh +# Copyright (C) 2012 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 . + +# Usage: is_newest FILE FILES +# Fail if any file in FILES is newer than FILE, and print the list of +# such files on the standard error. +# Resolve ties in favor of FILE. + +set -u + +me=is_newest + +if test $# -lt 2; then + echo "$me: too few arguments" >&2 + exit 2 +fi + +file=$1; shift +newer_files=$(find "$@" -prune -newer "$file") || exit $? + +if test -n "$newer_files"; then + echo "$me: these files are newer than '$file':" >&2 + for f in $newer_files; do echo "* $f" >&2; done + exit 1 +fi + +exit 0 diff --git a/t/ax/test-init.sh b/t/ax/test-init.sh index fe28f9a17..01d45840f 100644 --- a/t/ax/test-init.sh +++ b/t/ax/test-init.sh @@ -200,16 +200,6 @@ cross_compiling () test x"$host_alias" != x && test x"$build_alias" != x"$host_alias" } -# is_newest FILE FILES -# -------------------- -# Return false if any file in FILES is newer than FILE. -# Resolve ties in favor of FILE. -is_newest () -{ - is_newest_files=$(find "$@" -prune -newer "$1") - test -z "$is_newest_files" -} - # is_blocked_signal SIGNAL-NUMBER # -------------------------------- # Return success if the given signal number is blocked in the shell, -- 2.47.2