>From dbc218f5f5d7a3662a29ff8e1aeecd3aac311b44 Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Wed, 9 Jan 2019 00:24:34 +0100 Subject: [PATCH 08/12] tests: migrate 'exec-plus-last-file' to the new testsuite * find/testsuite/sv-48030-exec-plus-bug.sh: Move to ... * tests/find/exec-plus-last-file.sh: ... this, and apply the above. Simplify, and make more robust. * find/testsuite/Makefile.am (tests_shell_progs): Remove the reference to this test ... * tests/local.mk (all_tests): .. and add it here. --- find/testsuite/Makefile.am | 1 - find/testsuite/sv-48030-exec-plus-bug.sh | 148 ----------------------- tests/find/exec-plus-last-file.sh | 66 ++++++++++ tests/local.mk | 1 + 4 files changed, 67 insertions(+), 149 deletions(-) delete mode 100755 find/testsuite/sv-48030-exec-plus-bug.sh create mode 100755 tests/find/exec-plus-last-file.sh diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am index d476ede7..f8217828 100644 --- a/find/testsuite/Makefile.am +++ b/find/testsuite/Makefile.am @@ -253,7 +253,6 @@ find.posix/user-missing.exp test_shell_progs = \ test_type-list.sh \ -sv-48030-exec-plus-bug.sh \ sv-48180-refuse-noop.sh \ sv-52220.sh diff --git a/find/testsuite/sv-48030-exec-plus-bug.sh b/find/testsuite/sv-48030-exec-plus-bug.sh deleted file mode 100755 index f7e3c59b..00000000 --- a/find/testsuite/sv-48030-exec-plus-bug.sh +++ /dev/null @@ -1,148 +0,0 @@ -#! /bin/sh -# Copyright (C) 2016-2019 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 3 of the License, 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 . -# - -# This test verifies that find invokes the given command for the -# multiple-argument sytax '-exec CMD {} +'. Between FINDUTILS-4.2.12 -# and v4.6.0, find(1) would have failed to execute CMD another time -# if there was only one last single file argument. - -testname="$(basename $0)" - -. "${srcdir}"/binary_locations.sh - -# Require seq(1) for this test - which may not be available -# on some systems, e.g on some *BSDs. -seq 2 >/dev/null 2>&1 \ - || { echo "$testname: required utility 'seq' missing" >&2; exit 77; } - -die() { - echo "$@" >&2 - exit 1 -} - -# This is used to simplify checking of the return value -# which is useful when ensuring a command fails as desired. -# I.e., just doing `command ... &&fail=1` will not catch -# a segfault in command for example. With this helper you -# instead check an explicit exit code like -# returns_ 1 command ... || fail -returns_ () { - # Disable tracing so it doesn't interfere with stderr of the wrapped command - { set +x; } 2>/dev/null - - local exp_exit="$1" - shift - "$@" - test $? -eq $exp_exit && ret_=0 || ret_=1 - - set -x - { return $ret_; } 2>/dev/null -} - -# Define the nicest compare available (borrowed from gnulib). -if diff_out_=`exec 2>/dev/null; diff -u "$0" "$0" < /dev/null` \ - && diff -u Makefile "$0" 2>/dev/null | grep '^[+]#!' >/dev/null; then - # diff accepts the -u option and does not (like AIX 7 'diff') produce an - # extra space on column 1 of every content line. - if test -z "$diff_out_"; then - compare () { diff -u "$@"; } - else - compare () - { - if diff -u "$@" > diff.out; then - # No differences were found, but Solaris 'diff' produces output - # "No differences encountered". Hide this output. - rm -f diff.out - true - else - cat diff.out - rm -f diff.out - false - fi - } - fi -elif diff_out_=`exec 2>/dev/null; diff -c "$0" "$0" < /dev/null`; then - if test -z "$diff_out_"; then - compare () { diff -c "$@"; } - else - compare () - { - if diff -c "$@" > diff.out; then - # No differences were found, but AIX and HP-UX 'diff' produce output - # "No differences encountered" or "There are no differences between the - # files.". Hide this output. - rm -f diff.out - true - else - cat diff.out - rm -f diff.out - false - fi - } - fi -elif cmp -s /dev/null /dev/null 2>/dev/null; then - compare () { cmp -s "$@"; } -else - compare () { cmp "$@"; } -fi - -DIR='RashuBug' -# Name of the CMD to execute: the file name must be 6 characters long -# (to trigger the bug in combination with the test files). -CMD='tstcmd' - -# Create test files. -make_test_data() { - # Create the CMD script and check that it works. - mkdir "$DIR" 'bin' \ - && printf '%s\n' '#!/bin/sh' 'printf "%s\n" "$@"' > "bin/$CMD" \ - && chmod +x "bin/$CMD" \ - && PATH="$PWD/bin:$PATH" \ - && [ "$( "${ftsfind}" bin -maxdepth 0 -exec "$CMD" '{}' + )" = 'bin' ] \ - || return 1 - - # Create expected output file - also used for creating the test data. - { seq -f "${DIR}/abcdefghijklmnopqrstuv%04g" 901 && - seq -f "${DIR}/abcdefghijklmnopqrstu%04g" 902 3719 - } > exp2 \ - && LC_ALL=C sort exp2 > exp \ - && rm exp2 \ - || return 1 - - # Create test files, and check if test data has been created correctly. - xargs touch < exp \ - && [ -f "${DIR}/abcdefghijklmnopqrstu3719" ] \ - && [ 3719 = $( "${ftsfind}" "$DIR" -type f | wc -l ) ] \ - || return 1 -} - -set -x -tmpdir="$(mktemp -d)" \ - && cd "$tmpdir" \ - && make_test_data "${tmpdir}" \ - || die "FAIL: failed to set up the test in ${tmpdir}" - -fail=0 -for exe in "${ftsfind}" "${oldfind}"; do - "$exe" "$DIR" -type f -exec "$CMD" '{}' + > out || fail=1 - LC_ALL=C sort out > out2 || fail=1 - compare exp out2 || fail=1 -done - -cd .. -rm -rf "${tmpdir}" || exit 1 -exit $fail diff --git a/tests/find/exec-plus-last-file.sh b/tests/find/exec-plus-last-file.sh new file mode 100755 index 00000000..352beaa6 --- /dev/null +++ b/tests/find/exec-plus-last-file.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# This test verifies that find invokes the given command for the +# multiple-argument sytax '-exec CMD {} +'. Between FINDUTILS-4.2.12 +# and v4.6.0, find(1) would have failed to execute CMD another time +# if there was only one last single file argument. +# See Savannah bug #48030. + +# Copyright (C) 2016-2019 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 3 of the License, 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 . + +. "${srcdir=.}/tests/init.sh" +print_ver_ find oldfind + +# Require seq(1) for this test - which may not be available +# on some systems, e.g on some *BSDs. +seq 2 >/dev/null 2>&1 \ + || skip_ "required utility 'seq' missing" + +DIR='RashuBug' +# Name of the CMD to execute: the file name must be 6 characters long +# (to trigger the bug in combination with the test files). +CMD='tstcmd' + +# Create the CMD script and check that it works. +mkdir 'bin' \ + && printf '%s\n' '#!/bin/sh' 'printf "%s\n" "$@"' > "bin/$CMD" \ + && chmod +x "bin/$CMD" \ + && PATH="$PWD/bin:$PATH" \ + && [ "$( find bin -maxdepth 0 -exec "$CMD" '{}' + )" = 'bin' ] \ + || framework_failure_ + +# Create expected output file - also used for creating the test data. +{ seq -f "${DIR}/abcdefghijklmnopqrstuv%04g" 901 && + seq -f "${DIR}/abcdefghijklmnopqrstu%04g" 902 3719 +} > exp2 \ + && LC_ALL=C sort exp2 > exp \ + && rm exp2 \ + || framework_failure_ + +# Create test files, and check if test data has been created correctly. +mkdir "$DIR" \ + && xargs touch < exp \ + && [ -f "${DIR}/abcdefghijklmnopqrstu3719" ] \ + && [ 3719 = $( find "$DIR" -type f | wc -l ) ] \ + || framework_failure_ + + +for exe in find oldfind; do + "$exe" "$DIR" -type f -exec "$CMD" '{}' + > out || fail=1 + LC_ALL=C sort out > out2 || fail=1 + compare exp out2 || fail=1 +done + +Exit $fail diff --git a/tests/local.mk b/tests/local.mk index 3e01c6c3..fc345572 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -110,6 +110,7 @@ all_tests = \ tests/find/printf_escape_c.sh \ tests/find/printf_inode.sh \ tests/find/execdir-fd-leak.sh \ + tests/find/exec-plus-last-file.sh \ $(all_root_tests) $(TEST_LOGS): $(PROGRAMS) -- 2.20.1