#!/usr/bin/make -f

# benchmark/ is a separate Go module whose tests need the cgo driver
# github.com/mattn/go-sqlite3; examples/ is a demo program.
export DH_GOLANG_EXCLUDES := benchmark examples

# embed.db and embed2.db are excluded from the orig tarball (binaries without
# source, see debian/copyright). TestVFS embeds them with go:embed, so they are
# recreated from SQL in the build tree before the tests and removed afterwards,
# so that dh_auto_install does not ship them. autopkgtest runs this same target
# on the installed sources. See debian/README.source.
TEST_DB_DIR := debian/_build/src/github.com/glebarez/go-sqlite
TEST_DBS := embed embed2

%:
	dh $@ --builddirectory=debian/_build --buildsystem=golang --with=golang

execute_before_dh_auto_test:
	set -e; for db in $(TEST_DBS); do \
		rm -f $(TEST_DB_DIR)/$$db.db; \
		sqlite3 $(TEST_DB_DIR)/$$db.db < debian/testdata/$$db.sql; \
	done

execute_after_dh_auto_test:
	rm -f $(foreach db,$(TEST_DBS),$(TEST_DB_DIR)/$(db).db)
