-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·131 lines (90 loc) · 2.17 KB
/
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
124
125
126
127
128
129
130
131
#!/bin/zsh
autoload colors
colors
setopt shwordsplit
if [[ "$terminfo[colors]" -gt 8 ]]; then
colors
fi
for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
eval $COLOR='$fg_no_bold[${(L)COLOR}]'
eval BOLD_$COLOR='$fg_bold[${(L)COLOR}]'
done
eval RESET='$reset_color'
printEnd()
{
echo "------- end ${YELLOW}$1${RESET}"
}
printStart()
{
echo "----- start ${YELLOW}$1${RESET}"
}
printError()
{
echo "${RED}error: $1${RESET}"
}
INTERPRETER=python3
SCRIPT=epubtoc.py
TESTS_FOLDER=tests
if [[ -z $1 ]]; then
TEST_INPUT_FOLDERS=$(print $TESTS_FOLDER/test*)
else
TEST_INPUT_FOLDERS=$TESTS_FOLDER/$1
fi
FAIL=0
for folder in $TEST_INPUT_FOLDERS; do
folder_name=`basename $folder`
input_XML=$folder/input.xml
input_ARG=$folder/input.arg
output_ERR=$folder/result.err
output_OUT=$folder/result.out
expected_RET=$folder/expected.\!\!\!
expected_XML=$folder/expected.xml
diff_XML=$folder/diff.xml
TEST_FAIL=0
if [[ -e "$input_ARG" ]]; then
arg=`cat "$input_ARG" | sed "s|\@\.|$folder|"`
fi
printStart $folder_name
# ---------- run script -------------
if [[ -e $input_XML ]]; then
$INTERPRETER $SCRIPT ${=arg} "$input_XML" "$output_OUT" 2> "$output_ERR"
else
$INTERPRETER $SCRIPT ${=arg} > "$output_OUT" 2> "$output_ERR"
fi
# ----------- compare return code ------------
RET=$?
if [[ -e " $expected_RET" ]]; then
EXP_RET=`cat "$expected_RET"`
else
EXP_RET=0
fi
if [[ $EXP_RET != $RET ]]; then
printError "expected ret code: $EXP_RET ret code: $RET"
TEST_FAIL=1
FAIL=1
fi
if [[ $RET != 0 || $EXP_RET != 0 ]]; then
if [[ $TEST_FAIL == 0 ]]; then
print "${GREEN}OK${RESET}"
fi
printEnd $folder_name
continue
fi
# -------------------------------------
java -jar ~/bin/jexamxml.jar "$output_OUT" "$expected_XML" "$diff_XML" xml_options > /dev/null
if [[ $? != 0 ]]; then
printError "xml is not identical"
TEST_FAIL=1
FAIL=1
fi
if [[ $TEST_FAIL == 0 ]]; then
print "${GREEN}OK${RESET}"
fi
printEnd $folder_name
done
# ------------------------------------------------------------------------------
if [[ $FAIL == 0 ]]; then
echo -e "\n${GREEN}SUCCESS${RESET}\n"
else
echo -e "\n${BOLD_RED}FAIL${RESET}\n"
fi