# #-- 01-doc.test --#
# source the master var file when it's there
[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
# use .tpkg.var.test for in test variable passing
[ -f .tpkg.var.test ] && source .tpkg.var.test
. ../common.sh

set_doxygen_path

PRE="../.."
get_make
(cd $PRE ; $MAKE doc) > mylog 2>&1

bad=0
# filter out doxygen warnings about unsupported tags in the config, print first
grep -e "warning: ignoring unsupported tag.*file .*/doc/unbound.doxygen" mylog
grep -v -e "warning: ignoring unsupported tag.*file .*/doc/unbound.doxygen" mylog > ilog; mv ilog mylog
if grep -e "Warning" -e "warning" -e "Error" -e "error" mylog >/dev/null 2>&1;
then
	cat mylog
	bad=1
else
	# "doxygen ok"
	cat mylog
fi

(cd $PRE; find . -name "*.h" -print) >hlist
(cd $PRE; find . -name "*.c" -print) >>hlist
# filter out config.h
grep -F -v -e "config.h" hlist > ilist; mv ilist hlist
grep -F -v -e "util/configparser" hlist > ilist; mv ilist hlist
grep -F -v -e "util/configlexer" hlist > ilist; mv ilist hlist
grep -F -v -e "util/configyyrename" hlist > ilist; mv ilist hlist
grep -F -v -e "util/locks.h" hlist > ilist; mv ilist hlist
grep -F -v -e "util/storage/lookup3.c" hlist > ilist; mv ilist hlist
grep -F -v -e "ldns-src/" hlist > ilist; mv ilist hlist
grep -F -v -e "libunbound/python/libunbound_wrap.c" hlist > ilist; mv ilist hlist
grep -F -v -e "pythonmod/interface.h" hlist > ilist; mv ilist hlist
grep -F -v -e "dnstap" hlist > ilist; mv ilist hlist
grep -F -v -e "util/siphash.c" hlist > ilist; mv ilist hlist
# filter out compat
grep -F -v -e "compat/" hlist > ilist; mv ilist hlist
for h in `cat hlist`; do
	if grep -F "`basename $h`" $PRE/doc/html/files.html >/dev/null; then
		: # ok
	else
		echo "Warning: $h has no documentation."
		bad=1
	fi
done
exit $bad
