Skip to content

Commit da0ac64

Browse files
committed
WIP add test for different async versions
1 parent d0c18d3 commit da0ac64

File tree

7 files changed

+83
-0
lines changed

7 files changed

+83
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
packages: ./dependency-new
2+
./dependency-old
3+
package *
4+
ghc-options: -fwrite-ide-info
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Dependency where
2+
3+
import Control.Concurrent.Async (AsyncCancelled (..))
4+
5+
asyncCancelled :: AsyncCancelled
6+
asyncCancelled = AsyncCancelled
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: dependency-new
2+
version: 0.1.0.0
3+
cabal-version: 2.0
4+
build-type: Simple
5+
6+
library
7+
exposed-modules: Dependency
8+
default-language: Haskell2010
9+
build-depends: base
10+
, async == 2.2.4
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Dependency where
2+
3+
import Control.Concurrent.Async (AsyncCancelled (..))
4+
5+
asyncCancelled :: AsyncCancelled
6+
asyncCancelled = AsyncCancelled
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: dependency-old
2+
version: 0.1.0.0
3+
cabal-version: 2.0
4+
build-type: Simple
5+
6+
library
7+
exposed-modules: Dependency
8+
default-language: Haskell2010
9+
build-depends: base
10+
, async == 2.2.1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cradle:
2+
cabal:

ghcide/test/exe/Dependency.hs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ tests :: TestTree
3131
tests =
3232
testGroup "gotoDefinition for dependencies"
3333
[ dependencyTest
34+
, multiComponentDependencyTest
3435
]
3536
where
3637
dependencyTest :: TestTree
@@ -70,3 +71,47 @@ tests =
7071
bool Applicative.empty (pure fp) $
7172
fpSuffix `isSuffixOf` fpDirs
7273
other -> error $ "Failed to parse ghcide/reference/ready file: " <> show other
74+
75+
multiComponentDependencyTest :: TestTree
76+
multiComponentDependencyTest = testSessionWithExtraFiles "multi-component-dependency" "gotoDefinition in different versions of async" $
77+
\dir -> do
78+
docOld <- openDoc (dir </> "dependency-old" </> "Dependency" <.> "hs") "haskell"
79+
docNew <- openDoc (dir </> "dependency-new" </> "Dependency" <.> "hs") "haskell"
80+
_hieFile1 <- fileDoneIndexing ["Control", "Concurrent", "Async.hie"]
81+
_hieFile2 <- fileDoneIndexing ["Control", "Concurrent", "Async.hie"]
82+
defsOld <- getDefinitions docOld (Position 5 20)
83+
defsNew <- getDefinitions docNew (Position 5 20)
84+
-- The location of AsyncCancelled in async 2.2.1
85+
let expRangeOld = Range (Position 357 22) (Position 430 36)
86+
-- The location of AsyncCancelled in async 2.2.4
87+
expRangeNew = Range (Position 430 22) (Position 430 36)
88+
case defsOld of
89+
InL (Definition (InR [Location fp actualRange])) ->
90+
liftIO $ do
91+
let locationDirectories :: [String]
92+
locationDirectories =
93+
maybe [] splitDirectories $
94+
uriToFilePath fp
95+
assertBool "AsyncCancelled found in a module that is not Control.Concurrent Async"
96+
$ ["Control", "Concurrent", "Async.hs"]
97+
`isSuffixOf` locationDirectories
98+
actualRange @?= expRangeOld
99+
wrongLocation ->
100+
liftIO $
101+
assertFailure $ "Wrong location for AsyncCancelled in async 2.2.1: "
102+
++ show wrongLocation
103+
case defsNew of
104+
InL (Definition (InR [Location fp actualRange])) ->
105+
liftIO $ do
106+
let locationDirectories :: [String]
107+
locationDirectories =
108+
maybe [] splitDirectories $
109+
uriToFilePath fp
110+
assertBool "AsyncCancelled found in a module that is not Control.Concurrent Async"
111+
$ ["Control", "Concurrent", "Async.hs"]
112+
`isSuffixOf` locationDirectories
113+
actualRange @?= expRangeNew
114+
wrongLocation ->
115+
liftIO $
116+
assertFailure $ "Wrong location for AsyncCancelled in async 2.2.4: "
117+
++ show wrongLocation

0 commit comments

Comments
 (0)