logo

utils

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

basename (2352B)


  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. atf_check -o "inline:.\n" ../bin/basename
  7. }
  8. atf_test_case one_slash
  9. one_slash_body() {
  10. atf_check -o "inline:bin\n" ../bin/basename "/usr/bin"
  11. }
  12. atf_test_case two_slash
  13. two_slash_body() {
  14. atf_check -o "inline:bin\n" ../bin/basename "/usr//bin"
  15. }
  16. atf_test_case two_dash
  17. two_dash_body() {
  18. atf_check -o "inline:bin\n" ../bin/basename -- "/usr//bin"
  19. }
  20. atf_test_case testopt
  21. testopt_body() {
  22. atf_check -o "inline:bin\n" ../bin/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" ../bin/basename 1 2 3
  27. }
  28. atf_test_case devfull
  29. devfull_body() {
  30. has_glibc && atf_expect_fail "glibc ignoring write errors for puts()"
  31. [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()"
  32. [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()"
  33. atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../bin/basename >/dev/full'
  34. atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../bin/basename "/usr/bin" >/dev/full'
  35. atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../bin/basename "/usr//bin-test" "-test" >/dev/full'
  36. }
  37. atf_test_case nullarg
  38. nullarg_body() {
  39. atf_check -e "inline:.\n" ../bin/basename "$(printf '\x00')"
  40. atf_check -e "inline:bin\n" ../bin/basename "/usr/bin" "$(printf '\x00')"
  41. }
  42. atf_test_case doubledash
  43. doubledash_body() {
  44. atf_check -o 'inline:-\n' -- ../bin/basename '-'
  45. atf_check -o 'inline:.\n' -- ../bin/basename '--'
  46. atf_check -o 'inline:--\n' -- ../bin/basename --a a
  47. atf_check -o 'inline:---\n' -- ../bin/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. }