Skip to content

Commit 873667e

Browse files
committed
test: Also do self-debug test with DAP server
This test tried, but didn't exhibit the bug in #294. It is a good end-to-end test nonetheless, so we should keep it.
1 parent e122526 commit 873667e

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

haskell-debugger.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ test-suite haskell-debugger-test
243243
Test.Integration.Stdout,
244244
Test.Integration.Conditional,
245245
Test.Integration.Evaluate,
246-
Test.Integration.StackTrace
246+
Test.Integration.StackTrace,
247+
Test.Integration.SelfDebug
247248
build-depends:
248249
base >=4.14,
249250
async,

test/haskell/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import Test.Integration.Stdout (stdoutTests)
3838
import Test.Integration.Conditional (conditionalTests)
3939
import Test.Integration.Evaluate (evaluateTests)
4040
import Test.Integration.StackTrace (stackTraceTests)
41+
import Test.Integration.SelfDebug (selfDebugTests)
4142
import Test.Utils
4243
import qualified Data.Char as C
4344
import qualified Data.Text as T
@@ -102,6 +103,7 @@ unitTests =
102103
, conditionalTests
103104
, evaluateTests
104105
, stackTraceTests
106+
, selfDebugTests
105107
]
106108

107109
-- | Receives as an argument the path to the @*.hdb-test@ which contains the
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
module Test.Integration.SelfDebug (selfDebugTests) where
4+
5+
import System.Directory
6+
import System.FilePath
7+
import Control.Monad
8+
import Control.Monad.IO.Class (liftIO)
9+
import Data.Aeson
10+
import Test.DAP
11+
import Test.DAP.Messages.Parser (Event(..))
12+
import Test.Tasty
13+
import Test.Tasty.HUnit
14+
import qualified DAP
15+
import DAP.Types (StoppedEvent(..))
16+
#ifdef mingw32_HOST_OS
17+
import Test.Tasty.ExpectedFailure
18+
#endif
19+
20+
selfDebugTests :: TestTree
21+
selfDebugTests =
22+
#ifdef mingw32_HOST_OS
23+
ignoreTestBecause "Needs to be fixed for Windows (#199)" $
24+
#endif
25+
testGroup "DAP.Integration.SelfDebug"
26+
[ testCase "debug the debugger itself via DAP" selfDebugDAPTest
27+
]
28+
29+
selfDebugDAPTest :: Assertion
30+
selfDebugDAPTest = do
31+
withTestDAPServer "." [] $ \test_dir server -> do -- Self-debug test copies project root to temp dir
32+
doesFileExist (test_dir </> "cabal.project") >>= \exists ->
33+
unless exists $ writeFile (test_dir </> "cabal.project")
34+
"packages: . haskell-debugger-view\nallow-newer: ghc-bignum,containers,time,ghc,base,template-haskell"
35+
doesFileExist (test_dir </> "hie.yaml") >>= \exists ->
36+
unless exists $ writeFile (test_dir </> "hie.yaml")
37+
"cradle:\n cabal:\n component: \"all\""
38+
withTestDAPServerClient server $ do
39+
let cfg = LaunchConfig
40+
{ lcProjectRoot = test_dir
41+
, lcEntryFile = Just "hdb/Main.hs"
42+
, lcEntryPoint = Just "main"
43+
, lcEntryArgs = ["cli", "test/golden/self-debug-cli/Main.hs"]
44+
, lcExtraGhcArgs = []
45+
, lcInternalInterpreter = Nothing
46+
}
47+
48+
_ <- sync $ launchWith cfg
49+
waitFiltering_ EventTy "initialized"
50+
51+
_ <- sync $ setFunctionBreakpointsRequest @_ @Value $ object
52+
[ "breakpoints" .= [ object [ "name" .= ("runDebugger" :: String) ] ] ]
53+
54+
_ <- sync configurationDone
55+
56+
Event{eventBody = Just StoppedEvent{stoppedEventReason = reason}}
57+
<- waitFiltering EventTy "stopped"
58+
liftIO $ assertEqual "expected breakpoint stop"
59+
reason DAP.StoppedEventReasonBreakpoint
60+
-- fixme: should we reply with StoppedEventReasonFunctionBreakpoint instead?
61+
62+
disconnect

0 commit comments

Comments
 (0)