. "$BST_LIB"
require xmllint libxml2/present
tmp=${TMPDIR:-/tmp}/bst-libxml2.$$
# version banner (xmllint prints it on stderr; check_out captures both streams)
check_out libxml2/version "using libxml version" xmllint --version
cat > "$tmp.good.xml" <<'EOF'
- hello
- world
EOF
# well-formed XML: --noout exits 0 and stays silent
out=$(xmllint --noout "$tmp.good.xml" 2>&1); rc=$?
if [ "$rc" -eq 0 ] && [ -z "$out" ]; then bst_ok libxml2/wellformed
else bst_notok libxml2/wellformed "rc=$rc $(_bst_1line "$out")"; fi
# malformed XML: --noout reports a parser error and exits non-zero
printf '- hello
\n' > "$tmp.bad.xml"
out=$(xmllint --noout "$tmp.bad.xml" 2>&1); rc=$?
case "$out" in *"parser error"*) hit=1 ;; *) hit=0 ;; esac
if [ "$rc" -ne 0 ] && [ "$hit" -eq 1 ]; then bst_ok libxml2/malformed
else bst_notok libxml2/malformed "rc=$rc hit=$hit $(_bst_1line "$out")"; fi
# XPath evaluation over the parsed document
check_out libxml2/xpath "world" xmllint --xpath "string(/greeting/item[2])" "$tmp.good.xml"
rm -f "$tmp.good.xml" "$tmp.bad.xml"