Skip to content

Commit 569babf

Browse files
committed
test: Modules imported at breakpoint are available
Checks that the bindings imported from other modules at a specific breakpoint can be used when stopped there, with the same qualified names. E.g. `sort` and `nub` are imported, and `Map.lookup` works where `Map` is imported `qualified as Map` at the module in which we break. A second one tests that continuing from a breakpoint that has `Map` in scope, and stopping at a breakpoint which doesn't, then `Map` should no longer be available in scope. This one is currently failing. The evaluation succeeds somehow. Fixes #233
1 parent 1d84b81 commit 569babf

3 files changed

Lines changed: 82 additions & 3 deletions

File tree

test/haskell/Test/Integration/Evaluate.hs

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
-- | Evaluate request tests (issue #116) ported from the NodeJS testsuite.
1+
-- | Evaluate request tests ported from the NodeJS testsuite.
22
{-# LANGUAGE CPP #-}
33
{-# LANGUAGE OverloadedStrings #-}
44
module Test.Integration.Evaluate (evaluateTests) where
55

66
import Control.Monad.IO.Class (liftIO)
7+
import Data.List (isInfixOf)
78
import Test.DAP
89
import Test.Tasty
910
import Test.Tasty.HUnit
10-
#ifdef mingw32_HOST_OS
1111
import Test.Tasty.ExpectedFailure
12-
#endif
1312
import qualified DAP
1413

1514
evaluateTests :: TestTree
@@ -20,6 +19,11 @@ evaluateTests =
2019
testGroup "DAP.Integration.Evaluate"
2120
[ testCase "Return structured representation for evaluated expressions (issue #116)"
2221
evaluateStructured
22+
, testCase "Imported module bindings available in evaluate context (issue #233)"
23+
evaluateImportedBindings
24+
, expectFailBecause "#299" $
25+
testCase "Bindings from other modules not available in evaluate context (issue #233)"
26+
evaluateImportedBindingsNotInOtherModule
2327
]
2428

2529
evaluateStructured :: Assertion
@@ -38,3 +42,55 @@ evaluateStructured =
3842
[] -> liftIO $ assertFailure $
3943
"No variable named 1 in evaluation result: " ++ show respChildren
4044
disconnect
45+
46+
-- | Test that bindings from imported modules are available when evaluating
47+
-- expressions at a breakpoint (issue #233).
48+
evaluateImportedBindings :: Assertion
49+
evaluateImportedBindings =
50+
withTestDAPServer "test/integration/T233" [] $ \test_dir server ->
51+
withTestDAPServerClient server $ do
52+
let cfg = mkLaunchConfig test_dir "T233.hs"
53+
hitBreakpointWith cfg 15
54+
55+
-- sort is imported from Data.List
56+
sortResp <- evaluate "show (sort xs)"
57+
liftIO $ assertEqual "sort xs result" "\"[1,1,2,3,4,5,6,9]\"" (DAP.evaluateResponseResult sortResp)
58+
59+
-- Map is a qualified import
60+
mapResp <- evaluate "show (Map.lookup \"a\" m)"
61+
liftIO $ assertEqual "Map.lookup result" "\"Just 1\"" (DAP.evaluateResponseResult mapResp)
62+
63+
disconnect
64+
65+
-- | Test that bindings from modules not imported at the stopped location are
66+
-- NOT available in the evaluate context (issue #233).
67+
evaluateImportedBindingsNotInOtherModule :: Assertion
68+
evaluateImportedBindingsNotInOtherModule =
69+
withTestDAPServer "test/integration/T233" [] $ \test_dir server ->
70+
withTestDAPServerClient server $ do
71+
let cfg = mkLaunchConfig test_dir "T233.hs"
72+
73+
_ <- sync $ launchWith cfg
74+
waitFiltering_ EventTy "initialized"
75+
-- T233.hs imports Data.Map.Strict as Map; Other.hs does not
76+
_ <- sync $ setLineBreakpoints test_dir "T233.hs" [15]
77+
_ <- sync $ setLineBreakpoints test_dir "Other.hs" [4]
78+
_ <- sync configurationDone
79+
_ <- assertStoppedLocation DAP.StoppedEventReasonBreakpoint 15
80+
81+
-- Stopped in T233.hs which imports Data.List and Data.Map.Strict as Map
82+
sortResp <- evaluate "show (sort xs)"
83+
liftIO $ assertEqual "sort xs result" "\"[1,1,2,3,4,5,6,9]\"" (DAP.evaluateResponseResult sortResp)
84+
85+
-- Resume and stop at breakpoint in Other.hs, which does not import Map
86+
continueThread 0
87+
_ <- assertStoppedLocation DAP.StoppedEventReasonBreakpoint 4
88+
89+
-- Map is not imported in Other.hs; evaluating Map.fromList should fail
90+
mapFailResp <- evaluate "Map.fromList [(1,'a')]"
91+
let result = DAP.evaluateResponseResult mapFailResp
92+
liftIO $ assertBool
93+
("expected 'not in scope' error for Map.fromList, got: " ++ show result)
94+
("not in scope" `isInfixOf` show result)
95+
96+
disconnect

test/integration/T233/Other.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Other where
2+
3+
process :: [Int] -> IO ()
4+
process xs = do
5+
let n = length xs
6+
print n

test/integration/T233/T233.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Main where
2+
3+
import Data.List (sort, nub)
4+
import qualified Data.Map.Strict as Map
5+
import Other (process)
6+
7+
main :: IO ()
8+
main = do
9+
let xs = [3, 1, 4, 1, 5, 9, 2, 6] :: [Int]
10+
let m = Map.fromList [("a", 1), ("b", 2)] :: Map.Map String Int
11+
check xs m
12+
process xs
13+
14+
check :: [Int] -> Map.Map String Int -> IO ()
15+
check xs m = do
16+
print xs
17+
print m

0 commit comments

Comments
 (0)