Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate tests of plugins #1612

Merged
merged 10 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defaults: &defaults

- run:
name: Build Testsuite without running it
command: stack --stack-yaml=${STACK_FILE} build --test --no-run-tests
command: stack -j 1 --stack-yaml=${STACK_FILE} build --test --no-run-tests
no_output_timeout: 30m

- store_artifacts:
Expand All @@ -52,14 +52,6 @@ defaults: &defaults
- ~/build/.stack-work
- ~/build/ghcide/.stack-work

- run:
name: Setup stack eval hie.html
command: cp plugins/hls-eval-plugin/test/testdata/hie-stack.yaml plugins/hls-eval-plugin/test/testdata/hie.yaml

- run:
name: Setup stack eval stack.html
command: grep '^resolver:\|^compiler:' stack-build.txt > plugins/hls-eval-plugin/test/testdata/stack.yaml

- run:
name: Build including tests
command: stack --stack-yaml=${STACK_FILE} test --no-run-tests
Expand Down
35 changes: 19 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,30 @@ jobs:
# instances to be spun up for the poor github actions runner to handle
run: cabal test wrapper-test --test-options="-j1" || cabal test wrapper-test --test-options="-j1" || cabal test wrapper-test --test-options="-j1"

- name: Test hls-tactics-plugin test suite
- name: Test hls-brittany-plugin
if: ${{ matrix.test }}
run: LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-tactics-plugin --test-options="-j1"
run: cabal test hls-brittany-plugin || cabal test hls-brittany-plugin --test-options="-j1"

- name: Test brittany plugin
- name: Test hls-class-plugin
if: ${{ matrix.test }}
env:
HLS_TEST_EXE: hls
HLS_WRAPPER_TEST_EXE: hls-wrapper
run: cabal test hls-brittany-plugin || cabal test hls-brittany-plugin --test-options="-j1"
run: cabal test hls-class-plugin || cabal test hls-class-plugin --test-options="-j1"

- name: Test stylish-haskell plugin
- name: Test hls-eval-plugin
if: ${{ matrix.test }}
run: cabal test hls-eval-plugin --test-options="-j1 --rerun" || cabal test hls-eval-plugin --test-options="-j1 --rerun"

- name: Test hls-haddock-comments-plugin
if: ${{ matrix.test }}
run: cabal test hls-haddock-comments-plugin || cabal test hls-haddock-comments-plugin --test-options="-j1"

- name: Test hls-splice-plugin
if: ${{ matrix.test }}
run: cabal test hls-splice-plugin || cabal test hls-splice-plugin --test-options="-j1"

- name: Test hls-stylish-haskell-plugin
if: ${{ matrix.test }}
env:
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
- name: Test hls-tactics-plugin test suite
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"
run: LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-tactics-plugin --test-options="-j1"
8 changes: 2 additions & 6 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extra-source-files:
test/testdata/**/*.h
test/testdata/**/*.hs
test/testdata/**/*.expected
test/testdata/**/*.error

flag pedantic
description: Enable -Werror
Expand Down Expand Up @@ -394,11 +393,10 @@ test-suite func-test
, containers
, unordered-containers

hs-source-dirs: test/functional plugins/hls-splice-plugin/src
hs-source-dirs: test/functional test/utils

main-is: Main.hs
other-modules:
Class
Command
Completion
Config
Expand All @@ -417,9 +415,7 @@ test-suite func-test
Rename
Symbol
TypeDefinition
Splice
HaddockComments
Ide.Plugin.Splice.Types
Test.Hls.Command

