Skip to content

Commit 518a913

Browse files
committed
Make test more robust
1 parent 53a178d commit 518a913

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

plugins/hls-hindent-plugin/src/Path/Find.hs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ module Path.Find
1111
,findInParents)
1212
where
1313

14-
import Control.Exception (evaluate)
15-
import Control.DeepSeq (force)
16-
import Control.Monad
17-
import Control.Monad.Catch
18-
import Control.Monad.IO.Class
19-
import System.IO.Error (isPermissionError)
20-
import Data.List
21-
import Path
22-
import Path.IO hiding (findFiles)
23-
import System.PosixCompat.Files (getSymbolicLinkStatus, isSymbolicLink)
14+
import Control.DeepSeq (force)
15+
import Control.Exception (evaluate)
16+
import Control.Monad
17+
import Control.Monad.Catch
18+
import Control.Monad.IO.Class
19+
import Data.List
20+
import Path
21+
import Path.IO hiding (findFiles)
22+
import System.IO.Error (isPermissionError)
23+
import System.PosixCompat.Files (getSymbolicLinkStatus,
24+
isSymbolicLink)
2425

2526
-- | Find the location of a file matching the given predicate.
2627
findFileUp :: (MonadIO m,MonadThrow m)
@@ -95,4 +96,4 @@ findInParents f path = do
9596
let next = parent path
9697
if next == path
9798
then return Nothing
98-
else findInParents f next
99+
else findInParents f next

test/functional/Format.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Control.Lens ((^.))
66
import Control.Monad.IO.Class
77
import Data.Aeson
88
import qualified Data.ByteString.Lazy as BS
9+
import qualified Data.Text as T
910
import qualified Data.Text.Encoding as T
1011
import qualified Data.Text.IO as T
1112
import Language.LSP.Test
@@ -47,8 +48,7 @@ providerTests = testGroup "formatting provider" [
4748
testCase "respects none" $ runSessionWithConfig (formatConfig "none") hlsCommand fullCaps "test/testdata/format" $ do
4849
doc <- openDoc "Format.hs" "haskell"
4950
resp <- request STextDocumentFormatting $ DocumentFormattingParams Nothing doc (FormattingOptions 2 True Nothing Nothing Nothing)
50-
liftIO $ resp ^. LSP.result @?= Left (ResponseError InvalidRequest "No plugin enabled for STextDocumentFormatting, available:\nPluginId \"floskell\"\nPluginId \"fourmolu\"\nPluginId \"ormolu\"\nPluginId \"stylish-haskell\"\nPluginId \"brittany\"\n" Nothing)
51-
51+
liftIO $ foramattingNoneResultCorrect (resp ^. LSP.result) @? "Result incorrect"
5252
, requiresOrmoluPlugin . requiresFloskellPlugin $ testCase "can change on the fly" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
5353
formattedOrmolu <- liftIO $ T.readFile "test/testdata/format/Format.ormolu.formatted.hs"
5454
formattedFloskell <- liftIO $ T.readFile "test/testdata/format/Format.floskell.formatted.hs"
@@ -81,6 +81,10 @@ providerTests = testGroup "formatting provider" [
8181
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
8282
documentContents doc >>= liftIO . (@?= formattedFloskell)
8383
]
84+
where
85+
foramattingNoneResultCorrect (Left (ResponseError InvalidRequest text Nothing)) =
86+
T.isPrefixOf "No plugin enabled for STextDocumentFormatting" text
87+
foramattingNoneResultCorrect _ = False
8488

8589
formatLspConfig :: Value -> Value
8690
formatLspConfig provider = object [ "haskell" .= object ["formattingProvider" .= (provider :: Value)] ]

0 commit comments

Comments
 (0)