Skip to content

Commit 487dd18

Browse files
committed
test: Add test for #301
Refreshed DebugView field is still a thunk after being forced Marked as expect fail. Tracked by #301
1 parent f303903 commit 487dd18

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

test/haskell/Test/Integration/Variables.hs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import qualified Data.Text as T
88
import Test.DAP
99
import Test.Tasty
1010
import Test.Tasty.HUnit
11-
#ifdef mingw32_HOST_OS
1211
import Test.Tasty.ExpectedFailure
13-
#endif
1412
import DAP (Variable, variableValue)
1513

1614
variableTests :: 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

3838
intsAndStringsTest :: 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

test/integration/T301/Main.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Main where
2+
import GHC.Debugger.View.Class
3+
4+
data X = X String
5+
deriving Show
6+
7+
instance DebugView X where
8+
debugValue _ = simpleValue "T301-X" True
9+
debugFields (X s) = pure $ VarFields
10+
[ ("thunkInt", VarFieldValue intThunk)
11+
]
12+
where
13+
intThunk :: Int
14+
intThunk = sum [1 .. length s + 99]
15+
16+
main :: IO ()
17+
main = f (X "A")
18+
19+
f :: Show a => a -> IO ()
20+
f action = do
21+
print action

test/integration/T301/T301.cabal

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cabal-version: 3.14
2+
name: T301
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 t301
13+
import: warnings
14+
main-is: Main.hs
15+
build-depends: base, containers
16+
build-depends: haskell-debugger-view
17+
hs-source-dirs: .
18+
default-language: Haskell2010

0 commit comments

Comments
 (0)