2 # Exercise df's --output option.
4 # Copyright (C) 2012-2025 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
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.
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.
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
73 df
-h --o=source,fstype
,itotal
,iused
,iavail
,ipcent \
74 --o=size
,used
,avail
,pcent
,file,target
'.' >out || fail
=1
79 compare exp out2 || fail
=1
81 df
-h --output '.' >out || fail
=1
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_
94 df
-B1K --output=size
'.' >out || fail
=1
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
112 compare exp out2 || fail
=1
114 # ... but it should read "total" if there is no SOURCE field.
115 cat <<\EOF
> exp || framework_failure_
119 df
--output=target
--total '.' >out || fail
=1
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
138 compare exp out2 || fail
=1