-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit-test.sh
executable file
·123 lines (113 loc) · 2 KB
/
unit-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
set +x
function initOutPutColor
{
red='\e[0;31m'
nc='\e[0m'
green='\e[0;32m'
gray='\e[0;36m'
}
function getNode
{
isPrefixzero=false;
charNum=`echo -n $1|wc -m`
echo $1|grep -E "^0[0-9]+$" 2>&1 > /dev/null
RET=$?
if [[ $RET -eq 0 ]]; then
isPrefixzero=true;
if [[ $charNum -gt 2 ]]; then
echo "large than 9"
node="node"`echo -n $1|sed 's/^0//'`
else
echo "between 0 - 9"
node="node$1"
fi
else
isPrefixzero=false;
if [[ $charNum -gt 1 ]]; then
echo "large than 9"
node="node$1"
else
echo "bwteen 0 - 9"
node="node0$1"
fi
fi
echo "isPrefixzero = $isPrefixzero"
echo "$node"
}
function checkResult
{
if [[ $1 -ne 0 ]]; then
echo -e "${gray}Result ${red}:FAILD${nc}"
else
echo -e "${gray}Result ${green}:PASS${nc}"
fi
}
function testcase1
{
echo -e "${green}*****${gray}executing testcase1${green}*****${nc}"
getNode 09
test $node = "node09"
checkResult $?
}
function testcase2
{
echo -e "${green}*****${gray}executing testcase2${green}*****${nc}"
getNode 9
test $node = "node09"
checkResult $?
}
function testcase3
{
echo -e "${green}*****${gray}executing testcase3${green}*****${nc}"
getNode 090
test $node = "node90"
checkResult $?
}
function testcase4
{
echo -e "${green}*****${gray}executing testcase4${green}*****${nc}"
getNode 91110
test $node = "node91110"
checkResult $?
}
function testcase5
{
echo -e "${green}*****${gray}executing testcase5${green}*****${nc}"
echo "node111" >> know_clab.txt
echo "node222" >> know_clab.txt
echo "node333" >> know_clab.txt
delnode="node222"
sed "/$delnode/"d know_clab.txt >> know_clab.new
mv know_clab.new know_clab.txt
cat know_clab.txt
test !`grep node222 know_clab.txt`
checkResult $?
}
function runTest
{
initOutPutColor;
testcase1;
testcase2;
testcase3;
testcase4;
testcase5;
}
function Main
{
while [[ -n "$1" ]]; do
case $1 in
-test|-t )shift
runTest
exit 0
;;
*)
getNode $@
for (( i = 0; i < $#; i++ )); do
shift
done
;;
esac
done
}
Main $@