From a7e8ca70dc4a60401c0f83fb4837e02587173c2f Mon Sep 17 00:00:00 2001 From: Larpon Date: Thu, 21 Apr 2022 17:21:00 +0200 Subject: [PATCH] os: add behavior info to `is_dir_empty` documentation (#14110) --- vlib/os/os.v | 1 + vlib/os/os_test.v | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/vlib/os/os.v b/vlib/os/os.v index a39e7ae303..ffa6dd505e 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -162,6 +162,7 @@ pub fn rmdir_all(path string) ? { } // 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] pub fn is_dir_empty(path string) bool { items := ls(path) or { return true } diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index 862cc4e45a..3775dfcf80 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -355,6 +355,12 @@ fn test_mv() { 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() { // fileX -> dir/fileX // Note: clean up of the files happens inside the cleanup_leftovers function