diff --git a/plugins/hls-brittany-plugin/hls-brittany-plugin.cabal b/plugins/hls-brittany-plugin/hls-brittany-plugin.cabal index a29291593e9..1e919c43821 100644 --- a/plugins/hls-brittany-plugin/hls-brittany-plugin.cabal +++ b/plugins/hls-brittany-plugin/hls-brittany-plugin.cabal @@ -28,3 +28,42 @@ library , transformers default-language: Haskell2010 + +executable test-server + default-language: Haskell2010 + build-depends: + , base + , data-default + , ghcide + , hls-brittany-plugin + , hls-plugin-api + , shake + main-is: Server.hs + hs-source-dirs: test + ghc-options: -threaded + +test-suite tests + type: exitcode-stdio-1.0 + default-language: Haskell2010 + build-tool-depends: + hls-brittany-plugin:test-server -any, + hs-source-dirs: test + main-is: Main.hs + build-depends: + , aeson + , base + , bytestring + , data-default + , deepseq + , ghcide >= 0.7.5.0 + , hls-brittany-plugin + , hspec-expectations + , megaparsec + , lens + , lsp-test + , tasty + , tasty-ant-xml >=1.1.6 + , tasty-hunit + , tasty-golden + , tasty-rerun + , text diff --git a/plugins/hls-brittany-plugin/test/Main.hs b/plugins/hls-brittany-plugin/test/Main.hs new file mode 100644 index 00000000000..1065db972dc --- /dev/null +++ b/plugins/hls-brittany-plugin/test/Main.hs @@ -0,0 +1,54 @@ +{-# LANGUAGE OverloadedStrings #-} +module Main(main) where + +import Control.Monad.IO.Class +import Data.Aeson +import qualified Data.ByteString.Lazy as BS +import qualified Data.Text.Encoding as T +import qualified Data.Text.IO as T +import Language.LSP.Test +import Language.LSP.Types +import Test.Tasty +import Test.Tasty.Golden +import Test.Tasty.HUnit +import Test.Tasty.Runners ( + consoleTestReporter, + listingTests, + ) +import Test.Tasty.Ingredients.Rerun +import Test.Tasty.Runners.AntXML + +main :: IO () +main = defaultMainWithIngredients + [antXMLRunner, rerunningTests [listingTests, consoleTestReporter]] + tests + +testCommand = "test-server" + +tests :: TestTree +tests = testGroup "brittany" [ + goldenVsStringDiff "formats a document with LF endings" goldenGitDiff "test/testdata/BrittanyLF.formatted_document.hs" $ runSession testCommand fullCaps "test/testdata" $ do + doc <- openDoc "BrittanyLF.hs" "haskell" + formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) + BS.fromStrict . T.encodeUtf8 <$> documentContents doc + + , goldenVsStringDiff "formats a document with CRLF endings" goldenGitDiff "test/testdata/BrittanyCRLF.formatted_document.hs" $ runSession testCommand fullCaps "test/testdata" $ do + doc <- openDoc "BrittanyCRLF.hs" "haskell" + formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) + BS.fromStrict . T.encodeUtf8 <$> documentContents doc + + , goldenVsStringDiff "formats a range with LF endings" goldenGitDiff "test/testdata/BrittanyLF.formatted_range.hs" $ runSession testCommand fullCaps "test/testdata" $ do + doc <- openDoc "BrittanyLF.hs" "haskell" + let range = Range (Position 1 0) (Position 2 22) + formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range + BS.fromStrict . T.encodeUtf8 <$> documentContents doc + + , goldenVsStringDiff "formats a range with CRLF endings" goldenGitDiff "test/testdata/BrittanyCRLF.formatted_range.hs" $ runSession testCommand fullCaps "test/testdata" $ do + doc <- openDoc "BrittanyCRLF.hs" "haskell" + let range = Range (Position 1 0) (Position 2 22) + formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range + BS.fromStrict . T.encodeUtf8 <$> documentContents doc + ] + +goldenGitDiff :: FilePath -> FilePath -> [String] +goldenGitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew] diff --git a/plugins/hls-brittany-plugin/test/Server.hs b/plugins/hls-brittany-plugin/test/Server.hs new file mode 100644 index 00000000000..192103ec9cd --- /dev/null +++ b/plugins/hls-brittany-plugin/test/Server.hs @@ -0,0 +1,19 @@ +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE OverloadedStrings #-} +module Main(main) where + +import Data.Default +import Development.IDE.Main +import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide +import Ide.Plugin.Config +import Ide.Plugin.Brittany as B +import Ide.PluginUtils + +main :: IO () +main = defaultMain def + { argsHlsPlugins = pluginDescToIdePlugins $ + [ B.descriptor "brittany" + ] <> + Ghcide.descriptors + , argsDefaultHlsConfig = def { formattingProvider = "brittany" } + } diff --git a/test/testdata/format/BrittanyCRLF.formatted_document.hs b/plugins/hls-brittany-plugin/test/testdata/BrittanyCRLF.formatted_document.hs similarity index 100% rename from test/testdata/format/BrittanyCRLF.formatted_document.hs rename to plugins/hls-brittany-plugin/test/testdata/BrittanyCRLF.formatted_document.hs diff --git a/test/testdata/format/BrittanyCRLF.formatted_range.hs b/plugins/hls-brittany-plugin/test/testdata/BrittanyCRLF.formatted_range.hs similarity index 100% rename from test/testdata/format/BrittanyCRLF.formatted_range.hs rename to plugins/hls-brittany-plugin/test/testdata/BrittanyCRLF.formatted_range.hs diff --git a/test/testdata/format/BrittanyCRLF.hs b/plugins/hls-brittany-plugin/test/testdata/BrittanyCRLF.hs similarity index 100% rename from test/testdata/format/BrittanyCRLF.hs rename to plugins/hls-brittany-plugin/test/testdata/BrittanyCRLF.hs diff --git a/test/testdata/format/BrittanyLF.formatted_document.hs b/plugins/hls-brittany-plugin/test/testdata/BrittanyLF.formatted_document.hs similarity index 100% rename from test/testdata/format/BrittanyLF.formatted_document.hs rename to plugins/hls-brittany-plugin/test/testdata/BrittanyLF.formatted_document.hs diff --git a/test/testdata/format/BrittanyLF.formatted_range.hs b/plugins/hls-brittany-plugin/test/testdata/BrittanyLF.formatted_range.hs similarity index 100% rename from test/testdata/format/BrittanyLF.formatted_range.hs rename to plugins/hls-brittany-plugin/test/testdata/BrittanyLF.formatted_range.hs diff --git a/test/testdata/format/BrittanyLF.hs b/plugins/hls-brittany-plugin/test/testdata/BrittanyLF.hs similarity index 100% rename from test/testdata/format/BrittanyLF.hs rename to plugins/hls-brittany-plugin/test/testdata/BrittanyLF.hs diff --git a/test/functional/Format.hs b/test/functional/Format.hs index 75968373b7b..7a8b1911641 100644 --- a/test/functional/Format.hs +++ b/test/functional/Format.hs @@ -14,9 +14,7 @@ import Test.Tasty.Golden import Test.Tasty.HUnit import Control.Lens ((^.)) -#if AGPL import qualified Data.Text.IO as T -#endif tests :: TestTree tests = testGroup "format document" [ @@ -31,9 +29,6 @@ tests = testGroup "format document" [ , rangeTests , providerTests , stylishHaskellTests -#if AGPL - , brittanyTests -#endif , ormoluTests , fourmoluTests ] @@ -110,37 +105,6 @@ stylishHaskellTests = testGroup "stylish-haskell" [ BS.fromStrict . T.encodeUtf8 <$> documentContents doc ] -#if AGPL -brittanyTests :: TestTree -brittanyTests = testGroup "brittany" [ - goldenVsStringDiff "formats a document with LF endings" goldenGitDiff "test/testdata/format/BrittanyLF.formatted_document.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany")) - doc <- openDoc "BrittanyLF.hs" "haskell" - formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc - - , goldenVsStringDiff "formats a document with CRLF endings" goldenGitDiff "test/testdata/format/BrittanyCRLF.formatted_document.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany")) - doc <- openDoc "BrittanyCRLF.hs" "haskell" - formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc - - , goldenVsStringDiff "formats a range with LF endings" goldenGitDiff "test/testdata/format/BrittanyLF.formatted_range.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany")) - doc <- openDoc "BrittanyLF.hs" "haskell" - let range = Range (Position 1 0) (Position 2 22) - formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range - BS.fromStrict . T.encodeUtf8 <$> documentContents doc - - , goldenVsStringDiff "formats a range with CRLF endings" goldenGitDiff "test/testdata/format/BrittanyCRLF.formatted_range.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany")) - doc <- openDoc "BrittanyCRLF.hs" "haskell" - let range = Range (Position 1 0) (Position 2 22) - formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range - BS.fromStrict . T.encodeUtf8 <$> documentContents doc - ] -#endif - ormoluTests :: TestTree ormoluTests = testGroup "ormolu" [ goldenVsStringDiff "formats correctly" goldenGitDiff "test/testdata/format/Format.ormolu.formatted.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do @@ -172,11 +136,9 @@ fourmoluTests = testGroup "fourmolu" formatLspConfig :: Value -> Value formatLspConfig provider = object [ "haskell" .= object ["formattingProvider" .= (provider :: Value)] ] -#if AGPL -- | The same as 'formatLspConfig' but using the legacy section name formatLspConfigOld :: Value -> Value formatLspConfigOld provider = object [ "languageServerHaskell" .= object ["formattingProvider" .= (provider :: Value)] ] -#endif formatConfig :: Value -> SessionConfig formatConfig provider = defaultConfig { lspConfig = Just (formatLspConfig provider) } diff --git a/test/testdata/format/Format.brittany.formatted.hs b/test/testdata/format/Format.brittany.formatted.hs deleted file mode 100644 index 03aef77efa0..00000000000 --- a/test/testdata/format/Format.brittany.formatted.hs +++ /dev/null @@ -1,18 +0,0 @@ -module Format where -import Data.List - -import Data.Int -import Prelude -foo :: Int -> Int -foo 3 = 2 -foo x = x -bar :: String -> IO String -bar s = do - x <- return "hello" - return "asdf" - -data Baz = Baz - { a :: Int - , b :: String - } - diff --git a/test/testdata/format/Format.brittany_post_floskell.formatted.hs b/test/testdata/format/Format.brittany_post_floskell.formatted.hs deleted file mode 100644 index 6ea6a00b8dc..00000000000 --- a/test/testdata/format/Format.brittany_post_floskell.formatted.hs +++ /dev/null @@ -1,20 +0,0 @@ -module Format where - -import Data.Int -import Data.List -import Prelude - -foo :: Int -> Int -foo 3 = 2 -foo x = x - -bar :: String -> IO String -bar s = do - x <- return "hello" - return "asdf" - -data Baz = Baz - { a :: Int - , b :: String - } -