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

EAPI=8

# ebuild generated by hackport 0.9.0.0.9999

CABAL_FEATURES=""
inherit haskell-cabal

DESCRIPTION="Easy, repeatable testing of CLI programs/commands"
HOMEPAGE="https://github.com/simonmichael/shelltestrunner"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64"
IUSE="test"

RESTRICT="!test? ( test )"

RDEPEND=">=dev-haskell/cmdargs-0.7:=
	>=dev-haskell/diff-0.2.0:=
	>=dev-haskell/filemanip-0.3:=
	>=dev-haskell/hspec-2.9.0:=
	>=dev-haskell/hspec-contrib-0.5.1.1:=
	>=dev-haskell/hspec-core-2.9.0:=
	dev-haskell/hunit:=
	dev-haskell/parsec:=
	>=dev-haskell/pretty-show-1.6.5:=
	>=dev-haskell/regex-tdfa-1.1:=
	dev-haskell/safe:=
	>=dev-haskell/test-framework-0.3.2:=
	>=dev-haskell/test-framework-hunit-0.2:=
	>=dev-haskell/utf8-string-0.3.5:=
	>=dev-lang/ghc-9.0.2:=
"
DEPEND="${RDEPEND}
	>=dev-haskell/cabal-3.4.1.0
"
BDEPEND="
	test? (
		dev-haskell/stack
	)
"

src_prepare() {
	haskell-cabal_src_prepare

	# These tests are causing problems (stack exits with error code 1)

	rm -v \
		"${S}/tests/format1/large-output.test" \
		"${S}/tests/format1/large-regexp.test" \
		"${S}/tests/format2/large-output.test" \
		"${S}/tests/format3/large-output.test" || die

	# Replace these tests to remove the "stack" tests
	cp -v "${FILESDIR}/${PN}-1.10-format2-regexps.test" "${S}/tests/format2/regexps.test" || die
	cp -v "${FILESDIR}/${PN}-1.10-format3-regexps.test" "${S}/tests/format3/regexps.test" || die
}

src_test() {
	# First we have to prepend "dist/build/shelltest" to the PATH, so
	# that when the tests themselves run "shelltest", they get the
	# recently-built executable and not an already-installed one. Then
	# we exclude the Windows tests, leaving (for now...) only the Unix
	# and generic ones.
	#
	# We also skip the macro tests for now because the sdist is missing
	# some files:
	#
	#   https://github.com/simonmichael/shelltestrunner/issues/13
	#
	LANGUAGE=en \
	PATH="dist/build/shelltest:${PATH}" \
		shelltest -x .windows -x macros.test tests/ || die 'test suite failed'
}