From 0ed0829e004be7be6d76b6e056ebb09042f52a12 Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 1 May 2019 15:12:14 +0200 Subject: [PATCH 01/11] Add unit-tests for Package Plugin --- haskell-ide-engine.cabal | 3 +- src/Haskell/Ide/Engine/Plugin/Package.hs | 15 +- test/functional/FunctionalCodeActionsSpec.hs | 29 +++ .../addPackageTest/hybrid/AddPackage.hs | 2 + .../addPackageTest/hybrid/app/Asdf.hs | 5 + .../testdata/addPackageTest/hybrid/asdf.cabal | 60 ++++++ .../addPackageTest/hybrid/package.yaml | 48 +++++ .../addPackageTest/invalid/AddPackage.hs | 2 + test/unit/HaRePluginSpec.hs | 4 +- test/unit/PackagePluginSpec.hs | 194 ++++++++++++++++++ test/utils/TestUtils.hs | 5 +- 11 files changed, 357 insertions(+), 10 deletions(-) create mode 100644 test/testdata/addPackageTest/hybrid/AddPackage.hs create mode 100644 test/testdata/addPackageTest/hybrid/app/Asdf.hs create mode 100644 test/testdata/addPackageTest/hybrid/asdf.cabal create mode 100644 test/testdata/addPackageTest/hybrid/package.yaml create mode 100644 test/testdata/addPackageTest/invalid/AddPackage.hs create mode 100644 test/unit/PackagePluginSpec.hs diff --git a/haskell-ide-engine.cabal b/haskell-ide-engine.cabal index c9bbc0cc8..8f56df8c7 100644 --- a/haskell-ide-engine.cabal +++ b/haskell-ide-engine.cabal @@ -174,10 +174,11 @@ test-suite unit-test DiffSpec ExtensibleStateSpec GhcModPluginSpec - LiquidSpec HaRePluginSpec HooglePluginSpec JsonSpec + LiquidSpec + PackagePluginSpec Spec -- Technically cabal-helper should be a 'run-tool-depends', but that doesn't exist yet build-tool-depends: cabal-helper:cabal-helper-main, hspec-discover:hspec-discover diff --git a/src/Haskell/Ide/Engine/Plugin/Package.hs b/src/Haskell/Ide/Engine/Plugin/Package.hs index fa3e5b747..a9b6b2e5c 100644 --- a/src/Haskell/Ide/Engine/Plugin/Package.hs +++ b/src/Haskell/Ide/Engine/Plugin/Package.hs @@ -67,7 +67,7 @@ data AddParams = AddParams { rootDirParam :: FilePath -- ^ The root directory. , fileParam :: ModulePath -- ^ A path to a module inside the -- library/executable/test-suite you want to - -- add the package to. May be a realtive oir + -- add the package to. May be a relative or -- absolute path, thus, must be normalised. , packageParam :: Package -- ^ The name of the package to add. } @@ -88,8 +88,14 @@ type Package = T.Text -- Supported are `*.cabal` and `package.yaml` specifications. -- Moreover, may fail with an IOException in case of a filesystem problem. addCmd :: CommandFunc AddParams J.WorkspaceEdit -addCmd = CmdSync $ \(AddParams rootDir modulePath pkg) -> do +addCmd = CmdSync addCmd' +-- | Add a package to the project's dependencies. +-- May fail if no project dependency specification can be found. +-- Supported are `*.cabal` and `package.yaml` specifications. +-- Moreover, may fail with an IOException in case of a filesystem problem. +addCmd' :: AddParams -> IdeGhcM (IdeResult J.WorkspaceEdit) +addCmd' (AddParams rootDir modulePath pkg) = do packageType <- liftIO $ findPackageType rootDir fileMap <- GM.mkRevRedirMapFunc @@ -105,9 +111,10 @@ addCmd = CmdSync $ \(AddParams rootDir modulePath pkg) -> do liftToGhc $ editHpackPackage absFp relModulePath pkg NoPackage -> return $ IdeResultFail (IdeError PluginError "No package.yaml or .cabal found" Null) -data PackageType = CabalPackage FilePath -- ^ Location of Cabal File. - | HpackPackage FilePath -- ^ Location of `package.yaml` +data PackageType = CabalPackage FilePath -- ^ Location of Cabal File. May be relative. + | HpackPackage FilePath -- ^ Location of `package.yaml`. May be relative. | NoPackage -- ^ No package format has been found. + deriving (Show, Eq) -- | Find the package type the project with the given root uses. -- Might have weird results if there is more than one cabal package specification diff --git a/test/functional/FunctionalCodeActionsSpec.hs b/test/functional/FunctionalCodeActionsSpec.hs index c717a521b..b49f00038 100644 --- a/test/functional/FunctionalCodeActionsSpec.hs +++ b/test/functional/FunctionalCodeActionsSpec.hs @@ -231,6 +231,35 @@ spec = describe "code actions" $ do T.lines contents !! 12 `shouldNotSatisfy` T.isSuffixOf "zlib" T.lines contents !! 13 `shouldNotSatisfy` T.isSuffixOf "zlib" + it "adds to hpack package.yaml files if both are present" $ + runSession hieCommand fullCaps "test/testdata/addPackageTest/hybrid" $ do + doc <- openDoc "app/Asdf.hs" "haskell" + + -- ignore the first empty hlint diagnostic publish + [_,diag:_] <- count 2 waitForDiagnostics + + let preds = [ T.isPrefixOf "Could not load module ‘Codec.Compression.GZip’" + , T.isPrefixOf "Could not find module ‘Codec.Compression.GZip’" + ] + in liftIO $ diag ^. L.message `shouldSatisfy` \x -> any (\f -> f x) preds + + mActions <- getAllCodeActions doc + let allActions = map fromAction mActions + action = head allActions + + liftIO $ do + action ^. L.title `shouldBe` "Add zlib as a dependency" + forM_ allActions $ \a -> a ^. L.kind `shouldBe` Just CodeActionQuickFix + forM_ allActions $ \a -> a ^. L.command . _Just . L.command `shouldSatisfy` T.isSuffixOf "package:add" + + executeCodeAction action + + contents <- getDocumentEdit . TextDocumentIdentifier =<< getDocUri "package.yaml" + liftIO $ do + T.lines contents !! 33 `shouldSatisfy` T.isSuffixOf "zlib" + T.lines contents !! 12 `shouldNotSatisfy` T.isSuffixOf "zlib" + T.lines contents !! 13 `shouldNotSatisfy` T.isSuffixOf "zlib" + -- ----------------------------------- describe "redundant import code actions" $ do diff --git a/test/testdata/addPackageTest/hybrid/AddPackage.hs b/test/testdata/addPackageTest/hybrid/AddPackage.hs new file mode 100644 index 000000000..963020508 --- /dev/null +++ b/test/testdata/addPackageTest/hybrid/AddPackage.hs @@ -0,0 +1,2 @@ +import Data.Text +foo = pack "I'm a Text" \ No newline at end of file diff --git a/test/testdata/addPackageTest/hybrid/app/Asdf.hs b/test/testdata/addPackageTest/hybrid/app/Asdf.hs new file mode 100644 index 000000000..fdd639ffe --- /dev/null +++ b/test/testdata/addPackageTest/hybrid/app/Asdf.hs @@ -0,0 +1,5 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Codec.Compression.GZip + +main = return $ compress "hello" \ No newline at end of file diff --git a/test/testdata/addPackageTest/hybrid/asdf.cabal b/test/testdata/addPackageTest/hybrid/asdf.cabal new file mode 100644 index 000000000..79425af44 --- /dev/null +++ b/test/testdata/addPackageTest/hybrid/asdf.cabal @@ -0,0 +1,60 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.31.2. +-- +-- see: https://github.com/sol/hpack +-- +-- hash: a63a1c272a979a805027c5855cbe062ec4698b6ea6dbe59dd5f7aa34b15656a6 + +name: asdf +version: 0.1.0.0 +description: Please see the README on GitHub at +homepage: https://github.com/githubuser/asdf#readme +bug-reports: https://github.com/githubuser/asdf/issues +author: Author name here +maintainer: example@example.com +copyright: 2018 Author name here +license: BSD3 +build-type: Simple +extra-source-files: + README.md + ChangeLog.md + +source-repository head + type: git + location: https://github.com/githubuser/asdf + +library + other-modules: + Paths_asdf + hs-source-dirs: + src + build-depends: + base >=4.7 && <5 + default-language: Haskell2010 + +executable asdf-exe + main-is: Main.hs + other-modules: + Asdf + Paths_asdf + hs-source-dirs: + app + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + asdf + , base >=4.7 && <5 + default-language: Haskell2010 + +test-suite asdf-test + type: exitcode-stdio-1.0 + main-is: Spec.hs + other-modules: + Paths_asdf + hs-source-dirs: + test + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + asdf + , base >=4.7 && <5 + default-language: Haskell2010 diff --git a/test/testdata/addPackageTest/hybrid/package.yaml b/test/testdata/addPackageTest/hybrid/package.yaml new file mode 100644 index 000000000..bf6d37c39 --- /dev/null +++ b/test/testdata/addPackageTest/hybrid/package.yaml @@ -0,0 +1,48 @@ +name: asdf +version: 0.1.0.0 +github: "githubuser/asdf" +license: BSD3 +author: "Author name here" +maintainer: "example@example.com" +copyright: "2018 Author name here" + +extra-source-files: +- README.md +- ChangeLog.md + +# Metadata used when publishing your package +# synopsis: Short description of your package +# category: Web + +# To avoid duplicated efforts in documentation and dealing with the +# complications of embedding Haddock markup inside cabal files, it is +# common to point users to the README.md file. +description: Please see the README on GitHub at + +dependencies: +- base >= 4.7 && < 5 + +library: + source-dirs: src + +executables: + asdf-exe: + main: Main.hs + source-dirs: app + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - asdf + +tests: + asdf-test: + main: Spec.hs + source-dirs: test + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - asdf diff --git a/test/testdata/addPackageTest/invalid/AddPackage.hs b/test/testdata/addPackageTest/invalid/AddPackage.hs new file mode 100644 index 000000000..963020508 --- /dev/null +++ b/test/testdata/addPackageTest/invalid/AddPackage.hs @@ -0,0 +1,2 @@ +import Data.Text +foo = pack "I'm a Text" \ No newline at end of file diff --git a/test/unit/HaRePluginSpec.hs b/test/unit/HaRePluginSpec.hs index ec797ce70..6d425118f 100644 --- a/test/unit/HaRePluginSpec.hs +++ b/test/unit/HaRePluginSpec.hs @@ -239,9 +239,9 @@ hareSpec = do lreq = setTypecheckedModule u req = liftToGhc $ TestDeferM $ findTypeDef u (toPos (24, 7)) r <- dispatchRequestPGoto $ lreq >> req - r `shouldBe` IdeResultOk + r `shouldBe` IdeResultOk [ Location - (filePathToUri $ cwd "test/testdata/gototest/src/Lib.hs") + (filePathToUri $ cwd "test/testdata/gototest/src/Lib.hs") (Range (toPos (18, 1)) (toPos (18, 26))) ] it "can not find non-local definition of type def" $ do diff --git a/test/unit/PackagePluginSpec.hs b/test/unit/PackagePluginSpec.hs new file mode 100644 index 000000000..e828fc122 --- /dev/null +++ b/test/unit/PackagePluginSpec.hs @@ -0,0 +1,194 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} +module PackagePluginSpec where +import qualified Data.Aeson as Json +import qualified Data.Text as T +import qualified Data.HashMap.Strict as H +import Haskell.Ide.Engine.MonadTypes +import Haskell.Ide.Engine.Plugin.Package +import System.FilePath +import System.Directory +import Test.Hspec +import TestUtils + +main :: IO () +main = hspec spec + +spec :: Spec +spec = + describe "Package plugin" packageSpec + +testdata :: FilePath +testdata = "test/testdata/addPackageTest" + +testPlugins :: IdePlugins +testPlugins = pluginDescToIdePlugins [packageDescriptor "package"] + +packageSpec :: Spec +packageSpec = do + cwd <- runIO getCurrentDirectory + describe "Find correct package type" $ do + it "Find cabal file in cabal project" $ do + let fp = testdata "cabal" + packageType <- findPackageType fp + packageType `shouldBe` CabalPackage "add-package-test.cabal" + + it "Find package.yaml file in hpack project" $ do + let fp = testdata "hpack" + packageType <-findPackageType fp + packageType `shouldBe` HpackPackage (fp "package.yaml") + + it "Find package.yaml file in hpack project with generated cabal" $ do + let fp = testdata "hybrid" + packageType <- findPackageType fp + packageType `shouldBe` HpackPackage (fp "package.yaml") + + it "Find no project description if none is present " $ do + let fp = testdata "invalid" + packageType <- findPackageType fp + packageType `shouldBe` NoPackage + + it "Throws exception if path is invalid" $ do + let fp = testdata "unknownPath" + findPackageType fp `shouldThrow` anyIOException + describe "Add the package to the correct file" $ do + it "Add package to .cabal" $ withCurrentDirectory (testdata "cabal") $ do + let + fp = cwd testdata "cabal" + 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: luke_lau@icloud.com\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" + ] + ] + res = IdeResultOk $ WorkspaceEdit + (Just $ H.singleton uri textEdits) + Nothing + testCommand testPlugins act "package" "add" args res + it "Add package to package.yaml" $ withCurrentDirectory (testdata "hpack") $ do + let + fp = cwd testdata "hpack" + uri = filePathToUri $ fp "package.yaml" + args = AddParams fp (fp "app" "Asdf.hs") "zlib" + act = addCmd' args + res = IdeResultOk $ WorkspaceEdit + (Just $ H.singleton uri textEdits) + Nothing + textEdits = List + [ TextEdit (Range (Position 0 0) (Position 48 0)) $ T.concat + [ "library:\n" + , " source-dirs: src\n" + , "tests:\n" + , " asdf-test:\n" + , " source-dirs: test\n" + , " main: Spec.hs\n" + , " ghc-options:\n" + , " - -threaded\n" + , " - -rtsopts\n" + , " - -with-rtsopts=-N\n" + , " dependencies:\n" + , " - asdf\n" + , "copyright: 2018 Author name here\n" + , "maintainer: example@example.com\n" + , "dependencies:\n" + , "- base >= 4.7 && < 5\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" + , "executables:\n" + , " asdf-exe:\n" + , " source-dirs: app\n" + , " main: Main.hs\n" + , " ghc-options:\n" + , " - -threaded\n" + , " - -rtsopts\n" + , " - -with-rtsopts=-N\n" + , " dependencies:\n" + , " - zlib\n" + , " - asdf\n" + , "description: Please see the README on GitHub at \n" + ] + ] + testCommand testPlugins act "package" "add" args res + it "Add package to package.yaml in hpack project with generated cabal" $ withCurrentDirectory (testdata "hybrid") $ do + let + fp = cwd testdata "hybrid" + uri = filePathToUri $ fp "package.yaml" + args = AddParams fp (fp "app" "Asdf.hs") "zlib" + act = addCmd' args + res = IdeResultOk $ WorkspaceEdit + (Just $ H.singleton uri textEdits) + Nothing + textEdits = List + [ TextEdit (Range (Position 0 0) (Position 48 0)) $ T.concat + [ "library:\n" + , " source-dirs: src\n" + , "tests:\n" + , " asdf-test:\n" + , " source-dirs: test\n" + , " main: Spec.hs\n" + , " ghc-options:\n" + , " - -threaded\n" + , " - -rtsopts\n" + , " - -with-rtsopts=-N\n" + , " dependencies:\n" + , " - asdf\n" + , "copyright: 2018 Author name here\n" + , "maintainer: example@example.com\n" + , "dependencies:\n" + , "- base >= 4.7 && < 5\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" + , "executables:\n" + , " asdf-exe:\n" + , " source-dirs: app\n" + , " main: Main.hs\n" + , " ghc-options:\n" + , " - -threaded\n" + , " - -rtsopts\n" + , " - -with-rtsopts=-N\n" + , " dependencies:\n" + , " - zlib\n" + , " - asdf\n" + , "description: Please see the README on GitHub at \n" + ] + ] + testCommand testPlugins act "package" "add" args res + + it "Do nothing on NoPackage" $ withCurrentDirectory (testdata "invalid") $ do + let + fp = cwd testdata "invalid" + args = AddParams fp (fp "app" "Asdf.hs") "zlib" + act = addCmd' args + res = IdeResultFail (IdeError PluginError "No package.yaml or .cabal found" Json.Null) + testCommand testPlugins act "package" "add" args res \ No newline at end of file diff --git a/test/utils/TestUtils.hs b/test/utils/TestUtils.hs index 526608352..900a7bf4b 100644 --- a/test/utils/TestUtils.hs +++ b/test/utils/TestUtils.hs @@ -162,8 +162,7 @@ logFilePath = "functional-hie-" ++ stackYaml ++ ".log" -- We also need to unset STACK_EXE manually inside the tests if they are -- run with `stack test` hieCommand :: String -hieCommand = "stack exec --no-stack-exe --no-ghc-package-path --stack-yaml=" ++ stackYaml ++ - " hie -- -d -l test-logs/" ++ logFilePath +hieCommand = "hie -d -l test-logs/" ++ logFilePath hieCommandVomit :: String hieCommandVomit = hieCommand ++ " --vomit" @@ -253,7 +252,7 @@ xmlFormatter = silent { failure ! message (reasonAsString err) $ "" #if MIN_VERSION_hspec(2,5,0) - examplePending path _ reason = + examplePending path _ reason = #else examplePending path reason = #endif From 49307dde2e634bec369255b9748420e59e4e0602 Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 1 May 2019 17:10:20 +0200 Subject: [PATCH 02/11] Add add package tests for different components --- .../{cabal => cabal-exe}/AddPackage.hs | 0 .../cabal-exe/add-package-test.cabal | 14 + .../{hybrid => cabal-lib}/AddPackage.hs | 0 .../add-package-test.cabal | 0 .../{hpack => hpack-exe}/app/Asdf.hs | 0 .../{hpack => hpack-exe}/package.yaml | 13 +- .../{hybrid => hpack-lib}/app/Asdf.hs | 0 .../addPackageTest/hpack-lib/package.yaml | 25 ++ .../addPackageTest/hybrid-exe/AddPackage.hs | 2 + .../addPackageTest/hybrid-exe/app/Asdf.hs | 5 + .../{hybrid => hybrid-exe}/asdf.cabal | 0 .../{hybrid => hybrid-exe}/package.yaml | 13 +- .../addPackageTest/hybrid-lib/AddPackage.hs | 2 + .../addPackageTest/hybrid-lib/app/Asdf.hs | 5 + .../addPackageTest/hybrid-lib/asdf.cabal | 36 +++ .../addPackageTest/hybrid-lib/package.yaml | 25 ++ test/unit/PackagePluginSpec.hs | 303 +++++++++++------- 17 files changed, 311 insertions(+), 132 deletions(-) rename test/testdata/addPackageTest/{cabal => cabal-exe}/AddPackage.hs (100%) create mode 100644 test/testdata/addPackageTest/cabal-exe/add-package-test.cabal rename test/testdata/addPackageTest/{hybrid => cabal-lib}/AddPackage.hs (100%) rename test/testdata/addPackageTest/{cabal => cabal-lib}/add-package-test.cabal (100%) rename test/testdata/addPackageTest/{hpack => hpack-exe}/app/Asdf.hs (100%) rename test/testdata/addPackageTest/{hpack => hpack-exe}/package.yaml (83%) rename test/testdata/addPackageTest/{hybrid => hpack-lib}/app/Asdf.hs (100%) create mode 100644 test/testdata/addPackageTest/hpack-lib/package.yaml create mode 100644 test/testdata/addPackageTest/hybrid-exe/AddPackage.hs create mode 100644 test/testdata/addPackageTest/hybrid-exe/app/Asdf.hs rename test/testdata/addPackageTest/{hybrid => hybrid-exe}/asdf.cabal (100%) rename test/testdata/addPackageTest/{hybrid => hybrid-exe}/package.yaml (83%) create mode 100644 test/testdata/addPackageTest/hybrid-lib/AddPackage.hs create mode 100644 test/testdata/addPackageTest/hybrid-lib/app/Asdf.hs create mode 100644 test/testdata/addPackageTest/hybrid-lib/asdf.cabal create mode 100644 test/testdata/addPackageTest/hybrid-lib/package.yaml diff --git a/test/testdata/addPackageTest/cabal/AddPackage.hs b/test/testdata/addPackageTest/cabal-exe/AddPackage.hs similarity index 100% rename from test/testdata/addPackageTest/cabal/AddPackage.hs rename to test/testdata/addPackageTest/cabal-exe/AddPackage.hs diff --git a/test/testdata/addPackageTest/cabal-exe/add-package-test.cabal b/test/testdata/addPackageTest/cabal-exe/add-package-test.cabal new file mode 100644 index 000000000..edd2a92a7 --- /dev/null +++ b/test/testdata/addPackageTest/cabal-exe/add-package-test.cabal @@ -0,0 +1,14 @@ +name: add-package-test +version: 0.1.0.0 +license: BSD3 +author: Luke Lau +maintainer: luke_lau@icloud.com +build-type: Simple +extra-source-files: ChangeLog.md +cabal-version: >=1.10 + +executable AddPackage + exposed-modules: ./. + main-is: AddPackage.hs + build-depends: base >=4.7 && <5 + default-language: Haskell2010 \ No newline at end of file diff --git a/test/testdata/addPackageTest/hybrid/AddPackage.hs b/test/testdata/addPackageTest/cabal-lib/AddPackage.hs similarity index 100% rename from test/testdata/addPackageTest/hybrid/AddPackage.hs rename to test/testdata/addPackageTest/cabal-lib/AddPackage.hs diff --git a/test/testdata/addPackageTest/cabal/add-package-test.cabal b/test/testdata/addPackageTest/cabal-lib/add-package-test.cabal similarity index 100% rename from test/testdata/addPackageTest/cabal/add-package-test.cabal rename to test/testdata/addPackageTest/cabal-lib/add-package-test.cabal diff --git a/test/testdata/addPackageTest/hpack/app/Asdf.hs b/test/testdata/addPackageTest/hpack-exe/app/Asdf.hs similarity index 100% rename from test/testdata/addPackageTest/hpack/app/Asdf.hs rename to test/testdata/addPackageTest/hpack-exe/app/Asdf.hs diff --git a/test/testdata/addPackageTest/hpack/package.yaml b/test/testdata/addPackageTest/hpack-exe/package.yaml similarity index 83% rename from test/testdata/addPackageTest/hpack/package.yaml rename to test/testdata/addPackageTest/hpack-exe/package.yaml index bf6d37c39..9bb1916b1 100644 --- a/test/testdata/addPackageTest/hpack/package.yaml +++ b/test/testdata/addPackageTest/hpack-exe/package.yaml @@ -34,15 +34,4 @@ executables: - -rtsopts - -with-rtsopts=-N dependencies: - - asdf - -tests: - asdf-test: - main: Spec.hs - source-dirs: test - ghc-options: - - -threaded - - -rtsopts - - -with-rtsopts=-N - dependencies: - - asdf + - asdf \ No newline at end of file diff --git a/test/testdata/addPackageTest/hybrid/app/Asdf.hs b/test/testdata/addPackageTest/hpack-lib/app/Asdf.hs similarity index 100% rename from test/testdata/addPackageTest/hybrid/app/Asdf.hs rename to test/testdata/addPackageTest/hpack-lib/app/Asdf.hs diff --git a/test/testdata/addPackageTest/hpack-lib/package.yaml b/test/testdata/addPackageTest/hpack-lib/package.yaml new file mode 100644 index 000000000..2ba0fe5b4 --- /dev/null +++ b/test/testdata/addPackageTest/hpack-lib/package.yaml @@ -0,0 +1,25 @@ +name: asdf +version: 0.1.0.0 +github: "githubuser/asdf" +license: BSD3 +author: "Author name here" +maintainer: "example@example.com" +copyright: "2018 Author name here" + +extra-source-files: +- README.md +- ChangeLog.md + +# Metadata used when publishing your package +# synopsis: Short description of your package +# category: Web + +# To avoid duplicated efforts in documentation and dealing with the +# complications of embedding Haddock markup inside cabal files, it is +# common to point users to the README.md file. +description: Please see the README on GitHub at + +library: + source-dirs: app + dependencies: + - base >= 4.7 && < 5 diff --git a/test/testdata/addPackageTest/hybrid-exe/AddPackage.hs b/test/testdata/addPackageTest/hybrid-exe/AddPackage.hs new file mode 100644 index 000000000..963020508 --- /dev/null +++ b/test/testdata/addPackageTest/hybrid-exe/AddPackage.hs @@ -0,0 +1,2 @@ +import Data.Text +foo = pack "I'm a Text" \ No newline at end of file diff --git a/test/testdata/addPackageTest/hybrid-exe/app/Asdf.hs b/test/testdata/addPackageTest/hybrid-exe/app/Asdf.hs new file mode 100644 index 000000000..fdd639ffe --- /dev/null +++ b/test/testdata/addPackageTest/hybrid-exe/app/Asdf.hs @@ -0,0 +1,5 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Codec.Compression.GZip + +main = return $ compress "hello" \ No newline at end of file diff --git a/test/testdata/addPackageTest/hybrid/asdf.cabal b/test/testdata/addPackageTest/hybrid-exe/asdf.cabal similarity index 100% rename from test/testdata/addPackageTest/hybrid/asdf.cabal rename to test/testdata/addPackageTest/hybrid-exe/asdf.cabal diff --git a/test/testdata/addPackageTest/hybrid/package.yaml b/test/testdata/addPackageTest/hybrid-exe/package.yaml similarity index 83% rename from test/testdata/addPackageTest/hybrid/package.yaml rename to test/testdata/addPackageTest/hybrid-exe/package.yaml index bf6d37c39..9bb1916b1 100644 --- a/test/testdata/addPackageTest/hybrid/package.yaml +++ b/test/testdata/addPackageTest/hybrid-exe/package.yaml @@ -34,15 +34,4 @@ executables: - -rtsopts - -with-rtsopts=-N dependencies: - - asdf - -tests: - asdf-test: - main: Spec.hs - source-dirs: test - ghc-options: - - -threaded - - -rtsopts - - -with-rtsopts=-N - dependencies: - - asdf + - asdf \ No newline at end of file diff --git a/test/testdata/addPackageTest/hybrid-lib/AddPackage.hs b/test/testdata/addPackageTest/hybrid-lib/AddPackage.hs new file mode 100644 index 000000000..963020508 --- /dev/null +++ b/test/testdata/addPackageTest/hybrid-lib/AddPackage.hs @@ -0,0 +1,2 @@ +import Data.Text +foo = pack "I'm a Text" \ No newline at end of file diff --git a/test/testdata/addPackageTest/hybrid-lib/app/Asdf.hs b/test/testdata/addPackageTest/hybrid-lib/app/Asdf.hs new file mode 100644 index 000000000..fdd639ffe --- /dev/null +++ b/test/testdata/addPackageTest/hybrid-lib/app/Asdf.hs @@ -0,0 +1,5 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Codec.Compression.GZip + +main = return $ compress "hello" \ No newline at end of file diff --git a/test/testdata/addPackageTest/hybrid-lib/asdf.cabal b/test/testdata/addPackageTest/hybrid-lib/asdf.cabal new file mode 100644 index 000000000..dbe8509b7 --- /dev/null +++ b/test/testdata/addPackageTest/hybrid-lib/asdf.cabal @@ -0,0 +1,36 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.31.2. +-- +-- see: https://github.com/sol/hpack +-- +-- hash: 0a09a2280cfeb48f88861d105a48255e71ec34cc865390f1d038119511564661 + +name: asdf +version: 0.1.0.0 +description: Please see the README on GitHub at +homepage: https://github.com/githubuser/asdf#readme +bug-reports: https://github.com/githubuser/asdf/issues +author: Author name here +maintainer: example@example.com +copyright: 2018 Author name here +license: BSD3 +build-type: Simple +extra-source-files: + README.md + ChangeLog.md + +source-repository head + type: git + location: https://github.com/githubuser/asdf + +library + exposed-modules: + Asdf + other-modules: + Paths_asdf + hs-source-dirs: + app + build-depends: + base >=4.7 && <5 + default-language: Haskell2010 diff --git a/test/testdata/addPackageTest/hybrid-lib/package.yaml b/test/testdata/addPackageTest/hybrid-lib/package.yaml new file mode 100644 index 000000000..2ba0fe5b4 --- /dev/null +++ b/test/testdata/addPackageTest/hybrid-lib/package.yaml @@ -0,0 +1,25 @@ +name: asdf +version: 0.1.0.0 +github: "githubuser/asdf" +license: BSD3 +author: "Author name here" +maintainer: "example@example.com" +copyright: "2018 Author name here" + +extra-source-files: +- README.md +- ChangeLog.md + +# Metadata used when publishing your package +# synopsis: Short description of your package +# category: Web + +# To avoid duplicated efforts in documentation and dealing with the +# complications of embedding Haddock markup inside cabal files, it is +# common to point users to the README.md file. +description: Please see the README on GitHub at + +library: + source-dirs: app + dependencies: + - base >= 4.7 && < 5 diff --git a/test/unit/PackagePluginSpec.hs b/test/unit/PackagePluginSpec.hs index e828fc122..00065aca5 100644 --- a/test/unit/PackagePluginSpec.hs +++ b/test/unit/PackagePluginSpec.hs @@ -1,9 +1,12 @@ -{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} + module PackagePluginSpec where -import qualified Data.Aeson as Json -import qualified Data.Text as T -import qualified Data.HashMap.Strict as H + +import Control.Monad ( forM_ ) +import qualified Data.Aeson as Json +import qualified Data.Text as T +import qualified Data.HashMap.Strict as H import Haskell.Ide.Engine.MonadTypes import Haskell.Ide.Engine.Plugin.Package import System.FilePath @@ -15,8 +18,7 @@ main :: IO () main = hspec spec spec :: Spec -spec = - describe "Package plugin" packageSpec +spec = describe "Package plugin" packageSpec testdata :: FilePath testdata = "test/testdata/addPackageTest" @@ -24,89 +26,113 @@ testdata = "test/testdata/addPackageTest" testPlugins :: IdePlugins testPlugins = pluginDescToIdePlugins [packageDescriptor "package"] +cabalProject :: [FilePath] +cabalProject = ["cabal-lib", "cabal-exe"] + +hpackProject :: [FilePath] +hpackProject = ["hpack-lib", "hpack-exe", "hybrid-lib", "hybrid-exe"] + packageSpec :: Spec packageSpec = do cwd <- runIO getCurrentDirectory describe "Find correct package type" $ do - it "Find cabal file in cabal project" $ do - let fp = testdata "cabal" - packageType <- findPackageType fp - packageType `shouldBe` CabalPackage "add-package-test.cabal" - - it "Find package.yaml file in hpack project" $ do - let fp = testdata "hpack" - packageType <-findPackageType fp - packageType `shouldBe` HpackPackage (fp "package.yaml") - - it "Find package.yaml file in hpack project with generated cabal" $ do - let fp = testdata "hybrid" - packageType <- findPackageType fp - packageType `shouldBe` HpackPackage (fp "package.yaml") - + forM_ hpackProject $ \hpack -> + it ("hpack project find package.yaml (\"" ++ hpack ++ "\")") $ do + let fp = testdata hpack + packageType <- findPackageType fp + packageType `shouldBe` HpackPackage (fp "package.yaml") + forM_ cabalProject $ \cabal -> + it ("hpack project find cabal file (\"" ++ cabal ++ "\")") $ do + let fp = testdata cabal + packageType <- findPackageType fp + packageType `shouldBe` CabalPackage "add-package-test.cabal" it "Find no project description if none is present " $ do - let fp = testdata "invalid" + let fp = cwd testdata "invalid" packageType <- findPackageType fp packageType `shouldBe` NoPackage - it "Throws exception if path is invalid" $ do let fp = testdata "unknownPath" findPackageType fp `shouldThrow` anyIOException describe "Add the package to the correct file" $ do - it "Add package to .cabal" $ withCurrentDirectory (testdata "cabal") $ do - let - fp = cwd testdata "cabal" - 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: luke_lau@icloud.com\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" - ] + it "Add package to .cabal to executable component" + $ withCurrentDirectory (testdata "cabal-exe") + $ do + let + fp = cwd testdata "cabal-exe" + 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: luke_lau@icloud.com\n" + , "author: Luke Lau\n" + , "build-type: Simple\n" + , "extra-source-files:\n" + , " ChangeLog.md" ] - res = IdeResultOk $ WorkspaceEdit - (Just $ H.singleton uri textEdits) - Nothing - testCommand testPlugins act "package" "add" args res - it "Add package to package.yaml" $ withCurrentDirectory (testdata "hpack") $ do - let - fp = cwd testdata "hpack" - uri = filePathToUri $ fp "package.yaml" - args = AddParams fp (fp "app" "Asdf.hs") "zlib" - act = addCmd' args - res = IdeResultOk $ WorkspaceEdit - (Just $ H.singleton uri textEdits) - Nothing - textEdits = List - [ TextEdit (Range (Position 0 0) (Position 48 0)) $ T.concat + , 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" + ] + ] + res = IdeResultOk + $ WorkspaceEdit (Just $ H.singleton uri textEdits) Nothing + testCommand testPlugins act "package" "add" args res + + it "Add package to .cabal to library component" + $ withCurrentDirectory (testdata "cabal-lib") + $ do + let + fp = cwd testdata "cabal-lib" + 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: luke_lau@icloud.com\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" + ] + ] + 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 + let + fp = cwd testdata "hpack-exe" + uri = filePathToUri $ fp "package.yaml" + args = AddParams fp (fp "app" "Asdf.hs") "zlib" + act = addCmd' args + res = IdeResultOk + $ WorkspaceEdit (Just $ H.singleton uri textEdits) Nothing + textEdits = List + [ TextEdit (Range (Position 0 0) (Position 37 0)) $ T.concat [ "library:\n" , " source-dirs: src\n" - , "tests:\n" - , " asdf-test:\n" - , " source-dirs: test\n" - , " main: Spec.hs\n" - , " ghc-options:\n" - , " - -threaded\n" - , " - -rtsopts\n" - , " - -with-rtsopts=-N\n" - , " dependencies:\n" - , " - asdf\n" , "copyright: 2018 Author name here\n" , "maintainer: example@example.com\n" , "dependencies:\n" @@ -132,31 +158,55 @@ packageSpec = do , " - asdf\n" , "description: Please see the README on GitHub at \n" ] - ] - testCommand testPlugins act "package" "add" args res - it "Add package to package.yaml in hpack project with generated cabal" $ withCurrentDirectory (testdata "hybrid") $ do - let - fp = cwd testdata "hybrid" - uri = filePathToUri $ fp "package.yaml" - args = AddParams fp (fp "app" "Asdf.hs") "zlib" - act = addCmd' args - res = IdeResultOk $ WorkspaceEdit - (Just $ H.singleton uri textEdits) - Nothing - textEdits = List - [ TextEdit (Range (Position 0 0) (Position 48 0)) $ T.concat + ] + testCommand testPlugins act "package" "add" args res + + it "Add package to package.yaml to library component" + $ withCurrentDirectory (testdata "hpack-lib") + $ do + let + fp = cwd testdata "hpack-lib" + uri = filePathToUri $ fp "package.yaml" + args = AddParams fp (fp "app" "Asdf.hs") "zlib" + 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" + , " - base >= 4.7 && < 5\n" + , " - asdf\n" + , "copyright: 2018 Author name here\n" + , "maintainer: example@example.com\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 \n" + ] + ] + testCommand testPlugins act "package" "add" args res + it + "Add package to package.yaml in hpack project with generated cabal to executable component" + $ withCurrentDirectory (testdata "hybrid-exe") + $ do + let + fp = cwd testdata "hybrid-exe" + uri = filePathToUri $ fp "package.yaml" + args = AddParams fp (fp "app" "Asdf.hs") "zlib" + act = addCmd' args + res = IdeResultOk + $ WorkspaceEdit (Just $ H.singleton uri textEdits) Nothing + textEdits = List + [ TextEdit (Range (Position 0 0) (Position 37 0)) $ T.concat [ "library:\n" , " source-dirs: src\n" - , "tests:\n" - , " asdf-test:\n" - , " source-dirs: test\n" - , " main: Spec.hs\n" - , " ghc-options:\n" - , " - -threaded\n" - , " - -rtsopts\n" - , " - -with-rtsopts=-N\n" - , " dependencies:\n" - , " - asdf\n" , "copyright: 2018 Author name here\n" , "maintainer: example@example.com\n" , "dependencies:\n" @@ -182,13 +232,50 @@ packageSpec = do , " - asdf\n" , "description: Please see the README on GitHub at \n" ] - ] - testCommand testPlugins act "package" "add" args res - - it "Do nothing on NoPackage" $ withCurrentDirectory (testdata "invalid") $ do - let - fp = cwd testdata "invalid" - args = AddParams fp (fp "app" "Asdf.hs") "zlib" - act = addCmd' args - res = IdeResultFail (IdeError PluginError "No package.yaml or .cabal found" Json.Null) - testCommand testPlugins act "package" "add" args res \ No newline at end of file + ] + testCommand testPlugins act "package" "add" args res + it "Add package to package.yaml in hpack project with generated cabal to library component" + $ withCurrentDirectory (testdata "hybrid-lib") + $ do + let + fp = cwd testdata "hybrid-lib" + uri = filePathToUri $ fp "package.yaml" + args = AddParams fp (fp "app" "Asdf.hs") "zlib" + 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" + , " - base >= 4.7 && < 5\n" + , " - asdf\n" + , "copyright: 2018 Author name here\n" + , "maintainer: example@example.com\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 \n" + ] + ] + testCommand testPlugins act "package" "add" args res + it "Do nothing on NoPackage" + $ withCurrentDirectory (testdata "invalid") + $ do + let + fp = cwd testdata "invalid" + args = AddParams fp (fp "app" "Asdf.hs") "zlib" + act = addCmd' args + res = + IdeResultFail + (IdeError PluginError + "No package.yaml or .cabal found" + Json.Null + ) + testCommand testPlugins act "package" "add" args res From eefba536fdcb0fdafb5761a2fdcc891d7dcf2340 Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 1 May 2019 18:18:22 +0200 Subject: [PATCH 03/11] Rename type def to HpackFilePath --- src/Haskell/Ide/Engine/Plugin/Package.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Haskell/Ide/Engine/Plugin/Package.hs b/src/Haskell/Ide/Engine/Plugin/Package.hs index a9b6b2e5c..c30c6a9c9 100644 --- a/src/Haskell/Ide/Engine/Plugin/Package.hs +++ b/src/Haskell/Ide/Engine/Plugin/Package.hs @@ -76,7 +76,7 @@ data AddParams = AddParams -- | FilePath to a cabal package description file. type CabalFilePath = FilePath -- | FilePath to a package.yaml package description file. -type PackageYamlFilePath = FilePath +type HpackFilePath = FilePath -- | FilePath to a module within the project. -- May be used to establish what component the dependency shall be added to. type ModulePath = FilePath @@ -140,8 +140,8 @@ findPackageType rootDir = do -- Currently does not preserve format. -- Keep an eye out on this other GSOC project! -- https://github.com/wisn/format-preserving-yaml -editHpackPackage :: PackageYamlFilePath -- ^ Path to the package.yaml file - -- containing the package description. +editHpackPackage :: HpackFilePath -- ^ Path to the package.yaml file + -- containing the package description. -> ModulePath -- ^ Path to the module where the command has -- been issued in. -- Used to find out what component the From f0b79c4a84ffe38d253c154a10caf8f0b7023c2a Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 2 May 2019 12:55:42 +0200 Subject: [PATCH 04/11] Fix func-test suite for PackageTests --- test/functional/FunctionalCodeActionsSpec.hs | 6 +++--- test/utils/TestUtils.hs | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/test/functional/FunctionalCodeActionsSpec.hs b/test/functional/FunctionalCodeActionsSpec.hs index b49f00038..d2a96deec 100644 --- a/test/functional/FunctionalCodeActionsSpec.hs +++ b/test/functional/FunctionalCodeActionsSpec.hs @@ -177,7 +177,7 @@ spec = describe "code actions" $ do ] ] describe "add package suggestions" $ do - it "adds to .cabal files" $ runSession hieCommand fullCaps "test/testdata/addPackageTest/cabal" $ do + it "adds to .cabal files" $ runSession hieCommand fullCaps "test/testdata/addPackageTest/cabal-exe" $ do doc <- openDoc "AddPackage.hs" "haskell" -- ignore the first empty hlint diagnostic publish @@ -203,7 +203,7 @@ spec = describe "code actions" $ do liftIO $ T.lines contents `shouldSatisfy` \x -> any (\l -> "text -any" `T.isSuffixOf` (x !! l)) [15, 16] it "adds to hpack package.yaml files" $ - runSession hieCommand fullCaps "test/testdata/addPackageTest/hpack" $ do + runSession hieCommand fullCaps "test/testdata/addPackageTest/hpack-exe" $ do doc <- openDoc "app/Asdf.hs" "haskell" -- ignore the first empty hlint diagnostic publish @@ -232,7 +232,7 @@ spec = describe "code actions" $ do T.lines contents !! 13 `shouldNotSatisfy` T.isSuffixOf "zlib" it "adds to hpack package.yaml files if both are present" $ - runSession hieCommand fullCaps "test/testdata/addPackageTest/hybrid" $ do + runSession hieCommand fullCaps "test/testdata/addPackageTest/hybrid-exe" $ do doc <- openDoc "app/Asdf.hs" "haskell" -- ignore the first empty hlint diagnostic publish diff --git a/test/utils/TestUtils.hs b/test/utils/TestUtils.hs index 900a7bf4b..17bce1399 100644 --- a/test/utils/TestUtils.hs +++ b/test/utils/TestUtils.hs @@ -101,8 +101,12 @@ setupStackFiles = files :: [FilePath] files = [ "./test/testdata/" - , "./test/testdata/addPackageTest/cabal/" - , "./test/testdata/addPackageTest/hpack/" + , "./test/testdata/addPackageTest/cabal-exe/" + , "./test/testdata/addPackageTest/hpack-exe/" + , "./test/testdata/addPackageTest/hybrid-exe/" + , "./test/testdata/addPackageTest/cabal-lib/" + , "./test/testdata/addPackageTest/hpack-lib/" + , "./test/testdata/addPackageTest/hybrid-lib/" , "./test/testdata/addPragmas/" , "./test/testdata/badProjects/cabal/" , "./test/testdata/completion/" From cabaa3f4ee7cdd29ae70dc7bfeb912ae4b3c45a6 Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 2 May 2019 14:30:25 +0200 Subject: [PATCH 05/11] Add package to library component --- src/Haskell/Ide/Engine/Plugin/Package.hs | 6 ++++-- test/testdata/addPackageTest/cabal-lib/AddPackage.hs | 2 ++ test/testdata/addPackageTest/hpack-exe/package.yaml | 3 --- test/testdata/addPackageTest/hpack-lib/app/Asdf.hs | 2 ++ test/testdata/addPackageTest/hybrid-lib/AddPackage.hs | 2 -- test/testdata/addPackageTest/hybrid-lib/app/Asdf.hs | 2 +- test/unit/PackagePluginSpec.hs | 11 +++++------ 7 files changed, 14 insertions(+), 14 deletions(-) delete mode 100644 test/testdata/addPackageTest/hybrid-lib/AddPackage.hs diff --git a/src/Haskell/Ide/Engine/Plugin/Package.hs b/src/Haskell/Ide/Engine/Plugin/Package.hs index c30c6a9c9..2d702ec41 100644 --- a/src/Haskell/Ide/Engine/Plugin/Package.hs +++ b/src/Haskell/Ide/Engine/Plugin/Package.hs @@ -186,8 +186,10 @@ editHpackPackage fp modulePath pkgName = do mapMainDependencies :: (Value -> Value) -> Object -> Object mapMainDependencies f o = - let g "dependencies" = f - g _ = id + let g :: T.Text -> Value -> Value + g "dependencies" x = f x + g "library" (Y.Object o') = Y.Object (mapMainDependencies f o') + g _ x = x in HM.mapWithKey g o mapComponentTypes :: (Value -> Value) -> Object -> Object diff --git a/test/testdata/addPackageTest/cabal-lib/AddPackage.hs b/test/testdata/addPackageTest/cabal-lib/AddPackage.hs index 963020508..24015b598 100644 --- a/test/testdata/addPackageTest/cabal-lib/AddPackage.hs +++ b/test/testdata/addPackageTest/cabal-lib/AddPackage.hs @@ -1,2 +1,4 @@ +module AddPackage where + import Data.Text foo = pack "I'm a Text" \ No newline at end of file diff --git a/test/testdata/addPackageTest/hpack-exe/package.yaml b/test/testdata/addPackageTest/hpack-exe/package.yaml index 9bb1916b1..3be56682f 100644 --- a/test/testdata/addPackageTest/hpack-exe/package.yaml +++ b/test/testdata/addPackageTest/hpack-exe/package.yaml @@ -22,9 +22,6 @@ description: Please see the README on GitHub at = 4.7 && < 5 -library: - source-dirs: src - executables: asdf-exe: main: Main.hs diff --git a/test/testdata/addPackageTest/hpack-lib/app/Asdf.hs b/test/testdata/addPackageTest/hpack-lib/app/Asdf.hs index fdd639ffe..ec4b22911 100644 --- a/test/testdata/addPackageTest/hpack-lib/app/Asdf.hs +++ b/test/testdata/addPackageTest/hpack-lib/app/Asdf.hs @@ -1,5 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} +module Asdf where + import Codec.Compression.GZip main = return $ compress "hello" \ No newline at end of file diff --git a/test/testdata/addPackageTest/hybrid-lib/AddPackage.hs b/test/testdata/addPackageTest/hybrid-lib/AddPackage.hs deleted file mode 100644 index 963020508..000000000 --- a/test/testdata/addPackageTest/hybrid-lib/AddPackage.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Data.Text -foo = pack "I'm a Text" \ No newline at end of file diff --git a/test/testdata/addPackageTest/hybrid-lib/app/Asdf.hs b/test/testdata/addPackageTest/hybrid-lib/app/Asdf.hs index fdd639ffe..1bed3539c 100644 --- a/test/testdata/addPackageTest/hybrid-lib/app/Asdf.hs +++ b/test/testdata/addPackageTest/hybrid-lib/app/Asdf.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} - +module Asdf where import Codec.Compression.GZip main = return $ compress "hello" \ No newline at end of file diff --git a/test/unit/PackagePluginSpec.hs b/test/unit/PackagePluginSpec.hs index 00065aca5..374f628b1 100644 --- a/test/unit/PackagePluginSpec.hs +++ b/test/unit/PackagePluginSpec.hs @@ -130,12 +130,11 @@ packageSpec = do res = IdeResultOk $ WorkspaceEdit (Just $ H.singleton uri textEdits) Nothing textEdits = List - [ TextEdit (Range (Position 0 0) (Position 37 0)) $ T.concat - [ "library:\n" - , " source-dirs: src\n" - , "copyright: 2018 Author name here\n" + [ TextEdit (Range (Position 0 0) (Position 34 0)) $ T.concat + [ "copyright: 2018 Author name here\n" , "maintainer: example@example.com\n" , "dependencies:\n" + , "- zlib\n" , "- base >= 4.7 && < 5\n" , "name: asdf\n" , "version: 0.1.0.0\n" @@ -176,8 +175,8 @@ packageSpec = do [ "library:\n" , " source-dirs: app\n" , " dependencies:\n" + , " - zlib\n" , " - base >= 4.7 && < 5\n" - , " - asdf\n" , "copyright: 2018 Author name here\n" , "maintainer: example@example.com\n" , "name: asdf\n" @@ -249,8 +248,8 @@ packageSpec = do [ "library:\n" , " source-dirs: app\n" , " dependencies:\n" + , " - zlib\n" , " - base >= 4.7 && < 5\n" - , " - asdf\n" , "copyright: 2018 Author name here\n" , "maintainer: example@example.com\n" , "name: asdf\n" From 9680e4817aec2688022953bed42b517cc8dce162 Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 2 May 2019 14:56:35 +0200 Subject: [PATCH 06/11] Fix functional tests for AddPackage --- test/functional/FunctionalCodeActionsSpec.hs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/functional/FunctionalCodeActionsSpec.hs b/test/functional/FunctionalCodeActionsSpec.hs index d2a96deec..e0ebc8df2 100644 --- a/test/functional/FunctionalCodeActionsSpec.hs +++ b/test/functional/FunctionalCodeActionsSpec.hs @@ -227,9 +227,8 @@ spec = describe "code actions" $ do contents <- getDocumentEdit . TextDocumentIdentifier =<< getDocUri "package.yaml" liftIO $ do - T.lines contents !! 33 `shouldSatisfy` T.isSuffixOf "zlib" - T.lines contents !! 12 `shouldNotSatisfy` T.isSuffixOf "zlib" - T.lines contents !! 13 `shouldNotSatisfy` T.isSuffixOf "zlib" + T.lines contents !! 3 `shouldSatisfy` T.isSuffixOf "zlib" + T.lines contents !! 21 `shouldNotSatisfy` T.isSuffixOf "zlib" it "adds to hpack package.yaml files if both are present" $ runSession hieCommand fullCaps "test/testdata/addPackageTest/hybrid-exe" $ do @@ -256,9 +255,9 @@ spec = describe "code actions" $ do contents <- getDocumentEdit . TextDocumentIdentifier =<< getDocUri "package.yaml" liftIO $ do - T.lines contents !! 33 `shouldSatisfy` T.isSuffixOf "zlib" - T.lines contents !! 12 `shouldNotSatisfy` T.isSuffixOf "zlib" - T.lines contents !! 13 `shouldNotSatisfy` T.isSuffixOf "zlib" + T.lines contents !! 23 `shouldSatisfy` T.isSuffixOf "zlib" + T.lines contents !! 5 `shouldNotSatisfy` T.isSuffixOf "zlib" + T.lines contents !! 6 `shouldNotSatisfy` T.isSuffixOf "zlib" -- ----------------------------------- From 2b75c538a09506c23fa309946db55dc761b9fd43 Mon Sep 17 00:00:00 2001 From: fendor Date: Mon, 6 May 2019 21:18:16 +0200 Subject: [PATCH 07/11] Improve behaviour of addPackage for hpack Now addPackage will either add the package to all components the module is part of or only to the main "dependencies" object. --- src/Haskell/Ide/Engine/Plugin/Package.hs | 37 ++++++++++++++----- test/functional/FunctionalCodeActionsSpec.hs | 6 +-- .../addPackageTest/hybrid-exe/package.yaml | 3 -- test/unit/PackagePluginSpec.hs | 5 +-- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/Haskell/Ide/Engine/Plugin/Package.hs b/src/Haskell/Ide/Engine/Plugin/Package.hs index 2d702ec41..4344c9f30 100644 --- a/src/Haskell/Ide/Engine/Plugin/Package.hs +++ b/src/Haskell/Ide/Engine/Plugin/Package.hs @@ -136,6 +136,7 @@ findPackageType rootDir = do return $ fromMaybe NoPackage $ asum [HpackPackage <$> mHpack, CabalPackage <$> mCabal] -- | Edit a hpack package to add the given package to the package.yaml. +-- If package.yaml is not in an expected format, will fail fatally. -- -- Currently does not preserve format. -- Keep an eye out on this other GSOC project! @@ -155,19 +156,29 @@ editHpackPackage fp modulePath pkgName = do case Y.decodeThrow contents :: Maybe Object of Just obj -> do + -- Map over all major components, such as "executable", "executables", + -- "tests" and "benchmarks". Note, that "library" is a major component, + -- but its structure is different and can not be mapped over in the same way. + -- + -- Only adds the package if the declared "source-dirs" field is part of the + -- module path, or if no "source-dirs" is declared. let compsMapped = mapComponentTypes (ensureObject $ mapComponents (ensureObject $ mapCompDependencies addDep)) obj - let addDepToMainLib = fromMaybe True $ do - Object lib <- HM.lookup "library" compsMapped - sourceDirs <- HM.lookup "source-dirs" lib - return $ isInSourceDir sourceDirs + -- Is there a global "dependencies" yaml object? + let addDepToMainDep = fromMaybe False $ do + Array _ <- HM.lookup "dependencies" compsMapped + return True - let newPkg = if addDepToMainLib - then mapMainDependencies addDep compsMapped - else compsMapped + -- Either add the package to only the top-level "dependencies", + -- or to all main components of which the given module is part of. + let newPkg + | addDepToMainDep = mapMainDependencies addDep obj + -- Map over the library component at last, since it has different structure. + | otherwise = mapLibraryDependency addDep compsMapped - newPkgText = T.decodeUtf8 $ Y.encode newPkg + let newPkgText = T.decodeUtf8 $ Y.encode newPkg + -- Construct the WorkSpaceEdit let numOldLines = length $ T.lines $ T.decodeUtf8 contents range = J.Range (J.Position 0 0) (J.Position numOldLines 0) textEdit = J.TextEdit range newPkgText @@ -187,8 +198,14 @@ editHpackPackage fp modulePath pkgName = do mapMainDependencies :: (Value -> Value) -> Object -> Object mapMainDependencies f o = let g :: T.Text -> Value -> Value - g "dependencies" x = f x - g "library" (Y.Object o') = Y.Object (mapMainDependencies f o') + g "dependencies" = f + g _ = id + in HM.mapWithKey g o + + mapLibraryDependency :: (Value -> Value) -> Object -> Object + mapLibraryDependency f o = + let g :: T.Text -> Value -> Value + g "library" (Y.Object o') = Y.Object (mapCompDependencies f o') g _ x = x in HM.mapWithKey g o diff --git a/test/functional/FunctionalCodeActionsSpec.hs b/test/functional/FunctionalCodeActionsSpec.hs index e0ebc8df2..1fb5d2975 100644 --- a/test/functional/FunctionalCodeActionsSpec.hs +++ b/test/functional/FunctionalCodeActionsSpec.hs @@ -254,10 +254,8 @@ spec = describe "code actions" $ do executeCodeAction action contents <- getDocumentEdit . TextDocumentIdentifier =<< getDocUri "package.yaml" - liftIO $ do - T.lines contents !! 23 `shouldSatisfy` T.isSuffixOf "zlib" - T.lines contents !! 5 `shouldNotSatisfy` T.isSuffixOf "zlib" - T.lines contents !! 6 `shouldNotSatisfy` T.isSuffixOf "zlib" + liftIO $ + T.lines contents !! 21 `shouldSatisfy` T.isSuffixOf "zlib" -- ----------------------------------- diff --git a/test/testdata/addPackageTest/hybrid-exe/package.yaml b/test/testdata/addPackageTest/hybrid-exe/package.yaml index 9bb1916b1..8d9524972 100644 --- a/test/testdata/addPackageTest/hybrid-exe/package.yaml +++ b/test/testdata/addPackageTest/hybrid-exe/package.yaml @@ -19,9 +19,6 @@ extra-source-files: # common to point users to the README.md file. description: Please see the README on GitHub at -dependencies: -- base >= 4.7 && < 5 - library: source-dirs: src diff --git a/test/unit/PackagePluginSpec.hs b/test/unit/PackagePluginSpec.hs index 374f628b1..c30de7c97 100644 --- a/test/unit/PackagePluginSpec.hs +++ b/test/unit/PackagePluginSpec.hs @@ -153,7 +153,6 @@ packageSpec = do , " - -rtsopts\n" , " - -with-rtsopts=-N\n" , " dependencies:\n" - , " - zlib\n" , " - asdf\n" , "description: Please see the README on GitHub at \n" ] @@ -203,13 +202,11 @@ packageSpec = do res = IdeResultOk $ WorkspaceEdit (Just $ H.singleton uri textEdits) Nothing textEdits = List - [ TextEdit (Range (Position 0 0) (Position 37 0)) $ T.concat + [ TextEdit (Range (Position 0 0) (Position 34 0)) $ T.concat [ "library:\n" , " source-dirs: src\n" , "copyright: 2018 Author name here\n" , "maintainer: example@example.com\n" - , "dependencies:\n" - , "- base >= 4.7 && < 5\n" , "name: asdf\n" , "version: 0.1.0.0\n" , "extra-source-files:\n" From 809a10bd82c1ec9e9a0e945148dee44ce173280f Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 8 May 2019 16:05:58 +0200 Subject: [PATCH 08/11] Revert TestUtils executable runner --- test/utils/TestUtils.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/utils/TestUtils.hs b/test/utils/TestUtils.hs index 17bce1399..91ffc3203 100644 --- a/test/utils/TestUtils.hs +++ b/test/utils/TestUtils.hs @@ -166,7 +166,8 @@ logFilePath = "functional-hie-" ++ stackYaml ++ ".log" -- We also need to unset STACK_EXE manually inside the tests if they are -- run with `stack test` hieCommand :: String -hieCommand = "hie -d -l test-logs/" ++ logFilePath +hieCommand = "stack exec --no-stack-exe --no-ghc-package-path --stack-yaml=" ++ stackYaml ++ + " hie -- -d -l test-logs/" ++ logFilePath hieCommandVomit :: String hieCommandVomit = hieCommand ++ " --vomit" From aed6b42e4684e713e7d92e6896ceb8d9c0d0cca1 Mon Sep 17 00:00:00 2001 From: fendor Date: Sat, 11 May 2019 21:05:32 +0200 Subject: [PATCH 09/11] Fix problems related to ghc 8.2.* --- test/functional/FunctionalCodeActionsSpec.hs | 5 +- test/unit/PackagePluginSpec.hs | 163 ++++++++++++------- 2 files changed, 110 insertions(+), 58 deletions(-) diff --git a/test/functional/FunctionalCodeActionsSpec.hs b/test/functional/FunctionalCodeActionsSpec.hs index 1fb5d2975..67f7febea 100644 --- a/test/functional/FunctionalCodeActionsSpec.hs +++ b/test/functional/FunctionalCodeActionsSpec.hs @@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE CPP #-} module FunctionalCodeActionsSpec where @@ -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" @@ -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" diff --git a/test/unit/PackagePluginSpec.hs b/test/unit/PackagePluginSpec.hs index c30de7c97..ab75ebb4c 100644 --- a/test/unit/PackagePluginSpec.hs +++ b/test/unit/PackagePluginSpec.hs @@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE CPP #-} module PackagePluginSpec where @@ -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: luke_lau@icloud.com\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: luke_lau@icloud.com\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: luke_lau@icloud.com\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 @@ -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: luke_lau@icloud.com\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: luke_lau@icloud.com\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: luke_lau@icloud.com\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 @@ -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: example@example.com\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 \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: example@example.com\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 \n" + ] + ] testCommand testPlugins act "package" "add" args res it "Add package to package.yaml in hpack project with generated cabal to executable component" From c65f3bc87aad1c4397eca0def16f734510c2cdc9 Mon Sep 17 00:00:00 2001 From: fendor Date: Sat, 11 May 2019 22:51:07 +0200 Subject: [PATCH 10/11] Use concat for typed holes test --- test/functional/FunctionalCodeActionsSpec.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/functional/FunctionalCodeActionsSpec.hs b/test/functional/FunctionalCodeActionsSpec.hs index 67f7febea..512953e57 100644 --- a/test/functional/FunctionalCodeActionsSpec.hs +++ b/test/functional/FunctionalCodeActionsSpec.hs @@ -345,10 +345,11 @@ spec = describe "code actions" $ do contents <- documentContents doc - liftIO $ contents `shouldBe` - "module TypedHoles where\n\ - \foo :: [Int] -> Int\n\ - \foo x = " <> suggestion + liftIO $ contents `shouldBe` T.concat + [ "module TypedHoles where\n" + , "foo :: [Int] -> Int\n" + , "foo x = " <> suggestion + ] it "shows more suggestions" $ runSession hieCommand fullCaps "test/testdata" $ do From 9e3eae10338a7d559adb403768ce5fb4c8d444c6 Mon Sep 17 00:00:00 2001 From: fendor Date: Sat, 11 May 2019 23:34:58 +0200 Subject: [PATCH 11/11] Add missing trailing newlines to tests --- test/unit/PackagePluginSpec.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/PackagePluginSpec.hs b/test/unit/PackagePluginSpec.hs index ab75ebb4c..cc220ef22 100644 --- a/test/unit/PackagePluginSpec.hs +++ b/test/unit/PackagePluginSpec.hs @@ -92,7 +92,7 @@ packageSpec = do , "version: 0.1.0.0\n" , "cabal-version: >=1.10\n" , "build-type: Simple\n" - , "license: BSD3" + , "license: BSD3\n" , "maintainer: luke_lau@icloud.com\n" , "author: Luke Lau\n" , "extra-source-files:\n" @@ -100,7 +100,7 @@ packageSpec = do ] , TextEdit (Range (Position 9 0) (Position 13 34)) $ T.concat [ "executable AddPackage\n" - , " main-is: AddPackage.hs" + , " main-is: AddPackage.hs\n" ] ] #endif @@ -150,7 +150,7 @@ packageSpec = do , "maintainer: luke_lau@icloud.com\n" , "author: Luke Lau\n" , "extra-source-files:\n" - , " ChangeLog.md\n" + , " ChangeLog.md" ] , TextEdit (Range (Position 10 0) (Position 13 34)) $ T.concat [ " exposed-modules:\n"