Skip to content

Commit

Permalink
Install notification handlers for cabal files
Browse files Browse the repository at this point in the history
The cabal formatters read the file contents from the shake VFS. Thus, we
need to make sure there are notification handlers that add the cabal
files to the VFS!

Formatters have to depend on the `hls-cabal-plugin` to have the
necessary notification handlers installed during test time.
  • Loading branch information
fendor committed Aug 16, 2024
1 parent afb0023 commit 0b63299
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
6 changes: 6 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ library hls-cabal-fmt-plugin
, process-extras
, text

-- The `hls-cabal-plugin` is needed for tests, as we need to install notification handlers
test-suite hls-cabal-fmt-plugin-tests
import: defaults, pedantic, test-defaults, warnings
if !flag(cabalfmt)
Expand All @@ -148,7 +149,9 @@ test-suite hls-cabal-fmt-plugin-tests
, base
, directory
, filepath
, haskell-language-server:hls-cabal-plugin
, haskell-language-server:hls-cabal-fmt-plugin
, hls-plugin-api == 2.9.0.1
, hls-test-utils == 2.9.0.1

if flag(isolateCabalfmtTests)
Expand Down Expand Up @@ -192,6 +195,7 @@ library hls-cabal-gild-plugin
, mtl
, process-extras

-- The `hls-cabal-plugin` is needed for tests, as we need to install notification handlers
test-suite hls-cabal-gild-plugin-tests
import: defaults, pedantic, test-defaults, warnings
if !flag(cabalgild)
Expand All @@ -203,7 +207,9 @@ test-suite hls-cabal-gild-plugin-tests
, base
, directory
, filepath
, haskell-language-server:hls-cabal-plugin
, haskell-language-server:hls-cabal-gild-plugin
, hls-plugin-api == 2.9.0.1
, hls-test-utils == 2.9.0.1

if flag(isolateCabalGildTests)
Expand Down
19 changes: 17 additions & 2 deletions plugins/hls-cabal-fmt-plugin/test/Main.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Main
( main
) where

import Ide.Logger
import qualified Ide.Plugin.Cabal as Cabal
import qualified Ide.Plugin.CabalFmt as CabalFmt
import System.Directory (findExecutable)
import System.FilePath
import Test.Hls

data TestLog
= LogCabalFmt CabalFmt.Log
| LogCabal Cabal.Log

instance Pretty TestLog where
pretty = \case
LogCabalFmt msg -> pretty msg
LogCabal msg -> pretty msg

data CabalFmtFound = Found | NotFound

isTestIsolated :: Bool
Expand All @@ -30,8 +42,11 @@ main = do
foundCabalFmt <- isCabalFmtFound
defaultTestRunner (tests foundCabalFmt)

cabalFmtPlugin :: PluginTestDescriptor CabalFmt.Log
cabalFmtPlugin = mkPluginTestDescriptor CabalFmt.descriptor "cabal-fmt"
cabalFmtPlugin :: PluginTestDescriptor TestLog
cabalFmtPlugin = mconcat
[ mkPluginTestDescriptor (CabalFmt.descriptor . cmapWithPrio LogCabalFmt) "cabal-fmt"
, mkPluginTestDescriptor (Cabal.descriptor . cmapWithPrio LogCabal) "cabal"
]

tests :: CabalFmtFound -> TestTree
tests found = testGroup "cabal-fmt"
Expand Down
19 changes: 17 additions & 2 deletions plugins/hls-cabal-gild-plugin/test/Main.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Main
( main
) where

import Ide.Logger
import qualified Ide.Plugin.Cabal as Cabal
import qualified Ide.Plugin.CabalGild as CabalGild
import System.Directory (findExecutable)
import System.FilePath
import Test.Hls

data TestLog
= LogCabalGild CabalGild.Log
| LogCabal Cabal.Log

instance Pretty TestLog where
pretty = \case
LogCabalGild msg -> pretty msg
LogCabal msg -> pretty msg

data CabalGildFound = Found | NotFound

isTestIsolated :: Bool
Expand All @@ -30,8 +42,11 @@ main = do
foundCabalFmt <- isCabalFmtFound
defaultTestRunner (tests foundCabalFmt)

cabalGildPlugin :: PluginTestDescriptor CabalGild.Log
cabalGildPlugin = mkPluginTestDescriptor CabalGild.descriptor "cabal-gild"
cabalGildPlugin :: PluginTestDescriptor TestLog
cabalGildPlugin = mconcat
[ mkPluginTestDescriptor (CabalGild.descriptor . cmapWithPrio LogCabalGild) "cabal-gild"
, mkPluginTestDescriptor (Cabal.descriptor . cmapWithPrio LogCabal) "cabal"
]

tests :: CabalGildFound -> TestTree
tests found = testGroup "cabal-gild"
Expand Down

0 comments on commit 0b63299

Please sign in to comment.