From 1a813420896317aecf5598f76c852195796e534b Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 26 Oct 2009 22:21:22 -0600 Subject: [PATCH] tests: add printenv coverage * tests/misc/printenv: New test. * tests/Makefile.am (TESTS): Run it. * .gitignore: Ignore more cruft. --- .gitignore | 1 + tests/Makefile.am | 1 + tests/misc/printenv | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100755 tests/misc/printenv 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 . + +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 -- 2.11.4.GIT