Extract hls-test-utils (#1606)

* Extract hls-test-utils

* Use test utils in brittany plugin and stylish haskell plugin

* stack

* Set locale encoding to utf8 in defaultMain

* Remove with-utf8
This commit is contained in:
Potato Hatsue 2021-03-23 18:45:45 +08:00 committed by GitHub
parent 5724343ee2
commit 7255b408da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 572 additions and 441 deletions

View File

@ -148,3 +148,10 @@ jobs:
HLS_TEST_EXE: hls
HLS_WRAPPER_TEST_EXE: hls-wrapper
run: cabal test hls-stylish-haskell-plugin || cabal test hls-stylish-haskell-plugin --test-options="-j1"
- name: Test eval plugin
if: ${{ matrix.test }}
env:
HLS_TEST_EXE: hls
HLS_WRAPPER_TEST_EXE: hls-wrapper
run: cabal test hls-eval-plugin || cabal test hls-eval-plugin --test-options="-j1"

View File

@ -4,6 +4,7 @@ packages:
./shake-bench
./ghcide
./hls-plugin-api
./hls-test-utils
./plugins/hls-tactics-plugin
./plugins/hls-brittany-plugin
./plugins/hls-stylish-haskell-plugin

View File

@ -6,11 +6,10 @@ module Main(main) where
import Ide.Arguments (Arguments (..), LspArguments (..), getArguments)
import Ide.Main (defaultMain)
import Main.Utf8 (withUtf8)
import Plugins
main :: IO ()
main = withUtf8 $ do
main = do
args <- getArguments "haskell-language-server"
let withExamples =

View File

@ -53,6 +53,7 @@ import Development.IDE.Types.Options (IdeGhcSession,
defaultIdeOptions)
import Development.IDE.Types.Shake (Key (Key))
import Development.Shake (action)
import GHC.IO.Encoding (setLocaleEncoding)
import HIE.Bios.Cradle (findCradle)
import Ide.Plugin.Config (CheckParents (NeverCheck),
Config,
@ -116,6 +117,7 @@ stderrLogger = do
defaultMain :: Arguments -> IO ()
defaultMain Arguments{..} = do
setLocaleEncoding utf8
pid <- T.pack . show <$> getProcessID
logger <- argsLogger
hSetBuffering stderr LineBuffering

View File

@ -327,7 +327,6 @@ executable haskell-language-server
, temporary
, transformers
, unordered-containers
, with-utf8
include-dirs: include
default-language: Haskell2010
@ -363,43 +362,9 @@ executable haskell-language-server-wrapper
default-language: Haskell2010
-- This common stanza simulates a previous private lib
-- We removed it due to issues with stack when loading the project using a stack based hie.yaml
-- See https://github.com/haskell/haskell-language-server/issues/114
common hls-test-utils
import: common-deps
hs-source-dirs: test/utils
other-modules: Test.Hls.Util
build-depends:
, aeson
, blaze-markup
, containers
, data-default
, lsp
, hie-bios
, hls-plugin-api >= 1.0 && < 1.2
, hslogger
, hspec
, hspec-core
, lens
, lsp-test == 0.13.0.0
, stm
, tasty-expected-failure
, tasty-hunit
, temporary
, transformers
, unordered-containers
, yaml
ghc-options: -Wall -Wredundant-constraints
if flag(pedantic)
ghc-options: -Werror
default-language: Haskell2010
test-suite func-test
import: common-deps, hls-test-utils
import: common-deps
type: exitcode-stdio-1.0
default-language: Haskell2010
build-tool-depends:
@ -411,15 +376,16 @@ test-suite func-test
, data-default
, hspec-expectations
, lens
, tasty
, tasty-ant-xml >=1.1.6
, tasty-golden
, tasty-rerun
, megaparsec
, deepseq
, ghcide
, hls-test-utils
, lsp-types
, aeson
, hls-plugin-api >= 1.0 && < 1.2
, lsp-test == 0.13.0.0
, containers
, unordered-containers
hs-source-dirs: test/functional plugins/hls-eval-plugin/test plugins/hls-splice-plugin/src plugins/hls-eval-plugin/src
hs-source-dirs: test/functional plugins/hls-splice-plugin/src
main-is: Main.hs
other-modules:
@ -430,7 +396,6 @@ test-suite func-test
Deferred
Definition
Diagnostic
Eval
Format
FunctionalBadProject
FunctionalCodeAction
@ -446,7 +411,6 @@ test-suite func-test
Splice
HaddockComments
Ide.Plugin.Splice.Types
Ide.Plugin.Eval.Types
default-extensions: OverloadedStrings
ghc-options:
@ -456,7 +420,6 @@ test-suite func-test
ghc-options: -Werror -Wredundant-constraints
test-suite wrapper-test
import: hls-test-utils
type: exitcode-stdio-1.0
build-tool-depends:
haskell-language-server:haskell-language-server-wrapper -any
@ -466,9 +429,8 @@ test-suite wrapper-test
, base
, directory
, process
, tasty
, tasty-ant-xml >=1.1.6
, tasty-rerun
, hls-test-utils
, extra
hs-source-dirs: test/wrapper
main-is: Main.hs

201
hls-test-utils/LICENSE Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -0,0 +1,65 @@
cabal-version: 2.2
name: hls-test-utils
version: 1.0.0.0
synopsis: Utilities used in the tests of Haskell Language Server
description:
Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>
homepage:
https://github.com/haskell/haskell-language-server/hls-test-utils
bug-reports: https://github.com/haskell/haskell-language-server/issues
license: Apache-2.0
license-file: LICENSE
author: The Haskell IDE Team
maintainer: alan.zimm@gmail.com
copyright: The Haskell IDE Team
category: Development
build-type: Simple
flag pedantic
description: Enable -Werror
default: False
manual: True
source-repository head
type: git
location: https://github.com/haskell/haskell-language-server
library
exposed-modules:
Test.Hls
Test.Hls.Util
hs-source-dirs: src
build-depends:
, aeson
, base
, blaze-markup
, bytestring
, containers
, data-default
, directory
, extra
, filepath
, hspec
, hspec-core
, lens
, lsp-test ==0.13.0.0
, lsp-types ^>=1.1
, tasty
, tasty-ant-xml >=1.1.6
, tasty-expected-failure
, tasty-golden
, tasty-hunit
, tasty-rerun
, temporary
, text
, unordered-containers
ghc-options: -Wall
if flag(pedantic)
ghc-options: -Werror
default-language: Haskell2010

View File

@ -0,0 +1,46 @@
module Test.Hls
( module Test.Tasty.HUnit,
module Test.Tasty,
module Test.Tasty.ExpectedFailure,
module Test.Hls.Util,
module Language.LSP.Types,
module Language.LSP.Test,
module Control.Monad.IO.Class,
module Control.Applicative.Combinators,
defaultTestRunner,
goldenGitDiff,
testCommand,
def,
)
where
import Control.Applicative.Combinators
import Control.Monad.IO.Class
import Data.ByteString.Lazy (ByteString)
import Data.Default (def)
import Language.LSP.Test
import Language.LSP.Types
import Test.Hls.Util
import Test.Tasty hiding (Timeout)
import Test.Tasty.ExpectedFailure
import Test.Tasty.Golden
import Test.Tasty.HUnit
import Test.Tasty.Ingredients.Rerun
import Test.Tasty.Runners
import Test.Tasty.Runners.AntXML
-- | ingredient: xml runner writes json file of test results (https://github.com/ocharles/tasty-ant-xml/blob/master/Test/Tasty/Runners/AntXML.hs)
-- rerunningTests allow rerun of failed tests (https://github.com/ocharles/tasty-rerun/blob/master/src/Test/Tasty/Ingredients/Rerun.hs)
defaultTestRunner :: TestTree -> IO ()
defaultTestRunner =
defaultMainWithIngredients
[antXMLRunner, rerunningTests [listingTests, consoleTestReporter]]
gitDiff :: FilePath -> FilePath -> [String]
gitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew]
goldenGitDiff :: TestName -> FilePath -> IO ByteString -> TestTree
goldenGitDiff name = goldenVsStringDiff name gitDiff
testCommand :: String
testCommand = "test-server"

View File

@ -28,6 +28,7 @@ let
shake-bench = gitignoreSource ../shake-bench;
hie-compat = gitignoreSource ../hie-compat;
hls-plugin-api = gitignoreSource ../hls-plugin-api;
hls-test-utils = gitignoreSource ../hls-test-utils;
hls-brittany-plugin = gitignoreSource ../plugins/hls-brittany-plugin;
hls-stylish-haskell-plugin = gitignoreSource ../plugins/hls-stylish-haskell-plugin;
hls-class-plugin = gitignoreSource ../plugins/hls-class-plugin;

View File

@ -50,20 +50,8 @@ test-suite tests
hs-source-dirs: test
main-is: Main.hs
build-depends:
, aeson
, base
, bytestring
, data-default
, deepseq
, ghcide ^>= 1.1.0.0
, hls-brittany-plugin
, hspec-expectations
, megaparsec
, lens
, lsp-test
, tasty
, tasty-ant-xml >=1.1.6
, tasty-hunit
, tasty-golden
, tasty-rerun
, text
, hls-test-utils

View File

@ -1,54 +1,35 @@
{-# 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
import Test.Hls
main :: IO ()
main = defaultMainWithIngredients
[antXMLRunner, rerunningTests [listingTests, consoleTestReporter]]
tests
testCommand = "test-server"
main = defaultTestRunner tests
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
goldenGitDiff "formats a document with LF endings" "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
, goldenGitDiff "formats a document with CRLF endings" "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
, goldenGitDiff "formats a range with LF endings" "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
, goldenGitDiff "formats a range with CRLF endings" "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]

View File

@ -1,19 +1,29 @@
cabal-version: 2.2
cabal-version: 2.4
name: hls-eval-plugin
version: 1.0.0.0
synopsis: Eval plugin for Haskell Language Server
description: Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>
description:
Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>
category: Development
bug-reports: https://github.com/haskell/haskell-language-server/issues
license: Apache-2.0
license-file: LICENSE
author: https://github.com/haskell/haskell-language-server/contributors
maintainer: https://github.com/haskell/haskell-language-server/contributors
author:
https://github.com/haskell/haskell-language-server/contributors
maintainer:
https://github.com/haskell/haskell-language-server/contributors
build-type: Simple
extra-source-files:
LICENSE
README.md
test/testdata/*.yaml
test/testdata/*.hs
test/testdata/*.expected
test/testdata/*.lhs
test/testdata/*.cabal
flag pedantic
description: Enable -Werror
@ -25,15 +35,17 @@ source-repository head
location: https://github.com/haskell/haskell-language-server
library
exposed-modules: Ide.Plugin.Eval
hs-source-dirs: src
exposed-modules:
Ide.Plugin.Eval
Ide.Plugin.Eval.Types
hs-source-dirs: src
other-modules:
Ide.Plugin.Eval.Code
Ide.Plugin.Eval.CodeLens
Ide.Plugin.Eval.GHC
Ide.Plugin.Eval.Parse.Comments
Ide.Plugin.Eval.Parse.Option
Ide.Plugin.Eval.Types
Ide.Plugin.Eval.Util
build-depends:
@ -49,12 +61,12 @@ library
, ghc
, ghc-boot-th
, ghc-paths
, ghcide ^>= 1.1.0.0
, ghcide ^>=1.1.0.0
, hashable
, hls-plugin-api >=1.0 && <1.2
, lens
, lsp
, lsp-types
, hls-plugin-api >= 1.0 && < 1.2
, lens
, megaparsec >=9.0
, mtl
, parser-combinators
@ -66,13 +78,50 @@ library
, text
, time
, transformers
, unordered-containers
, unliftio
, unordered-containers
ghc-options: -Wall -Wno-name-shadowing -Wno-unticked-promoted-constructors
ghc-options:
-Wall -Wno-name-shadowing -Wno-unticked-promoted-constructors
if flag(pedantic)
ghc-options: -Werror
default-language: Haskell2010
default-extensions:
DataKinds
TypeOperators
executable test-server
default-language: Haskell2010
default-extensions: DataKinds, TypeOperators
build-depends:
, base
, data-default
, ghcide
, hls-eval-plugin
, hls-plugin-api
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-eval-plugin:test-server -any
hs-source-dirs: test
main-is: Main.hs
ghc-options: -Wunused-packages
build-depends:
, aeson
, base
, directory
, extra
, filepath
, hls-eval-plugin
, hls-test-utils
, lens
, lsp-test
, lsp-types
, text

View File

@ -4,60 +4,52 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ViewPatterns #-}
module Eval (
tests,
module Main (
main,
) where
import Control.Applicative.Combinators (skipManyTill)
import Control.Lens (_Just, preview, view)
import Control.Monad (when)
import Control.Monad.IO.Class (MonadIO (liftIO))
import Data.Aeson (fromJSON)
import Data.Aeson.Types (Result (Success))
import Data.List.Extra (nubOrdOn)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Ide.Plugin.Eval.Types (EvalParams (..))
import Language.LSP.Test
import Language.LSP.Types
import Language.LSP.Types.Lens (command, range, title)
import System.Directory (doesFileExist)
import System.FilePath ((<.>), (</>))
import Test.Hls.Util (EnvSpec (GhcVer, HostOS),
GhcVersion (GHC84, GHC86),
OS (Windows), hlsCommand,
knownBrokenForGhcVersions,
knownBrokenInEnv)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.ExpectedFailure (expectFailBecause)
import Test.Tasty.HUnit (testCase, (@?=))
import Control.Lens (_Just, preview, view)
import Control.Monad (when)
import Data.Aeson (fromJSON)
import Data.Aeson.Types (Result (Success))
import Data.List.Extra (nubOrdOn)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Ide.Plugin.Eval.Types (EvalParams (..))
import Language.LSP.Types.Lens (command, range, title)
import System.Directory (doesFileExist)
import System.FilePath ((<.>), (</>))
import Test.Hls
main :: IO ()
main = defaultTestRunner tests
tests :: TestTree
tests =
testGroup
"eval"
[ testCase "Produces Evaluate code lenses" $
runSession hlsCommand fullCaps evalPath $ do
runSession testCommand fullCaps evalPath $ do
doc <- openDoc "T1.hs" "haskell"
lenses <- getEvalCodeLenses doc
liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Evaluate..."]
, testCase "Produces Refresh code lenses" $
runSession hlsCommand fullCaps evalPath $ do
runSession testCommand fullCaps evalPath $ do
doc <- openDoc "T2.hs" "haskell"
lenses <- getEvalCodeLenses doc
liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Refresh..."]
, testCase "Code lenses have ranges" $
runSession hlsCommand fullCaps evalPath $ do
runSession testCommand fullCaps evalPath $ do
doc <- openDoc "T1.hs" "haskell"
lenses <- getEvalCodeLenses doc
liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)]
, testCase "Multi-line expressions have a multi-line range" $ do
runSession hlsCommand fullCaps evalPath $ do
runSession testCommand fullCaps evalPath $ do
doc <- openDoc "T3.hs" "haskell"
lenses <- getEvalCodeLenses doc
liftIO $ map (view range) lenses @?= [Range (Position 3 0) (Position 5 0)]
, testCase "Executed expressions range covers only the expression" $ do
runSession hlsCommand fullCaps evalPath $ do
runSession testCommand fullCaps evalPath $ do
doc <- openDoc "T2.hs" "haskell"
lenses <- getEvalCodeLenses doc
liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)]
@ -140,7 +132,7 @@ tests =
"Can handle eval inside nested comment properly"
$ goldenTest "TNested.hs"
, testCase "Test on last line insert results correctly" $ do
runSession hlsCommand fullCaps evalPath $
runSession testCommand fullCaps evalPath $
liftIO $ do
let mdl = "TLastLine.hs"
-- Write the test file, to make sure that it has no final line return
@ -168,7 +160,7 @@ goldenTest = goldenTestBy isEvalTest
Compare results with the contents of corresponding '.expected' file (and creates it, if missing)
-}
goldenTestBy :: (CodeLens -> Bool) -> FilePath -> IO ()
goldenTestBy fltr input = runSession hlsCommand fullCaps evalPath $ do
goldenTestBy fltr input = runSession testCommand fullCaps evalPath $ do
doc <- openDoc input "haskell"
-- Execute lenses backwards, to avoid affecting their position in the source file
@ -221,4 +213,4 @@ replaceUnicodeQuotes :: T.Text -> T.Text
replaceUnicodeQuotes = T.replace "" "'" . T.replace "" "'"
evalPath :: FilePath
evalPath = "plugins/hls-eval-plugin/test/testdata"
evalPath = "test/testdata"

View File

@ -0,0 +1,17 @@
{-# 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 qualified Ide.Plugin.Eval as Eval
import Ide.PluginUtils
main :: IO ()
main = defaultMain def
{ argsHlsPlugins = pluginDescToIdePlugins $
[ Eval.descriptor "eval"
] <>
Ghcide.descriptors
}

View File

@ -1,63 +1,58 @@
cabal-version: 2.2
name: hls-stylish-haskell-plugin
version: 1.0.0.0
synopsis: Integration with the Stylish Haskell code formatter
license: Apache-2.0
license-file: LICENSE
author: The Haskell IDE Team
copyright: The Haskell IDE Team
maintainer: alan.zimm@gmail.com
category: Development
build-type: Simple
cabal-version: 2.4
name: hls-stylish-haskell-plugin
version: 1.0.0.0
synopsis: Integration with the Stylish Haskell code formatter
license: Apache-2.0
license-file: LICENSE
author: The Haskell IDE Team
copyright: The Haskell IDE Team
maintainer: alan.zimm@gmail.com
category: Development
build-type: Simple
extra-source-files:
LICENSE
test/testdata/*.hs
library
exposed-modules: Ide.Plugin.StylishHaskell
hs-source-dirs: src
build-depends: base
, stylish-haskell ^>=0.12
, filepath
, ghc
, ghc-boot-th
, directory
, ghcide ^>= 1.1.0.0
, lsp-types
, hls-plugin-api >= 1.0 && < 1.2
, text
, mtl
build-depends:
, base
, directory
, filepath
, ghc
, ghc-boot-th
, ghcide ^>=1.1.0.0
, hls-plugin-api >=1.0 && <1.2
, lsp-types
, mtl
, stylish-haskell ^>=0.12
, text
default-language: Haskell2010
executable test-server
default-language: Haskell2010
default-language: Haskell2010
build-depends:
, base
, data-default
, ghcide
, hls-stylish-haskell-plugin
, hls-plugin-api
main-is: Server.hs
hs-source-dirs: test
ghc-options: -threaded
, hls-stylish-haskell-plugin
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-stylish-haskell-plugin:test-server -any,
hs-source-dirs: test
main-is: Main.hs
build-tool-depends: hls-stylish-haskell-plugin:test-server -any
hs-source-dirs: test
main-is: Main.hs
build-depends:
, aeson
, base
, bytestring
, ghcide ^>= 1.1.0.0
, hls-stylish-haskell-plugin
, lsp-test
, tasty
, tasty-ant-xml >=1.1.6
, tasty-hunit
, tasty-golden
, tasty-rerun
, hls-test-utils
, text

View File

@ -1,39 +1,22 @@
{-# 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.Ingredients.Rerun
import Test.Tasty.Runners (consoleTestReporter,
listingTests)
import Test.Tasty.Runners.AntXML
import Test.Hls
main :: IO ()
main = defaultMainWithIngredients
[antXMLRunner, rerunningTests [listingTests, consoleTestReporter]]
tests
testCommand = "test-server"
main = defaultTestRunner tests
tests :: TestTree
tests = testGroup "stylish-haskell" [
goldenVsStringDiff "formats a document" goldenGitDiff "test/testdata/StylishHaskell.formatted_document.hs" $ runSession testCommand fullCaps "test/testdata" $ do
goldenGitDiff "formats a document" "test/testdata/StylishHaskell.formatted_document.hs" $ runSession testCommand fullCaps "test/testdata" $ do
doc <- openDoc "StylishHaskell.hs" "haskell"
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
, goldenVsStringDiff "formats a range" goldenGitDiff "test/testdata/StylishHaskell.formatted_range.hs" $ runSession testCommand fullCaps "test/testdata" $ do
, goldenGitDiff "formats a range" "test/testdata/StylishHaskell.formatted_range.hs" $ runSession testCommand fullCaps "test/testdata" $ do
doc <- openDoc "StylishHaskell.hs" "haskell"
formatRange doc (FormattingOptions 2 True Nothing Nothing Nothing) (Range (Position 0 0) (Position 2 21))
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
]
goldenGitDiff :: FilePath -> FilePath -> [String]
goldenGitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew]

View File

@ -5,6 +5,7 @@ packages:
- ./hie-compat
- ./ghcide/
- ./hls-plugin-api
- ./hls-test-utils
# - ./shake-bench
- ./plugins/hls-class-plugin
- ./plugins/hls-haddock-comments-plugin
@ -53,8 +54,6 @@ extra-deps:
- constraints-extras-0.3.0.2@sha256:013b8d0392582c6ca068e226718a4fe8be8e22321cc0634f6115505bf377ad26,1853
- some-1.0.1@sha256:26e5bab7276f48b25ea8660d3fd1166c0f20fd497dac879a40f408e23211f93e,2055
- unliftio-core-0.2.0.1@sha256:9b3e44ea9aacacbfc35b3b54015af450091916ac3618a41868ebf6546977659a,1082
# To avoid issue #1372
- with-utf8-1.0.2.2
configure-options:
ghcide:

View File

@ -5,6 +5,7 @@ packages:
- ./hie-compat
- ./ghcide/
- ./hls-plugin-api
- ./hls-test-utils
# - ./shake-bench
- ./plugins/hls-class-plugin
- ./plugins/hls-haddock-comments-plugin
@ -51,8 +52,6 @@ extra-deps:
- constraints-extras-0.3.0.2@sha256:013b8d0392582c6ca068e226718a4fe8be8e22321cc0634f6115505bf377ad26,1853
- some-1.0.1@sha256:26e5bab7276f48b25ea8660d3fd1166c0f20fd497dac879a40f408e23211f93e,2055
- unliftio-core-0.2.0.1@sha256:9b3e44ea9aacacbfc35b3b54015af450091916ac3618a41868ebf6546977659a,1082
# To avoid issue #1372
- with-utf8-1.0.2.2
configure-options:
ghcide:

View File

@ -5,6 +5,7 @@ packages:
- ./hie-compat
- ./ghcide/
- ./hls-plugin-api
- ./hls-test-utils
# - ./shake-bench
- ./plugins/hls-class-plugin
- ./plugins/hls-haddock-comments-plugin
@ -49,8 +50,6 @@ extra-deps:
- constraints-extras-0.3.0.2@sha256:013b8d0392582c6ca068e226718a4fe8be8e22321cc0634f6115505bf377ad26,1853
- some-1.0.1@sha256:26e5bab7276f48b25ea8660d3fd1166c0f20fd497dac879a40f408e23211f93e,2055
- unliftio-core-0.2.0.1@sha256:9b3e44ea9aacacbfc35b3b54015af450091916ac3618a41868ebf6546977659a,1082
# To avoid issue #1372
- with-utf8-1.0.2.2
configure-options:
ghcide:

View File

@ -7,6 +7,7 @@ packages:
- ./ghcide/
# - ./shake-bench
- ./hls-plugin-api
- ./hls-test-utils
- ./plugins/hls-class-plugin
- ./plugins/hls-haddock-comments-plugin
- ./plugins/hls-eval-plugin
@ -91,8 +92,6 @@ extra-deps:
- some-1.0.1@sha256:26e5bab7276f48b25ea8660d3fd1166c0f20fd497dac879a40f408e23211f93e,2055
- unliftio-core-0.2.0.1@sha256:9b3e44ea9aacacbfc35b3b54015af450091916ac3618a41868ebf6546977659a,1082
- resourcet-1.2.3
# To avoid issue #1372
- with-utf8-1.0.2.2
flags:
haskell-language-server:

View File

@ -5,6 +5,7 @@ packages:
- ./hie-compat
- ./ghcide/
- ./hls-plugin-api
- ./hls-test-utils
# - ./shake-bench
- ./plugins/hls-class-plugin
- ./plugins/hls-haddock-comments-plugin
@ -90,8 +91,6 @@ extra-deps:
- some-1.0.1@sha256:26e5bab7276f48b25ea8660d3fd1166c0f20fd497dac879a40f408e23211f93e,2055
- unliftio-core-0.2.0.1@sha256:9b3e44ea9aacacbfc35b3b54015af450091916ac3618a41868ebf6546977659a,1082
- resourcet-1.2.3
# To avoid issue #1372
- with-utf8-1.0.2.2
configure-options:
ghcide:

View File

@ -5,6 +5,7 @@ packages:
- ./hie-compat
- ./ghcide/
- ./hls-plugin-api
- ./hls-test-utils
- ./shake-bench
- ./plugins/hls-class-plugin
- ./plugins/hls-haddock-comments-plugin
@ -76,8 +77,6 @@ extra-deps:
- constraints-extras-0.3.0.2@sha256:013b8d0392582c6ca068e226718a4fe8be8e22321cc0634f6115505bf377ad26,1853
- some-1.0.1@sha256:26e5bab7276f48b25ea8660d3fd1166c0f20fd497dac879a40f408e23211f93e,2055
- unliftio-core-0.2.0.1@sha256:9b3e44ea9aacacbfc35b3b54015af450091916ac3618a41868ebf6546977659a,1082
# To avoid issue #1372
- with-utf8-1.0.2.2
configure-options:
ghcide:

View File

@ -6,6 +6,7 @@ packages:
- ./ghcide/
- ./shake-bench
- ./hls-plugin-api
- ./hls-test-utils
- ./plugins/hls-class-plugin
- ./plugins/hls-haddock-comments-plugin
- ./plugins/hls-eval-plugin
@ -70,8 +71,6 @@ extra-deps:
- constraints-extras-0.3.0.2@sha256:013b8d0392582c6ca068e226718a4fe8be8e22321cc0634f6115505bf377ad26,1853
- some-1.0.1@sha256:26e5bab7276f48b25ea8660d3fd1166c0f20fd497dac879a40f408e23211f93e,2055
- unliftio-core-0.2.0.1@sha256:9b3e44ea9aacacbfc35b3b54015af450091916ac3618a41868ebf6546977659a,1082
# To avoid issue #1372
- with-utf8-1.0.2.2
configure-options:
ghcide:

View File

@ -6,6 +6,7 @@ packages:
- ./ghcide/
- ./shake-bench
- ./hls-plugin-api
- ./hls-test-utils
- ./plugins/hls-class-plugin
- ./plugins/hls-haddock-comments-plugin
- ./plugins/hls-eval-plugin
@ -67,8 +68,6 @@ extra-deps:
- constraints-extras-0.3.0.2@sha256:013b8d0392582c6ca068e226718a4fe8be8e22321cc0634f6115505bf377ad26,1853
- some-1.0.1@sha256:26e5bab7276f48b25ea8660d3fd1166c0f20fd497dac879a40f408e23211f93e,2055
- unliftio-core-0.2.0.1@sha256:9b3e44ea9aacacbfc35b3b54015af450091916ac3618a41868ebf6546977659a,1082
# To avoid issue #1372
- with-utf8-1.0.2.2
configure-options:
ghcide:

View File

@ -5,6 +5,7 @@ packages:
- ./hie-compat
- ./ghcide/
- ./hls-plugin-api
- ./hls-test-utils
# - ./shake-bench
- ./plugins/hls-class-plugin
- ./plugins/hls-haddock-comments-plugin
@ -92,8 +93,6 @@ extra-deps:
- some-1.0.1@sha256:26e5bab7276f48b25ea8660d3fd1166c0f20fd497dac879a40f408e23211f93e,2055
- unliftio-core-0.2.0.1@sha256:9b3e44ea9aacacbfc35b3b54015af450091916ac3618a41868ebf6546977659a,1082
- resourcet-1.2.3
# To avoid issue #1372
- with-utf8-1.0.2.2
configure-options:
ghcide:

View File

@ -7,19 +7,12 @@ module Class
)
where
import Control.Applicative.Combinators
import Control.Lens hiding ((<.>))
import Control.Monad.IO.Class (MonadIO (liftIO))
import qualified Data.ByteString.Lazy as BS
import qualified Data.Text.Encoding as T
import Language.LSP.Test
import Language.LSP.Types hiding (_command, _title)
import qualified Language.LSP.Types.Lens as J
import Control.Lens hiding ((<.>))
import qualified Data.ByteString.Lazy as BS
import qualified Data.Text.Encoding as T
import qualified Language.LSP.Types.Lens as J
import System.FilePath
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.Golden
import Test.Tasty.HUnit
import Test.Hls
tests :: TestTree
tests = testGroup
@ -65,18 +58,15 @@ classPath = "test" </> "testdata" </> "class"
glodenTest :: String -> FilePath -> FilePath -> ([CodeAction] -> Session ()) -> TestTree
glodenTest name fp deco execute
= goldenVsStringDiff name goldenGitDiff (classPath </> fpWithDeco <.> "expected" <.> "hs")
= goldenGitDiff name (classPath </> fpWithDeco <.> "expected" <.> "hs")
$ runSession hlsCommand fullCaps classPath
$ do
doc <- openDoc (fp <.> "hs") "haskell"
_ <- waitForDiagnosticsFromSource doc "typecheck"
actions <- concatMap (^.. _CACodeAction) <$> getAllCodeActions doc
execute actions
BS.fromStrict . T.encodeUtf8 <$> (skipManyTill anyMessage $ getDocumentEdit doc)
BS.fromStrict . T.encodeUtf8 <$> skipManyTill anyMessage (getDocumentEdit doc)
where
fpWithDeco
| deco == "" = fp
| otherwise = fp <.> deco
goldenGitDiff :: FilePath -> FilePath -> [String]
goldenGitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew]

View File

@ -2,15 +2,11 @@
module Command (tests) where
import Control.Lens hiding (List)
import Control.Monad.IO.Class
import Data.Char
import qualified Data.Text as T
import Language.LSP.Test
import Language.LSP.Types as LSP
import Language.LSP.Types.Lens as LSP
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.HUnit
import Test.Hls
tests :: TestTree
tests = testGroup "commands" [

View File

@ -2,19 +2,12 @@
{-# LANGUAGE ScopedTypeVariables #-}
module Completion(tests) where
import Control.Lens hiding ((.=))
import Control.Monad.IO.Class
import Data.Aeson (object, (.=))
import Data.Default (def)
import qualified Data.Text as T
import Ide.Plugin.Config (Config (maxCompletions))
import Language.LSP.Test
import Language.LSP.Types
import Language.LSP.Types.Lens hiding (applyEdit)
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import Control.Lens hiding ((.=))
import Data.Aeson (object, (.=))
import qualified Data.Text as T
import Ide.Plugin.Config (maxCompletions)
import Language.LSP.Types.Lens hiding (applyEdit)
import Test.Hls
tests :: TestTree
tests = testGroup "completions" [

View File

@ -2,22 +2,16 @@
module Config (tests) where
import Control.Applicative.Combinators (skipManyTill)
import Control.Lens hiding (List)
import Control.Lens hiding (List)
import Control.Monad
import Control.Monad.IO.Class
import Data.Aeson
import Data.Default
import qualified Data.Map as Map
import qualified Data.Text as T
import qualified Data.Map as Map
import qualified Data.Text as T
import Ide.Plugin.Config
import Language.LSP.Test as Test
import Language.LSP.Types
import qualified Language.LSP.Types.Lens as L
import System.FilePath ((</>))
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.HUnit
import Language.LSP.Test as Test
import qualified Language.LSP.Types.Lens as L
import System.FilePath ((</>))
import Test.Hls
{-# ANN module ("HLint: ignore Reduce duplication"::String) #-}

View File

@ -3,19 +3,12 @@
{-# LANGUAGE OverloadedStrings #-}
module Deferred(tests) where
import Control.Applicative.Combinators
import Control.Lens hiding (List)
import Control.Monad.IO.Class
import Control.Lens hiding (List)
-- import Control.Monad
-- import Data.Maybe
import Language.LSP.Test
import Language.LSP.Types
import Language.LSP.Types.Lens hiding (id, message)
import Language.LSP.Types.Lens hiding (id, message)
-- import qualified Language.LSP.Types.Lens as LSP
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import Test.Hls
tests :: TestTree

View File

@ -1,15 +1,9 @@
module Definition (tests) where
import Control.Lens
import Control.Monad.IO.Class
import Language.LSP.Test
import Language.LSP.Types
import Language.LSP.Types.Lens
import System.Directory
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import Test.Hls
tests :: TestTree
tests = testGroup "definitions" [

View File

@ -2,19 +2,12 @@
module Diagnostic (tests) where
import Control.Applicative.Combinators
import Control.Lens hiding (List)
import Control.Monad.IO.Class
import Data.Aeson (toJSON)
import Control.Lens hiding (List)
import Data.Aeson (toJSON)
import qualified Data.Default
import Ide.Plugin.Config
import Language.LSP.Test hiding (message)
import Language.LSP.Types
import qualified Language.LSP.Types.Lens as LSP
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import qualified Language.LSP.Types.Lens as LSP
import Test.Hls
-- ---------------------------------------------------------------------

View File

@ -11,18 +11,15 @@ import qualified Data.Text.IO as T
import Language.LSP.Test
import Language.LSP.Types
import qualified Language.LSP.Types.Lens as LSP
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.Golden
import Test.Tasty.HUnit
import Test.Hls
tests :: TestTree
tests = testGroup "format document" [
goldenVsStringDiff "works" goldenGitDiff "test/testdata/format/Format.formatted_document.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
goldenGitDiff "works" "test/testdata/format/Format.formatted_document.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
doc <- openDoc "Format.hs" "haskell"
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
, goldenVsStringDiff "works with custom tab size" goldenGitDiff "test/testdata/format/Format.formatted_document_with_tabsize.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
, goldenGitDiff "works with custom tab size" "test/testdata/format/Format.formatted_document_with_tabsize.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
doc <- openDoc "Format.hs" "haskell"
formatDoc doc (FormattingOptions 5 True Nothing Nothing Nothing)
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
@ -34,11 +31,11 @@ tests = testGroup "format document" [
rangeTests :: TestTree
rangeTests = testGroup "format range" [
goldenVsStringDiff "works" goldenGitDiff "test/testdata/format/Format.formatted_range.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
goldenGitDiff "works" "test/testdata/format/Format.formatted_range.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
doc <- openDoc "Format.hs" "haskell"
formatRange doc (FormattingOptions 2 True Nothing Nothing Nothing) (Range (Position 5 0) (Position 7 10))
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
, goldenVsStringDiff "works with custom tab size" goldenGitDiff "test/testdata/format/Format.formatted_range_with_tabsize.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
, goldenGitDiff "works with custom tab size" "test/testdata/format/Format.formatted_range_with_tabsize.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
doc <- openDoc "Format.hs" "haskell"
formatRange doc (FormattingOptions 5 True Nothing Nothing Nothing) (Range (Position 8 0) (Position 11 19))
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
@ -49,7 +46,7 @@ providerTests = testGroup "formatting provider" [
testCase "respects none" $ runSessionWithConfig (formatConfig "none") hlsCommand fullCaps "test/testdata/format" $ do
doc <- openDoc "Format.hs" "haskell"
resp <- request STextDocumentFormatting $ DocumentFormattingParams Nothing doc (FormattingOptions 2 True Nothing Nothing Nothing)
liftIO $ resp ^. LSP.result @?= (Left $ ResponseError InvalidRequest "No plugin enabled for STextDocumentFormatting, available: []" Nothing)
liftIO $ resp ^. LSP.result @?= Left (ResponseError InvalidRequest "No plugin enabled for STextDocumentFormatting, available: []" Nothing)
, testCase "respects initial" $ runSessionWithConfig (formatConfig "floskell") hlsCommand fullCaps "test/testdata/format" $ do
doc <- openDoc "Format.hs" "haskell"
@ -93,12 +90,12 @@ providerTests = testGroup "formatting provider" [
ormoluTests :: TestTree
ormoluTests = testGroup "ormolu"
[ goldenVsStringDiff "formats correctly" goldenGitDiff "test/testdata/format/Format.ormolu.formatted.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
[ goldenGitDiff "formats correctly" "test/testdata/format/Format.ormolu.formatted.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu"))
doc <- openDoc "Format.hs" "haskell"
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
, goldenVsStringDiff "formats imports correctly" goldenGitDiff "test/testdata/format/Format2.ormolu.formatted.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
, goldenGitDiff "formats imports correctly" "test/testdata/format/Format2.ormolu.formatted.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu"))
doc <- openDoc "Format2.hs" "haskell"
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
@ -107,12 +104,12 @@ ormoluTests = testGroup "ormolu"
fourmoluTests :: TestTree
fourmoluTests = testGroup "fourmolu"
[ goldenVsStringDiff "formats correctly" goldenGitDiff "test/testdata/format/Format.fourmolu.formatted.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
[ goldenGitDiff "formats correctly" "test/testdata/format/Format.fourmolu.formatted.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "fourmolu"))
doc <- openDoc "Format.hs" "haskell"
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
, goldenVsStringDiff "formats imports correctly" goldenGitDiff "test/testdata/format/Format2.fourmolu.formatted.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
, goldenGitDiff "formats imports correctly" "test/testdata/format/Format2.fourmolu.formatted.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "fourmolu"))
doc <- openDoc "Format2.hs" "haskell"
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
@ -128,6 +125,3 @@ formatLspConfigOld provider = object [ "languageServerHaskell" .= object ["forma
formatConfig :: Value -> SessionConfig
formatConfig provider = defaultConfig { lspConfig = Just (formatLspConfig provider) }
goldenGitDiff :: FilePath -> FilePath -> [String]
goldenGitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew]

View File

@ -8,9 +8,7 @@ module FunctionalBadProject (tests) where
-- import Language.LSP.Test hiding (message)
-- import Language.LSP.Types as LSP
-- import Language.LSP.Types.Lens as LSP hiding (contents, error )
-- import Test.Hls.Util
import Test.Tasty
import Test.Tasty.HUnit
import Test.Hls
-- ---------------------------------------------------------------------
-- TODO: Currently this can not succeed, since such an error is thrown in "runActionWithContext" which

View File

@ -6,30 +6,22 @@
module FunctionalCodeAction (tests) where
import Control.Applicative.Combinators
import Control.Lens hiding (List)
import Control.Monad
import Control.Monad.IO.Class
import Data.Aeson
import Data.Default
import qualified Data.HashMap.Strict as HM
import Data.List
import Data.Maybe
import qualified Data.Text as T
import Ide.Plugin.Config
import Language.LSP.Test as Test
import Language.LSP.Types
import qualified Language.LSP.Types.Capabilities as C
import qualified Language.LSP.Types.Lens as L
import Test.Hls.Util
import Test.Hls
import Test.Hspec.Expectations
import System.FilePath ((</>))
import System.IO.Extra (withTempDir)
import Test.Tasty
import Test.Tasty.ExpectedFailure (expectFailBecause,
ignoreTestBecause)
import Test.Tasty.HUnit
{-# ANN module ("HLint: ignore Reduce duplication"::String) #-}

View File

@ -2,19 +2,11 @@
module FunctionalLiquid (tests) where
import Control.Lens hiding (List)
import Control.Monad.IO.Class
import Control.Lens hiding (List)
import Data.Aeson
import Data.Default
import Ide.Plugin.Config
import Language.LSP.Test hiding (message)
import Language.LSP.Types as LSP
import Language.LSP.Types.Lens as LSP hiding (contents)
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import Language.LSP.Types.Lens as LSP hiding (contents)
import Test.Hls
-- ---------------------------------------------------------------------
tests :: TestTree

View File

@ -11,19 +11,13 @@ module HaddockComments
)
where
import Control.Monad.IO.Class (liftIO)
import qualified Data.ByteString.Lazy as LBS
import Data.Foldable (find)
import Data.Maybe (mapMaybe)
import Data.Text (Text)
import Data.Text.Encoding (encodeUtf8)
import Language.LSP.Test
import Language.LSP.Types
import System.FilePath ((<.>), (</>))
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.Golden
import Test.Tasty.HUnit
import qualified Data.ByteString.Lazy as LBS
import Data.Foldable (find)
import Data.Maybe (mapMaybe)
import Data.Text (Text)
import Data.Text.Encoding (encodeUtf8)
import System.FilePath ((<.>), (</>))
import Test.Hls
tests :: TestTree
tests =
@ -40,7 +34,7 @@ tests =
]
goldenTest :: FilePath -> GenCommentsType -> Int -> Int -> TestTree
goldenTest fp (toTitle -> expectedTitle) l c = goldenVsStringDiff (fp <> " (golden)") goldenGitDiff goldenFilePath $
goldenTest fp (toTitle -> expectedTitle) l c = goldenGitDiff (fp <> " (golden)") goldenFilePath $
runSession hlsCommand fullCaps haddockCommentsPath $ do
doc <- openDoc hsFilePath "haskell"
_ <- waitForDiagnostics
@ -75,5 +69,3 @@ caTitle _ = Nothing
haddockCommentsPath :: String
haddockCommentsPath = "test" </> "testdata" </> "haddockComments"
goldenGitDiff :: FilePath -> FilePath -> [String]
goldenGitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew]

View File

@ -4,13 +4,10 @@ module HieBios (tests) where
import Control.Lens ((^.))
import Control.Monad.IO.Class
import qualified Data.Text as T
import Language.LSP.Test
import Language.LSP.Types
import qualified Language.LSP.Types.Lens as L
import System.FilePath ((</>))
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.HUnit
import Test.Hls
tests :: TestTree
tests = testGroup "hie-bios" [

View File

@ -1,12 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}
module Highlight (tests) where
import Control.Monad.IO.Class
import Language.LSP.Test
import Language.LSP.Types
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.HUnit
import Test.Hls
tests :: TestTree
tests = testGroup "highlight" [

View File

@ -7,7 +7,6 @@ import Config
import Deferred
import Definition
import Diagnostic
import Eval
import Format
import FunctionalBadProject
import FunctionalCodeAction
@ -21,19 +20,11 @@ import Reference
import Rename
import Splice
import Symbol
import Test.Tasty
import Test.Tasty.Ingredients.Rerun
import Test.Tasty.Runners (consoleTestReporter,
listingTests)
import Test.Tasty.Runners.AntXML
import Test.Hls
import TypeDefinition
main :: IO ()
main =
-- ingredient: xml runner writes json file of test results (https://github.com/ocharles/tasty-ant-xml/blob/master/Test/Tasty/Runners/AntXML.hs)
-- rerunningTests allow rerun of failed tests (https://github.com/ocharles/tasty-rerun/blob/master/src/Test/Tasty/Ingredients/Rerun.hs)
defaultMainWithIngredients
[antXMLRunner, rerunningTests [listingTests, consoleTestReporter]]
main = defaultTestRunner
$ testGroup
"haskell-language-server"
[ Class.tests
@ -43,7 +34,6 @@ main =
, Deferred.tests
, Definition.tests
, Diagnostic.tests
, Eval.tests
, Format.tests
, FunctionalBadProject.tests
, FunctionalCodeAction.tests

View File

@ -1,24 +1,15 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module ModuleName
( tests
)
where
import Control.Applicative.Combinators (skipManyTill)
import Control.Monad.IO.Class (MonadIO (liftIO))
import qualified Data.Text.IO as T
import Language.LSP.Test (anyMessage, documentContents,
executeCommand, fullCaps,
getCodeLenses, message,
openDoc, runSession)
import Language.LSP.Types
import System.FilePath ((<.>), (</>))
import Test.Hls.Util (hlsCommand)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (testCase, (@?=))
import qualified Data.Text.IO as T
import System.FilePath ((<.>), (</>))
import Test.Hls
tests :: TestTree
tests = testGroup

View File

@ -7,25 +7,17 @@
module Progress (tests) where
import Control.Applicative.Combinators
import Control.Lens hiding ((.=))
import Control.Monad.IO.Class
import Data.Aeson (Value, decode, encode, object,
toJSON, (.=))
import Data.Default
import Data.List (delete)
import Data.Maybe (fromJust)
import Data.Text (Text, pack)
import Ide.Plugin.Config
import Language.LSP.Test
import Language.LSP.Types
import Language.LSP.Types.Capabilities
import qualified Language.LSP.Types.Lens as L
import System.FilePath ((</>))
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import Test.Hls
tests :: TestTree
tests =

View File

@ -1,16 +1,10 @@
module Reference (tests) where
import Control.Lens
import Control.Monad.IO.Class
import Data.Coerce
import Data.List
import Language.LSP.Test
import Language.LSP.Types
import Language.LSP.Types.Lens
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import Test.Hls
tests :: TestTree
tests = testGroup "references" [

View File

@ -1,13 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}
module Rename (tests) where
import Control.Monad.IO.Class (liftIO)
import Language.LSP.Test
import Language.LSP.Types
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import Test.Hls
tests :: TestTree
tests = testGroup "rename" [

View File

@ -8,22 +8,16 @@
module Splice (tests) where
import Control.Applicative.Combinators
import Control.Monad
import Control.Monad.IO.Class
import Data.List (find)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.List (find)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Ide.Plugin.Splice.Types
import Language.LSP.Test
import Language.LSP.Types
import System.Directory
import System.FilePath
import System.Time.Extra (sleep)
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.HUnit
import System.Time.Extra (sleep)
import Test.Hls
tests :: TestTree
tests =

View File

@ -2,16 +2,11 @@
module Symbol (tests) where
import Control.Lens (_Just, ix, to, (^?))
import Control.Monad.IO.Class
import Data.List
import Language.LSP.Test as Test
import Language.LSP.Types
import Language.LSP.Types.Capabilities
import qualified Language.LSP.Types.Lens as L
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
import Test.Tasty.HUnit
import Test.Hls
tests :: TestTree
tests = testGroup "document symbols" [

View File

@ -1,13 +1,8 @@
module TypeDefinition (tests) where
import Control.Monad.IO.Class
import Data.Tuple.Extra (first3)
import Language.LSP.Test
import Language.LSP.Types
import System.FilePath ((</>))
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.HUnit
import Data.Tuple.Extra (first3)
import System.FilePath ((</>))
import Test.Hls
tests :: TestTree
tests = testGroup "type definitions" [

View File

@ -1,20 +1,13 @@
import Data.List.Extra (trimEnd)
import Data.List.Extra (trimEnd)
import Data.Maybe
import System.Environment
import System.Process
import Test.Hls.Util
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.Ingredients.Rerun
import Test.Tasty.Runners (consoleTestReporter,
listingTests)
import Test.Hls
main :: IO ()
main = do
flushStackEnvironment
defaultMainWithIngredients
[rerunningTests [listingTests, consoleTestReporter]] $
testGroup "haskell-language-server-wrapper" [projectGhcVersionTests]
defaultTestRunner $ testGroup "haskell-language-server-wrapper" [projectGhcVersionTests]
projectGhcVersionTests :: TestTree
projectGhcVersionTests = testGroup "--project-ghc-version"