1#!/bin/sh 2# Test the --interactive[=WHEN] changes added to coreutils 6.0 3 4# Copyright (C) 2006-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ rm 21 22touch file1-1 file1-2 file2-1 file2-2 file3-1 file3-2 file4-1 file4-2 \ 23 || framework_failure_ 24# If asked, answer no to first question, then yes to second. 25echo 'n 26y' > in || framework_failure_ 27rm -f out err || framework_failure_ 28 29 30# The prompt has a trailing space, and no newline, so an extra 31# 'echo .' is inserted after each rm to make it obvious what was asked. 32 33echo 'no WHEN' > err || framework_failure_ 34rm -R --interactive file1-* < in >> out 2>> err || fail=1 35echo . >> err || framework_failure_ 36test -f file1-1 || fail=1 37test -f file1-2 && fail=1 38 39echo 'WHEN=never' >> err || framework_failure_ 40rm -R --interactive=never file2-* < in >> out 2>> err || fail=1 41echo . >> err || framework_failure_ 42test -f file2-1 && fail=1 43test -f file2-2 && fail=1 44 45echo 'WHEN=once' >> err || framework_failure_ 46rm -R --interactive=once file3-* < in >> out 2>> err || fail=1 47echo . >> err || framework_failure_ 48test -f file3-1 || fail=1 49test -f file3-2 || fail=1 50 51echo 'WHEN=always' >> err || framework_failure_ 52rm -R --interactive=always file4-* < in >> out 2>> err || fail=1 53echo . >> err || framework_failure_ 54test -f file4-1 || fail=1 55test -f file4-2 && fail=1 56 57echo '-f overrides --interactive' >> err || framework_failure_ 58rm -R --interactive=once -f file1-* < in >> out 2>> err || fail=1 59echo . >> err || framework_failure_ 60test -f file1-1 && fail=1 61 62echo '--interactive overrides -f' >> err || framework_failure_ 63rm -R -f --interactive=once file4-* < in >> out 2>> err || fail=1 64echo . >> err || framework_failure_ 65test -f file4-1 || fail=1 66 67cat <<\EOF > experr.t || framework_failure_ 68no WHEN 69@remove_empty 'file1-1'? @remove_empty 'file1-2'? . 70WHEN=never 71. 72WHEN=once 73rm: remove 2 arguments recursively? . 74WHEN=always 75@remove_empty 'file4-1'? @remove_empty 'file4-2'? . 76-f overrides --interactive 77. 78--interactive overrides -f 79rm: remove 1 argument recursively? . 80EOF 81sed 's/@remove_empty/rm: remove regular empty file/g' < experr.t > experr || 82 framework_failure_ 83 84compare /dev/null out || fail=1 85compare experr err || fail=1 86 87Exit $fail 88