default-extensions: OverloadedStrings
ghc-options:
Expand Down
2 changes: 1 addition & 1 deletion hls-plugin-api/hls-plugin-api.cabal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cabal-version: 2.2
cabal-version: 2.4
name: hls-plugin-api
version: 1.1.0.0
synopsis: Haskell Language Server API for plugin communication
Expand Down
2 changes: 1 addition & 1 deletion hls-test-utils/hls-test-utils.cabal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cabal-version: 2.2
cabal-version: 2.4
name: hls-test-utils
version: 1.0.0.0
synopsis: Utilities used in the tests of Haskell Language Server
Expand Down
25 changes: 0 additions & 25 deletions hls-test-utils/src/Test/Hls/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ module Test.Hls.Util
, ghcVersion, GhcVersion(..)
, hostOS, OS(..)
, matchesCurrentEnv, EnvSpec(..)
, hlsCommand
, hlsCommandExamplePlugin
, hlsCommandVomit
, ignoreForGhcVersions
, ignoreInEnv
, inspectCodeAction
Expand All @@ -26,7 +23,6 @@ module Test.Hls.Util
, knownBrokenOnWindows
, knownBrokenForGhcVersions
, knownBrokenInEnv
, logFilePath
, setupBuildToolFiles
, SymbolLocation
, waitForDiagnosticsFrom
Expand Down Expand Up @@ -57,7 +53,6 @@ import System.Environment
import System.Time.Extra (Seconds, sleep)
import System.FilePath
import System.IO.Temp
import System.IO.Unsafe
import Test.Hspec.Runner
import Test.Hspec.Core.Formatters hiding (Seconds)
import Test.Tasty (TestTree)
Expand Down Expand Up @@ -164,26 +159,6 @@ ignoreForGhcVersions vers reason
| ghcVersion `elem` vers = ignoreTestBecause reason
| otherwise = id

logFilePath :: String
logFilePath = "hls-" ++ show ghcVersion ++ ".log"

