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 #-}
44module Test.Integration.Evaluate (evaluateTests ) where
55
66import Control.Monad.IO.Class (liftIO )
7+ import Data.List (isInfixOf )
78import Test.DAP
89import Test.Tasty
910import Test.Tasty.HUnit
10- #ifdef mingw32_HOST_OS
1111import Test.Tasty.ExpectedFailure
12- #endif
1312import qualified DAP
1413
1514evaluateTests :: 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
2529evaluateStructured :: 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
0 commit comments