From 1a813420896317aecf5598f76c852195796e534b Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 26 Oct 2009 22:21:22 -0600 Subject: tests: add printenv coverage * tests/misc/printenv: New test. * tests/Makefile.am (TESTS): Run it. * .gitignore: Ignore more cruft. --- tests/misc/printenv | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 tests/misc/printenv (limited to 'tests/misc/printenv') 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 . + +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 < 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 < 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 -- cgit v1.2.3-54-g00ecf