del (1811B)
- #!/usr/bin/env atf-sh
- # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: MPL-2.0
- atf_test_case basic cleanup
- basic_body() {
- touch inputs/del-test || atf_fail "touching del-test"
- atf_check ../cmd/del inputs/del-test
- mkdir -p inputs/del-test.d || atf_fail "mkdir del-test.d"
- atf_check ../cmd/del inputs/del-test.d
- }
- basic_cleanup() {
- rm -fr inputs/del-test inputs/del-test.d || atf_fail "rm inputs/del-test{,.d}"
- }
- atf_test_case nopermf cleanup
- nopermf_body() {
- touch inputs/chmod_000 || atf_fail "touching chmod_000"
- chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000"
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:del: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/del inputs/chmod_000
- }
- nopermf_cleanup() {
- rm -fr inputs/chmod_000 inputs/chmod_000.d || atf_fail "rm chmod_000{,.d}"
- }
- atf_test_case nopermd cleanup
- nopermd_body() {
- mkdir -p inputs/chmod_000.d || atf_fail "mkdir chmod_000.d"
- chmod 0000 inputs/chmod_000.d || atf_fail "chmod 0000 chmod_000.d"
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:del: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/del inputs/chmod_000.d
- }
- nopermd_cleanup() {
- rm -fr inputs/chmod_000 inputs/chmod_000.d || atf_fail "rm chmod_000{,.d}"
- }
- atf_test_case enoent
- enoent_body() {
- # shellcheck disable=SC1112
- 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
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- atf_add_test_case basic
- # None of the supported implementations of remove(3) seem to have checks
- # based on file mode
- #atf_add_test_case nopermf
- #atf_add_test_case nopermd
- atf_add_test_case enoent
- }