Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hspec-expectations #260

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ test-suite func-test
, haskell-language-server
, haskell-lsp
, haskell-lsp-types
, hspec-expectations
, lens
, lsp-test >= 0.11.0.3
, tasty
Expand Down
7 changes: 3 additions & 4 deletions test/functional/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Test.Hls.Util
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Hspec.Expectations


--TODO : Response Message no longer has 4 inputs
Expand All @@ -24,8 +23,8 @@ tests = testGroup "commands" [
let List cmds = res ^. LSP.capabilities . executeCommandProvider . _Just . commands
f x = (T.length (T.takeWhile isNumber x) >= 1) && (T.count ":" x >= 2)
liftIO $ do
cmds `shouldSatisfy` all f
cmds `shouldNotSatisfy` null
all f cmds @? "All prefixed"
not (null cmds) @? "Commands aren't empty"
, ignoreTestBecause "Broken: Plugin package doesn't exist" $
testCase "get de-prefixed" $
runSession hieCommand fullCaps "test/testdata/" $ do
Expand All @@ -34,5 +33,5 @@ tests = testGroup "commands" [
(ExecuteCommandParams "1234:package:add" (Just (List [])) Nothing) :: Session ExecuteCommandResponse
let ResponseError _ msg _ = err
-- We expect an error message about the dud arguments, but should pickup "add" and "package"
liftIO $ msg `shouldSatisfy` T.isInfixOf "while parsing args for add in plugin package"
liftIO $ (msg `T.isInfixOf` "while parsing args for add in plugin package") @? "Has error message"
]
149 changes: 74 additions & 75 deletions test/functional/Completion.hs

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions test/functional/Deferred.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import Test.Hspec.Expectations


tests :: TestTree
Expand All @@ -30,16 +29,16 @@ tests = testGroup "deferred responses" [

-- skipMany anyNotification
-- hoverRsp <- message :: Session HoverResponse
-- liftIO $ hoverRsp ^? result . _Just . _Just . contents `shouldBe` Nothing
-- liftIO $ hoverRsp ^. LSP.id `shouldBe` responseId id1
-- liftIO $ hoverRsp ^? result . _Just . _Just . contents @?= Nothing
-- liftIO $ hoverRsp ^. LSP.id @?= responseId id1

-- id2 <- sendRequest TextDocumentDocumentSymbol (DocumentSymbolParams doc Nothing)
-- symbolsRsp <- skipManyTill anyNotification message :: Session DocumentSymbolsResponse
-- liftIO $ symbolsRsp ^. LSP.id `shouldBe` responseId id2
-- liftIO $ symbolsRsp ^. LSP.id @?= responseId id2

-- id3 <- sendRequest TextDocumentHover (TextDocumentPositionParams doc (Position 4 2) Nothing)
-- hoverRsp2 <- skipManyTill anyNotification message :: Session HoverResponse
-- liftIO $ hoverRsp2 ^. LSP.id `shouldBe` responseId id3
-- liftIO $ hoverRsp2 ^. LSP.id @?= responseId id3

-- let contents2 = hoverRsp2 ^? result . _Just . _Just . contents
-- liftIO $ contents2 `shouldNotSatisfy` null
Expand All @@ -48,7 +47,7 @@ tests = testGroup "deferred responses" [
-- let highlightParams = TextDocumentPositionParams doc (Position 7 0) Nothing
-- highlightRsp <- request TextDocumentDocumentHighlight highlightParams
-- let (Just (List locations)) = highlightRsp ^. result
-- liftIO $ locations `shouldBe` [ DocumentHighlight
-- liftIO $ locations @?= [ DocumentHighlight
-- { _range = Range
-- { _start = Position {_line = 7, _character = 0}
-- , _end = Position {_line = 7, _character = 2}
Expand Down Expand Up @@ -95,15 +94,15 @@ tests = testGroup "deferred responses" [
testCase "instantly respond to failed modules with no cache" $ runSession hieCommand fullCaps "test/testdata" $ do
doc <- openDoc "FuncTestFail.hs" "haskell"
defs <- getDefinitions doc (Position 1 11)
liftIO $ defs `shouldBe` []
liftIO $ defs @?= []

-- TODO: the benefits of caching parsed modules is doubted.
-- TODO: add issue link
-- , testCase "respond to untypecheckable modules with parsed module cache" $
-- runSession hieCommand fullCaps "test/testdata" $ do
-- doc <- openDoc "FuncTestFail.hs" "haskell"
-- (Left (sym:_)) <- getDocumentSymbols doc
-- liftIO $ sym ^. name `shouldBe` "main"
-- liftIO $ sym ^. name @?= "main"

-- TODO does not compile
-- , testCase "returns hints as diagnostics" $ runSession hieCommand fullCaps "test/testdata" $ do
Expand All @@ -113,7 +112,7 @@ tests = testGroup "deferred responses" [
-- let testUri = filePathToUri $ cwd </> "test/testdata/FuncTest.hs"

-- diags <- skipManyTill loggingNotification publishDiagnosticsNotification
-- liftIO $ diags ^? params `shouldBe` (Just $ PublishDiagnosticsParams
-- liftIO $ diags ^? params @?= (Just $ PublishDiagnosticsParams
-- { _uri = testUri
-- , _diagnostics = List
-- [ Diagnostic
Expand All @@ -130,12 +129,12 @@ tests = testGroup "deferred responses" [
-- args = List [Object args']
--
-- executeRsp <- request WorkspaceExecuteCommand (ExecuteCommandParams "hare:demote" (Just args) Nothing)
-- liftIO $ executeRsp ^. result `shouldBe` Just (Object H.empty)
-- liftIO $ executeRsp ^. result @?= Just (Object H.empty)

-- editReq <- message :: Session ApplyWorkspaceEditRequest
-- let expectedTextEdits = List [TextEdit (Range (Position 6 0) (Position 7 6)) " where\n bb = 5"]
-- expectedTextDocEdits = List [TextDocumentEdit (VersionedTextDocumentIdentifier testUri (Just 0)) expectedTextEdits]
-- liftIO $ editReq ^. params . edit `shouldBe` WorkspaceEdit
-- liftIO $ editReq ^. params . edit @?= WorkspaceEdit
-- Nothing
-- (Just expectedTextDocEdits)
-- , multiServerTests
Expand Down Expand Up @@ -165,13 +164,13 @@ multiMainTests = testGroup "multiple main modules" [
diagsRspGhc <- skipManyTill anyNotification message :: Session PublishDiagnosticsNotification
let (List diags) = diagsRspGhc ^. params . diagnostics

liftIO $ length diags `shouldBe` 2
liftIO $ length diags @?= 2

_doc2 <- openDoc "HaReRename.hs" "haskell"
_diagsRspHlint2 <- skipManyTill anyNotification message :: Session PublishDiagnosticsNotification
-- errMsg <- skipManyTill anyNotification notification :: Session ShowMessageNotification
diagsRsp2 <- skipManyTill anyNotification message :: Session PublishDiagnosticsNotification
let (List diags2) = diagsRsp2 ^. params . diagnostics

liftIO $ show diags2 `shouldBe` "[]"
liftIO $ show diags2 @?= "[]"
]
11 changes: 5 additions & 6 deletions test/functional/Definition.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import Test.Hspec.Expectations

tests :: TestTree
tests = testGroup "definitions" [
Expand All @@ -20,7 +19,7 @@ tests = testGroup "definitions" [
doc <- openDoc "References.hs" "haskell"
defs <- getDefinitions doc (Position 7 8)
let expRange = Range (Position 4 0) (Position 4 3)
liftIO $ defs `shouldBe` [Location (doc ^. uri) expRange]
liftIO $ defs @?= [Location (doc ^. uri) expRange]

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

Expand All @@ -30,15 +29,15 @@ tests = testGroup "definitions" [
defs <- getDefinitions doc (Position 2 8)
liftIO $ do
fp <- canonicalizePath "test/testdata/definition/Bar.hs"
defs `shouldBe` [Location (filePathToUri fp) zeroRange]
defs @?= [Location (filePathToUri fp) zeroRange]

, ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/Bar.hs" $
testCase "goto's exported modules" $ runSession hieCommand fullCaps "test/testdata/definition" $ do
doc <- openDoc "Foo.hs" "haskell"
defs <- getDefinitions doc (Position 0 15)
liftIO $ do
fp <- canonicalizePath "test/testdata/definition/Bar.hs"
defs `shouldBe` [Location (filePathToUri fp) zeroRange]
defs @?= [Location (filePathToUri fp) zeroRange]

, ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/Bar.hs" $
testCase "goto's imported modules that are loaded" $ runSession hieCommand fullCaps "test/testdata/definition" $ do
Expand All @@ -47,7 +46,7 @@ tests = testGroup "definitions" [
defs <- getDefinitions doc (Position 2 8)
liftIO $ do
fp <- canonicalizePath "test/testdata/definition/Bar.hs"
defs `shouldBe` [Location (filePathToUri fp) zeroRange]
defs @?= [Location (filePathToUri fp) zeroRange]

, ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/Bar.hs" $
testCase "goto's imported modules that are loaded, and then closed" $
Expand All @@ -60,7 +59,7 @@ tests = testGroup "definitions" [
liftIO $ putStrLn "D"
liftIO $ do
fp <- canonicalizePath "test/testdata/definition/Bar.hs"
defs `shouldBe` [Location (filePathToUri fp) zeroRange]
defs @?= [Location (filePathToUri fp) zeroRange]
liftIO $ putStrLn "E" -- AZ

noDiagnostics
Expand Down
31 changes: 15 additions & 16 deletions test/functional/Diagnostic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import Test.Hspec.Expectations

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

Expand All @@ -41,26 +40,26 @@ triggerTests = testGroup "diagnostics triggers" [
diags@(reduceDiag:_) <- waitForDiagnostics

liftIO $ do
length diags `shouldBe` 2
reduceDiag ^. LSP.range `shouldBe` Range (Position 1 0) (Position 1 12)
reduceDiag ^. LSP.severity `shouldBe` Just DsInfo
reduceDiag ^. LSP.code `shouldBe` Just (StringValue "Eta reduce")
reduceDiag ^. LSP.source `shouldBe` Just "hlint"
length diags @?= 2
reduceDiag ^. LSP.range @?= Range (Position 1 0) (Position 1 12)
reduceDiag ^. LSP.severity @?= Just DsInfo
reduceDiag ^. LSP.code @?= Just (StringValue "Eta reduce")
reduceDiag ^. LSP.source @?= Just "hlint"

diags2a <- waitForDiagnostics

liftIO $ length diags2a `shouldBe` 2
liftIO $ length diags2a @?= 2

sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc)

diags3@(d:_) <- waitForDiagnosticsSource "eg2"

liftIO $ do
length diags3 `shouldBe` 1
d ^. LSP.range `shouldBe` Range (Position 0 0) (Position 1 0)
d ^. LSP.severity `shouldBe` Nothing
d ^. LSP.code `shouldBe` Nothing
d ^. LSP.message `shouldBe` T.pack "Example plugin diagnostic, triggered byDiagnosticOnSave"
length diags3 @?= 1
d ^. LSP.range @?= Range (Position 0 0) (Position 1 0)
d ^. LSP.severity @?= Nothing
d ^. LSP.code @?= Nothing
d ^. LSP.message @?= T.pack "Example plugin diagnostic, triggered byDiagnosticOnSave"
]

errorTests :: TestTree
Expand All @@ -69,7 +68,7 @@ errorTests = testGroup "typed hole errors" [
runSession hieCommand fullCaps "test/testdata" $ do
_ <- openDoc "TypedHoles.hs" "haskell"
[diag] <- waitForDiagnosticsSource "bios"
liftIO $ diag ^. LSP.severity `shouldBe` Just DsWarning
liftIO $ diag ^. LSP.severity @?= Just DsWarning
]

warningTests :: TestTree
Expand All @@ -78,7 +77,7 @@ warningTests = testGroup "Warnings are warnings" [
runSession hieCommand fullCaps "test/testdata/wErrorTest" $ do
_ <- openDoc "src/WError.hs" "haskell"
[diag] <- waitForDiagnosticsSource "bios"
liftIO $ diag ^. LSP.severity `shouldBe` Just DsWarning
liftIO $ diag ^. LSP.severity @?= Just DsWarning
]

saveTests :: TestTree
Expand All @@ -91,7 +90,7 @@ saveTests = testGroup "only diagnostics on save" [
diags <- waitForDiagnostics

liftIO $ do
length diags `shouldBe` 0
length diags @?= 0

let te = TextEdit (Range (Position 0 0) (Position 0 13)) ""
_ <- applyEdit doc te
Expand All @@ -100,5 +99,5 @@ saveTests = testGroup "only diagnostics on save" [
sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc)
diags2 <- waitForDiagnostics
liftIO $
length diags2 `shouldBe` 1
length diags2 @?= 1
]
6 changes: 6 additions & 0 deletions test/functional/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ stylishHaskellTests = testGroup "stylish-haskell" [
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
]

#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0) || !defined(AGPL)
#else
brittanyTests :: TestTree
brittanyTests = testGroup "brittany" [
goldenVsStringDiff "formats a document with LF endings" goldenGitDiff "test/testdata/BrittanyLF.formatted_document.hs" $ runSession hieCommand fullCaps "test/testdata" $ do
Expand Down Expand Up @@ -141,6 +143,7 @@ brittanyTests = testGroup "brittany" [
formatRange doc (FormattingOptions 4 True) range
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
]
#endif

ormoluTests :: TestTree
ormoluTests = testGroup "ormolu" [
Expand All @@ -160,9 +163,12 @@ ormoluTests = testGroup "ormolu" [
formatLspConfig :: Value -> Value
formatLspConfig provider = object [ "haskell" .= object ["formattingProvider" .= (provider :: Value)] ]

#if MIN_VERSION_GLASGOW_HASKELL(8,10,0,0) || !defined(AGPL)
#else
-- | The same as 'formatLspConfig' but using the legacy section name
formatLspConfigOld :: Value -> Value
formatLspConfigOld provider = object [ "languageServerHaskell" .= object ["formattingProvider" .= (provider :: Value)] ]
#endif

formatConfig :: Value -> SessionConfig
formatConfig provider = defaultConfig { lspConfig = Just (formatLspConfig provider) }
Expand Down
17 changes: 8 additions & 9 deletions test/functional/FunctionalBadProject.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module FunctionalBadProject (tests) where
-- import Test.Hls.Util
import Test.Tasty
import Test.Tasty.HUnit
import Test.Hspec.Expectations

-- ---------------------------------------------------------------------
-- TODO: Currently this can not succeed, since such an error is thrown in "runActionWithContext" which
Expand All @@ -20,7 +19,7 @@ import Test.Hspec.Expectations
--
tests :: TestTree
tests = testGroup "behaviour on malformed projects" [
testCase "no test executed" $ True `shouldBe` True
testCase "no test executed" $ True @?= True
]

-- testCase "deals with cabal file with unsatisfiable dependency" $
Expand All @@ -29,14 +28,14 @@ tests = testGroup "behaviour on malformed projects" [
-- _doc <- openDoc "Foo.hs" "haskell"

-- diags@(d:_) <- waitForDiagnosticsSource "bios"
-- -- liftIO $ show diags `shouldBe` ""
-- -- liftIO $ show diags @?= ""
-- -- liftIO $ putStrLn $ show diags
-- -- liftIO $ putStrLn "a"
-- liftIO $ do
-- length diags `shouldBe` 1
-- d ^. range `shouldBe` Range (Position 0 0) (Position 1 0)
-- d ^. severity `shouldBe` (Just DsError)
-- d ^. code `shouldBe` Nothing
-- d ^. source `shouldBe` Just "bios"
-- d ^. message `shouldBe`
-- length diags @?= 1
-- d ^. range @?= Range (Position 0 0) (Position 1 0)
-- d ^. severity @?= (Just DsError)
-- d ^. code @?= Nothing
-- d ^. source @?= Just "bios"
-- d ^. message @?=
-- (T.pack "readCreateProcess: stack \"build\" \"--only-configure\" \".\" (exit 1): failed\n")
Loading