Testing a Haskell Source Distribution with Stack

When developing a Haskell package which will end up on Hackage, you need to have a strategy for testing your source distribution. This is the actual .tar.gz file that end users will receive when they run a Cabal/Stack install.

This feature has, so far, not arrived on Cabal (See #1141) or Stack (See #717). The travis-complex.yml from the Stack documentation does include a working script which relies on Cabal.

I wanted something that relied on Stack and would fit nicely into a Makefile. Here's what I came up with:

  stack sdist

DIST_DIR:=$$(stack path --dist-dir)
SDIST_TAR:=$$(find $(DIST_DIR) -name "*.tar.gz" | tail -1)
untar-sdist: sdist
  tar xzf $(SDIST_TAR)

SDIST_FOLDER:=$$(basename $(SDIST_TAR) .tar.gz)
INIT:=$$(stack init --force)
TEST:=$$(stack build --test --haddock --no-haddock-deps)
test_sdist: untar-sdist
  cd $(SDIST_FOLDER) && $(INIT) && $(TEST)

Running 'make test_sdist' will create a source distribution, untar the files, build the project as well as the haddock documentation and run the tests.

Something wrong? Please raise an issue.