|
| 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