logo

utils

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

env (2608B)


  1. #!/usr/bin/env atf-sh
  2. # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  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 ../cmd/env
  8. }
  9. atf_test_case badarg
  10. badarg_body() {
  11. 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
  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" ../cmd/env -i FOO=BAR ../cmd/env
  17. atf_check -o "inline:FOO=BAR\n" ../cmd/env -i FOO=BAR
  18. atf_check -o "not-inline:FOO=BAR\n" ../cmd/env FOO=BAR ../cmd/env
  19. atf_check -o "not-inline:FOO=BAR\n" ../cmd/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" ../cmd/env -i FOO=BAR BAR=FOO ../cmd/env -u BAR
  25. 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
  26. }
  27. atf_test_case unsetflag
  28. unsetflag_body() {
  29. [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment"
  30. atf_check -o "inline:FOO=BAR\n" ../cmd/env -i FOO=BAR BAR=FOO ../cmd/env --unset=BAR
  31. 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
  32. }
  33. atf_test_case devfull
  34. devfull_body() {
  35. [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()"
  36. [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()"
  37. atf_check -s exit:1 -e 'inline:env: puts(environ[i]): No space left on device\n' sh -c '../cmd/env >/dev/full'
  38. }
  39. atf_test_case noutil
  40. noutil_body() {
  41. 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
  42. }
  43. atf_test_case false
  44. false_body() {
  45. atf_check -s exit:1 ../cmd/env false
  46. }
  47. atf_init_test_cases() {
  48. cd "$(atf_get_srcdir)" || exit 1
  49. atf_add_test_case noargs
  50. atf_add_test_case badarg
  51. atf_add_test_case iflag
  52. atf_add_test_case uflag
  53. atf_add_test_case unsetflag
  54. atf_add_test_case devfull
  55. atf_add_test_case noutil
  56. atf_add_test_case false
  57. }