[GSoC][PATCH v2 1/3] test functions: add function `test_file_not_empty`

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



test-lib-functions: add a helper function that checks for a file and that
the file is not empty. The helper function will provide better error message
in case of failure and improve readability

The function `test_file_not_empty`, first checks if a file is provided,
if it is not then an error message is printed, skipping the remaining
code, if <path> is indeed a file then check `test -s` is applied to check
if size of file is greater than zero, failing which another error message
is printed.

Signed-off-by: Rohit Ashiwal <rohit.ashiwal265@xxxxxxxxx>
---
 t/test-lib-functions.sh | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 80402a428f..f9fcd2e013 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -593,6 +593,21 @@ test_dir_is_empty () {
 	fi
 }
 
+# Check if the file exists and has a size greater than zero
+test_file_not_empty () {
+	if ! test -f "$1"
+	then
+		echo "'$1' does not exist or not a file."
+		false
+	else
+		if ! test -s "$1"
+		then
+			echo "'$1' is an empty file."
+			false
+		fi
+	fi
+}
+
 test_path_is_missing () {
 	if test -e "$1"
 	then
-- 
2.17.1




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux