forked from ric2k1/qsyn.lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDOFILE.sh
executable file
·105 lines (94 loc) · 3.01 KB
/
DOFILE.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
#!/bin/bash
source benchmark/qsyn_testing_code/BASH_UTIL.sh
RETURN_CODE=0
function USAGE () {
printf "%s\t%-12s%-17s%-16s%-9s%s\n" "Usage:" "./DOFILE.sh" "<path/to/dofile>" "[-Diff|-UPdate]" "[-Quiet]"
printf "\t%-9s%-2s%-12s\n" "-Diff" ":" "Compare the result to the reference"
printf "\t%-9s%-2s%-12s\n" "-UPdate" ":" "Update the reference file"
printf "\t%-9s%-2s%-12s\n" "" "" "If neither -Diff or -UPdate is specified, default to -Diff mode."
printf "\t%-9s%-2s%-12s\n" "-Quiet " ":" "Don't print diff message"
printf "\t%-9s%-2s%-12s\n" "-Help" ":" "Print this help message"
exit 1
} >&2
if (( $# < 1 || $# > 4 )); then
USAGE
fi
DODIFF=0
DOUPDATE=0
DOQUIET=0
DOHELP=0
for TOKEN in "$@"; do
if [[ $(MATCH_STR "$TOKEN" "-help" 2) == 1 ]]; then
USAGE
fi
done
for TOKEN in "$@"; do
if [[ $(MATCH_STR "$TOKEN" "-diff" 2) == 1 ]]; then
if [[ $DOUPDATE == 1 ]]; then
printf "Error: Cannot use -Diff and -UPdate at the same time!!\n"
exit 1
fi
if [[ $DODIFF == 1 ]]; then
printf "Error: extra option (%s)!!\n" $TOKEN
exit 1
fi
DODIFF=1
elif [[ $(MATCH_STR "$TOKEN" "-update" 3) == 1 ]]; then
if [[ $DODIFF == 1 ]]; then
echo "Error: Cannot use -Diff and -UPdate at the same time!!"
exit 1
fi
if [[ $DOUPDATE == 1 ]]; then
printf "Error: Extra Option (%s)!!\n" $TOKEN
exit 1
fi
DOUPDATE=1
elif [[ $(MATCH_STR "$TOKEN" "-quiet" 2) == 1 ]]; then
if [[ $DOQUIET == 1 ]]; then
printf "Error: Extra Option (%s)!!\n" $TOKEN
exit 1
fi
DOQUIET=1
elif [ -f $TOKEN ]; then
FILE_PATH=$TOKEN
else
printf "Error: invalid option!! (%s)\n" $TOKEN
exit 1
fi
done
if [[ $DODIFF == 0 && $DOUPDATE == 0 ]]; then DODIFF=1; fi
DOFILE=$(basename $FILE_PATH)
DOFILE_DIR=$(dirname $FILE_PATH)
PKG_NAME=$(dirname $DOFILE_DIR)
REF_FILE=${PKG_NAME}/ref/${DOFILE%%.*}.log
PASS_TEXT="Passed"
FAIL_TEXT="Failed"
DIFF_HEAD="------------------- Differences --------------------"
DIFF_FOOT="----------------------------------------------------"
PASS_TEXT="${BOLD}${GREEN}${PASS_TEXT}${WHITE}${NORMAL}"
FAIL_TEXT="${BOLD}${RED}${FAIL_TEXT}${WHITE}${NORMAL}"
DIFF_HEAD="${BOLD}${RED}${DIFF_HEAD}${WHITE}${NORMAL}"
DIFF_FOOT="${BOLD}${RED}${DIFF_FOOT}${WHITE}${NORMAL}"
if [[ $DODIFF == 1 ]]; then
printf "Testing %-30s" ${DOFILE}
OUTPUT=$(./qsyn -f ${FILE_PATH} 2>&1 | diff ${REF_FILE} - )
STATUS=$?
if [[ $STATUS == 0 ]]; then
echo -e ${PASS_TEXT};
else
echo -e ${FAIL_TEXT}
RETURN_CODE=1
if [[ $DOQUIET == 0 ]]; then
echo -e "${DIFF_HEAD}"
echo -e "${OUTPUT}"
echo -e "${DIFF_FOOT}"
fi
fi
elif [[ $DOUPDATE == 1 ]]; then
printf "Updating %s\n" $(basename ${REF_FILE})
./qsyn -f ${FILE_PATH} > ${REF_FILE} 2>&1
else
echo -e "Error"
USAGE
fi
exit ${RETURN_CODE}