1#!/bin/sh
2# Test whether mv -n works as documented (not overwrite target).
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_ mv
21
22
23# test miscellaneous combinations of -f -i -n parameters
24touch a b || framework_failure_
25echo "renamed 'a' -> 'b'" > out_move
26echo "mv: not replacing 'b'" > err_skip || framework_failure_
27> out_empty
28
29# ask for overwrite, answer no
30touch a b || framework_failure_
31echo n | returns_ 1 mv -vi a b 2>/dev/null > out1 || fail=1
32compare out1 out_empty || fail=1
33
34# ask for overwrite, answer yes
35touch a b || framework_failure_
36echo y | mv -vi a b 2>/dev/null > out2 || fail=1
37compare out2 out_move || fail=1
38
39# -n wins (as the last option)
40touch a b || framework_failure_
41echo y | returns_ 1 mv -vin a b 2>/dev/null > out3 || fail=1
42compare out3 out_empty || fail=1
43
44# -n wins (non verbose)
45touch a b || framework_failure_
46echo y | returns_ 1 mv -in a b 2>err3 > out3 || fail=1
47compare out3 out_empty || fail=1
48compare err3 err_skip || fail=1
49
50# -n wins (as the last option)
51touch a b || framework_failure_
52echo y | returns_ 1 mv -vfn a b 2>/dev/null > out4 || fail=1
53compare out4 out_empty || fail=1
54
55# -n wins (as the last option)
56touch a b || framework_failure_
57echo y | returns_ 1 mv -vifn a b 2>/dev/null > out5 || fail=1
58compare out5 out_empty || fail=1
59
60# options --backup and --no-clobber are mutually exclusive
61touch a || framework_failure_
62returns_ 1 mv -bn a b 2>/dev/null || fail=1
63
64Exit $fail
65