~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/df/df-output.sh

  • Committer: Colin Watson
  • Date: 2013-10-30 15:48:33 UTC
  • mfrom: (8.3.5 sid)
  • Revision ID: cjwatson@canonical.com-20131030154833-xdt6e1yfffqom1c4
merge from Debian 8.21-1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# Exercise df's --output option.
 
3
 
 
4
# Copyright (C) 2012-2013 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 <http://www.gnu.org/licenses/>.
 
18
 
 
19
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 
20
print_ver_ df
 
21
 
 
22
# Ensure that --output is mutually exclusive with -i, -P, and -T.
 
23
# Ensure that this limitation is not depending on the order of options.
 
24
cat <<\EOF > exp || framework_failure_
 
25
df: options OPT and --output are mutually exclusive
 
26
Try 'df --help' for more information.
 
27
EOF
 
28
 
 
29
df -i --output '.' 2>out && fail=1
 
30
sed 's/ -i / OPT /' out > out2
 
31
compare exp out2 || fail=1
 
32
 
 
33
df --output -i '.' 2>out && fail=1
 
34
sed 's/ -i / OPT /' out > out2
 
35
compare exp out2 || fail=1
 
36
 
 
37
df -P --output '.' 2>out && fail=1
 
38
sed 's/ -P / OPT /' out > out2
 
39
compare exp out2 || fail=1
 
40
 
 
41
df --output -P '.' 2>out && fail=1
 
42
sed 's/ -P / OPT /' out > out2
 
43
compare exp out2 || fail=1
 
44
 
 
45
df -T --output '.' 2>out && fail=1
 
46
sed 's/ -T / OPT /' out > out2
 
47
compare exp out2 || fail=1
 
48
 
 
49
df --output -T '.' 2>out && fail=1
 
50
sed 's/ -T / OPT /' out > out2
 
51
compare exp out2 || fail=1
 
52
 
 
53
# Ensure that each field is only used once for the --output argument.
 
54
cat <<\EOF > exp || framework_failure_
 
55
df: option --output: field 'target' used more than once
 
56
Try 'df --help' for more information.
 
57
EOF
 
58
 
 
59
df --output=target,source,target '.' 2>out && fail=1
 
60
compare exp out || fail=1
 
61
 
 
62
# Ensure that this limitation also works for splitted --output options.
 
63
df --out=target,source --out=target '.' 2>out && fail=1
 
64
compare exp out || fail=1
 
65
 
 
66
# Ensure that the full output includes all fields, and
 
67
# that --o (without argument) is identical to the full list.
 
68
 
 
69
cat <<\EOF > exp || framework_failure_
 
70
Filesystem Type Inodes IUsed IFree IUse% Size Used Avail Use% Mounted on
 
71
EOF
 
72
 
 
73
df -h --o=source,fstype,itotal,iused,iavail,ipcent \
 
74
 --o=size,used,avail,pcent,target '.' >out || fail=1
 
75
sed -e '1 {
 
76
          s/ [ ]*/ /g
 
77
          q
 
78
        }' out > out2
 
79
compare exp out2 || fail=1
 
80
 
 
81
df -h --output '.' >out || fail=1
 
82
sed -e '1 {
 
83
          s/ [ ]*/ /g
 
84
          q
 
85
        }' out > out2
 
86
compare exp out2 || fail=1
 
87
 
 
88
# Ensure that --output indicates the block size
 
89
# when not using --human-readable
 
90
cat <<\EOF > exp || framework_failure_
 
91
1K-blocks
 
92
EOF
 
93
 
 
94
df -B1K --output=size '.' >out || fail=1
 
95
sed -e '1 {
 
96
          s/ //
 
97
          q
 
98
        }' out > out2
 
99
compare exp out2 || fail=1
 
100
 
 
101
# Ensure that the grand total line now contains a "-" in the TARGET field ...
 
102
cat <<\EOF > exp || framework_failure_
 
103
-
 
104
EOF
 
105
 
 
106
df --output=source,target --total '.' >out || fail=1
 
107
sed -n -e '3 {
 
108
             s/^total[ ]*//
 
109
             p
 
110
             q
 
111
           }' out > out2
 
112
compare exp out2 || fail=1
 
113
 
 
114
# ... but it should read "total" if there is no SOURCE field.
 
115
cat <<\EOF > exp || framework_failure_
 
116
total
 
117
EOF
 
118
 
 
119
df --output=target --total '.' >out || fail=1
 
120
sed -n -e '3 {
 
121
             p
 
122
             q
 
123
           }' out > out2
 
124
compare exp out2 || fail=1
 
125
 
 
126
# Ensure that --output is mentioned in the usage.
 
127
df --help > out || fail=1
 
128
grep ' --output' out >/dev/null || { fail=1; cat out; }
 
129
 
 
130
Exit $fail