diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..d33c3a2 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.12.0 \ No newline at end of file diff --git a/tests/test-all.sh b/tests/test-all.sh index 6c5d74c..aa492e3 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -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 diff --git a/tests/test-html-base.sh b/tests/test-html-base.sh index 9bc8b86..ff8af10 100755 --- a/tests/test-html-base.sh +++ b/tests/test-html-base.sh @@ -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 "$?" diff --git a/tests/test-lib-src.sh b/tests/test-lib-src.sh index d95cd03..18eac69 100644 --- a/tests/test-lib-src.sh +++ b/tests/test-lib-src.sh @@ -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 #--------------------------------------------------------------------------------------- @@ -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 } @@ -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 } @@ -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" @@ -82,4 +86,4 @@ function test_run(){ #--------------------------------------------------------------------------------------- function test_run_count(){ ../xml2xpath.sh "${test_opts[@]}" "${test_type_opts[@]}" | wc -l -} \ No newline at end of file +} diff --git a/tests/test-xml-ns-01.sh b/tests/test-xml-ns-01.sh index 74d944d..45f0fb9 100755 --- a/tests/test-xml-ns-01.sh +++ b/tests/test-xml-ns-01.sh @@ -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)" diff --git a/tests/test-xml-ns-02.sh b/tests/test-xml-ns-02.sh index 33d7eb8..1d08326 100755 --- a/tests/test-xml-ns-02.sh +++ b/tests/test-xml-ns-02.sh @@ -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)" diff --git a/tests/test-xml-ns-03.sh b/tests/test-xml-ns-03.sh index fec621f..f870141 100755 --- a/tests/test-xml-ns-03.sh +++ b/tests/test-xml-ns-03.sh @@ -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)" diff --git a/tests/test-xml-ns-no-default.sh b/tests/test-xml-ns-no-default.sh index 9bb4b45..84e2985 100755 --- a/tests/test-xml-ns-no-default.sh +++ b/tests/test-xml-ns-no-default.sh @@ -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)" diff --git a/xml2xpath.sh b/xml2xpath.sh index db895cc..0339a6c 100755 --- a/xml2xpath.sh +++ b/xml2xpath.sh @@ -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 } @@ -131,7 +131,7 @@ function print_separator(){ # print to stderr #--------------------------------------------------------------------------------------- function log_error(){ - echo -e "$@" >> /dev/stderr + printf "%b" "$@" >> /dev/stderr } #--------------------------------------------------------------------------------------- @@ -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" @@ -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" @@ -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[@]}"