commit: cef47e495209a31cceeaff73a39fdb1fb2046344
parent 0a26b32f58a9f21547d4c6289576b8a2529ca6ef
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 1 Mar 2022 14:34:30 +0100
test-bin/del: New
Diffstat:
2 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/test-bin/Kyuafile b/test-bin/Kyuafile
@@ -9,6 +9,7 @@ atf_test_program{name="args", required_files=basedir.."/bin/args"}
atf_test_program{name="basename", required_files=basedir.."/bin/basename"}
atf_test_program{name="cat", required_files=basedir.."/bin/cat"}
atf_test_program{name="date", required_files=basedir.."/bin/date"}
+atf_test_program{name="del", required_files=basedir.."/bin/del"}
atf_test_program{name="dirname", required_files=basedir.."/bin/dirname"}
atf_test_program{name="echo", required_files=basedir.."/bin/echo"}
atf_test_program{name="env", required_files=basedir.."/bin/env"}
diff --git a/test-bin/del b/test-bin/del
@@ -0,0 +1,60 @@
+#!/usr/bin/env atf-sh
+atf_test_case basic cleanup
+basic_body() {
+ touch inputs/del-test || atf_fail "touching del-test"
+ atf_check ../bin/del inputs/del-test
+
+ mkdir -p inputs/del-test.d || atf_fail "mkdir del-test.d"
+ atf_check ../bin/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() {
+ if test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h
+ then
+ atf_expect_fail "glibc ignoring permission errors in remove(3)"
+ fi
+
+ 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:Error opening ‘inputs/chmod_000’: Permission denied\n' ../bin/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() {
+ if test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h
+ then
+ atf_expect_fail "glibc ignoring permission errors in remove(3)"
+ fi
+
+ 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:Error opening ‘inputs/chmod_000’: Permission denied\n' ../bin/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:remove(/var/empty/e/no/ent) error: No such file or directory\n' ../bin/del /var/empty/e/no/ent
+}
+
+atf_init_test_cases() {
+ cd "$(atf_get_srcdir)" || exit 1
+ atf_add_test_case basic
+ atf_add_test_case nopermf
+ atf_add_test_case nopermd
+ atf_add_test_case enoent
+}