Tests: Add helper functions for printing status and banner
authorChristian Babeux <christian.babeux@efficios.com>
Mon, 24 Sep 2012 16:11:45 +0000 (12:11 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 24 Sep 2012 20:26:12 +0000 (16:26 -0400)
Add three new printing functions:

print_ok: Print the OK status with optional color support.
print_fail: Print the FAIL status with optional color support.
print_test_banner: Print a test banner of the test description.

e.g.:
sometest.sh:
TEST_DESC="A really useful test"
[...]
source $TESTDIR/utils.sh
print_test_banner $TEST_DESC
[...]
print_ok
print_fail
[...]

$ ./sometest.sh
----------------------
A really useful test
----------------------
OK
FAIL

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
tests/utils.sh

index 42b18e383d6104b52c70beba6608d5d58c48e8fa..8fcb0da38c2a8f4a3f9ca8af0484edf8b8aa4ee3 100644 (file)
@@ -25,6 +25,38 @@ KERNEL_MAJOR_VERSION=2
 KERNEL_MINOR_VERSION=6
 KERNEL_PATCHLEVEL_VERSION=27
 
+function print_ok ()
+{
+       # Check if we are a terminal
+       if [ -t 1 ]; then
+               echo -e "\e[1;32mOK\e[0m"
+       else
+               echo -e "OK"
+       fi
+}
+
+function print_fail ()
+{
+       # Check if we are a terminal
+       if [ -t 1 ]; then
+               echo -e "\e[1;31mFAIL\e[0m"
+       else
+               echo -e "FAIL"
+       fi
+}
+
+function print_test_banner ()
+{
+       desc="$1"
+
+       count=$((${#desc}+2))
+       str=$(printf "%${count}s");
+       echo -e "\n"
+       echo -e ${str// /-}
+       echo -e " $desc "
+       echo -e ${str// /-}
+}
+
 function validate_kernel_version ()
 {
        kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
This page took 0.026958 seconds and 4 git commands to generate.