# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=test-framework
pkgname=haskell-test-framework
pkgver=0.8.2.1
pkgrel=6
pkgdesc="Framework for running and organising tests, with HUnit and QuickCheck support"
url="https://github.com/haskell/test-framework"
license=('BSD-3-Clause')
arch=('x86_64' 'aarch64')
depends=('ghc-libs' 'haskell-ansi-terminal' 'haskell-ansi-wl-pprint' 'haskell-hostname'
         'haskell-old-locale' 'haskell-random' 'haskell-regex-posix' 'haskell-xml')
makedepends=('ghc' 'uusi')
checkdepends=('haskell-hunit' 'haskell-quickcheck' 'haskell-libxml'
              'haskell-utf8-string')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('2d52b78271aabe089963804d8927c7164a62dc7ab869ba50dc98c140cfcb2019078dc679cd6370edbb019e04c8ce957569f31de3903c3438ec4fc5e39e6e851b')

prepare() {
    cd $_hkgname-$pkgver
    gen-setup
    uusi -d semigroups
}

build() {
    cd $_hkgname-$pkgver

    if (( CHECKFUNC )); then
        _opts=('--enable-tests')
    else
        _opts=('--disable-tests')
    fi

    runhaskell Setup configure -O --enable-shared --enable-debug-info --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname "${_opts[@]}" \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
