Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cabal doctest and ghc 8.8.1 #267

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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).
  • Loading branch information
sevanspowell authored and Samuel Evans-Powell committed Oct 28, 2019
commit a4fe8efeb0d67199d9cd260c7d8aba922b15ff03
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ cache:
directories:
- $HOME/.cabal/store

cabal: "2.4"
cabal: "3.0"

matrix:
include:
- ghc: "8.8.1"
- ghc: "8.6.5"
- ghc: "8.4.4"

Expand All @@ -29,7 +30,8 @@ script:
# If there are no other `.tar.gz` files in `dist`, this can be even simpler:
# `cabal install --force-reinstalls dist/*-*.tar.gz`
- SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz &&
(cd dist && cabal install --force-reinstalls "$SRC_TGZ")
(cd dist-newstyle/sdist && cabal v1-install --force-reinstalls "$SRC_TGZ")


- cabal v2-build polysemy-plugin
- cabal v2-test --enable-test polysemy-plugin
Expand Down
5 changes: 3 additions & 2 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import Distribution.Simple
main = defaultMain
import Distribution.Extra.Doctest (defaultMainWithDoctests)

main = defaultMainWithDoctests "polysemy-test"
8 changes: 7 additions & 1 deletion polysemy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ maintainer: sandy@sandymaguire.me
copyright: 2019 Sandy Maguire
license: BSD3
license-file: LICENSE
build-type: Simple
build-type: Custom
extra-source-files:
README.md
ChangeLog.md

custom-setup
setup-depends:
base
, Cabal
, cabal-doctest >=1.0.6 && <1.1

source-repository head
type: git
location: https://github.com/isovector/polysemy
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extra-deps:
- aeson-1.4.3.0
- bifunctors-5.5.4
- dump-core-0.1.3.2
- first-class-families-0.5.0.0
- first-class-families-0.6.0.0
- ghc-lib-0.20190204
- inspection-testing-0.4.2
- loopbreaker-0.1.1.1
Expand Down
60 changes: 31 additions & 29 deletions test/DoctestSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,41 @@ module DoctestSpec where
import Test.Hspec
import Test.DocTest

spec :: Spec
spec = parallel $ describe "Error messages" $ it "should pass the doctest" $ doctest
[ "-isrc/"
, "--fast"
, "-XDataKinds"
, "-XDeriveFunctor"
, "-XFlexibleContexts"
, "-XGADTs"
, "-XLambdaCase"
, "-XPolyKinds"
, "-XRankNTypes"
, "-XScopedTypeVariables"
, "-XStandaloneDeriving"
, "-XTypeApplications"
, "-XTypeFamilies"
, "-XTypeOperators"
, "-XUnicodeSyntax"

, "-package type-errors"
import Build_doctests (flags, pkgs, module_sources)

spec :: Spec
spec = parallel $ describe "Error messages" $ it "should pass the doctest" $ doctest $
[ "--fast"
#if __GLASGOW_HASKELL__ < 806
, "-XMonadFailDesugaring"
, "-XTypeInType"
#endif

, "test/TypeErrors.hs"

-- Modules that are explicitly imported for this test must be listed here
, "src/Polysemy.hs"
, "src/Polysemy/Error.hs"
, "src/Polysemy/Output.hs"
, "src/Polysemy/Reader.hs"
, "src/Polysemy/Resource.hs"
, "src/Polysemy/State.hs"
, "src/Polysemy/Trace.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