From 386e23e3f885b50c833d0c73da3a14965f350359 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 11 Oct 2014 00:36:37 +0300 Subject: [PATCH 1/1] Added common functions for tests. --- functest/functions | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 functest/functions diff --git a/functest/functions b/functest/functions new file mode 100644 index 00000000..183ddc4a --- /dev/null +++ b/functest/functions @@ -0,0 +1,40 @@ +trim() +{ + printf "$1" | sed -e 's/^ *//' -e 's/ *$//' +} + +getField() +{ + NAME="$1" + DATA="$2" + + printf "$DATA" | grep "$NAME" > /dev/null 2> /dev/null + if [ "$?" != "0" ] + then + return 1 + fi + + trim `printf "$DATA" | cut -d: -f2` +} + +getFields() +{ + NAME=$1 + DATA=$2 + + IFS=`printf '\n+'` + for LINE in $DATA + do + VALUE=`getField $NAME $LINE` && printf "%s\n" "$VALUE" + done +} + +count() +{ + if [ "$1" == "" ] + then + printf "0\n" + else + printf "$1\n" | wc -l + fi +} -- 2.44.2