@@ -13,7 +13,7 @@ echo_with_pid(){
1313# ---------------------------------------------------------------------------------------
1414# Verify test case result and return result and description
1515# ---------------------------------------------------------------------------------------
16- function test_result(){
16+ test_result (){
1717 retval=1
1818 [ -n " $2 " ] && retval=" $2 "
1919
@@ -27,13 +27,13 @@ function test_result(){
2727
2828}
2929
30- function show_color(){
30+ show_color (){
3131 while read -r line; do
3232 echo -e " \e[01;31m$line \e[0m"
3333 done
3434}
3535
36- function quote_opts(){
36+ quote_opts (){
3737 local str=' '
3838 for o in " $@ " ; do
3939 if grep -q " ^[-][a-z]" <<< " $o" ; then
@@ -48,18 +48,19 @@ function quote_opts(){
4848# ---------------------------------------------------------------------------------------
4949# Run test case
5050# ---------------------------------------------------------------------------------------
51- function show_errors(){
51+ show_errors (){
52+ err_pattern=' XPath error|No xpath found|Boolean : false'
5253 if [ " $DBG " -eq 1 ]; then
53- tee /dev/stderr 2> >( show_color) | grep -Eq ' XPath error|No xpath found '
54+ tee /dev/stderr 2> >( show_color) | grep -Eq " $err_pattern "
5455 else
55- grep -Eq ' XPath error|No xpath found '
56+ grep -Eq " $err_pattern "
5657 fi
5758}
5859
5960# ---------------------------------------------------------------------------------------
60- # Run test case
61+ # Print test case description
6162# ---------------------------------------------------------------------------------------
62- function print_test_descr(){
63+ print_test_descr (){
6364 descr=" $1 : ${! 1} "
6465 echo_with_pid " $descr "
6566 if [ " $DBG " -eq 1 ]; then
@@ -71,19 +72,42 @@ function print_test_descr(){
7172# ---------------------------------------------------------------------------------------
7273# Run test case
7374# ---------------------------------------------------------------------------------------
74- function test_run(){
75+ test_run (){
7576 if [ ! -f " ${test_type_opts[${#test_type_opts[@]} - 1]}" ]; then
7677 echo_with_pid " ERROR file not found: ${test_type_opts[${#test_type_opts[@]} - 1]}" | show_color
7778 exit 1
7879 fi
79- print_test_descr " $1 "
80- print_test_descr " $1 " >> " $TRACE_FILE "
80+ print_test_descr " $1 " | tee -a " $TRACE_FILE "
8181 ../xml2xpath.sh " ${test_opts[@]} " " ${test_type_opts[@]} " 2>&1 1>> " $TRACE_FILE " | show_errors
8282}
8383
84+ # ---------------------------------------------------------------------------------------
85+ # Run count test case
86+ # ---------------------------------------------------------------------------------------
87+ test_run_count (){
88+ if [ ! -f " ${test_type_opts[${#test_type_opts[@]} - 1]}" ]; then
89+ echo_with_pid " ERROR file not found: ${test_type_opts[${#test_type_opts[@]} - 1]}" | show_color
90+ exit 1
91+ fi
92+ print_test_descr " $1 " | tee -a " $TRACE_FILE "
93+ result=$( ../xml2xpath.sh " ${test_opts[@]} " " ${test_type_opts[@]} " )
94+ gawk ' BEGIN{RS="\n\n";FS="\n"}
95+ {
96+ if(NR == 1) printf "%s\n","setrootns"
97+ for(i=1; i<=NF; i++) {
98+ if($i == "") continue
99+ if($0 ~ /^[^=\/]+=/){
100+ printf "%s\n", "setns " $i
101+ } else {
102+ printf "%s\n", "xpath count(" $i ") > 0"
103+ }
104+ }
105+ }END{ printf "bye\n" }' <<< " $result" | xmllint --shell " ${test_type_opts[@]} " 2>&1 | show_errors
106+ }
107+
84108# ---------------------------------------------------------------------------------------
85109# Run test case for duplicates count
86110# ---------------------------------------------------------------------------------------
87- function test_run_count (){
111+ test_run_basic_count (){
88112 ../xml2xpath.sh " ${test_opts[@]} " " ${test_type_opts[@]} " | wc -l
89113}
0 commit comments