41a9b53c0a9f8bf33e2b58b7d6b9c36b12a17f3b
[platform/upstream/coreutils.git] / tests / du / trailing-slash
1 #!/bin/sh
2 # Ensure that du works properly for an argument that refers to a
3 # symbolic link, and that is specified with a trailing slash.
4 # Before coreutils-4.5.3, it would remove a single trailing slash.
5
6 if test "$VERBOSE" = yes; then
7   set -x
8   du --version
9 fi
10
11 . $srcdir/../envvar-check
12
13 pwd=`pwd`
14 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
15 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
16 trap '(exit $?); exit $?' 1 2 13 15
17
18 framework_failure=0
19 mkdir -p $tmp || framework_failure=1
20 cd $tmp || framework_failure=1
21 mkdir -p dir/1/2 || framework_failure=1
22 ln -s dir slink || framework_failure=1
23
24 if test $framework_failure = 1; then
25   echo "$0: failure in testing framework" 1>&2
26   (exit 1); exit 1
27 fi
28
29 fail=0
30
31 du slink/ | sed 's/^[0-9][0-9]* //' > out
32 echo === >> out
33
34 # Ensure that with -L we get the same results (modulo the trailing slash
35 # on the third line) even without the trailing slash on the command line.
36 du -L slink | sed 's/^[0-9][0-9]*       //' >> out
37 cat <<\EOF > exp
38 slink/1/2
39 slink/1
40 slink/
41 ===
42 slink/1/2
43 slink/1
44 slink
45 EOF
46
47 cmp out exp || fail=1
48 test $fail = 1 && diff out exp 2> /dev/null
49
50 (exit $fail); exit $fail