@@ -8,9 +8,7 @@ import qualified Data.Text as T
88import Test.DAP
99import Test.Tasty
1010import Test.Tasty.HUnit
11- #ifdef mingw32_HOST_OS
1211import Test.Tasty.ExpectedFailure
13- #endif
1412import DAP (Variable , variableValue )
1513
1614variableTests :: TestTree
@@ -33,6 +31,8 @@ variableTests =
3331 , testCase " hdv with containers (issue #47c)" hdvContainersDepTest
3432 , testCase " hdv in-memory with containers (issue #47d)" hdvContainersMemTest
3533 , testCase " hdv in-memory with text (issue #47e)" hdvTextMemTest
34+ , expectFailBecause " issue #301" $
35+ testCase " force thunk in custom DebugView field (issue #301)" thunkFieldTest
3636 ]
3737
3838intsAndStringsTest :: Assertion
@@ -319,3 +319,29 @@ hdvTextMemTest =
319319 action <- forceLazy (locals % " action" )
320320 action @==? " \" this should be displayed as a simple string\" "
321321 disconnect
322+
323+ -- | A custom DebugView field that wraps a thunk, when forced, should return
324+ -- the forced value. A subsequent request should still show the result forced.
325+ -- It is no longer a thunk after being forced the first time!
326+ --
327+ -- Issue #301 observes that the subsequent request showed the field again as a
328+ -- thunk.
329+ thunkFieldTest :: Assertion
330+ thunkFieldTest =
331+ withTestDAPServer " test/integration/T301" [] $ \ test_dir server ->
332+ withTestDAPServerClient server $ do
333+ let cfg = mkLaunchConfig test_dir " Main.hs"
334+ hitBreakpointWith cfg 21
335+ locals <- fetchLocalVars
336+ action <- forceLazy (locals % " action" )
337+ action @==? " T301-X"
338+ ac <- expandVar action
339+ ti <- forceLazy (ac % " thunkInt" )
340+ ti @==? " 5050"
341+
342+ -- Re-request the parent and check the field is still evaluated.
343+ -- (it does not need to be forced again!)
344+ locals2 <- fetchLocalVars
345+ ac2 <- expandVar (locals2 % " action" )
346+ (ac2 % " thunkInt" ) @==? " 5050"
347+ disconnect
0 commit comments