# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

# ebuild generated by hackport 0.9.1.0
#hackport: flags: build-example:examples

CABAL_FEATURES="lib profile haddock hoogle hscolour test-suite"
inherit haskell-cabal

DESCRIPTION="Golden tests support for tasty"
HOMEPAGE="https://github.com/UnkindPartition/tasty-golden"

LICENSE="MIT"
SLOT="0/${PV}"
KEYWORDS="~amd64 ~arm64 ~ppc64 ~riscv ~x86"
IUSE="examples"

PATCHES=(
	"${FILESDIR}/${PN}-2.3.6-fix-tests.patch"
)

CABAL_CHDEPS=(
	'executable example' "executable ${PN}-example"
	'tasty-golden:example' "tasty-golden:${PN}-example"
)

CABAL_TEST_REQUIRED_BINS=(
	"${PN}-example"
)

RDEPEND=">=dev-haskell/optparse-applicative-0.3.1:=[profile?]
	>=dev-haskell/tasty-1.3:=[profile?]
	dev-haskell/temporary:=[profile?]
	dev-haskell/text:=[profile?]
	dev-haskell/typed-process:=[profile?]
	>=dev-lang/ghc-9.0.2:=
"
DEPEND="${RDEPEND}
	>=dev-haskell/cabal-3.4.1.0
	test? ( dev-haskell/tasty-hunit )
"

src_configure() {
	if use examples || use test; then
		local example_flag=build-example
	else
		local example_flag=-build-example
	fi

	haskell-cabal_src_configure \
		--flag="${example_flag}"
}

src_install() {
	local components=(
		"lib:${PN}"
	)

	if use examples; then
		components+=(
			"exe:${PN}-example"
		)
	fi

	haskell-cabal_src_install "${components[@]}"
}

pkg_postinst() {
	if use examples; then
		elog "The example executable installed with this package (normally named 'example')"
		elog "has been renamed to '${PN}-example' to help prevent name collisions."
	fi

	haskell-cabal_pkg_postinst
}
