Skip to content

Commit 8738761

Browse files
committed
test: Add newtype debug view tests for #234
This is a regression test for #234, where DebugView instances for newtype constructors don't work. These duplicate T130c, but use a `newtype` instead of `data`.
1 parent 41f7b73 commit 8738761

10 files changed

Lines changed: 99 additions & 0 deletions

File tree

test/golden/T234/T234.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: T234
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+
library
13+
import: warnings
14+
exposed-modules: Lib
15+
build-depends: base, haskell-debugger-view
16+
hs-source-dirs: lib
17+
default-language: Haskell2010
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[1 of 1] Compiling Lib ( <TEMPORARY-DIRECTORY>/lib/Lib.hs, interpreted )[T234-0.1.0.0-inplace]
2+
(hdb) BreakFound {changed = True, breakId = [InternalBreakpointId Lib 0], sourceSpan = SourceSpan {file = "<TEMPORARY-DIRECTORY>/lib/Lib.hs", startLine = 16, endLine = 16, startCol = 3, endCol = 14}}
3+
(hdb) Stopped at breakpoint
4+
(hdb) _result : IO () = <fn> :: IO ()
5+
value : ColonList = _
6+
value : ColonList = alpha:beta:gamma
7+
(hdb) Exiting...

test/golden/T234/T234.hdb-stdin

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
break lib/Lib.hs 16
2+
run
3+
variables

test/golden/T234/T234.hdb-test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
$HDB -v0 --entry-point mainish lib/Lib.hs 2>&1 < T234.hdb-stdin

test/golden/T234/lib/Lib.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Lib (mainish) where
2+
3+
import Data.List (intercalate)
4+
import GHC.Debugger.View.Class
5+
6+
newtype ColonList = ColonList [String]
7+
deriving Show
8+
9+
instance DebugView ColonList where
10+
debugValue (ColonList xs) = simpleValue (intercalate ":" xs) False
11+
debugFields _ = pure (VarFields [])
12+
13+
mainish :: IO ()
14+
mainish = do
15+
let value = mkValue
16+
print value
17+
18+
mkValue :: ColonList
19+
mkValue = ColonList ["alpha", "beta", "gamma"]
20+
{-# OPAQUE mkValue #-}

test/golden/T234b/T234b.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: T234b
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+
library
13+
import: warnings
14+
exposed-modules: Lib
15+
build-depends: base, haskell-debugger-view
16+
hs-source-dirs: lib
17+
default-language: Haskell2010
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[1 of 1] Compiling Lib ( <TEMPORARY-DIRECTORY>/lib/Lib.hs, interpreted )[T234b-0.1.0.0-inplace]
2+
(hdb) BreakFound {changed = True, breakId = [InternalBreakpointId Lib 0], sourceSpan = SourceSpan {file = "<TEMPORARY-DIRECTORY>/lib/Lib.hs", startLine = 18, endLine = 18, startCol = 3, endCol = 14}}
3+
(hdb) Stopped at breakpoint
4+
(hdb) _result : IO () = <fn> :: IO ()
5+
value : ColonList = _
6+
value : ColonList = This is an IORef!
7+
(hdb) Exiting...

test/golden/T234b/T234b.hdb-stdin

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
break lib/Lib.hs 18
2+
run
3+
variables

test/golden/T234b/T234b.hdb-test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$HDB -v0 --entry-point mainish lib/Lib.hs 2>&1 < T234b.hdb-stdin

test/golden/T234b/lib/Lib.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Lib (mainish) where
2+
3+
import Data.IORef (IORef, newIORef)
4+
import GHC.Debugger.View.Class
5+
6+
newtype ColonList = ColonList (IORef [String])
7+
8+
instance Show ColonList where
9+
show _ = "<colon-list>"
10+
11+
instance DebugView ColonList where
12+
debugValue _ = simpleValue "This is an IORef!" False
13+
debugFields _ = pure (VarFields [])
14+
15+
mainish :: IO ()
16+
mainish = do
17+
value <- mkValue
18+
print value
19+
20+
mkValue :: IO ColonList
21+
mkValue = ColonList <$> newIORef ["alpha", "beta", "gamma"]

0 commit comments

Comments
 (0)