Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Commit

Permalink
Fix problems related to ghc 8.2.*
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor committed May 11, 2019
1 parent 809a10b commit aed6b42
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 58 deletions.
5 changes: 4 additions & 1 deletion test/functional/FunctionalCodeActionsSpec.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}

module FunctionalCodeActionsSpec where

Expand Down Expand Up @@ -177,6 +178,8 @@ spec = describe "code actions" $ do
]
]
describe "add package suggestions" $ do
-- Only execute this test with ghc 8.4.4, below seems to be broken in the package.
#if (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,4,0,0)))
it "adds to .cabal files" $ runSession hieCommand fullCaps "test/testdata/addPackageTest/cabal-exe" $ do
doc <- openDoc "AddPackage.hs" "haskell"

Expand All @@ -201,7 +204,7 @@ spec = describe "code actions" $ do

contents <- getDocumentEdit . TextDocumentIdentifier =<< getDocUri "add-package-test.cabal"
liftIO $ T.lines contents `shouldSatisfy` \x -> any (\l -> "text -any" `T.isSuffixOf` (x !! l)) [15, 16]

#endif
it "adds to hpack package.yaml files" $
runSession hieCommand fullCaps "test/testdata/addPackageTest/hpack-exe" $ do
doc <- openDoc "app/Asdf.hs" "haskell"
Expand Down
163 changes: 106 additions & 57 deletions test/unit/PackagePluginSpec.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE CPP #-}

module PackagePluginSpec where

