logo

utils

Old programs, got split in utils-std and utils-extra git clone https://hacktivis.me/git/utils.git

del (1811B)


  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 basic cleanup
  5. basic_body() {
  6. touch inputs/del-test || atf_fail "touching del-test"
  7. atf_check ../cmd/del inputs/del-test
  8. mkdir -p inputs/del-test.d || atf_fail "mkdir del-test.d"
  9. atf_check ../cmd/del inputs/del-test.d
  10. }
  11. basic_cleanup() {
  12. rm -fr inputs/del-test inputs/del-test.d || atf_fail "rm inputs/del-test{,.d}"
  13. }
  14. atf_test_case nopermf cleanup
  15. nopermf_body() {
  16. touch inputs/chmod_000 || atf_fail "touching chmod_000"
  17. chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000"
  18. # shellcheck disable=SC1112
  19. atf_check -s exit:1 -e 'inline:del: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/del inputs/chmod_000
  20. }
  21. nopermf_cleanup() {
  22. rm -fr inputs/chmod_000 inputs/chmod_000.d || atf_fail "rm chmod_000{,.d}"
  23. }
  24. atf_test_case nopermd cleanup
  25. nopermd_body() {
  26. mkdir -p inputs/chmod_000.d || atf_fail "mkdir chmod_000.d"
  27. chmod 0000 inputs/chmod_000.d || atf_fail "chmod 0000 chmod_000.d"
  28. # shellcheck disable=SC1112
  29. atf_check -s exit:1 -e 'inline:del: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/del inputs/chmod_000.d
  30. }
  31. nopermd_cleanup() {
  32. rm -fr inputs/chmod_000 inputs/chmod_000.d || atf_fail "rm chmod_000{,.d}"
  33. }
  34. atf_test_case enoent
  35. enoent_body() {
  36. # shellcheck disable=SC1112
  37. atf_check -s exit:1 -e 'inline:del: remove(/var/empty/e/no/ent) error: No such file or directory\n' ../cmd/del /var/empty/e/no/ent
  38. }
  39. atf_init_test_cases() {
  40. cd "$(atf_get_srcdir)" || exit 1
  41. atf_add_test_case basic
  42. # None of the supported implementations of remove(3) seem to have checks
  43. # based on file mode
  44. #atf_add_test_case nopermf
  45. #atf_add_test_case nopermd
  46. atf_add_test_case enoent
  47. }