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

Commit f68a538

Browse files
committed
Add failing test-cases for #1576
1 parent 86ccb3d commit f68a538

File tree

6 files changed

+102
-34
lines changed

6 files changed

+102
-34
lines changed

haskell-ide-engine.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ test-suite unit-test
220220
, ghc
221221
, haskell-ide-engine
222222
, haskell-lsp-types == 0.19.*
223+
, hie-bios
223224
, hie-test-utils
224225
, hie-plugin-api
225226
, hoogle > 5.0.11
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cabal-version: >=1.10
2+
name: multi-source-dirs
3+
version: 0.1.0.0
4+
license-file: LICENSE
5+
build-type: Simple
6+
7+
library
8+
exposed-modules: Lib, BetterLib
9+
hs-source-dirs: src, src/input
10+
build-depends: base >=4.12 && <5
11+
default-language: Haskell2010
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module BetterLib where
2+
3+
4+
foo = 3
5+
bar = "String"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Lib where
2+
3+
foobar = 15
4+
5+
fizbuzz :: Int -> String
6+
fizbuzz n = "Fizz"

test/unit/CabalHelperSpec.hs

Lines changed: 77 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module CabalHelperSpec where
33

44
import Data.Maybe (isJust)
55
import Haskell.Ide.Engine.Cradle
6+
import HIE.Bios.Types (runCradle, cradleOptsProg, Cradle, CradleLoadResult(..))
67
import Test.Hspec
78
import System.FilePath
89
import System.Directory (findExecutable, getCurrentDirectory, removeFile)
@@ -26,6 +27,9 @@ simpleCabalPath cwd = rootPath cwd </> "simple-cabal"
2627
simpleStackPath :: FilePath -> FilePath
2728
simpleStackPath cwd = rootPath cwd </> "simple-stack"
2829

30+
multiSourceDirsPath :: FilePath -> FilePath
31+
multiSourceDirsPath cwd = rootPath cwd </> "multi-source-dirs"
32+
2933
spec :: Spec
3034
spec = beforeAll_ setupStackFiles $ do
3135
describe "stack and cabal executables should be accesible" $ do
@@ -36,88 +40,124 @@ spec = beforeAll_ setupStackFiles $ do
3640
cabal <- findExecutable "stack"
3741
cabal `shouldSatisfy` isJust
3842
describe "cabal-helper spec" $ do
39-
describe "find cabal entry point spec" findCabalHelperEntryPointSpec
40-
describe "cradle discovery" cabalHelperCradleSpec
43+
describe "find entry point" findCabalHelperEntryPointSpec
44+
describe "cradle discovery and loading" cabalHelperCradleSpec
4145

4246
cabalHelperCradleSpec :: Spec
4347
cabalHelperCradleSpec = do
4448
cwd <- runIO getCurrentDirectory
4549
describe "dummy filepath, finds none-cradle" $ do
46-
it "implicit exe, dummy filepath" $ do
50+
it "implicit exe" $ do
4751
crdl <- cabalHelperCradle (implicitExePath cwd </> "File.hs")
4852
crdl `shouldSatisfy` isCabalCradle
49-
it "mono repo, dummy filepath" $ do
53+
it "mono repo" $ do
5054
crdl <- cabalHelperCradle (monoRepoPath cwd </> "File.hs")
5155
crdl `shouldSatisfy` isCabalCradle
52-
it "stack repo, dummy filepath" $ do
56+
it "stack repo" $ do
5357
crdl <- cabalHelperCradle (simpleStackPath cwd </> "File.hs")
5458
crdl `shouldSatisfy` isStackCradle
55-
it "cabal repo, dummy filepath" $
59+
it "cabal repo" $
5660
pendingWith "Can not work because of global `cabal.project`"
5761
-- crdl <- cabalHelperCradle (simpleCabalPath cwd </> "File.hs")
5862
-- crdl `shouldSatisfy` isCabalCradle
59-
it "sub package, dummy filepath" $ do
63+
it "sub package" $ do
6064
crdl <- cabalHelperCradle (subPackagePath cwd </> "File.hs")
6165
crdl `shouldSatisfy` isStackCradle
66+
it "multi-source-dirs" $ do
67+
crdl <- cabalHelperCradle (multiSourceDirsPath cwd </> "File.hs")
68+
crdl `shouldSatisfy` isStackCradle
6269

