1#!/bin/sh 2# make sure --update works as advertised 3 4# Copyright (C) 2001-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_ cp mv 21 22test_reset() { 23 echo old > old || framework_failure_ 24 touch -d yesterday old || framework_failure_ 25 echo new > new || framework_failure_ 26} 27 28test_reset 29for interactive in '' -i; do 30 for cp_or_mv in cp mv; do 31 # This is a no-op, with no prompt. 32 # With coreutils-6.9 and earlier, using --update with -i would 33 # mistakenly elicit a prompt. 34 $cp_or_mv $interactive --update old new < /dev/null > out 2>&1 || fail=1 35 compare /dev/null out || fail=1 36 case "$(cat new)" in new) ;; *) fail=1 ;; esac 37 case "$(cat old)" in old) ;; *) fail=1 ;; esac 38 done 39done 40 41# These should perform the rename / copy 42for update_option in '--update' '--update=older' '--update=all' \ 43 '--update=none --update=all'; do 44 test_reset 45 mv $update_option new old || fail=1 46 test -f new && fail=1 47 case "$(cat old)" in new) ;; *) fail=1 ;; esac 48 49 test_reset 50 cp $update_option new old || fail=1 51 case "$(cat old)" in new) ;; *) fail=1 ;; esac 52 case "$(cat new)" in new) ;; *) fail=1 ;; esac 53done 54 55# These should not perform the rename / copy 56for update_option in '--update=none' \ 57 '--update=all --update=none'; do 58 test_reset 59 mv $update_option new old || fail=1 60 case "$(cat new)" in new) ;; *) fail=1 ;; esac 61 case "$(cat old)" in old) ;; *) fail=1 ;; esac 62 63 test_reset 64 cp $update_option new old || fail=1 65 case "$(cat new)" in new) ;; *) fail=1 ;; esac 66 case "$(cat old)" in old) ;; *) fail=1 ;; esac 67done 68 69Exit $fail 70