From e73bb23f4f1165c3fd387308e7f76684fabc8c0e Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Sun, 23 Sep 2012 22:29:25 +0200 Subject: df: add a test for the --output option * 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. --- tests/df/df-output.sh | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/local.mk | 1 + 2 files changed, 120 insertions(+) create mode 100644 tests/df/df-output.sh (limited to 'tests') diff --git a/tests/df/df-output.sh b/tests/df/df-output.sh new file mode 100644 index 000000000..0b40b2842 --- /dev/null +++ b/tests/df/df-output.sh @@ -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 . + +. "${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 diff --git a/tests/local.mk b/tests/local.mk index 8fc403012..1b0ace4c5 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -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 \ -- cgit v1.2.3-70-g09d2