os: add behavior info to `is_dir_empty` documentation (#14110)

master
Larpon 2022-04-21 17:21:00 +02:00 committed by GitHub
parent 26b0e7fd34
commit 506259adb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -162,6 +162,7 @@ pub fn rmdir_all(path string) ? {
} }
// is_dir_empty will return a `bool` whether or not `path` is empty. // is_dir_empty will return a `bool` whether or not `path` is empty.
// Note that it will return `true` if `path` does not exist.
[manualfree] [manualfree]
pub fn is_dir_empty(path string) bool { pub fn is_dir_empty(path string) bool {
items := ls(path) or { return true } items := ls(path) or { return true }

View File

@ -355,6 +355,12 @@ fn test_mv() {
assert !os.is_dir(expected) assert !os.is_dir(expected)
} }
fn test_is_dir_empty() {
// Test that is_dir_empty returns true on
// non-existent directories ***as stated in it's doc string***
assert os.is_dir_empty('dir that does not exist at all')
}
fn test_cp_all() { fn test_cp_all() {
// fileX -> dir/fileX // fileX -> dir/fileX
// Note: clean up of the files happens inside the cleanup_leftovers function // Note: clean up of the files happens inside the cleanup_leftovers function