summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-10-26 22:21:22 -0600
committerEric Blake <ebb9@byu.net>2009-10-27 19:53:37 -0600
commit1a813420896317aecf5598f76c852195796e534b (patch)
tree8c975b5ea13181dd3e95e90277fb1d933c13c99f
parent0cc0424119ec66c9005fb905cc1001a64b978ce3 (diff)
downloadcoreutils-1a813420896317aecf5598f76c852195796e534b.tar.xz
tests: add printenv coverage
* tests/misc/printenv: New test. * tests/Makefile.am (TESTS): Run it. * .gitignore: Ignore more cruft.
-rw-r--r--.gitignore1
-rw-r--r--tests/Makefile.am1
-rwxr-xr-xtests/misc/printenv80
3 files changed, 82 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 3ae9bf014..a28415479 100644
--- a/.gitignore
+++ b/.gitignore
@@ -74,4 +74,5 @@ src/version.c
src/version.h
stamp-h1
tests/*/*.log
+tests/t?
tests/test-suite.log
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 03fe6f17f..731f65783 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -192,6 +192,7 @@ TESTS = \
misc/od-x8 \
misc/paste \
misc/pathchk1 \
+ misc/printenv \
misc/printf \
misc/printf-cov \
misc/printf-hex \
diff --git a/tests/misc/printenv b/tests/misc/printenv
new file mode 100755
index 000000000..bbda1dbd4
--- /dev/null
+++ b/tests/misc/printenv
@@ -0,0 +1,80 @@
+#!/bin/sh
+# Verify behavior of printenv.
+
+# Copyright (C) 2009 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/>.
+
+if test "$VERBOSE" = yes; then
+ set -x
+ env -- printenv --version
+fi
+
+. $srcdir/test-lib.sh
+
+fail=0
+
+# Without arguments, printenv behaves like env. Some shells provide
+# printenv as a builtin, so we must test via absolute name.
+# But beware of $_, set by many shells to the last command run.
+env | grep -v '^_' > exp || framework_failure
+env -- printenv | grep -v '^_' > out || fail=1
+compare exp out || fail=1
+
+# POSIX is clear that environ may, but need not be, sorted.
+# Environment variable values may contain newlines, which cannot be
+# observed by merely inspecting output from printenv.
+if env -- printenv | grep '^ENV_TEST' >/dev/null ; then
+ skip_test_ "environment has potential interference from ENV_TEST*"
+fi
+
+# Printing a single variable's value.
+env -- printenv ENV_TEST > out
+test $? = 1 || fail=1
+test -s out && fail=1
+echo a > exp || framework_failure
+ENV_TEST=a env -- printenv ENV_TEST > out || fail=1
+compare exp out || fail=1
+
+# Printing multiple variables. Order follows command line.
+ENV_TEST1=a ENV_TEST2=b env -- printenv ENV_TEST2 ENV_TEST1 ENV_TEST2 > out \
+ || fail=1
+ENV_TEST1=a ENV_TEST2=b env -- printenv ENV_TEST1 ENV_TEST2 >> out || fail=1
+cat <<EOF > exp || framework_failure
+b
+a
+b
+a
+b
+EOF
+compare exp out || fail=1
+
+# Exit status reflects missing variable, but remaining arguments processed.
+ENV_TEST1=a env -- printenv ENV_TEST2 ENV_TEST1 > out
+test $? = 1 || fail=1
+ENV_TEST1=a env -- printenv ENV_TEST1 ENV_TEST2 >> out
+test $? = 1 || fail=1
+cat <<EOF > exp || framework_failure
+a
+a
+EOF
+compare exp out || fail=1
+
+# Non-standard environment variable name. Shells won't create it, but
+# env can, and printenv must be able to deal with it.
+echo b > exp || framework_failure
+env -- -a=b printenv -- -a > out || fail=1
+compare exp out || fail=1
+
+Exit $fail