Skip to content

Commit bb5a0f9

Browse files
committed
test: IM value remains forced after refreshing var
Unlike in #301, the `DebugView` instance for `IntMap` displays as a `debugFields` value the actual heap referenced stored in the `IntMap`. This means that forcing an IM value once, then displaying with `DebugView` the same IntMap a second time, should display the IM value still forced. Because the heap reference is the same. This commit just adds a test which asserts this (it wasn't tested before).
1 parent f303903 commit bb5a0f9

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

test/haskell/Test/Integration/Variables.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ variableTests =
3333
, testCase "hdv with containers (issue #47c)" hdvContainersDepTest
3434
, testCase "hdv in-memory with containers (issue #47d)" hdvContainersMemTest
3535
, testCase "hdv in-memory with text (issue #47e)" hdvTextMemTest
36+
, testCase "force thunk in IntMap value persists (issue #47f)" thunkIntMapTest
3637
]
3738

3839
intsAndStringsTest :: Assertion
@@ -319,3 +320,27 @@ hdvTextMemTest =
319320
action <- forceLazy (locals % "action")
320321
action @==? "\"this should be displayed as a simple string\""
321322
disconnect
323+
324+
-- | An IntMap with lazy thunk values. The field value is the actual IntMap
325+
-- elem heap value, so forcing it is persisted across refreshes (because we're
326+
-- still referring to the same heap value, and now it happens to be forced)
327+
thunkIntMapTest :: Assertion
328+
thunkIntMapTest =
329+
withTestDAPServer "test/integration/T47f" [] $ \test_dir server ->
330+
withTestDAPServerClient server $ do
331+
let cfg = mkLaunchConfig test_dir "Main.hs"
332+
hitBreakpointWith cfg 12
333+
locals <- fetchLocalVars
334+
action <- forceLazy (locals % "action")
335+
action @==? "IntMap"
336+
ac <- expandVar action
337+
v1 <- forceLazy (ac % "1")
338+
v1 @==? "5050"
339+
340+
-- Re-request the parent and check the previously-forced value remains
341+
-- evaluated (no force needed).
342+
locals2 <- fetchLocalVars
343+
ac2 <- expandVar (locals2 % "action")
344+
(ac2 % "1") @==? "5050"
345+
disconnect
346+

test/integration/T47f/Main.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Main where
2+
-- IntMap with lazy thunk values: the thunk lives in the real data
3+
-- structure, so forcing it persists across debugFields calls.
4+
5+
import qualified Data.IntMap.Lazy as IM
6+
7+
main :: IO ()
8+
main = f (IM.fromList [(1, sum [1 .. 100 :: Int]), (2, sum [1 .. 200 :: Int])])
9+
10+
f :: Show a => a -> IO ()
11+
f action = do
12+
print action

test/integration/T47f/T47f.cabal

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cabal-version: 3.14
2+
name: T47f
3+
version: 0.1.0.0
4+
license: NONE
5+
author: Rodrigo Mesquita
6+
maintainer: rodrigo.m.mesquita@gmail.com
7+
build-type: Simple
8+
9+
common warnings
10+
ghc-options: -Wall
11+
12+
executable t47f
13+
import: warnings
14+
main-is: Main.hs
15+
build-depends: base, containers
16+
hs-source-dirs: .
17+
default-language: Haskell2010

0 commit comments

Comments
 (0)