env (2608B)
- #!/usr/bin/env atf-sh
- # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: MPL-2.0
- atf_test_case noargs
- noargs_body() {
- [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment"
- atf_check -o "inline:FOO=BAR\n" env -i FOO=BAR ../cmd/env
- }
- atf_test_case badarg
- badarg_body() {
- atf_check -s not-exit:0 -e "inline:env: Error: Unrecognised option: '-f'\nenv [-i] [-u key | --unset=key] [key=value ...] [command [args]]\n" ../cmd/env -f
- }
- atf_test_case iflag
- iflag_body() {
- [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment"
- atf_check -o "inline:FOO=BAR\n" ../cmd/env -i FOO=BAR ../cmd/env
- atf_check -o "inline:FOO=BAR\n" ../cmd/env -i FOO=BAR
- atf_check -o "not-inline:FOO=BAR\n" ../cmd/env FOO=BAR ../cmd/env
- atf_check -o "not-inline:FOO=BAR\n" ../cmd/env FOO=BAR
- }
- atf_test_case uflag
- uflag_body() {
- [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment"
- atf_check -o "inline:FOO=BAR\n" ../cmd/env -i FOO=BAR BAR=FOO ../cmd/env -u BAR
- atf_check -s not-exit:0 -e "inline:env: Error: Missing operand for option: '-u'\nenv [-i] [-u key | --unset=key] [key=value ...] [command [args]]\n" ../cmd/env -u
- }
- atf_test_case unsetflag
- unsetflag_body() {
- [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment"
- atf_check -o "inline:FOO=BAR\n" ../cmd/env -i FOO=BAR BAR=FOO ../cmd/env --unset=BAR
- atf_check -s not-exit:0 -e "inline:env: Error: Missing operand for option: '-u'\nenv [-i] [-u key | --unset=key] [key=value ...] [command [args]]\n" ../cmd/env -u
- }
- atf_test_case devfull
- devfull_body() {
- [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()"
- [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()"
- atf_check -s exit:1 -e 'inline:env: puts(environ[i]): No space left on device\n' sh -c '../cmd/env >/dev/full'
- }
- atf_test_case noutil
- noutil_body() {
- atf_check -s exit:127 -e 'inline:env: execvp("/var/empty/e/no/ent", ...): No such file or directory\n' ../cmd/env /var/empty/e/no/ent
- }
- atf_test_case false
- false_body() {
- atf_check -s exit:1 ../cmd/env false
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- atf_add_test_case noargs
- atf_add_test_case badarg
- atf_add_test_case iflag
- atf_add_test_case uflag
- atf_add_test_case unsetflag
- atf_add_test_case devfull
- atf_add_test_case noutil
- atf_add_test_case false
- }