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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,5 @@ To test the generated man page use:
`MANPATH="./man" man man/xml2xpath.sh.1`

## Known issues
* No one! ... that I know of :-p but [performance](#performance) with big documents can always be an issue.
* `-p` might give inconsistent namespace prefixes on documents with multiple namespaces.
[Performance](#performance) with big documents can always be an issue.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.2
0.12.3
4 changes: 2 additions & 2 deletions tests/test-html-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ test_result "$?"

test_opts=(-a -r)
print_test_descr "TC05"
dup_cnt=$(test_run_count)
dup_cnt=$(test_run_basic_count)
test_opts=(-a)
uniq_cnt=$(test_run_count)
uniq_cnt=$(test_run_basic_count)
#[ ! "$dup_cnt" -gt "$uniq_cnt" ] && echo "duplicates: $dup_cnt -gt $uniq_cnt $?"
[ ! "$dup_cnt" -gt "$uniq_cnt" ]
test_result "$?"
Expand Down
48 changes: 36 additions & 12 deletions tests/test-lib-src.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo_with_pid(){
#---------------------------------------------------------------------------------------
# Verify test case result and return result and description
#---------------------------------------------------------------------------------------
function test_result(){
test_result(){
retval=1
[ -n "$2" ] && retval="$2"

Expand All @@ -27,13 +27,13 @@ function test_result(){

}

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

function quote_opts(){
quote_opts(){
local str=''
for o in "$@"; do
if grep -q "^[-][a-z]" <<<"$o"; then
Expand All @@ -48,18 +48,19 @@ function quote_opts(){
#---------------------------------------------------------------------------------------
# Run test case
#---------------------------------------------------------------------------------------
function show_errors(){
show_errors(){
err_pattern='XPath error|No xpath found|Boolean : false'
if [ "$DBG" -eq 1 ]; then
tee /dev/stderr 2> >(show_color) | grep -Eq 'XPath error|No xpath found'
tee /dev/stderr 2> >(show_color) | grep -Eq "$err_pattern"
else
grep -Eq 'XPath error|No xpath found'
grep -Eq "$err_pattern"
fi
}

#---------------------------------------------------------------------------------------
# Run test case
# Print test case description
#---------------------------------------------------------------------------------------
function print_test_descr(){
print_test_descr(){
descr="$1 : ${!1}"
echo_with_pid "$descr"
if [ "$DBG" -eq 1 ]; then
Expand All @@ -71,19 +72,42 @@ function print_test_descr(){
#---------------------------------------------------------------------------------------
# Run test case
#---------------------------------------------------------------------------------------
function test_run(){
test_run(){
if [ ! -f "${test_type_opts[${#test_type_opts[@]} - 1]}" ]; then
echo_with_pid "ERROR file not found: ${test_type_opts[${#test_type_opts[@]} - 1]}" | show_color
exit 1
fi
print_test_descr "$1"
print_test_descr "$1" >>"$TRACE_FILE"
print_test_descr "$1" | tee -a "$TRACE_FILE"
../xml2xpath.sh "${test_opts[@]}" "${test_type_opts[@]}" 2>&1 1>>"$TRACE_FILE" | show_errors
}

#---------------------------------------------------------------------------------------
# Run count test case
#---------------------------------------------------------------------------------------
test_run_count(){
if [ ! -f "${test_type_opts[${#test_type_opts[@]} - 1]}" ]; then
echo_with_pid "ERROR file not found: ${test_type_opts[${#test_type_opts[@]} - 1]}" | show_color
exit 1
fi
print_test_descr "$1" | tee -a "$TRACE_FILE"
result=$(../xml2xpath.sh "${test_opts[@]}" "${test_type_opts[@]}")
gawk 'BEGIN{RS="\n\n";FS="\n"}
{
if(NR == 1) printf "%s\n","setrootns"
for(i=1; i<=NF; i++) {
if($i == "") continue
if($0 ~ /^[^=\/]+=/){
printf "%s\n", "setns " $i
} else {
printf "%s\n", "xpath count(" $i ") > 0"
}
}
}END{ printf "bye\n" }' <<<"$result" | xmllint --shell "${test_type_opts[@]}" 2>&1 | show_errors
}

#---------------------------------------------------------------------------------------
# Run test case for duplicates count
#---------------------------------------------------------------------------------------
function test_run_count(){
test_run_basic_count(){
../xml2xpath.sh "${test_opts[@]}" "${test_type_opts[@]}" | wc -l
}
8 changes: 7 additions & 1 deletion tests/test-xml-ns-01.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ script_name=$(basename "$0")
source test-lib-src.sh
xml_file="resources/HL7.xml"
test_opts=()
test_type_opts=(-x "$xml_file")
test_type_opts=("$xml_file")
rel_xpath='/defaultns:ClinicalDocument/defaultns:recordTarget'

echo_with_pid "*** XML tests - namespaces on root element ($script_name) ***"
Expand All @@ -19,6 +19,7 @@ TC01="Basic test (-x)"
TC02="Replace default namespace definition (-o), relative path (-s)"
TC03="Find nodes using namespaces (-n)"
TC04="Find nodes by absolute xpath using namespaces (-a -n)"
TC05="Count nodes with replaced default namespace definition (-o), relative path (-s)"

test_run "TC01"
test_result "$?"
Expand All @@ -40,3 +41,8 @@ test_result "$?"
test_opts=(-a -n -s "${rel_xpath}")
test_run "TC04"
test_result "$?"

test_opts=('-q' '-n' '-o' 'defns=urn:hl7-org:v3' '-s' '//defns:addr')
#xml2xpath.sh "${test_opts[@]}" -x "$xml_file" | grep -q 'XPath error'
test_run_count "TC05"
test_result "$?"
9 changes: 8 additions & 1 deletion tests/test-xml-ns-02.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ script_name=$(basename "$0")
source test-lib-src.sh
xml_file="resources/soap.xml"
test_opts=()
test_type_opts=(-x "$xml_file")
test_type_opts=("$xml_file")
rel_xpath='//incident'

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)"
TC04="Test count of nodes found 'TC02' is greater than 0 for all found expressions"

test_run "TC01"
test_result "$?"
Expand All @@ -28,3 +29,9 @@ test_result "$?"
test_opts=(-o 'defns=http://example.com/ns1' -s "//defns:incident")
test_run "TC02"
test_result "$?"

#test_type_opts=("resources/ns-with-default.xml")
#test_opts=( '-q' '-s' '//*[local-name()="x"]' )
test_opts=('-q' '-n' '-o' 'defns=http://example.com/ns1' -s "//defns:incident")
test_run_count "TC04"
test_result "$?"
7 changes: 5 additions & 2 deletions tests/test-xml-ns-03.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ script_name=$(basename "$0")
source test-lib-src.sh
xml_file="resources/html5.html"
test_opts=()
test_type_opts=(-x "$xml_file")
test_type_opts=( "$xml_file" )

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)"
TC03="Replace default namespace definition (-o), relative path (-s)"

TC04="Test count of nodes TC03 is greater than 0 for all found expressions"

test_run "TC01"
test_result "$?"
Expand All @@ -40,3 +40,6 @@ test_opts=(-o 'dft01=http://www.w3.org/1998/Math/MathML' -s '//dft01:math/dft01:
test_run "TC03"
test_result "$?"

test_opts=("-q" '-n' "-o" 'dft01=http://www.w3.org/1998/Math/MathML' -s '//dft01:math/dft01:mrow/dft01:mn')
test_run_count "TC04"
test_result "$?"
Loading