diff --git a/Language/Haskell/GhcMod/Cradle.hs b/Language/Haskell/GhcMod/Cradle.hs index 19f17c9..15c8981 100644 --- a/Language/Haskell/GhcMod/Cradle.hs +++ b/Language/Haskell/GhcMod/Cradle.hs @@ -73,7 +73,7 @@ stackCradle wdir = do let cabalDir = takeDirectory cabalFile - stackConfigFile <- MaybeT $ findStackConfigFile cabalDir + _stackConfigFile <- MaybeT $ findStackConfigFile cabalDir return Cradle { cradleProjectType = StackProject diff --git a/test/CabalHelperSpec.hs b/test/CabalHelperSpec.hs index 42211d8..69e3814 100644 --- a/test/CabalHelperSpec.hs +++ b/test/CabalHelperSpec.hs @@ -56,6 +56,13 @@ spec = do then forM_ opts (\o -> o `shouldContain` ["-no-user-package-conf","-package-conf", cwd "test/data/cabal-project/.cabal-sandbox/"++ghcSandboxPkgDbDir bp]) else forM_ opts (\o -> o `shouldContain` ["-no-user-package-db","-package-db",cwd "test/data/cabal-project/.cabal-sandbox/"++ghcSandboxPkgDbDir bp]) + it "handles stack project" $ do + let tdir = "test/data/stack-project" + opts <- map gmcGhcOpts <$> runD' tdir getComponents + let ghcOpts = head opts + pkgs = pkgOptions ghcOpts + pkgs `shouldBe` ["Cabal","base","new-template"] + it "extracts build dependencies" $ do let tdir = "test/data/cabal-project" opts <- map gmcGhcOpts <$> runD' tdir getComponents diff --git a/test/Main.hs b/test/Main.hs index 18aa1eb..bbc6804 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -28,6 +28,11 @@ main = do genSandboxCfg `mapM_` sandboxes genGhcPkgCache `mapM_` pkgDirs + let stackDir = "test/data/stack-project" + withDirectory stackDir $ \_ -> do + system "stack init --force" + system "stack build" + let caches = [ "setup-config" , "setup-config.ghc-mod.cabal-helper" , "setup-config.ghc-mod.cabal-components" diff --git a/test/PathsAndFilesSpec.hs b/test/PathsAndFilesSpec.hs index 760b583..1e15b1d 100644 --- a/test/PathsAndFilesSpec.hs +++ b/test/PathsAndFilesSpec.hs @@ -25,6 +25,10 @@ spec = do it "finds cabal files in parent directories" $ do findCabalFile "test/data/cabal-project/subdir1/subdir2" `shouldReturn` Just "test/data/cabal-project/cabalapi.cabal" + describe "findStackConfigFile" $ do + it "works" $ do + findStackConfigFile "test/data/stack-project" `shouldReturn` Just "test/data/stack-project/stack.yaml" + describe "findCabalSandboxDir" $ do it "works" $ do findCabalSandboxDir "test/data/cabal-project" `shouldReturn` Just "test/data/cabal-project" diff --git a/test/data/stack-project/Setup.hs b/test/data/stack-project/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/test/data/stack-project/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/test/data/stack-project/app/Main.hs b/test/data/stack-project/app/Main.hs new file mode 100644 index 0000000..de1c1ab --- /dev/null +++ b/test/data/stack-project/app/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Lib + +main :: IO () +main = someFunc diff --git a/test/data/stack-project/new-template.cabal b/test/data/stack-project/new-template.cabal new file mode 100644 index 0000000..34a3a0b --- /dev/null +++ b/test/data/stack-project/new-template.cabal @@ -0,0 +1,41 @@ +name: new-template +version: 0.1.0.0 +synopsis: Initial project template from stack +description: Please see README.md +homepage: http://github.com/name/project +-- license: BSD3 +-- license-file: LICENSE +author: Your name here +maintainer: your.address@example.com +-- copyright: +category: Web +build-type: Simple +-- extra-source-files: +cabal-version: >=1.10 + +library + hs-source-dirs: src + exposed-modules: Lib + build-depends: base >= 4.7 && < 5 + default-language: Haskell2010 + +executable new-template-exe + hs-source-dirs: app + main-is: Main.hs + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: base + , new-template + default-language: Haskell2010 + +test-suite new-template-test + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Spec.hs + build-depends: base + , new-template + ghc-options: -threaded -rtsopts -with-rtsopts=-N + default-language: Haskell2010 + +source-repository head + type: git + location: https://github.com/name/project diff --git a/test/data/stack-project/src/Lib.hs b/test/data/stack-project/src/Lib.hs new file mode 100644 index 0000000..d36ff27 --- /dev/null +++ b/test/data/stack-project/src/Lib.hs @@ -0,0 +1,6 @@ +module Lib + ( someFunc + ) where + +someFunc :: IO () +someFunc = putStrLn "someFunc" diff --git a/test/data/stack-project/test/Spec.hs b/test/data/stack-project/test/Spec.hs new file mode 100644 index 0000000..cd4753f --- /dev/null +++ b/test/data/stack-project/test/Spec.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "Test suite not yet implemented"