polysemy/polysemy-plugin/test/DoctestSpec.hs
Samuel Evans-Powell 95b4b5508c Feature/cabal doctest and ghc 8.8.1 (#267)
* Use cabal-doctest

- Haskell build tools run in slightly different environments (meaning different
  package databases are available).
- The nixpkgs build for polysemy-plugin is failing due to a missing package
  database, which causes the doctest to fail (more information here:
  https://github.com/NixOS/nixpkgs/issues/71164).
- By using cabal-doctest we can expose the Haskell packages required to the
  doctests no matter the build tool we're using.

* Use cabal-doctest in polysemy, build on GHC 8.8.1

- Use @googleson78 's changes to build polysemy on GHC 8.8.1, with slight
  modifications. The source distribution is now found in "dist-newstyle/sdist",
  so we've updated the command to point at that folder. Additionally, cabal
  v2-install doesn't support installing .tar.gz files in the same way v1-install
  did, so updated the command to use "cabal v1-install".
- Modified polysemy to use "cabal-doctest" and so overcome issues with the
  doctest tests (see issue #258, PR #265).
2019-10-28 17:13:44 +01:00

49 lines
1.5 KiB
Haskell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{-# LANGUAGE CPP #-}
module DoctestSpec where
import Test.Hspec
import Test.DocTest
import Build_doctests (flags, pkgs, module_sources)
spec :: Spec
spec = parallel $ describe "Error messages" $ it "should pass the doctest" $ doctest $
[ "--fast"
, "-fobject-code"
#if __GLASGOW_HASKELL__ < 806
, "-XMonadFailDesugaring"
, "-XTypeInType"
#endif
, "test/TypeErrors.hs"
]
<> pkgs
<> removeFlagSearchPathSrc flags
-- | Designed to remove flags that add the "polysemy-plugin/src" directory. For
-- example, it will remove the following flag:
-- "-i/Users/bob/code/polysemy/polysemy-plugin/src".
--
-- This was done because the presence of this flag causes the following error:
-- test/TypeErrors.hs:9: failure in expression `:set -fplugin=Polysemy.Plugin'
-- expected:
-- but got: attempting to use module main:Polysemy.Plugin
-- (.../polysemy/polysemy-plugin/src/Polysemy/Plugin.hs) which is not loaded.
--
-- Without this flag, the tests pass as expected. My understanding of GHC isn't
-- great, so feel free to remove this function if you know of some way of making
-- this flag a non-issue.
removeFlagSearchPathSrc :: [String] -> [String]
removeFlagSearchPathSrc = filter (not . isSrcSearchPath)
where
isSrcSearchPath flag = isSearchPathFlag flag && isSrcDir flag
isSearchPathFlag ('-':'i':_) = True
isSearchPathFlag _ = False
isSrcDir ('s':'r':c':[]) = True
isSrcDir (x:xs) = isSrcDir xs
isSrcDir [] = False