-- | The command to execute the version of hls for the current compiler.
--
-- Both @stack test@ and @cabal new-test@ setup the environment so @hls@ is
-- on PATH. Cabal seems to respond to @build-tool-depends@ specifically while
-- stack just puts all project executables on PATH.
hlsCommand :: String
{-# NOINLINE hlsCommand #-}
hlsCommand = unsafePerformIO $ do
testExe <- fromMaybe "haskell-language-server" <$> lookupEnv "HLS_TEST_EXE"
pure $ testExe ++ " --lsp -d -j2 -l test-logs/" ++ logFilePath

hlsCommandVomit :: String
hlsCommandVomit = hlsCommand ++ " --vomit"

hlsCommandExamplePlugin :: String
hlsCommandExamplePlugin = hlsCommand ++ " --example"

-- ---------------------------------------------------------------------

hieYamlCradleDirectContents :: String
Expand Down
81 changes: 60 additions & 21 deletions plugins/hls-class-plugin/hls-class-plugin.cabal
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
cabal-version: 2.2
cabal-version: 2.4
name: hls-class-plugin
version: 1.0.0.0
synopsis: Class/instance management plugin for Haskell Language Server
synopsis:
Class/instance management plugin for Haskell Language Server

description:
Class/instance management plugin for Haskell Language Server.
For usage, please see README of HLS on GitHub at <https://github.com/haskell/haskell-language-server#readme>
Class/instance management plugin for Haskell Language Server.
For usage, please see README of HLS on GitHub at <https://github.com/haskell/haskell-language-server#readme>

license: Apache-2.0
license-file: LICENSE
author: Junyoung Clare Jang
Expand All @@ -13,24 +16,60 @@ homepage: https://github.com/haskell/haskell-language-server#readme
bug-reports: https://github.com/haskell/haskell-language-server/issues
category: Development
build-type: Simple
extra-source-files:
LICENSE
test/testdata/*.hs

library
exposed-modules: Ide.Plugin.Class
hs-source-dirs: src
build-depends: aeson
, base >=4.12 && <5
, containers
, lsp
, hls-plugin-api >= 1.0 && < 1.2
, ghc
, ghc-exactprint
, ghcide ^>= 1.1.0.0
, lens
, shake
, text
, transformers
, unordered-containers
exposed-modules: Ide.Plugin.Class
hs-source-dirs: src
build-depends:
, aeson
, base >=4.12 && <5
, containers
, ghc
, ghc-exactprint
, ghcide ^>=1.1.0.0
, hls-plugin-api >=1.0 && <1.2
, lens
, lsp
, shake
, text
, transformers
, unordered-containers

default-language: Haskell2010
default-extensions:
DataKinds
TypeOperators

ghc-options: -Wno-unticked-promoted-constructors

executable test-server
default-language: Haskell2010
default-extensions: DataKinds, TypeOperators
ghc-options: -Wno-unticked-promoted-constructors
build-depends:
, base
, data-default
, ghcide
, hls-class-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-class-plugin:test-server -any
hs-source-dirs: test
main-is: Main.hs
build-depends:
, base
, bytestring
, filepath
, hls-test-utils
, lens
, lsp-test
, lsp-types
, text
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
module Class
( tests
module Main
( main
)
where

Expand All @@ -14,19 +14,21 @@ import qualified Language.LSP.Types.Lens as J
import System.FilePath
import Test.Hls

main :: IO ()
main = defaultTestRunner tests

tests :: TestTree
tests = testGroup
"class"
[ testCase "Produces addMinimalMethodPlaceholders code actions for one instance" $ do
runSession hlsCommand fullCaps classPath $ do
runSession testCommand fullCaps classPath $ do
doc <- openDoc "T1.hs" "haskell"
_ <- waitForDiagnosticsFromSource doc "typecheck"
caResults <- getAllCodeActions doc
liftIO $ map (^? _CACodeAction . J.title) caResults
@?=
[ Just "Add placeholders for '=='"
, Just "Add placeholders for '/='"
, Just "Disable \"missing-methods\" warnings"
]
, glodenTest "Creates a placeholder for '=='" "T1" "eq"
$ \(eqAction:_) -> do
Expand Down Expand Up @@ -54,12 +56,12 @@ _CACodeAction = prism' InR $ \case
_ -> Nothing

classPath :: FilePath
classPath = "test" </> "testdata" </> "class"
classPath = "test" </> "testdata"

glodenTest :: String -> FilePath -> FilePath -> ([CodeAction] -> Session ()) -> TestTree
glodenTest name fp deco execute
= goldenGitDiff name (classPath </> fpWithDeco <.> "expected" <.> "hs")
$ runSession hlsCommand fullCaps classPath
$ runSession testCommand fullCaps classPath
$ do
doc <- openDoc (fp <.> "hs") "haskell"
_ <- waitForDiagnosticsFromSource doc "typecheck"
Expand Down
18 changes: 18 additions & 0 deletions plugins/hls-class-plugin/test/Server.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

{-# LANGUAGE OverloadedStrings #-}
module Main(main) where

import Data.Default
import Development.IDE.Main
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
import qualified Ide.Plugin.Class as Class
import Ide.Plugin.Config
import Ide.PluginUtils

main :: IO ()
main = defaultMain def
{ argsHlsPlugins = pluginDescToIdePlugins $
[ Class.descriptor "class"
] <>
Ghcide.descriptors
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion plugins/hls-eval-plugin/hls-eval-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ test-suite tests
build-tool-depends: hls-eval-plugin:test-server -any
hs-source-dirs: test
main-is: Main.hs
ghc-options: -Wunused-packages

build-depends:
, aeson
Expand Down
2 changes: 1 addition & 1 deletion plugins/hls-eval-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,4 @@ replaceUnicodeQuotes :: T.Text -> T.Text
replaceUnicodeQuotes = T.replace "‘" "'" . T.replace "’" "'"

evalPath :: FilePath
evalPath = "test/testdata"
evalPath = "test" </> "testdata"
4 changes: 0 additions & 4 deletions plugins/hls-eval-plugin/test/testdata/hie-cabal.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions plugins/hls-eval-plugin/test/testdata/hie-stack.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions plugins/hls-eval-plugin/test/testdata/stack.yaml

This file was deleted.

Loading