Skip to content

Commit dc64fc4

Browse files
committed
Test Fourmolu with CLI option
1 parent 594777a commit dc64fc4

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ test-suite tests
4141
hs-source-dirs: test
4242
main-is: Main.hs
4343
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
44+
build-tool-depends:
45+
fourmolu:fourmolu
4446
build-depends:
4547
, base
4648
, aeson

plugins/hls-fourmolu-plugin/test/Main.hs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ module Main
33
( main
44
) where
55

6+
import Data.Aeson
7+
import Data.Functor
8+
import Ide.Plugin.Config
69
import qualified Ide.Plugin.Fourmolu as Fourmolu
710
import Language.LSP.Test
811
import Language.LSP.Types
@@ -16,15 +19,21 @@ fourmoluPlugin :: PluginDescriptor IdeState
1619
fourmoluPlugin = Fourmolu.descriptor "fourmolu"
1720

1821
tests :: TestTree
19-
tests = testGroup "fourmolu"
20-
[ goldenWithFourmolu "formats correctly" "Fourmolu" "formatted" $ \doc -> do
21-
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
22-
, goldenWithFourmolu "formats imports correctly" "Fourmolu" "formatted" $ \doc -> do
23-
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
24-
]
22+
tests =
23+
testGroup "fourmolu" $
24+
[False, True] <&> \cli ->
25+
testGroup
26+
(if cli then "cli" else "lib")
27+
[ goldenWithFourmolu cli "formats correctly" "Fourmolu" "formatted" $ \doc -> do
28+
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
29+
, goldenWithFourmolu cli "formats imports correctly" "Fourmolu" "formatted" $ \doc -> do
30+
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
31+
]
2532

26-
goldenWithFourmolu :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
27-
goldenWithFourmolu title path desc = goldenWithHaskellDocFormatter fourmoluPlugin "fourmolu" def title testDataDir path desc "hs"
33+
goldenWithFourmolu :: Bool -> TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
34+
goldenWithFourmolu cli title path desc = goldenWithHaskellDocFormatter fourmoluPlugin "fourmolu" conf title testDataDir path desc "hs"
35+
where
36+
conf = def{plcConfig = (\(Object obj) -> obj) $ object ["cli" .= cli]}
2837

2938
testDataDir :: FilePath
3039
testDataDir = "test" </> "testdata"

0 commit comments

Comments
 (0)