logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git

env (2115B)


  1. #!/usr/bin/env atf-sh
  2. # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
  4. atf_test_case noargs
  5. noargs_body() {
  6. [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment"
  7. atf_check -o "inline:FOO=BAR\n" env -i FOO=BAR ../bin/env
  8. }
  9. atf_test_case badarg
  10. badarg_body() {
  11. atf_check -s not-exit:0 -e "inline:Error: Unrecognised option: '-f'\nenv [-i] [-u key] [key=value ...] [command [args]]\n" ../bin/env -f
  12. }
  13. atf_test_case iflag
  14. iflag_body() {
  15. [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment"
  16. atf_check -o "inline:FOO=BAR\n" ../bin/env -i FOO=BAR ../bin/env
  17. atf_check -o "inline:FOO=BAR\n" ../bin/env -i FOO=BAR
  18. atf_check -o "not-inline:FOO=BAR\n" ../bin/env FOO=BAR ../bin/env
  19. atf_check -o "not-inline:FOO=BAR\n" ../bin/env FOO=BAR
  20. }
  21. atf_test_case uflag
  22. uflag_body() {
  23. [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment"
  24. atf_check -o "inline:FOO=BAR\n" ../bin/env -i FOO=BAR BAR=FOO ../bin/env -u BAR
  25. atf_check -s not-exit:0 -e "inline:Error: Missing operand for option: '-u'\nenv [-i] [-u key] [key=value ...] [command [args]]\n" ../bin/env -u
  26. }
  27. atf_test_case devfull
  28. devfull_body() {
  29. [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()"
  30. [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()"
  31. atf_check -s exit:1 -e 'inline:env: puts: No space left on device\n' sh -c '../bin/env >/dev/full'
  32. }
  33. atf_test_case noutil
  34. noutil_body() {
  35. atf_check -s exit:127 -e 'inline:env: execve: No such file or directory\n' ../bin/env /var/empty/e/no/ent
  36. }
  37. atf_test_case false
  38. false_body() {
  39. atf_check -s exit:1 ../bin/env false
  40. }
  41. atf_init_test_cases() {
  42. cd "$(atf_get_srcdir)" || exit 1
  43. atf_add_test_case noargs
  44. atf_add_test_case badarg
  45. atf_add_test_case iflag
  46. atf_add_test_case uflag
  47. atf_add_test_case devfull
  48. atf_add_test_case noutil
  49. atf_add_test_case false
  50. }