df: add a test for the --output option
authorBernhard Voelker <mail@bernhard-voelker.de>
Sun, 23 Sep 2012 20:29:25 +0000 (22:29 +0200)
committerPádraig Brady <P@draigBrady.com>
Thu, 8 Nov 2012 16:12:07 +0000 (16:12 +0000)
* tests/df/df-output.sh: Add a test case.
* tests/local.mk (all_tests): Mention the test.
* cfg.mk (sc_file_system): Exempt the test from this syntax-check.

cfg.mk
tests/df/df-output.sh [new file with mode: 0644]
tests/local.mk

diff --git a/cfg.mk b/cfg.mk
index 53295b4..2ddf414 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -554,7 +554,7 @@ exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = ^tests/pr/
 exclude_file_name_regexp--sc_program_name = \
   ^(gl/.*|lib/euidaccess-stat|src/make-prime-list)\.c$$
 exclude_file_name_regexp--sc_file_system = \
-  NEWS|^(init\.cfg|src/df\.c|tests/df/df-P\.sh)$$
+  NEWS|^(init\.cfg|src/df\.c|tests/df/df-P\.sh|tests/df/df-output\.sh)$$
 exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \
   ^m4/stat-prog\.m4$$
 exclude_file_name_regexp--sc_prohibit_fail_0 = \
diff --git a/tests/df/df-output.sh b/tests/df/df-output.sh
new file mode 100644 (file)
index 0000000..0b40b28
--- /dev/null
@@ -0,0 +1,119 @@
+#!/bin/sh
+# Exercise df's --output option.
+
+# Copyright (C) 2012 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ df
+
+# Ensure that --output is mutually exclusive with -i, -P, and -T.
+# Ensure that this limitation is not depending on the order of options.
+cat <<\EOF > exp || framework_failure_
+df: options OPT and --output are mutually exclusive
+Try 'df --help' for more information.
+EOF
+
+df -i --output '.' 2>out && fail=1
+sed -i 's/ -i / OPT /' out
+compare exp out || fail=1
+
+df --output -i '.' 2>out && fail=1
+sed -i 's/ -i / OPT /' out
+compare exp out || fail=1
+
+df -P --output '.' 2>out && fail=1
+sed -i 's/ -P / OPT /' out
+compare exp out || fail=1
+
+df --output -P '.' 2>out && fail=1
+sed -i 's/ -P / OPT /' out
+compare exp out || fail=1
+
+df -T --output '.' 2>out && fail=1
+sed -i 's/ -T / OPT /' out
+compare exp out || fail=1
+
+df --output -T '.' 2>out && fail=1
+sed -i 's/ -T / OPT /' out
+compare exp out || fail=1
+
+# Ensure that each field is only used once for the --output argument.
+cat <<\EOF > exp || framework_failure_
+df: option --output: field 'target' used more than once
+Try 'df --help' for more information.
+EOF
+
+df --output=target,source,target '.' 2>out && fail=1
+compare exp out || fail=1
+
+# Ensure that this limitation also works for splitted --output options.
+df --out=target,source --out=target '.' 2>out && fail=1
+compare exp out || fail=1
+
+# Ensure that the full output includes all fields, and
+# that --o (without argument) is identical to the full list.
+
+cat <<\EOF > exp || framework_failure_
+Filesystem Type Size Used Avail Use% Inodes IUsed IFree IUse% Mounted on
+EOF
+
+df -h --o=source,fstype,size,used,avail,pcent \
+ --o=itotal,iused,iavail,ipcent,target '.' >out || fail=1
+sed -e '1 {s/ [ ]*/ /g;q}' out > out2
+compare exp out2 || fail=1
+
+df -h --output '.' >out || fail=1
+sed -e '1 {s/ [ ]*/ /g;q}' out > out2
+compare exp out2 || fail=1
+
+# Ensure that --output indicates the block size
+# when not using --human-readable
+cat <<\EOF > exp || framework_failure_
+1K-blocks
+EOF
+
+df -B1K --output=size '.' >out || fail=1
+sed -e '1 {s/ [ ]*/ /g;q}' out > out2
+compare exp out2 || fail=1
+
+# Ensure that the grand total line now contains a "-" in the TARGET field ...
+cat <<\EOF > exp || framework_failure_
+-
+EOF
+
+df --output=source,target --total '.' >out || fail=1
+sed -n -e '3 {s/^total[ ]*//;p;q}' out > out2
+compare exp out2 || fail=1
+
+# ... but it should read "total" if there is no SOURCE field.
+cat <<\EOF > exp || framework_failure_
+total
+EOF
+
+df --output=target --total '.' >out || fail=1
+sed -n -e '3 {p;q}' out > out2
+compare exp out2 || fail=1
+
+# Ensure that --output is mentioned in the usage.
+cat <<\EOF > exp || framework_failure_
+--output
+EOF
+
+df --help > out || fail=1
+grep ' --output' out | sed 's/^.*\(--output\).*$/\1/;q' > out2
+compare exp out2 || fail=1
+
+Exit $fail
index 8fc4030..1b0ace4 100644 (file)
@@ -453,6 +453,7 @@ all_tests =                                 \
   tests/cp/thru-dangling.sh                    \
   tests/df/header.sh                           \
   tests/df/df-P.sh                             \
+  tests/df/df-output.sh                                \
   tests/df/unreadable.sh                       \
   tests/df/total-unprocessed.sh                        \
   tests/df/no-mtab-status.sh                   \