Expand Down Expand Up @@ -62,26 +63,47 @@ packageSpec = do
uri = filePathToUri $ fp </> "add-package-test.cabal"
args = AddParams fp (fp </> "AddPackage.hs") "text"
act = addCmd' args
textEdits = List
[ TextEdit (Range (Position 0 0) (Position 7 27)) $ T.concat
[ "cabal-version: >=1.10\n"
, "name: add-package-test\n"
, "version: 0.1.0.0\n"
, "license: BSD3\n"
, "maintainer: [email protected]\n"
, "author: Luke Lau\n"
, "build-type: Simple\n"
, "extra-source-files:\n"
, " ChangeLog.md"
textEdits =
#if (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,4,0,0)))
List
[ TextEdit (Range (Position 0 0) (Position 7 27)) $ T.concat
[ "cabal-version: >=1.10\n"
, "name: add-package-test\n"
, "version: 0.1.0.0\n"
, "license: BSD3\n"
, "maintainer: [email protected]\n"
, "author: Luke Lau\n"
, "build-type: Simple\n"
, "extra-source-files:\n"
, " ChangeLog.md"
]
, TextEdit (Range (Position 10 0) (Position 13 34)) $ T.concat
[ " main-is: AddPackage.hs\n"
, " default-language: Haskell2010\n"
, " build-depends:\n"
, " base >=4.7 && <5,\n"
, " text -any"
]
]
, TextEdit (Range (Position 10 0) (Position 13 34)) $ T.concat
[ " main-is: AddPackage.hs\n"
, " default-language: Haskell2010\n"
, " build-depends:\n"
, " base >=4.7 && <5,\n"
, " text -any"
#else
List -- TODO: this seems to indicate that the command does nothing
[ TextEdit (Range (Position 0 0) (Position 7 27)) $ T.concat
[ "name: add-package-test\n"
, "version: 0.1.0.0\n"
, "cabal-version: >=1.10\n"
, "build-type: Simple\n"
, "license: BSD3"
, "maintainer: [email protected]\n"
, "author: Luke Lau\n"
, "extra-source-files:\n"
, " ChangeLog.md"
]
, TextEdit (Range (Position 9 0) (Position 13 34)) $ T.concat
[ "executable AddPackage\n"
, " main-is: AddPackage.hs"
]
]
]
#endif
res = IdeResultOk
$ WorkspaceEdit (Just $ H.singleton uri textEdits) Nothing
testCommand testPlugins act "package" "add" args res
Expand All @@ -94,31 +116,57 @@ packageSpec = do
uri = filePathToUri $ fp </> "add-package-test.cabal"
args = AddParams fp (fp </> "AddPackage.hs") "text"
act = addCmd' args
textEdits = List
[ TextEdit (Range (Position 0 0) (Position 7 27)) $ T.concat
[ "cabal-version: >=1.10\n"
, "name: add-package-test\n"
, "version: 0.1.0.0\n"
, "license: BSD3\n"
, "maintainer: [email protected]\n"
, "author: Luke Lau\n"
, "build-type: Simple\n"
, "extra-source-files:\n"
, " ChangeLog.md"
textEdits =
#if (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,4,0,0)))
List
[ TextEdit (Range (Position 0 0) (Position 7 27)) $ T.concat
[ "cabal-version: >=1.10\n"
, "name: add-package-test\n"
, "version: 0.1.0.0\n"
, "license: BSD3\n"
, "maintainer: [email protected]\n"
, "author: Luke Lau\n"
, "build-type: Simple\n"
, "extra-source-files:\n"
, " ChangeLog.md"
]
, TextEdit (Range (Position 10 0) (Position 13 34)) $ T.concat
[ " exposed-modules:\n"
, " AddPackage\n"
, " default-language: Haskell2010\n"
, " build-depends:\n"
, " base >=4.7 && <5,\n"
, " text -any"
]
]
, TextEdit (Range (Position 10 0) (Position 13 34)) $ T.concat
[ " exposed-modules:\n"
, " AddPackage\n"
, " default-language: Haskell2010\n"
, " build-depends:\n"
, " base >=4.7 && <5,\n"
, " text -any"
#else
List
[ TextEdit (Range (Position 0 0) (Position 7 27)) $ T.concat
[ "name: add-package-test\n"
, "version: 0.1.0.0\n"
, "cabal-version: >=1.10\n"
, "build-type: Simple\n"
, "license: BSD3\n"
, "maintainer: [email protected]\n"
, "author: Luke Lau\n"
, "extra-source-files:\n"
, " ChangeLog.md\n"
]
, TextEdit (Range (Position 10 0) (Position 13 34)) $ T.concat
[ " exposed-modules:\n"
, " AddPackage\n"
, " build-depends:\n"
, " base >=4.7 && <5,\n"
, " text -any\n"
, " default-language: Haskell2010\n"
]
]
]
#endif
res = IdeResultOk
$ WorkspaceEdit (Just $ H.singleton uri textEdits) Nothing
testCommand testPlugins act "package" "add" args res


it "Add package to package.yaml to executable component"
$ withCurrentDirectory (testdata </> "hpack-exe")
$ do
Expand Down Expand Up @@ -169,26 +217,27 @@ packageSpec = do
act = addCmd' args
res = IdeResultOk
$ WorkspaceEdit (Just $ H.singleton uri textEdits) Nothing
textEdits = List
[ TextEdit (Range (Position 0 0) (Position 25 0)) $ T.concat
[ "library:\n"
, " source-dirs: app\n"
, " dependencies:\n"
, " - zlib\n"
, " - base >= 4.7 && < 5\n"
, "copyright: 2018 Author name here\n"
, "maintainer: [email protected]\n"
, "name: asdf\n"
, "version: 0.1.0.0\n"
, "extra-source-files:\n"
, "- README.md\n"
, "- ChangeLog.md\n"
, "author: Author name here\n"
, "github: githubuser/asdf\n"
, "license: BSD3\n"
, "description: Please see the README on GitHub at <https://github.com/githubuser/asdf#readme>\n"
]
]
textEdits =
List
[ TextEdit (Range (Position 0 0) (Position 25 0)) $ T.concat
[ "library:\n"
, " source-dirs: app\n"
, " dependencies:\n"
, " - zlib\n"
, " - base >= 4.7 && < 5\n"
, "copyright: 2018 Author name here\n"
, "maintainer: [email protected]\n"
, "name: asdf\n"
, "version: 0.1.0.0\n"
, "extra-source-files:\n"
, "- README.md\n"
, "- ChangeLog.md\n"
, "author: Author name here\n"
, "github: githubuser/asdf\n"
, "license: BSD3\n"
, "description: Please see the README on GitHub at <https://github.com/githubuser/asdf#readme>\n"
]
]
testCommand testPlugins act "package" "add" args res
it
"Add package to package.yaml in hpack project with generated cabal to executable component"
Expand Down

0 comments on commit aed6b42

Please sign in to comment.