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

Commit

Permalink
Merge pull request #1291 from alanz/stack-2.1.1
Browse files Browse the repository at this point in the history
Stack 2.1.1
  • Loading branch information
alanz authored Jun 16, 2019
2 parents e300e64 + 837983e commit 30908ee
Show file tree
Hide file tree
Showing 21 changed files with 170 additions and 49 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ test-results/
.vscode

# shake build information
_build/
_build/

# stack 2.1 stack.yaml lock files
stack*.yaml.lock
1 change: 1 addition & 0 deletions haskell-ide-engine.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ library
, transformers
, unordered-containers
, vector
, versions
, yaml >= 0.8.31
ghc-options: -Wall -Wredundant-constraints
if flag(pedantic)
Expand Down
25 changes: 23 additions & 2 deletions src/Haskell/Ide/Engine/Plugin/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Data.Maybe
import Data.Semigroup
#endif
import qualified Data.Text as T
import qualified Data.Versions as V
import Development.GitRev (gitCommitCount)
import Distribution.System (buildArch)
import Distribution.Text (display)
Expand Down Expand Up @@ -126,14 +127,34 @@ getProjectGhcVersion = do
then tryCommand "ghc --numeric-version"
else return "No System GHC found"

tryCommand cmd =
init <$> readCreateProcess (shell cmd) ""

tryCommand :: String -> IO String
tryCommand cmd =
init <$> readCreateProcess (shell cmd) ""

hieGhcVersion :: String
hieGhcVersion = VERSION_ghc

-- ---------------------------------------------------------------------

getStackVersion :: IO (Maybe V.Version)
getStackVersion = do
isStackInstalled <- isJust <$> findExecutable "stack"
if isStackInstalled
then do
versionStr <- tryCommand "stack --numeric-version"
case V.version (T.pack versionStr) of
Left _err -> return Nothing
Right v -> return (Just v)
else return Nothing

stack193Version :: V.Version
stack193Version = case V.version "1.9.3" of
Left err -> error $ "stack193Version:err=" ++ show err
Right v -> v

-- ---------------------------------------------------------------------

checkCabalInstall :: IO Bool
checkCabalInstall = isJust <$> findExecutable "cabal"

Expand Down
7 changes: 4 additions & 3 deletions src/Haskell/Ide/Engine/Plugin/Liquid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ generateDiagnosics cb uri file = do

-- ---------------------------------------------------------------------

-- Find and run the liquid haskell executable
-- | Find and run the liquid haskell executable
runLiquidHaskell :: FilePath -> IO (Maybe (ExitCode,[String]))
runLiquidHaskell fp = do
mexe <- findExecutable "liquid"
Expand All @@ -168,13 +168,14 @@ runLiquidHaskell fp = do
let cmd = lh ++ " --json \"" ++ fp ++ "\""
dir = takeDirectory fp
cp = (shell cmd) { cwd = Just dir }
logm $ "runLiquidHaskell:cmd=[" ++ cmd ++ "]"
-- logm $ "runLiquidHaskell:cmd=[" ++ cmd ++ "]"
mpp <- lookupEnv "GHC_PACKAGE_PATH"
-- logm $ "runLiquidHaskell:mpp=[" ++ show mpp ++ "]"
(ec,o,e) <- bracket
(unsetEnv "GHC_PACKAGE_PATH")
(\_ -> mapM_ (setEnv "GHC_PACKAGE_PATH") mpp)
(\_ -> readCreateProcessWithExitCode cp "")
logm $ "runLiquidHaskell:v=" ++ show (ec,o,e)
-- logm $ "runLiquidHaskell:v=" ++ show (ec,o,e)
return $ Just (ec,[o,e])

-- ---------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/functional/FunctionalCodeActionsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ spec = describe "code actions" $ do

contents <- getDocumentEdit . TextDocumentIdentifier =<< getDocUri "package.yaml"
liftIO $
T.lines contents !! 21 `shouldSatisfy` T.isSuffixOf "zlib"
T.lines contents !! 23 `shouldSatisfy` T.isSuffixOf "zlib"

-- -----------------------------------

Expand Down
5 changes: 4 additions & 1 deletion test/testdata/addPackageTest/hybrid-exe/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ description: Please see the README on GitHub at <https://github.com/gith