63-
describe "Existing projects" $ do
70+
describe "existing projects" $ do
6471
it "implicit exe" $ do
65-
crdl <- cabalHelperCradle (implicitExePath cwd </> "src" </> "Exe.hs")
66-
crdl `shouldSatisfy` isCabalCradle
72+
let fp = implicitExePath cwd </> "src" </> "Exe.hs"
73+
componentTest fp isCabalCradle
6774
it "mono repo" $ do
68-
crdl <- cabalHelperCradle (monoRepoPath cwd </> "A" </> "Main.hs")
69-
crdl `shouldSatisfy` isCabalCradle
75+
let fp = monoRepoPath cwd </> "A" </> "Main.hs"
76+
componentTest fp isCabalCradle
7077
it "stack repo" $ do
71-
crdl <- cabalHelperCradle (simpleStackPath cwd </> "MyLib.hs")
72-
crdl `shouldSatisfy` isStackCradle
78+
let fp = simpleStackPath cwd </> "MyLib.hs"
79+
componentTest fp isStackCradle
7380
it "cabal repo" $
7481
pendingWith "Can not work because of global `cabal.project`"
75-
-- crdl <- cabalHelperCradle (simpleCabalPath cwd </> "MyLib.hs")
76-
-- crdl `shouldSatisfy` isCabalCradle
82+
-- let fp = (simpleCabalPath cwd </> "MyLib.hs")
83+
-- componentTest fp isStackCradle
7784
it "sub package" $ do
78-
crdl <- cabalHelperCradle (subPackagePath cwd </> "plugins-api" </> "PluginLib.hs")
79-
crdl `shouldSatisfy` isStackCradle
85+
let fp = subPackagePath cwd </> "plugins-api" </> "PluginLib.hs"
86+
componentTest fp isStackCradle
87+
it "multi-source-dirs, nested dir" $ do
88+
let fp = multiSourceDirsPath cwd </> "src" </> "input" </> "Lib.hs"
89+
componentTest fp isStackCradle
90+
it "multi-source-dirs" $ do
91+
let fp = multiSourceDirsPath cwd </> "src" </> "BetterLib.hs"
92+
componentTest fp isStackCradle
93+
94+
componentTest :: FilePath -> (Cradle -> Bool) -> Expectation
95+
componentTest fp testCradleType = do
96+
crdl <- cabalHelperCradle fp
97+
crdl `shouldSatisfy` testCradleType
98+
loadComponent crdl fp
99+
100+
loadComponent :: Cradle -> FilePath -> Expectation
101+
loadComponent crdl fp = do
102+
result <- runCradle (cradleOptsProg crdl) (\_ -> return ()) fp
103+
case result of
104+
CradleFail err -> expectationFailure $ "Loading should not have failed: " ++ show err
105+
_ -> return ()
106+
return ()
80107

81108
findCabalHelperEntryPointSpec :: Spec
82109
findCabalHelperEntryPointSpec = do
83110
cwd <- runIO getCurrentDirectory
84111
describe "implicit exe" $ do
85-
it "Find project root with dummy filepath" $ do
112+
it "dummy filepath" $ do
86113
let dummyFile = implicitExePath cwd </> "File.hs"
87114
cabalTest dummyFile
88-
it "Find project root from source component" $ do
115+
it "source component" $ do
89116
let libFile = implicitExePath cwd </> "src" </> "Lib.hs"
90117
cabalTest libFile
91-
it "Find project root from executable component" $ do
118+
it "executable component" $ do
92119
let mainFile = implicitExePath cwd </> "src" </> "Exe.hs"
93120
cabalTest mainFile
94121

