chown: port test to macOS 12.6 nogroup user
[coreutils.git] / tests / df / df-output.sh
blobf7a36dd09837573fb5f35a583ea5adfe5d19ac7c
1 #!/bin/sh
2 # Exercise df's --output option.
4 # Copyright (C) 2012-2024 Free Software Foundation, Inc.
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.
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.
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/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ df
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
29 df -i --output '.' 2>out && fail=1
30 sed 's/ -i / OPT /' out > out2
31 compare exp out2 || fail=1
33 df --output -i '.' 2>out && fail=1
34 sed 's/ -i / OPT /' out > out2
35 compare exp out2 || fail=1
37 df -P --output '.' 2>out && fail=1
38 sed 's/ -P / OPT /' out > out2
39 compare exp out2 || fail=1
41 df --output -P '.' 2>out && fail=1
42 sed 's/ -P / OPT /' out > out2
43 compare exp out2 || fail=1
45 df -T --output '.' 2>out && fail=1
46 sed 's/ -T / OPT /' out > out2
47 compare exp out2 || fail=1
49 df --output -T '.' 2>out && fail=1
50 sed 's/ -T / OPT /' out > out2
51 compare exp out2 || fail=1
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
59 df --output=target,source,target '.' 2>out && fail=1
60 compare exp out || fail=1
62 # Ensure that this limitation also works for split --output options.
63 df --out=target,source --out=target '.' 2>out && fail=1
64 compare exp out || fail=1
66 # Ensure that the full output includes all fields, and
67 # that --o (without argument) is identical to the full list.
69 cat <<\EOF > exp || framework_failure_
70 Filesystem Type Inodes IUsed IFree IUse% Size Used Avail Use% File Mounted on
71 EOF
73 df -h --o=source,fstype,itotal,iused,iavail,ipcent \
74 --o=size,used,avail,pcent,file,target '.' >out || fail=1
75 sed -e '1 {
76 s/ [ ]*/ /g
78 }' out > out2
79 compare exp out2 || fail=1
81 df -h --output '.' >out || fail=1
82 sed -e '1 {
83 s/ [ ]*/ /g
85 }' out > out2
86 compare exp out2 || fail=1
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
94 df -B1K --output=size '.' >out || fail=1
95 sed -e '1 {
96 s/ *//
98 }' out > out2
99 compare exp out2 || fail=1
101 # Ensure that the grand total line now contains a "-" in the TARGET field ...
102 cat <<\EOF > exp || framework_failure_
106 df --output=source,target --total '.' >out || fail=1
107 sed -n -e '3 {
108 s/^total[ ]*//
111 }' out > out2
112 compare exp out2 || fail=1
114 # ... but it should read "total" if there is no SOURCE field.
115 cat <<\EOF > exp || framework_failure_
116 total
119 df --output=target --total '.' >out || fail=1
120 sed -n -e '3 {
123 }' out > out2
124 compare exp out2 || fail=1
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; }
130 # Ensure that the FILE field contains the argument.
131 cat <<\EOF > exp || framework_failure_
136 df --output=file '.' exp >out || fail=1
137 sed '1d' out > out2
138 compare exp out2 || fail=1
140 Exit $fail