library:
source-dirs: src
dependencies:
- base

executables:
asdf-exe:
Expand All @@ -31,4 +33,5 @@ executables:
- -rtsopts
- -with-rtsopts=-N
dependencies:
- asdf
- base
- asdf
2 changes: 2 additions & 0 deletions test/testdata/wrapper/8.2.1/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
1 change: 1 addition & 0 deletions test/testdata/wrapper/8.2.1/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
25 changes: 25 additions & 0 deletions test/testdata/wrapper/8.2.1/cabal1.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Initial cabal1.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/

name: cabal1
version: 0.1.0.0
-- synopsis:
-- description:
license: PublicDomain
-- license-file: LICENSE
author: Alan Zimmerman
maintainer: alan.zimm@gmail.com
-- copyright:
-- category:
build-type: Simple
-- extra-source-files:
-- cabal-helper for cabal 2.2/GHC 8.4 needs a cabal version >= 2
cabal-version: >=2.0

executable cabal1
main-is: main.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.6 && <5
hs-source-dirs: src
default-language: Haskell2010
3 changes: 3 additions & 0 deletions test/testdata/wrapper/8.2.1/src/Foo/Bar.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Foo.Bar where

baz = 6
7 changes: 7 additions & 0 deletions test/testdata/wrapper/8.2.1/src/main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- | Testing that HaRe can find source files from a cabal file

import qualified Foo.Bar as B

main = putStrLn "foo"

baz = 3 + B.baz
2 changes: 2 additions & 0 deletions test/testdata/wrapper/lts-11.14/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
1 change: 1 addition & 0 deletions test/testdata/wrapper/lts-11.14/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
25 changes: 25 additions & 0 deletions test/testdata/wrapper/lts-11.14/cabal1.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Initial cabal1.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/

name: cabal1
version: 0.1.0.0
-- synopsis:
-- description:
license: PublicDomain
-- license-file: LICENSE
author: Alan Zimmerman
maintainer: alan.zimm@gmail.com
-- copyright:
-- category:
build-type: Simple
-- extra-source-files:
-- cabal-helper for cabal 2.2/GHC 8.4 needs a cabal version >= 2
cabal-version: >=2.0

executable cabal1
main-is: main.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.6 && <5
hs-source-dirs: src
default-language: Haskell2010
3 changes: 3 additions & 0 deletions test/testdata/wrapper/lts-11.14/src/Foo/Bar.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Foo.Bar where

baz = 6
7 changes: 7 additions & 0 deletions test/testdata/wrapper/lts-11.14/src/main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- | Testing that HaRe can find source files from a cabal file

import qualified Foo.Bar as B

main = putStrLn "foo"

baz = 3 + B.baz
10 changes: 8 additions & 2 deletions test/unit/GhcModPluginSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import qualified Data.Map as Map
-- import Data.Monoid
#endif
import qualified Data.Set as S
-- import qualified Data.Text as T
import qualified Data.Text as T
import Haskell.Ide.Engine.Ghc
import Haskell.Ide.Engine.MonadTypes
import Haskell.Ide.Engine.Plugin.GhcMod
Expand Down Expand Up @@ -44,8 +44,14 @@ ghcmodSpec =
fp <- makeAbsolute "./FileWithWarning.hs"
let act = setTypecheckedModule arg
arg = filePathToUri fp
IdeResultOk (_,env) <- runSingle testPlugins act
case env of
[] -> return ()
[s] -> T.unpack s `shouldStartWith` "Loaded package environment from"
ss -> fail $ "got:" ++ show ss
let
res = IdeResultOk $
(Map.singleton arg (S.singleton diag), [])
(Map.singleton arg (S.singleton diag), env)
diag = Diagnostic (Range (toPos (4,7))
(toPos (4,8)))
(Just DsError)
Expand Down
25 changes: 14 additions & 11 deletions test/unit/LiquidSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ module LiquidSpec where

import Data.Aeson
import qualified Data.ByteString.Lazy as BS
import Data.List
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.Monoid ((<>))
import Data.Maybe (isJust)
import Haskell.Ide.Engine.MonadTypes
import Haskell.Ide.Engine.Plugin.Liquid
import System.Directory
import System.Exit
import System.FilePath
import Test.Hspec

