git.stg.codes
/
stg.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
384b6aa
)
Added common functions for tests.
author
Maxim Mamontov
<faust.madf@gmail.com>
Fri, 10 Oct 2014 21:36:37 +0000
(
00:36
+0300)
committer
Maxim Mamontov
<faust.madf@gmail.com>
Fri, 10 Oct 2014 21:36:37 +0000
(
00:36
+0300)
functest/functions
[new file with mode: 0644]
patch
|
blob
diff --git a/functest/functions
b/functest/functions
new file mode 100644
(file)
index 0000000..
183ddc4
--- /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
+}