Skip to content

Commit 0359222

Browse files
alt-romesclaude
andcommitted
test: check imported module bindings are available in REPL and Evaluate contexts (issue #233)
Adds two integration tests and a helper `evaluateWith` to `Test.DAP`: - `evaluateImportedBindings`: verifies that `Data.List` unqualified imports (`sort`, `nub`) and qualified imports (`Map.lookup`) are in scope when evaluating expressions at a breakpoint. - `replImportedBindings`: same check via the DAP `repl` evaluate context. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1197309 commit 0359222

3 files changed

Lines changed: 66 additions & 2 deletions

File tree

test/haskell/Test/DAP.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,15 @@ continueThread tid = do
333333
pure ()
334334

335335
evaluate :: T.Text -> TestDAP EvaluateResponse
336-
evaluate expr = do
336+
evaluate = evaluateWith Nothing
337+
338+
evaluateWith :: Maybe DAP.EvaluateArgumentsContext -> T.Text -> TestDAP EvaluateResponse
339+
evaluateWith ctx expr = do
337340
Response{responseBody=Just r} <- sync $ evaluateRequest $
338341
EvaluateArguments
339342
{ DAP.evaluateArgumentsExpression = expr
340343
, DAP.evaluateArgumentsFrameId = Nothing
341-
, DAP.evaluateArgumentsContext = Nothing
344+
, DAP.evaluateArgumentsContext = ctx
342345
, DAP.evaluateArgumentsFormat = Nothing
343346
}
344347
return r

test/haskell/Test/Integration/Evaluate.hs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ evaluateTests =
2020
testGroup "DAP.Integration.Evaluate"
2121
[ testCase "Return structured representation for evaluated expressions (issue #116)"
2222
evaluateStructured
23+
, testCase "Imported module bindings available in evaluate context (issue #233)"
24+
evaluateImportedBindings
25+
, testCase "Imported module bindings available in repl context (issue #233)"
26+
replImportedBindings
2327
]
2428

2529
evaluateStructured :: Assertion
@@ -38,3 +42,45 @@ 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 14
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+
-- nub is imported from Data.List
60+
nubResp <- evaluate "show (nub xs)"
61+
liftIO $ assertEqual "nub xs result" "\"[3,1,4,5,9,2,6]\"" (DAP.evaluateResponseResult nubResp)
62+
63+
-- Map is a qualified import
64+
mapResp <- evaluate "show (Map.lookup \"a\" m)"
65+
liftIO $ assertEqual "Map.lookup result" "\"Just 1\"" (DAP.evaluateResponseResult mapResp)
66+
67+
disconnect
68+
69+
-- | Test that bindings from imported modules are available in the REPL context
70+
-- at a breakpoint (issue #233).
71+
replImportedBindings :: Assertion
72+
replImportedBindings =
73+
withTestDAPServer "test/integration/T233" [] $ \test_dir server ->
74+
withTestDAPServerClient server $ do
75+
let cfg = mkLaunchConfig test_dir "T233.hs"
76+
hitBreakpointWith cfg 14
77+
78+
-- sort is imported from Data.List
79+
sortResp <- evaluateWith (Just DAP.EvaluateArgumentsContextRepl) "show (sort xs)"
80+
liftIO $ assertEqual "sort xs result (repl)" "\"[1,1,2,3,4,5,6,9]\"" (DAP.evaluateResponseResult sortResp)
81+
82+
-- Map is a qualified import
83+
mapResp <- evaluateWith (Just DAP.EvaluateArgumentsContextRepl) "show (Map.lookup \"a\" m)"
84+
liftIO $ assertEqual "Map.lookup result (repl)" "\"Just 1\"" (DAP.evaluateResponseResult mapResp)
85+
86+
disconnect

test/integration/T233/T233.hs

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

0 commit comments

Comments
 (0)