95122
describe "mono repo" $ do
96-
it "Find project root with dummy filepath" $ do
123+
it "dummy filepath" $ do
97124
let dummyFile = monoRepoPath cwd </> "File.hs"
98125
cabalTest dummyFile
99-
it "Find project root with existing executable" $ do
126+
it "existing executable" $ do
100127
let mainFile = monoRepoPath cwd </> "A" </> "Main.hs"
101128
cabalTest mainFile
102129

103130
describe "sub package repo" $ do
104-
it "Find project root with dummy filepath" $ do
131+
it "dummy filepath" $ do
105132
let dummyFile = subPackagePath cwd </> "File.hs"
106133
stackTest dummyFile
107-
it "Find project root with existing executable" $ do
134+
it "existing executable" $ do
108135
let mainFile = subPackagePath cwd </> "plugins-api" </> "PluginLib.hs"
109136
stackTest mainFile
110137

111138
describe "stack repo" $ do
112-
it "Find project root with dummy filepath" $ do
139+
it "dummy filepath" $ do
113140
let dummyFile = simpleStackPath cwd </> "File.hs"
114141
stackTest dummyFile
115-
it "Find project root with real filepath" $ do
142+
it "real filepath" $ do
116143
let dummyFile = simpleStackPath cwd </> "MyLib.hs"
117144
stackTest dummyFile
118145

146+
describe "multi-source-dirs" $ do
147+
it "dummy filepath" $ do
148+
let dummyFile = multiSourceDirsPath cwd </> "File.hs"
149+
stackTest dummyFile
150+
151+
it "real filepath" $ do
152+
let dummyFile = multiSourceDirsPath cwd </> "src" </> "BetterLib.hs"
153+
stackTest dummyFile
154+
155+
it "nested filpath" $ do
156+
let dummyFile = multiSourceDirsPath cwd </> "src" </> "input" </> "Lib.hs"
157+
stackTest dummyFile
158+
119159
describe "simple cabal repo" $
120-
it "Find porject root with dummy filepath" $
160+
it "Find project root with dummy filepath" $
121161
pendingWith "Change test-setup, we will always find `cabal.project` in root dir"
122162

123163
-- -------------------------------------------------------------
@@ -141,20 +181,23 @@ stackTest fp = do
141181
setupStackFiles :: IO ()
142182
setupStackFiles = do
143183
resolver <- readResolver
144-
cwd <- getCurrentDirectory
184+
cwd <- getCurrentDirectory
145185
writeFile (implicitExePath cwd </> "stack.yaml") (standardStackYaml resolver)
146-
writeFile (monoRepoPath cwd </> "stack.yaml") (monoRepoStackYaml resolver)
147-
writeFile (subPackagePath cwd </> "stack.yaml") (subPackageStackYaml resolver)
186+
writeFile (monoRepoPath cwd </> "stack.yaml") (monoRepoStackYaml resolver)
187+
writeFile (subPackagePath cwd </> "stack.yaml") (subPackageStackYaml resolver)
148188
writeFile (simpleStackPath cwd </> "stack.yaml") (standardStackYaml resolver)
189+
writeFile (multiSourceDirsPath cwd </> "stack.yaml")
190+
(standardStackYaml resolver)
149191

150192

151193
cleanupStackFiles :: IO ()
152194
cleanupStackFiles = do
153-
cwd <- getCurrentDirectory
195+
cwd <- getCurrentDirectory
154196
removeFile (implicitExePath cwd </> "stack.yaml")
155-
removeFile (monoRepoPath cwd </> "stack.yaml")
156-
removeFile (subPackagePath cwd </> "stack.yaml")
197+
removeFile (monoRepoPath cwd </> "stack.yaml")
198+
removeFile (subPackagePath cwd </> "stack.yaml")
157199
removeFile (simpleStackPath cwd </> "stack.yaml")
200+
removeFile (multiSourceDirsPath cwd </> "stack.yaml")
158201

159202
-- -------------------------------------------------------------
160203

0 commit comments

Comments
 (0)