Blame tests/misc/printenv.sh

Packit Service 2723c6
#!/bin/sh
Packit Service 2723c6
# Verify behavior of printenv.
Packit Service 2723c6
Packit Service 2723c6
# Copyright (C) 2009-2018 Free Software Foundation, Inc.
Packit Service 2723c6
Packit Service 2723c6
# This program is free software: you can redistribute it and/or modify
Packit Service 2723c6
# it under the terms of the GNU General Public License as published by
Packit Service 2723c6
# the Free Software Foundation, either version 3 of the License, or
Packit Service 2723c6
# (at your option) any later version.
Packit Service 2723c6
Packit Service 2723c6
# This program is distributed in the hope that it will be useful,
Packit Service 2723c6
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 2723c6
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 2723c6
# GNU General Public License for more details.
Packit Service 2723c6
Packit Service 2723c6
# You should have received a copy of the GNU General Public License
Packit Service 2723c6
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
Packit Service 2723c6
Packit Service 2723c6
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
Packit Service 2723c6
print_ver_ printenv
Packit Service 2723c6
Packit Service 2723c6
# Without arguments, printenv behaves like env.  Some shells provide
Packit Service 2723c6
# printenv as a builtin, so we must invoke it via "env".
Packit Service 2723c6
# But beware of $_, set by many shells to the last command run.
Packit Service 2723c6
# Also, filter out LD_PRELOAD, which is set when running under valgrind.
Packit Service 2723c6
# Note the apparently redundant "env  env": this is to ensure to get
Packit Service 2723c6
# env's output the same way as that of printenv and works around a bug
Packit Service 2723c6
# on aarch64 at least where libc's execvp reverses the order of the
Packit Service 2723c6
# output.
Packit Service 2723c6
env -- env | grep -Ev '^(_|LD_PRELOAD)=' > exp || framework_failure_
Packit Service 2723c6
env -- printenv | grep -Ev '^(_|LD_PRELOAD)=' > out || fail=1
Packit Service 2723c6
compare exp out || fail=1
Packit Service 2723c6
Packit Service 2723c6
# POSIX is clear that environ may, but need not be, sorted.
Packit Service 2723c6
# Environment variable values may contain newlines, which cannot be
Packit Service 2723c6
# observed by merely inspecting output from printenv.
Packit Service 2723c6
if env -- printenv | grep '^ENV_TEST' >/dev/null ; then
Packit Service 2723c6
  skip_ "environment has potential interference from ENV_TEST*"
Packit Service 2723c6
fi
Packit Service 2723c6
Packit Service 2723c6
# Printing a single variable's value.
Packit Service 2723c6
returns_ 1 env -- printenv ENV_TEST > out || fail=1
Packit Service 2723c6
compare /dev/null out || fail=1
Packit Service 2723c6
echo a > exp || framework_failure_
Packit Service 2723c6
ENV_TEST=a env -- printenv ENV_TEST > out || fail=1
Packit Service 2723c6
compare exp out || fail=1
Packit Service 2723c6
Packit Service 2723c6
# Printing multiple variables.  Order follows command line.
Packit Service 2723c6
ENV_TEST1=a ENV_TEST2=b env -- printenv ENV_TEST2 ENV_TEST1 ENV_TEST2 > out \
Packit Service 2723c6
  || fail=1
Packit Service 2723c6
ENV_TEST1=a ENV_TEST2=b env -- printenv ENV_TEST1 ENV_TEST2 >> out || fail=1
Packit Service 2723c6
cat <<EOF > exp || framework_failure_
Packit Service 2723c6
b
Packit Service 2723c6
a
Packit Service 2723c6
b
Packit Service 2723c6
a
Packit Service 2723c6
b
Packit Service 2723c6
EOF
Packit Service 2723c6
compare exp out || fail=1
Packit Service 2723c6
Packit Service 2723c6
# Exit status reflects missing variable, but remaining arguments processed.
Packit Service 2723c6
export ENV_TEST1=a
Packit Service 2723c6
returns_ 1 env -- printenv ENV_TEST2 ENV_TEST1 > out || fail=1
Packit Service 2723c6
returns_ 1 env -- printenv ENV_TEST1 ENV_TEST2 >> out || fail=1
Packit Service 2723c6
unset ENV_TEST1
Packit Service 2723c6
cat <<EOF > exp || framework_failure_
Packit Service 2723c6
a
Packit Service 2723c6
a
Packit Service 2723c6
EOF
Packit Service 2723c6
compare exp out || fail=1
Packit Service 2723c6
Packit Service 2723c6
# Non-standard environment variable name.  Shells won't create it, but
Packit Service 2723c6
# env can, and printenv must be able to deal with it.
Packit Service 2723c6
echo b > exp || framework_failure_
Packit Service 2723c6
env -- -a=b printenv -- -a > out || fail=1
Packit Service 2723c6
compare exp out || fail=1
Packit Service 2723c6
Packit Service 2723c6
# Silently reject invalid env-var names.
Packit Service 2723c6
# Bug present through coreutils 8.0.
Packit Service 2723c6
returns_ 1 env a=b=c printenv a=b > out || fail=1
Packit Service 2723c6
compare /dev/null out || fail=1
Packit Service 2723c6
Packit Service 2723c6
Exit $fail