tests: add printenv coverage
authorEric Blake <ebb9@byu.net>
Tue, 27 Oct 2009 04:21:22 +0000 (22:21 -0600)
committerEric Blake <ebb9@byu.net>
Wed, 28 Oct 2009 01:53:37 +0000 (19:53 -0600)
* tests/misc/printenv: New test.
* tests/Makefile.am (TESTS): Run it.
* .gitignore: Ignore more cruft.

.gitignore
tests/Makefile.am
tests/misc/printenv [new file with mode: 0755]

index 3ae9bf0..a284154 100644 (file)
@@ -74,4 +74,5 @@ src/version.c
 src/version.h
 stamp-h1
 tests/*/*.log
+tests/t?
 tests/test-suite.log
index 03fe6f1..731f657 100644 (file)
@@ -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 (executable)
index 0000000..bbda1db
--- /dev/null
@@ -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