Expand All @@ -25,18 +23,23 @@ spec = do
cwd <- runIO getCurrentDirectory

-- ---------------------------------

it "finds liquid haskell exe in $PATH" $ findExecutable "liquid" >>= (`shouldSatisfy` isJust)

-- ---------------------------------
-- This produces some products in /test/testdata/liquid/.liquid/ that is used in subsequent test
it "runs the liquid haskell exe" $ do
let
fp = cwd </> "test/testdata/liquid/Evens.hs"
-- fp = "/home/alanz/tmp/haskell-proc-play/Evens.hs"
-- uri = filePathToUri fp
Just (ef, (msg:_)) <- runLiquidHaskell fp
msg `shouldSatisfy` isPrefixOf "RESULT\n[{\"start\":{\"line\":9,\"column\":1},\"stop\":{\"line\":9,\"column\":8},\"message\":\"Error: Liquid Type Mismatch\\n Inferred type\\n VV : {v : Int | v == (7 : int)}\\n \\n not a subtype of Required type\\n VV : {VV : Int | VV mod 2 == 0}\\n"
ef `shouldBe` ExitFailure 1

-- AZ: this test has been moved to func-tests, stack > 2.1 sets
-- its own package environment, we can't run it from here.

-- -- This produces some products in /test/testdata/liquid/.liquid/ that is used in subsequent test
-- it "runs the liquid haskell exe" $ do
-- let
-- fp = cwd </> "test/testdata/liquid/Evens.hs"
-- -- fp = "/home/alanz/tmp/haskell-proc-play/Evens.hs"
-- -- uri = filePathToUri fp
-- Just (ef, (msg:_)) <- runLiquidHaskell fp
-- msg `shouldSatisfy` isPrefixOf "RESULT\n[{\"start\":{\"line\":9,\"column\":1},\"stop\":{\"line\":9,\"column\":8},\"message\":\"Error: Liquid Type Mismatch\\n Inferred type\\n VV : {v : Int | v == (7 : int)}\\n \\n not a subtype of Required type\\n VV : {VV : Int | VV mod 2 == 0}\\n"
-- ef `shouldBe` ExitFailure 1

-- ---------------------------------
it "gets annot file paths" $ do
Expand Down
57 changes: 30 additions & 27 deletions test/unit/PackagePluginSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -251,33 +251,36 @@ packageSpec = do
res = IdeResultOk
$ WorkspaceEdit (Just $ H.singleton uri textEdits) Nothing
textEdits = List
[ 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"
, "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 <https://github.com/githubuser/asdf#readme>\n"
]
]
[ TextEdit (Range (Position 0 0) (Position 37 0)) $ T.concat
[ "library:\n"
, " source-dirs: src\n"
, " dependencies:\n"
, " - base\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"
, "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"
, " - base\n"
, " - asdf\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 library component"
$ withCurrentDirectory (testdata </> "hybrid-lib")
Expand Down
4 changes: 4 additions & 0 deletions test/utils/TestUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module TestUtils
, withFileLogging
, setupStackFiles
, testCommand
, runSingle
, runSingleReq
, makeRequest
, runIGM
Expand Down Expand Up @@ -60,6 +61,9 @@ testCommand testPlugins act plugin cmd arg res = do
newApiRes `shouldBe` res
fmap fromDynJSON oldApiRes `shouldBe` fmap Just res

runSingle :: IdePlugins -> IdeGhcM (IdeResult b) -> IO (IdeResult b)
runSingle testPlugins act = runIGM testPlugins act

runSingleReq :: ToJSON a
=> IdePlugins -> PluginId -> CommandName -> a -> IO (IdeResult DynamicJSON)
runSingleReq testPlugins plugin com arg = runIGM testPlugins (makeRequest plugin com arg)
Expand Down
2 changes: 1 addition & 1 deletion test/wrapper/HieWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ main = hspec $
withCurrentDirectory "test/testdata/wrapper/ghc" $ do
ghcDisplayVer <- readCreateProcess (shell "ghc --version") ""
ghcVer <- getProjectGhcVersion
init ghcDisplayVer `shouldEndWith` ghcVer
init ghcDisplayVer `shouldEndWith` ghcVer

0 comments on commit 30908ee

Please sign in to comment.