Skip to content

Commit

Permalink
Add test for inconsistent diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
wz1000 authored and pepeiborra committed Jun 17, 2020
1 parent 1f3639e commit 459b3e4
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/data/recomp/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
1 change: 1 addition & 0 deletions test/data/recomp/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
1 change: 1 addition & 0 deletions test/data/recomp/hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cradle: {cabal: {component: "lib:recomp"}}
6 changes: 6 additions & 0 deletions test/data/recomp/lib/A.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module A where

import B

x :: Int
x = y
4 changes: 4 additions & 0 deletions test/data/recomp/lib/B.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module B where

y :: Int
y = undefined
5 changes: 5 additions & 0 deletions test/data/recomp/lib/P.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module P where
import A
import B

bar = x :: Int
13 changes: 13 additions & 0 deletions test/data/recomp/recomp.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cabal-version: >=1.10
name: recomp
version: 0.1.0.0
author: Zubin Duggal
maintainer: [email protected]
build-type: Simple

library
exposed-modules: A, B, P
ghc-options: -Wmissing-signatures
hs-source-dirs: lib
build-depends: base
default-language: Haskell2010
40 changes: 40 additions & 0 deletions test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ diagnosticTests = testGroup "diagnostics"
Lens.filtered (T.isInfixOf ("/" <> name <> ".hs:"))
failure msg = liftIO $ assertFailure $ "Expected file path to be stripped but got " <> T.unpack msg
Lens.mapMOf_ offenders failure notification
, ifaceErrorTest
]

codeActionTests :: TestTree
Expand Down Expand Up @@ -2190,6 +2191,45 @@ simpleMultiTest2 = testCase "simple-multi-test2" $ withoutStackEnv $ runWithExtr
checkDefs locs (pure [fooL])
expectNoMoreDiagnostics 0.5

ifaceErrorTest :: TestTree
ifaceErrorTest = testCase "iface-error-test" $ withoutStackEnv $ runWithExtraFiles "recomp" $ \dir -> do
let aPath = dir </> "lib/A.hs"
bPath = dir </> "lib/B.hs"
pPath = dir </> "lib/P.hs"

aSource <- liftIO $ readFileUtf8 aPath -- x = y :: Int
bSource <- liftIO $ readFileUtf8 bPath -- y :: Int
pSource <- liftIO $ readFileUtf8 pPath -- bar = x :: Int

bdoc <- createDoc bPath "haskell" bSource
pdoc <- createDoc pPath "haskell" pSource
expectDiagnostics [("lib/P.hs", [(DsWarning,(4,0), "Top-level binding")]) -- So what we know P has been loaded
]

-- Change y from Int to B
changeDoc bdoc [TextDocumentContentChangeEvent Nothing Nothing $ T.unlines ["module B where", "y :: Bool", "y = undefined"]]

-- Check that the error propogates to A
adoc <- createDoc aPath "haskell" aSource
expectDiagnostics
[("lib/A.hs", [(DsError, (5, 4), "Couldn't match expected type 'Int' with actual type 'Bool'")])]
closeDoc adoc -- Close A

changeDoc pdoc [TextDocumentContentChangeEvent Nothing Nothing $ pSource <> "\nfoo = y :: Bool" ]
-- Now in P we have
-- bar = x :: Int
-- foo = y :: Bool
-- HOWEVER, in A...
-- x = y :: Int
-- This is clearly inconsistent, yet we don't get an error
expectDiagnostics [("lib/P.hs", [(DsWarning,(4,0), "Top-level binding")])
,("lib/P.hs", [(DsWarning,(6,0), "Top-level binding")])
]
expectDiagnostics
[("lib/A.hs", [(DsError, (5, 4), "Couldn't match expected type 'Int' with actual type 'Bool'")])]
expectNoMoreDiagnostics 2


sessionDepsArePickedUp :: TestTree
sessionDepsArePickedUp = testSession'
"session-deps-are-picked-up"
Expand Down

0 comments on commit 459b3e4

Please sign in to comment.