tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / cp / cp-mv-enotsup-xattr
1 #!/bin/sh
2 # Ensure that mv, cp -a and cp --preserve=xattr(all) options do work
3 # as expected on file system without their support and do show correct
4 # diagnostics when required
5
6 # Copyright (C) 2009 Free Software Foundation, Inc.
7
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 if test "$VERBOSE" = yes; then
22   set -x
23   cp --version
24   mv --version
25 fi
26
27 . $srcdir/test-lib.sh
28 require_root_
29
30 cwd=`pwd`
31 cleanup_() { cd /; umount "$cwd/mnt"; }
32
33 skip=0
34 # Create a file system without user xattr support, then mount it.
35 dd if=/dev/zero of=blob bs=8192 count=200 > /dev/null 2>&1 \
36                                              || skip=1
37 mkdir mnt                                    || skip=1
38 mkfs -t ext2 -F blob ||
39   skip_test_ "failed to create ext2 file system"
40
41 mount -oloop,nouser_xattr blob mnt           || skip=1
42 echo test > mnt/f                            || skip=1
43 test -s mnt/f                                || skip=1
44
45 test $skip = 1 \
46     && skip_test_ "insufficient mount/ext2 support"
47
48 # testing xattr name-value pair
49 xattr_name="user.foo"
50 xattr_value="bar"
51 xattr_pair="$xattr_name=\"$xattr_value\""
52
53 echo test > a || framework_failure
54 getfattr -d a >out_a || skip_test_ "failed to get xattr of file"
55 grep -F "$xattr_pair" out_a >/dev/null && framework_failure
56 setfattr -n "$xattr_name" -v "$xattr_value" a >out_a \
57   || skip_test_ "failed to set xattr of file"
58 getfattr -d a >out_a || skip_test_ "failed to get xattr of file"
59 grep -F "$xattr_pair" out_a >/dev/null \
60   || skip_test_ "failed to set xattr of file"
61
62
63 # This should pass without diagnostics
64 cp -a a mnt/ 2>err  || fail=1
65 test -s mnt/a       || fail=1  # destination file must not be empty
66 test -s err         && fail=1  # there must be no stderr output
67
68 rm -f err mnt/a
69
70 # This should pass without diagnostics
71 cp --preserve=all a mnt/ 2>err  || fail=1
72 test -s mnt/a       || fail=1  # destination file must not be empty
73 test -s err         && fail=1  # there must be no stderr output
74
75 rm -f err mnt/a
76
77 # This should fail with coresponding diagnostics
78 cp -a --preserve=xattr a mnt/ 2>err  && fail=1
79 cat <<\EOF > exp || fail=1
80 cp: setting attributes for `mnt/a': Operation not supported
81 EOF
82
83 compare err exp     || fail=1
84
85 rm -f err mnt/a
86
87 # This should pass without diagnostics
88 mv a mnt/ 2>err     || fail=1
89 test -s mnt/a       || fail=1  # destination file must not be empty
90 test -s err         && fail=1  # there must be no stderr output
91
92 Exit $fail