Change BSD-2.0 to BSD-3-Clause
[platform/upstream/libiri.git] / run_test.sh
1 #!/bin/bash
2
3 PACKAGE_NAME=$1
4 PACKAGE_VERSION=$2
5
6 TEST_LOG="/tmp/${PACKAGE_NAME}_test"
7 export TEST_LOG
8 rm -f ${TEST_LOG}
9
10 # Color
11 Color_Off='\e[0m'       # Text Reset
12
13 # Regular Colors
14 Red='\e[0;31m'          # Red
15 Green='\e[0;32m'        # Green
16 Cyan='\e[0;36m'         # Cyank
17
18 # Bold
19 BWhite='\e[1;37m'       # White
20
21 result_check() {
22     result=$?
23     test_case=$1
24     if [ $result -eq 0 ]
25     then
26         echo -e "${Green}PASS${Color_Off}: $test_case"
27         echo "TEST: PASS: $test_case" >> ${TEST_LOG}
28     else
29         echo -e "${Red}FAIL${Color_Off}: $test_case"
30         echo -e "TEST: FAIL: $test_case" >> ${TEST_LOG}
31     fi
32 }
33
34 skip_test() {
35     test_case=$1
36     echo -e "${Cyan}SKIP${Color_Off}: $test_case"
37     echo "TEST: SKIP: $test_case" >> ${TEST_LOG}
38 }
39
40 run_test() {
41     test_case=$1
42     test_arg=$2
43     pushd tests
44     ./${test_case} ${test_arg} > ${test_case}.ref 2>&1
45     diff ${test_case}.ans ${test_case}.ref
46     result_check "diff ${test_case}.ans ${test_case}.ref"
47     popd
48
49 }
50
51 run_test_sort() {
52     test_case=$1
53     test_arg=$2
54     pushd tests
55     ./${test_case} ${test_arg} 2>&1 | sort > ${test_case}.ref
56     diff ${test_case}.ans ${test_case}.ref
57     result_check "diff ${test_case}.ans ${test_case}.ref"
58     popd
59
60 }
61
62     run_test iridump "abc://username:password@example.com:123/path/data?key=value#fragid1"
63
64 TOTAL_CNT=`grep "TEST:" ${TEST_LOG} | wc -l`
65 PASS_CNT=`grep "PASS:" ${TEST_LOG} | wc -l`
66 FAIL_CNT=`grep "FAIL:" ${TEST_LOG} | wc -l`
67 SKIP_CNT=`grep "SKIP:" ${TEST_LOG} | wc -l`
68
69
70 br='==================='; br=$br$br$br$br;
71
72 echo -e "${Green}$br ${Color_Off}"
73 echo -e "${Green}Testsuite summary for ${PACKAGE_NAME} ${PACKAGE_VERSION}${Color_Off}"
74 echo -e "${Green}$br ${Color_Off}"
75 echo -e "#${BWhite} TOTAL: $TOTAL_CNT ${Color_Off}"
76 echo -e "#${Green} PASS${Color_Off} : $PASS_CNT"
77 echo -e "#${Red} FAIL${Color_Off} : $FAIL_CNT"
78 echo -e "#${Cyan} SKIP${Color_Off} : $SKIP_CNT"
79 echo -e "${Green}$br ${Color_Off}"
80
81 rm -f ${TEST_LOG}
82 exit 0
83