Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.12.0
41 changes: 30 additions & 11 deletions tests/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,38 @@
#
#
#
BG=${BG:-0}

run_tests_in_background(){
./test-html-base.sh &
./test-xml-ns-01.sh &
./test-xml-ns-02.sh &
./test-xml-ns-03.sh &
./test-xml-ns-no-default.sh &
}

sep="\n-------------------------------------------------------------\n"

echo

./test-html-base.sh
echo -e "$sep"
./test-xml-ns-01.sh
echo -e "$sep"
./test-xml-ns-02.sh

echo -e "$sep"
./test-xml-ns-03.sh

echo -e "$sep"
./test-xml-ns-no-default.sh
if [ "$BG" -eq 1 ];then
# sorting stdout by PID keeps test description and results more or less ordered but it's not perfect.
# To get a clean output run tests without BG=1. Added at issue #15.
for i in 1 2 3;do
# BG=1 ./test-all.sh
run_tests_in_background
done | sort -k1,2r

else
./test-html-base.sh
echo -e "$sep"
./test-xml-ns-01.sh
echo -e "$sep"
./test-xml-ns-02.sh

echo -e "$sep"
./test-xml-ns-03.sh

echo -e "$sep"
./test-xml-ns-no-default.sh
fi
2 changes: 1 addition & 1 deletion tests/test-html-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TC05="HTML absolute paths with duplicates (-a -r)"
TC06="HTML relative paths (-s) containing axes expression axes::elem"
# TODO: invalid html

echo "*** HTML tests ($script_name) ***"
echo_with_pid "Test Suite *** HTML tests ($script_name) ***"
test_run "TC01"
test_result "$?"

Expand Down
22 changes: 13 additions & 9 deletions tests/test-lib-src.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ DBG=0

TRACE_FILE='/dev/null'
[[ -n "$trace" && "$trace" != '/dev/null' ]] && TRACE_FILE="$trace" ;


echo_with_pid(){
printf "[%d] %b\n" "$$" "$@"
}

#---------------------------------------------------------------------------------------
# Verify test case result and return result and description
#---------------------------------------------------------------------------------------
Expand All @@ -16,16 +20,16 @@ function test_result(){
tc_result="FAILED"
if [ "$1" -eq "$retval" ]; then
tc_result="PASSED"
echo "${tc_result}"
echo_with_pid "${tc_result}"
else
echo "${tc_result}" | show_color
echo_with_pid "${tc_result}" | show_color
fi

}

function show_color(){
while read -r line; do
echo -e " \e[01;31m$line\e[0m" >&2
echo -e "\e[01;31m$line\e[0m"
done
}

