@@ -27,8 +27,9 @@ import Ide.Types (IdePlugins (IdePlugins))
27
27
import Language.LSP.Protocol.Lens (arguments , command , range ,
28
28
title )
29
29
import Language.LSP.Protocol.Message hiding (error )
30
- import System.FilePath ((</>) )
30
+ import System.FilePath ((<.>) , (< />) )
31
31
import Test.Hls
32
+ import qualified Test.Hls.FileSystem as FS
32
33
33
34
main :: IO ()
34
35
main = defaultTestRunner tests
@@ -40,27 +41,27 @@ tests :: TestTree
40
41
tests =
41
42
testGroup " eval"
42
43
[ testCase " Produces Evaluate code lenses" $
43
- runSessionWithServer evalPlugin testDataDir $ do
44
+ runSessionWithServerInTmpDir evalPlugin (mkFs $ FS. directProject " T1.hs " ) $ do
44
45
doc <- openDoc " T1.hs" " haskell"
45
46
lenses <- getCodeLenses doc
46
47
liftIO $ map (preview $ command . _Just . title) lenses @?= [Just " Evaluate..." ]
47
48
, testCase " Produces Refresh code lenses" $
48
- runSessionWithServer evalPlugin testDataDir $ do
49
+ runSessionWithServerInTmpDir evalPlugin (mkFs $ FS. directProject " T2.hs " ) $ do
49
50
doc <- openDoc " T2.hs" " haskell"
50
51
lenses <- getCodeLenses doc
51
52
liftIO $ map (preview $ command . _Just . title) lenses @?= [Just " Refresh..." ]
52
53
, testCase " Code lenses have ranges" $
53
- runSessionWithServer evalPlugin testDataDir $ do
54
+ runSessionWithServerInTmpDir evalPlugin (mkFs $ FS. directProject " T1.hs " ) $ do
54
55
doc <- openDoc " T1.hs" " haskell"
55
56
lenses <- getCodeLenses doc
56
57
liftIO $ map (view range) lenses @?= [Range (Position 4 0 ) (Position 5 0 )]
57
58
, testCase " Multi-line expressions have a multi-line range" $ do
58
- runSessionWithServer evalPlugin testDataDir $ do
59
+ runSessionWithServerInTmpDir evalPlugin (mkFs $ FS. directProject " T3.hs " ) $ do
59
60
doc <- openDoc " T3.hs" " haskell"
60
61
lenses <- getCodeLenses doc
61
62
liftIO $ map (view range) lenses @?= [Range (Position 3 0 ) (Position 5 0 )]
62
63
, testCase " Executed expressions range covers only the expression" $ do
63
- runSessionWithServer evalPlugin testDataDir $ do
64
+ runSessionWithServerInTmpDir evalPlugin (mkFs $ FS. directProject " T2.hs " ) $ do
64
65
doc <- openDoc " T2.hs" " haskell"
65
66
lenses <- getCodeLenses doc
66
67
liftIO $ map (view range) lenses @?= [Range (Position 4 0 ) (Position 5 0 )]
@@ -122,15 +123,15 @@ tests =
122
123
]
123
124
, goldenWithEval " :kind! treats a multilined result properly" " T24" " hs"
124
125
, goldenWithEval " :kind treats a multilined result properly" " T25" " hs"
125
- , goldenWithEval " local imports" " T26" " hs"
126
+ , goldenWithEvalAndFs " local imports" ( FS. directProjectMulti [ " T26.hs " , " Util.hs " ]) " T26" " hs"
126
127
, goldenWithEval " Preserves one empty comment line after prompt" " T27" " hs"
127
128
, goldenWithEval " Multi line comments" " TMulti" " hs"
128
129
, goldenWithEval " Multi line comments, with the last test line ends without newline" " TEndingMulti" " hs"
129
130
, goldenWithEval " Evaluate expressions in Plain comments in both single line and multi line format" " TPlainComment" " hs"
130
131
, goldenWithEval " Evaluate expressions in Haddock comments in both single line and multi line format" " THaddock" " hs"
131
132
, goldenWithEval " Compare results (for Haddock tests only)" " TCompare" " hs"
132
- , goldenWithEval " Local Modules imports are accessible in a test" " TLocalImport" " hs"
133
- , goldenWithEval " Transitive local dependency" " TTransitive" " hs"
133
+ , goldenWithEvalAndFs " Local Modules imports are accessible in a test" ( FS. directProjectMulti [ " TLocalImport.hs " , " Util.hs " ]) " TLocalImport" " hs"
134
+ , goldenWithEvalAndFs " Transitive local dependency" ( FS. directProjectMulti [ " TTransitive.hs " , " TLocalImport.hs " , " Util.hs " ]) " TTransitive" " hs"
134
135
-- , goldenWithEval "Local Modules can be imported in a test" "TLocalImportInTest" "hs"
135
136
, goldenWithEval " Setting language option TupleSections" " TLanguageOptionsTupleSections" " hs"
136
137
, goldenWithEval' " :set accepts ghci flags" " TFlags" " hs" (if ghcVersion >= GHC92 then " ghc92.expected" else " expected" )
@@ -142,8 +143,8 @@ tests =
142
143
else " -- id :: forall {a}. a -> a" )
143
144
, goldenWithEval " The default language extensions for the eval plugin are the same as those for ghci" " TSameDefaultLanguageExtensionsAsGhci" " hs"
144
145
, goldenWithEval " IO expressions are supported, stdout/stderr output is ignored" " TIO" " hs"
145
- , goldenWithEval " Property checking" " TProperty" " hs"
146
- , goldenWithEval ' " Property checking with exception" " TPropertyError" " hs" (
146
+ , goldenWithEvalAndFs " Property checking" cabalProjectFS " TProperty" " hs"
147
+ , goldenWithEvalAndFs ' " Property checking with exception" cabalProjectFS " TPropertyError" " hs" (
147
148
if ghcVersion >= GHC96 then
148
149
" ghc96.expected"
149
150
else if ghcVersion >= GHC94 && hostOS == Windows then
@@ -212,7 +213,7 @@ tests =
212
213
not (" Baz Foo" `isInfixOf` output) @? " Output includes instance Baz Foo"
213
214
]
214
215
, testCase " Interfaces are reused after Eval" $ do
215
- runSessionWithServer evalPlugin testDataDir $ do
216
+ runSessionWithServerInTmpDir evalPlugin (mkFs $ FS. directProjectMulti [ " TLocalImport.hs " , " Util.hs " ]) $ do
216
217
doc <- openDoc " TLocalImport.hs" " haskell"
217
218
waitForTypecheck doc
218
219
lenses <- getCodeLenses doc
@@ -231,13 +232,22 @@ tests =
231
232
232
233
goldenWithEval :: TestName -> FilePath -> FilePath -> TestTree
233
234
goldenWithEval title path ext =
234
- goldenWithHaskellDoc evalPlugin title testDataDir path " expected" ext executeLensesBackwards
235
+ goldenWithHaskellDocInTmpDir evalPlugin title (mkFs $ FS. directProject (path <.> ext)) path " expected" ext executeLensesBackwards
236
+
237
+ goldenWithEvalAndFs :: TestName -> [FS. FileTree ] -> FilePath -> FilePath -> TestTree
238
+ goldenWithEvalAndFs title tree path ext =
239
+ goldenWithHaskellDocInTmpDir evalPlugin title (mkFs tree) path " expected" ext executeLensesBackwards
235
240
236
241
-- | Similar function as 'goldenWithEval' with an alternate reference file
237
242
-- naming. Useful when reference file may change because of GHC version.
238
243
goldenWithEval' :: TestName -> FilePath -> FilePath -> FilePath -> TestTree
239
244
goldenWithEval' title path ext expected =
240
- goldenWithHaskellDoc evalPlugin title testDataDir path expected ext executeLensesBackwards
245
+ goldenWithHaskellDocInTmpDir evalPlugin title (mkFs $ FS. directProject (path <.> ext)) path expected ext executeLensesBackwards
246
+
247
+ goldenWithEvalAndFs' :: TestName -> [FS. FileTree ] -> FilePath -> FilePath -> FilePath -> TestTree
248
+ goldenWithEvalAndFs' title tree path ext expected =
249
+ goldenWithHaskellDocInTmpDir evalPlugin title (mkFs tree) path expected ext executeLensesBackwards
250
+
241
251
242
252
-- | Execute lenses backwards, to avoid affecting their position in the source file
243
253
executeLensesBackwards :: TextDocumentIdentifier -> Session ()
@@ -264,7 +274,7 @@ executeCmd cmd = do
264
274
pure ()
265
275
266
276
evalLenses :: FilePath -> IO [CodeLens ]
267
- evalLenses path = runSessionWithServer evalPlugin testDataDir $ do
277
+ evalLenses path = runSessionWithServerInTmpDir evalPlugin (mkFs cabalProjectFS) $ do
268
278
doc <- openDoc path " haskell"
269
279
executeLensesBackwards doc
270
280
getCodeLenses doc
@@ -298,16 +308,43 @@ exceptionConfig exCfg = changeConfig ["exception" .= exCfg]
298
308
299
309
goldenWithEvalConfig' :: TestName -> FilePath -> FilePath -> FilePath -> Config -> TestTree
300
310
goldenWithEvalConfig' title path ext expected cfg =
301
- goldenWithHaskellDoc evalPlugin title testDataDir path expected ext $ \ doc -> do
311
+ goldenWithHaskellDocInTmpDir evalPlugin title (mkFs $ FS. directProject $ path <.> ext) path expected ext $ \ doc -> do
302
312
sendConfigurationChanged (toJSON cfg)
303
313
executeLensesBackwards doc
304
314
305
315
evalInFile :: HasCallStack => FilePath -> T. Text -> T. Text -> IO ()
306
- evalInFile fp e expected = runSessionWithServer evalPlugin testDataDir $ do
316
+ evalInFile fp e expected = runSessionWithServerInTmpDir evalPlugin (mkFs $ FS. directProject fp) $ do
307
317
doc <- openDoc fp " haskell"
308
318
origin <- documentContents doc
309
319
let withEval = origin <> e
310
320
changeDoc doc [TextDocumentContentChangeEvent . InR . (.==) # text $ withEval]
311
321
executeLensesBackwards doc
312
322
result <- fmap T. strip . T. stripPrefix withEval <$> documentContents doc
313
323
liftIO $ result @?= Just (T. strip expected)
324
+
325
+ -- ----------------------------------------------------------------------------
326
+ -- File system definitions
327
+ -- Used for declaring a test file tree
328
+ -- ----------------------------------------------------------------------------
329
+
330
+ mkFs :: [FS. FileTree ] -> FS. VirtualFileTree
331
+ mkFs = FS. mkVirtualFileTree testDataDir
332
+
333
+ cabalProjectFS :: [FS. FileTree ]
334
+ cabalProjectFS = FS. simpleCabalProject'
335
+ [ FS. copy " test.cabal"
336
+ , FS. file " cabal.project"
337
+ (FS. text " packages: ./info-util .\n "
338
+ )
339
+ , FS. copy " TProperty.hs"
340
+ , FS. copy " TPropertyError.hs"
341
+ , FS. copy " TI_Info.hs"
342
+ , FS. copy " TInfo.hs"
343
+ , FS. copy " TInfoBang.hs"
344
+ , FS. copy " TInfoBangMany.hs"
345
+ , FS. copy " TInfoMany.hs"
346
+ , FS. directory " info-util"
347
+ [ FS. copy " info-util/info-util.cabal"
348
+ , FS. copy " info-util/InfoUtil.hs"
349
+ ]
350
+ ]
0 commit comments