logo

utils-std

Collection of commonly available Unix tools

basename (2305B)


  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. atf_check -o "inline:.\n" ../cmd/basename
  7. }
  8. atf_test_case one_slash
  9. one_slash_body() {
  10. atf_check -o "inline:bin\n" ../cmd/basename "/usr/bin"
  11. }
  12. atf_test_case two_slash
  13. two_slash_body() {
  14. atf_check -o "inline:bin\n" ../cmd/basename "/usr//bin"
  15. }
  16. atf_test_case two_dash
  17. two_dash_body() {
  18. atf_check -o "inline:bin\n" ../cmd/basename -- "/usr//bin"
  19. }
  20. atf_test_case testopt
  21. testopt_body() {
  22. atf_check -o "inline:bin\n" ../cmd/basename "/usr//bin-test" "-test"
  23. }
  24. atf_test_case usage
  25. usage_body() {
  26. atf_check -s exit:1 -e "inline:usage: basename string [suffix]\n" ../cmd/basename 1 2 3
  27. }
  28. atf_test_case devfull
  29. devfull_body() {
  30. has_glibc && atf_skip "glibc ignoring write errors for puts()"
  31. [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for puts()"
  32. [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for puts()"
  33. atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../cmd/basename >/dev/full'
  34. atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../cmd/basename "/usr/bin" >/dev/full'
  35. atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../cmd/basename "/usr//bin-test" "-test" >/dev/full'
  36. }
  37. atf_test_case nullarg
  38. nullarg_body() {
  39. atf_check -e "inline:.\n" ../cmd/basename "$(printf '\x00')"
  40. atf_check -e "inline:bin\n" ../cmd/basename "/usr/bin" "$(printf '\x00')"
  41. }
  42. atf_test_case doubledash
  43. doubledash_body() {
  44. atf_check -o 'inline:-\n' -- ../cmd/basename '-'
  45. atf_check -o 'inline:.\n' -- ../cmd/basename '--'
  46. atf_check -o 'inline:--\n' -- ../cmd/basename --a a
  47. atf_check -o 'inline:---\n' -- ../cmd/basename '---'
  48. }
  49. atf_init_test_cases() {
  50. cd "$(atf_get_srcdir)" || exit 1
  51. . ../test_functions.sh
  52. atf_add_test_case noargs
  53. atf_add_test_case one_slash
  54. atf_add_test_case two_slash
  55. atf_add_test_case two_dash
  56. atf_add_test_case testopt
  57. atf_add_test_case usage
  58. # puts in glibc doesn't returns -1 on failure
  59. atf_add_test_case devfull
  60. # Broken behavior in ATF, might be caused by stripping out \x00
  61. #atf_add_test_case nullarg
  62. atf_add_test_case doubledash
  63. }