mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-21 15:22:42 +00:00
fix directory-is-empty and add tests to avoid regressions
This commit is contained in:
parent
c4f984b205
commit
8bdb0ca77b
2 changed files with 30 additions and 1 deletions
|
@ -324,7 +324,7 @@ function file-exists()
|
|||
# @exitcode 1 If $1 does *NOT* contain files
|
||||
function directory-is-empty()
|
||||
{
|
||||
path-exists "${1}" && [[ -z "$(ls -A "${1}")" ]]
|
||||
! path-exists "${1}" || [[ -z "$(ls -A "${1}")" ]]
|
||||
}
|
||||
|
||||
# @description Ensures a directory exists (via mkdir)
|
||||
|
|
|
@ -5,6 +5,12 @@ setup() {
|
|||
load "$ROOT/docker/shared/root/docker/helpers.sh"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
if [[ -e test_dir ]]; then
|
||||
rm -rf test_dir
|
||||
fi
|
||||
}
|
||||
|
||||
@test "test [is-true]" {
|
||||
is-true "1"
|
||||
is-true "true"
|
||||
|
@ -72,3 +78,26 @@ setup() {
|
|||
|
||||
return 1
|
||||
}
|
||||
|
||||
@test "test [directory-is-empty] - non existing" {
|
||||
directory-is-empty test_dir
|
||||
}
|
||||
|
||||
@test "test [directory-is-empty] - actually empty" {
|
||||
mkdir -p test_dir
|
||||
|
||||
directory-is-empty test_dir
|
||||
}
|
||||
|
||||
@test "test [directory-is-empty] - not empty (directory)" {
|
||||
mkdir -p test_dir/sub-dir
|
||||
|
||||
! directory-is-empty test_dir
|
||||
}
|
||||
|
||||
@test "test [directory-is-empty] - not empty (file)" {
|
||||
mkdir -p test_dir/
|
||||
touch test_dir/hello-world.txt
|
||||
|
||||
! directory-is-empty test_dir
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue