#!/bin/sh
set -exfu

# we have to export PYTHONHASHSEED because otherwise networkx will create
# content with random output order
#   https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=749710
#   https://github.com/networkx/networkx/issues/1181
export PYTHONHASHSEED=0
# to make the sort order in the tests locale independent
export LC_COLLATE=C
# because botch-dose2html outputs utf8 on standard output
export PYTHONIOENCODING=utf-8

rm -rf $ADTTMP/out $ADTTMP/tmp
botch-native --debug --verbose --output $ADTTMP/out --tmp $ADTTMP/tmp --latest --clean --self-contained --optuniv --sapsb --strong --no-drop amd64 tests/sid-amd64-packages-20140101T000000Z tests/sid-sources-20140101T000000Z
for f in tests/selfcontained/tmp/* $ADTTMP/tmp/*; do basename "$$f"; done | sort | uniq | while read f; do \
	echo checking $$f; \
	case "$$f" in \
		*.xml) botch-graph-difference "tests/selfcontained/tmp/$$f" "$ADTTMP/tmp/$$f" || exit 1;; \
		*) diff -u "tests/selfcontained/tmp/$$f" "$ADTTMP/tmp/$$f" || exit 1;; \
	esac; \
done
for f in tests/selfcontained/out/* $ADTTMP/out/*; do basename "$$f"; done | sort | uniq | while read f; do \
	echo checking $$f; \
	case "$$f" in \
		*.xml) botch-graph-difference "tests/selfcontained/out/$$f" "$ADTTMP/out/$$f" || exit 1;; \
		*) diff -u "tests/selfcontained/out/$$f" "$ADTTMP/out/$$f" || exit 1;; \
	esac; \
done
