logo

utils-std

Collection of commonly available Unix tools

env (2495B)


  1. #!/usr/bin/env atf-sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. atf_test_case noargs
  5. noargs_body() {
  6. gentoo_sandbox && atf_skip "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. gentoo_sandbox && atf_skip "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. gentoo_sandbox && atf_skip "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. gentoo_sandbox && atf_skip "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_skip "NetBSD ignoring write errors for puts()"
  36. [ "$(uname -s)" = "FreeBSD" ] && atf_skip "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. . ../test_functions.sh
  50. atf_add_test_case noargs
  51. atf_add_test_case badarg
  52. atf_add_test_case iflag
  53. atf_add_test_case uflag
  54. atf_add_test_case unsetflag
  55. atf_add_test_case devfull
  56. atf_add_test_case noutil
  57. atf_add_test_case false
  58. }