123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #!/bin/bash
- #shellcheck disable=SC2016,SC1090
-
- . "$TF_DIR/include/subtest.sh"
- . "$TF_DIR/include/tools.sh"
-
- PRETTY=plain
-
- . "$(sfpath)" || tf_exit_error "failed to init shellfu"
- shellfu import pxpath || tf_exit_error "failed to import pxpath"
-
- tf_enum_subtests() {
- echo elem_abs
- echo elem_rel
- echo attr
- echo inv_xpath
- echo usage_noargs
- echo usage_1arg
- echo io_nofile
- echo io_pipe
- #FIXME: missing coverage: more usage/xml/io errors, [] expressions, namespaces...
- }
-
- mkxml() {
- echo '<benchmark>'
- echo ' <testresult>'
- echo ' <foo id="one">'
- echo ' <bar>pass</bar>'
- echo ' </foo>'
- echo ' <foo id="two">'
- echo ' <bar>none</bar>'
- echo ' </foo>'
- echo ' <foo id="three">'
- echo ' <bar>pass</bar>'
- echo ' </foo>'
- echo ' </testresult>'
- echo '</benchmark>'
- }
-
- mka() {
- local what=$1
- case $name:$what in
- elem_abs:xpath)
- echo '/benchmark/testresult/foo'
- ;;
- elem_abs:o_out)
- echo '<foo id="one">'
- echo ' <bar>pass</bar>'
- echo ' </foo>'
- echo '<foo id="two">'
- echo ' <bar>none</bar>'
- echo ' </foo>'
- echo '<foo id="three">'
- echo ' <bar>pass</bar>'
- echo ' </foo>'
- ;;
- elem_rel:xpath)
- echo '//foo/bar'
- ;;
- elem_rel:o_out)
- echo '<bar>pass</bar>'
- echo '<bar>none</bar>'
- echo '<bar>pass</bar>'
- ;;
- attr:xpath)
- echo '//foo/@id'
- ;;
- attr:o_out)
- echo 'one'
- echo 'two'
- echo 'three'
- ;;
- inv_xpath:xpath)
- echo '//foo@id'
- ;;
- inv_xpath:o_err)
- echo 'Invalid expression'
- echo 'Traceback (most recent call last):'
- echo ' File _SOME_FILE_, line _SOME_LINE_, in <module>'
- echo ' matches = context.xpathEvalExpression(expr)'
- echo ' File _SOME_FILE_, line _SOME_LINE_, in xpathEvalExpression'
- echo " if ret is None:raise xpathError('xmlXPathEvalExpression() failed')"
- echo 'libxml2.xpathError: xmlXPathEvalExpression() failed'
- ;;
- inv_xpath:o_es)
- echo 1
- ;;
- usage_*:o_err)
- echo 'usage: __pxpath__usage usage: pxpath [-f FMT] EXPR FILE [NSNAME:NSURI]'
- ;;
- usage_*:o_es)
- echo 2
- ;;
- io_nofile:o_err)
- echo 'no such file, ignoring query: nonexistent.xml'
- ;;
- io_nofile:o_es)
- echo 1
- ;;
- io_pipe:o_out)
- echo '<bar>pass</bar>'
- echo '<bar>none</bar>'
- echo '<bar>pass</bar>'
- ;;
- *:o_out) true ;;
- *:o_err) true ;;
- *:o_es) echo 0 ;;
- *:xpath) echo '//foo/bar' ;;
- *:*) tf_exit_error "bad test name or part name: $name:$what" ;;
- esac
- }
-
- runtest() {
- local xpath
- local r_es=0
- mkdir -p "test" "result/$name"
- mkxml > "test.xml"
- xpath=$(mka xpath)
- case $name in
- usage_1arg) pxpath "$xpath" ;;
- usage_noargs) pxpath ;;
- io_nofile) pxpath "$xpath" "nonexistent.xml" ;;
- io_adir) pxpath "$xpath" oracle ;;
- io_pipe) <"test.xml" pxpath "$xpath" - ;;
- *) pxpath "$xpath" "test.xml" ;;
- esac >out.cache 2>err.cache; r_es=$?
- cat out.cache
- <err.cache sed '
- /^ File /s/File ".*",/File _SOME_FILE_,/
- /^ File /s/line [1-9][0-9]*,/line _SOME_LINE_,/
- ' >&2
- return $r_es
- }
-
- tf_do_subtest() {
- local name=$1
- local o_out=oracle/$name.stdout
- local o_err=oracle/$name.stderr
- mka o_out >"$o_out"
- mka o_err >"$o_err"
- o_es=$(mka o_es)
- tf_testflt -n "$name" -E "$o_err" -O "$o_out" -S "$o_es" runtest
- }
-
- mkdir -p oracle
-
- tf_do_subtests
|