tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / cp / cp-parents
1 #!/bin/sh
2 # cp -R --parents dir-specified-with-trailing-slash/ other-dir
3 # would get a failed assertion.
4
5 # Copyright (C) 2000, 2002, 2004-2009 Free Software Foundation, Inc.
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 if test "$VERBOSE" = yes; then
21   set -x
22   mv --version
23 fi
24
25 . $srcdir/test-lib.sh
26
27 working_umask_or_skip_
28
29 # Run the setgid check from the just-created directory.
30 skip_if_setgid_
31
32 mkdir foo bar || framework_failure
33 mkdir -p a/b/c d e g || framework_failure
34 ln -s d/a sym || framework_failure
35 touch f || framework_failure
36
37
38 # With 4.0.37 and earlier (back to when?), this would fail
39 # with the failed assertion from dirname.c.
40 cp -R --parents foo/ bar || fail=1
41
42 # Exercise the make_path and re_protect code in cp.c.
43 # FIXME: compare verbose output with expected output.
44 cp --verbose -a --parents a/b/c d > /dev/null 2>&1 || fail=1
45 test -d d/a/b/c || fail=1
46
47 # With 6.7 and earlier, cp --parents f/g d would mistakenly create a
48 # directory d/f, even though f is a regular file.
49 cp --parents f/g d 2>/dev/null && fail=1
50 test -d d/f && fail=1
51
52 # Check that re_protect works.
53 chmod go=w d/a
54 cp -a --parents d/a/b/c e || fail=1
55 cp -a --parents sym/b/c g || fail=1
56 p=`ls -ld e/d|cut -b-10`; case $p in drwxr-xr-x);; *) fail=1;; esac
57 p=`ls -ld e/d/a|cut -b-10`; case $p in drwx-w--w-);; *) fail=1;; esac
58 p=`ls -ld g/sym|cut -b-10`; case $p in drwx-w--w-);; *) fail=1;; esac
59 p=`ls -ld e/d/a/b/c|cut -b-10`; case $p in drwxr-xr-x);; *) fail=1;; esac
60 p=`ls -ld g/sym/b/c|cut -b-10`; case $p in drwxr-xr-x);; *) fail=1;; esac
61
62 Exit $fail