build: ensure make-prime-list doesn't access out of bounds memory
[platform/upstream/coreutils.git] / tests / misc / printenv.sh
1 #!/bin/sh
2 # Verify behavior of printenv.
3
4 # Copyright (C) 2009-2013 Free Software Foundation, Inc.
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ printenv
21
22 # Without arguments, printenv behaves like env.  Some shells provide
23 # printenv as a builtin, so we must invoke it via "env".
24 # But beware of $_, set by many shells to the last command run.
25 # Also, filter out LD_PRELOAD, which is set when running under valgrind.
26 env | grep -Ev '^(_|LD_PRELOAD=)' > exp || framework_failure_
27 env -- printenv | grep -Ev '^(_|LD_PRELOAD=)' > out || fail=1
28 compare exp out || fail=1
29
30 # POSIX is clear that environ may, but need not be, sorted.
31 # Environment variable values may contain newlines, which cannot be
32 # observed by merely inspecting output from printenv.
33 if env -- printenv | grep '^ENV_TEST' >/dev/null ; then
34   skip_ "environment has potential interference from ENV_TEST*"
35 fi
36
37 # Printing a single variable's value.
38 env -- printenv ENV_TEST > out
39 test $? = 1 || fail=1
40 test -s out && fail=1
41 echo a > exp || framework_failure_
42 ENV_TEST=a env -- printenv ENV_TEST > out || fail=1
43 compare exp out || fail=1
44
45 # Printing multiple variables.  Order follows command line.
46 ENV_TEST1=a ENV_TEST2=b env -- printenv ENV_TEST2 ENV_TEST1 ENV_TEST2 > out \
47   || fail=1
48 ENV_TEST1=a ENV_TEST2=b env -- printenv ENV_TEST1 ENV_TEST2 >> out || fail=1
49 cat <<EOF > exp || framework_failure_
50 b
51 a
52 b
53 a
54 b
55 EOF
56 compare exp out || fail=1
57
58 # Exit status reflects missing variable, but remaining arguments processed.
59 ENV_TEST1=a env -- printenv ENV_TEST2 ENV_TEST1 > out
60 test $? = 1 || fail=1
61 ENV_TEST1=a env -- printenv ENV_TEST1 ENV_TEST2 >> out
62 test $? = 1 || fail=1
63 cat <<EOF > exp || framework_failure_
64 a
65 a
66 EOF
67 compare exp out || fail=1
68
69 # Non-standard environment variable name.  Shells won't create it, but
70 # env can, and printenv must be able to deal with it.
71 echo b > exp || framework_failure_
72 env -- -a=b printenv -- -a > out || fail=1
73 compare exp out || fail=1
74
75 # Silently reject invalid env-var names.
76 # Bug present through coreutils 8.0.
77 env a=b=c printenv a=b > out
78 test $? = 1 || fail=1
79 test -s out && fail=1
80
81 Exit $fail