pkgname=bash-bats-core
pkgver=1.1.0
pkgrel=0
pkgdesc="Bash Automated Testing System"
arch=("any")
url="https://github.com/bats-core/bats-core"
license=("MIT")
depends=('bash')
provides=("bash-bats")
conflicts=("bash-bats")
makedepends=('git')
source=(
  "git+https://github.com/bats-core/bats-core.git#tag=v$pkgver"
  "lib.patch"
)
md5sums=(
  "SKIP"
  "d422fbfd0aab6eccb0a76d901d6b13d2"
)

check() {
  cd "${srcdir}/${pkgname#bash-}"
  bin/bats --tap test
}

package() {
  cd "${srcdir}/${pkgname#bash-}"

  for fn in libexec/bats-core/*; do
    install -Dm755 ${fn} \
      "${pkgdir}"/usr/lib/bats-core/$(basename ${fn})
  done

  (
    cd "${pkgdir}"
    patch -p1 < "${srcdir}/lib.patch"
  )

  install -dm755 "${pkgdir}"/usr/bin
  ln -s ../lib/bats-core/bats "${pkgdir}"/usr/bin/bats
  install -Dm744 man/bats.1 "${pkgdir}"/usr/share/man/man1/bats.1
  install -Dm744 man/bats.7 "${pkgdir}"/usr/share/man/man7/bats.7
  install -Dm644 LICENSE.md "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}