Expand Down Expand Up @@ -56,11 +60,11 @@ function show_errors(){
# Run test case
#---------------------------------------------------------------------------------------
function print_test_descr(){
descr="\n$1 : ${!1}"
echo -e "$descr"
descr="$1 : ${!1}"
echo_with_pid "$descr"
if [ "$DBG" -eq 1 ]; then
topts=$(quote_opts "${test_opts[@]}")
echo "cmd : ../xml2xpath.sh $topts ${test_type_opts[*]}"
echo_with_pid "cmd : ../xml2xpath.sh $topts ${test_type_opts[*]}"
fi
}

Expand All @@ -69,7 +73,7 @@ function print_test_descr(){
#---------------------------------------------------------------------------------------
function test_run(){
if [ ! -f "${test_type_opts[${#test_type_opts[@]} - 1]}" ]; then
echo "ERROR file not found: ${test_type_opts[${#test_type_opts[@]} - 1]}" | show_color
echo_with_pid "ERROR file not found: ${test_type_opts[${#test_type_opts[@]} - 1]}" | show_color
exit 1
fi
print_test_descr "$1"
Expand All @@ -82,4 +86,4 @@ function test_run(){
#---------------------------------------------------------------------------------------
function test_run_count(){
../xml2xpath.sh "${test_opts[@]}" "${test_type_opts[@]}" | wc -l
}
}
2 changes: 1 addition & 1 deletion tests/test-xml-ns-01.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test_opts=()
test_type_opts=(-x "$xml_file")
rel_xpath='/defaultns:ClinicalDocument/defaultns:recordTarget'

echo "*** XML tests - namespaces on root element ($script_name) ***"
echo_with_pid "*** XML tests - namespaces on root element ($script_name) ***"
# Test case descriptions
TC01="Basic test (-x)"
TC02="Replace default namespace definition (-o), relative path (-s)"
Expand Down
2 changes: 1 addition & 1 deletion tests/test-xml-ns-02.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_opts=()
test_type_opts=(-x "$xml_file")
rel_xpath='//incident'

echo "*** XML tests - Namespaces on root element and body ($script_name) ***"
echo_with_pid "*** XML tests - Namespaces on root element and body ($script_name) ***"
# Test case descriptions
TC01="Basic test (-x)"
TC02="Replace default namespace definition (-o), relative path (-s)"
Expand Down
2 changes: 1 addition & 1 deletion tests/test-xml-ns-03.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ xml_file="resources/html5.html"
test_opts=()
test_type_opts=(-x "$xml_file")

echo "*** XHTML tests - Namespaces on root element and body. Multiple default namespaces across document. ($script_name) ***"
echo_with_pid "*** XHTML tests - Namespaces on root element and body. Multiple default namespaces across document. ($script_name) ***"
# Test case descriptions
TC01="Basic test (-x)"
TC02="Replace 'defaultns' prefix (-p)"
Expand Down
2 changes: 1 addition & 1 deletion tests/test-xml-ns-no-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ xml_file="resources/nodefaultns.xml"
test_opts=()
test_type_opts=(-x "$xml_file")

echo "*** XML tests - namespaces on root element but no default ns ($script_name) ***"
echo_with_pid "*** XML tests - namespaces on root element but no default ns ($script_name) ***"
# Test case descriptions
TC01="Basic test (-x)"

Expand Down
20 changes: 10 additions & 10 deletions xml2xpath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ trap_with_arg() { # from https://stackoverflow.com/a/2183063/804678

stop() {
trap - SIGINT EXIT
printf '\n%s\n' "received $1, bye!"
printf '\n%s\n' "[$$] received $1, bye!"
print_separator
rm -f "$fifo_in" "$fifo_out";
pkill -f xmllint
pkill --parent $$ -f xmllint
#kill -s SIGINT 0
}

Expand All @@ -131,7 +131,7 @@ function print_separator(){
# print to stderr
#---------------------------------------------------------------------------------------
function log_error(){
echo -e "$@" >> /dev/stderr
printf "%b" "$@" >> /dev/stderr
}

#---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -167,9 +167,9 @@ function set_html_opts(){

function is_read_error(){
if [ "$1" -ge 128 ]; then
log_error "\nTimeout reading from file descriptor $1 $2 . Current timeout: $rtout secs. Try extending the timeout with: XML_XPATH_RTOUT=[int or float > $rtout] xml2xpath.sh ...\n"
log_error "\n[$$] Timeout reading from file descriptor $1 $2 . Current timeout: $rtout secs. Try extending the timeout with: XML_XPATH_RTOUT=[int or float > $rtout] xml2xpath.sh ...\n"
elif [ "$1" -gt 0 ]; then
log_error "\nError reading from file descriptor: $1 $2\n"
log_error "\n[$$] Error reading from file descriptor: $1 $2\n"
fi
read_error="$1"
return "$1"
Expand Down Expand Up @@ -427,12 +427,12 @@ function init_env(){
ns_prefix="defaultns"
fi

fifo_in='xffin'
fifo_out='xffout'
fifo_in="/tmp/xffin.$$"
fifo_out="/tmp/xffout.$$"
trap_with_arg 'stop' EXIT SIGINT SIGTERM SIGHUP

[ ! -p "$fifo_in" ] && mkfifo "$fifo_in"
[ ! -p "$fifo_out" ] && mkfifo "$fifo_out"
[ ! -p "$fifo_in" ] && mkfifo --mode=600 "$fifo_in"
[ ! -p "$fifo_out" ] && mkfifo --mode=600 "$fifo_out"

exec 3<>"$fifo_in"
exec 4<>"$fifo_out"
Expand Down Expand Up @@ -504,7 +504,7 @@ fi
# ################################################
# Start process
# ################################################
echo -e "\nxml2xpath: find XPath expressions on $xml_file"
echo -e "\n[$$] xml2xpath: find XPath expressions on $xml_file"
print_separator
echo
printf " %s\n" "${all_opts[@]}"
Expand Down