Skip to content

Commit 57f224e

Browse files
committed
Move tactic tests to be standalone
1 parent ff9a182 commit 57f224e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+152
-77
lines changed

plugins/hls-tactics-plugin/hls-tactics-plugin.cabal

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,64 @@ library
7878
default-language: Haskell2010
7979
default-extensions: DataKinds, TypeOperators
8080

81+
82+
executable test-server
83+
default-language: Haskell2010
84+
build-depends:
85+
, base
86+
, data-default
87+
, ghcide
88+
, hls-tactics-plugin
89+
, hls-plugin-api
90+
, shake
91+
main-is: Server.hs
92+
hs-source-dirs: test
93+
ghc-options:
94+
"-with-rtsopts=-I0 -A128M"
95+
-threaded -Wall -Wno-name-shadowing -Wredundant-constraints
96+
8197
test-suite tests
8298
type: exitcode-stdio-1.0
8399
main-is: Main.hs
84100
other-modules:
85101
AutoTupleSpec
102+
GoldenSpec
86103
UnificationSpec
87104
hs-source-dirs:
88105
test
89106
ghc-options: -Wall -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
90107
build-depends:
91108
QuickCheck
109+
, aeson
92110
, base
111+
, bytestring
93112
, checkers
113+
, containers
114+
, data-default
115+
, deepseq
116+
, directory
117+
, filepath
118+
, ghc
119+
, ghcide >= 0.7.5.0
120+
, hie-bios
121+
, hls-plugin-api
122+
, hls-tactics-plugin
94123
, hspec
124+
, hspec-expectations
125+
, lens
126+
, lsp-test
127+
, lsp-types
128+
, megaparsec
95129
, mtl
96-
, hls-tactics-plugin
97-
, hls-plugin-api
98-
, hie-bios
99-
, ghc
100-
, containers
101-
build-tool-depends: hspec-discover:hspec-discover
130+
, tasty
131+
, tasty-ant-xml >=1.1.6
132+
, tasty-expected-failure
133+
, tasty-golden
134+
, tasty-hunit
135+
, tasty-rerun
136+
, text
137+
build-tool-depends:
138+
hspec-discover:hspec-discover
139+
, hls-tactics-plugin:test-server -any
102140
default-language: Haskell2010
103141

plugins/hls-tactics-plugin/test/AutoTupleSpec.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ import TysPrim (alphaTyVars)
1717
import TysWiredIn (mkBoxedTupleTy)
1818

1919

20-
instance Show Type where
21-
show = unsafeRender
22-
23-
2420
spec :: Spec
2521
spec = describe "auto for tuple" $ do
2622
it "should always be able to discover an auto solution" $ do

test/functional/Tactic.hs renamed to plugins/hls-tactics-plugin/test/GoldenSpec.hs

Lines changed: 89 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
{-# LANGUAGE OverloadedStrings #-}
2-
{-# LANGUAGE ScopedTypeVariables #-}
3-
{-# LANGUAGE ViewPatterns #-}
4-
{-# LANGUAGE TypeOperators #-}
1+
{-# LANGUAGE DataKinds #-}
52
{-# LANGUAGE DuplicateRecordFields #-}
6-
{-# LANGUAGE DataKinds #-}
3+
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE ScopedTypeVariables #-}
5+
{-# LANGUAGE TypeOperators #-}
6+
{-# LANGUAGE ViewPatterns #-}
77

8-
module Tactic
9-
( tests
10-
)
11-
where
8+
module GoldenSpec where
129

1310
import Control.Applicative.Combinators ( skipManyTill )
1411
import Control.Lens hiding ((<.>))
@@ -28,33 +25,18 @@ import Ide.Plugin.Tactic.FeatureSet (FeatureSet, allFeatures)
2825
import Ide.Plugin.Tactic.TestTypes
2926
import Language.LSP.Test
3027
import Language.LSP.Types
31-
import Language.LSP.Types.Lens hiding (id, capabilities, message, executeCommand, applyEdit, rename)
28+
import Language.LSP.Types.Lens hiding (id, capabilities, message, executeCommand, applyEdit, rename, line, title, name, actions)
3229
import System.Directory (doesFileExist)
3330
import System.FilePath
34-
import Test.Hls.Util
31+
import Test.Hspec
3532
import Test.Tasty
3633
import Test.Tasty.ExpectedFailure (ignoreTestBecause)
3734
import Test.Tasty.HUnit
35+
import Test.Tasty.Ingredients.Rerun
36+
import Test.Tasty.Runners (consoleTestReporter, listingTests)
37+
import Test.Tasty.Runners.AntXML
3838

3939

40-
------------------------------------------------------------------------------
41-
-- | Get a range at the given line and column corresponding to having nothing
42-
-- selected.
43-
--
44-
-- NB: These coordinates are in "file space", ie, 1-indexed.
45-
pointRange :: Int -> Int -> Range
46-
pointRange
47-
(subtract 1 -> line)
48-
(subtract 1 -> col) =
49-
Range (Position line col) (Position line $ col + 1)
50-
51-
52-
------------------------------------------------------------------------------
53-
-- | Get the title of a code action.
54-
codeActionTitle :: (Command |? CodeAction) -> Maybe Text
55-
codeActionTitle InL{} = Nothing
56-
codeActionTitle (InR(CodeAction title _ _ _ _ _ _)) = Just title
57-
5840

5941
tests :: TestTree
6042
tests = testGroup
@@ -96,41 +78,72 @@ tests = testGroup
9678
"T2.hs" 11 25
9779
[ (not, DestructLambdaCase, "")
9880
]
99-
, goldenTest "GoldenIntros.hs" 2 8 Intros ""
100-
, goldenTest "GoldenEitherAuto.hs" 2 11 Auto ""
101-
, goldenTest "GoldenJoinCont.hs" 4 12 Auto ""
102-
, goldenTest "GoldenIdentityFunctor.hs" 3 11 Auto ""
103-
, goldenTest "GoldenIdTypeFam.hs" 7 11 Auto ""
104-
, goldenTest "GoldenEitherHomomorphic.hs" 2 15 Auto ""
105-
, goldenTest "GoldenNote.hs" 2 8 Auto ""
106-
, goldenTest "GoldenPureList.hs" 2 12 Auto ""
107-
, goldenTest "GoldenListFmap.hs" 2 12 Auto ""
108-
, goldenTest "GoldenFromMaybe.hs" 2 13 Auto ""
109-
, goldenTest "GoldenFoldr.hs" 2 10 Auto ""
110-
, goldenTest "GoldenSwap.hs" 2 8 Auto ""
111-
, goldenTest "GoldenFmapTree.hs" 4 11 Auto ""
112-
, goldenTest "GoldenGADTDestruct.hs" 7 17 Destruct "gadt"
113-
, goldenTest "GoldenGADTDestructCoercion.hs" 8 17 Destruct "gadt"
114-
, goldenTest "GoldenGADTAuto.hs" 7 13 Auto ""
115-
, goldenTest "GoldenSwapMany.hs" 2 12 Auto ""
116-
, goldenTest "GoldenBigTuple.hs" 4 12 Auto ""
117-
, goldenTest "GoldenShow.hs" 2 10 Auto ""
118-
, goldenTest "GoldenShowCompose.hs" 2 15 Auto ""
119-
, goldenTest "GoldenShowMapChar.hs" 2 8 Auto ""
120-
, goldenTest "GoldenSuperclass.hs" 7 8 Auto ""
81+
, goldenTest "GoldenIntros.hs"
82+
2 8 Intros ""
83+
, autoTest "GoldenEitherAuto.hs" 2 11
84+
, autoTest "GoldenJoinCont.hs" 4 12
85+
, autoTest "GoldenIdentityFunctor.hs" 3 11
86+
, autoTest "GoldenIdTypeFam.hs" 7 11
87+
, autoTest "GoldenEitherHomomorphic.hs" 2 15
88+
, autoTest "GoldenNote.hs" 2 8
89+
, autoTest "GoldenPureList.hs" 2 12
90+
, autoTest "GoldenListFmap.hs" 2 12
91+
, autoTest "GoldenFromMaybe.hs" 2 13
92+
, autoTest "GoldenFoldr.hs" 2 10
93+
, autoTest "GoldenSwap.hs" 2 8
94+
, autoTest "GoldenFmapTree.hs" 4 11
95+
, goldenTest "GoldenGADTDestruct.hs"
96+
7 17 Destruct "gadt"
97+
, goldenTest "GoldenGADTDestructCoercion.hs"
98+
8 17 Destruct "gadt"
99+
, autoTest "GoldenGADTAuto.hs" 7 13
100+
, autoTest "GoldenSwapMany.hs" 2 12
101+
, autoTest "GoldenBigTuple.hs" 4 12
102+
, autoTest "GoldenShow.hs" 2 10
103+
, autoTest "GoldenShowCompose.hs" 2 15
104+
, autoTest "GoldenShowMapChar.hs" 2 8
105+
, autoTest "GoldenSuperclass.hs" 7 8
121106
, ignoreTestBecause "It is unreliable in circleci builds"
122-
$ goldenTest "GoldenApplicativeThen.hs" 2 11 Auto ""
123-
, goldenTest "GoldenSafeHead.hs" 2 12 Auto ""
124-
, expectFail "GoldenFish.hs" 5 18 Auto ""
125-
, goldenTest "GoldenArbitrary.hs" 25 13 Auto ""
126-
, goldenTest "FmapBoth.hs" 2 12 Auto ""
127-
, goldenTest "RecordCon.hs" 7 8 Auto ""
128-
, goldenTest "FmapJoin.hs" 2 14 Auto ""
129-
, goldenTest "Fgmap.hs" 2 9 Auto ""
130-
, goldenTest "FmapJoinInLet.hs" 4 19 Auto ""
107+
$ autoTest "GoldenApplicativeThen.hs" 2 11
108+
, autoTest "GoldenSafeHead.hs" 2 12
109+
, expectFail "GoldenFish.hs"
110+
5 18 Auto ""
111+
, autoTest "GoldenArbitrary.hs" 25 13
112+
, autoTest "FmapBoth.hs" 2 12
113+
, autoTest "RecordCon.hs" 7 8
114+
, autoTest "FmapJoin.hs" 2 14
115+
, autoTest "Fgmap.hs" 2 9
116+
, autoTest "FmapJoinInLet.hs" 4 19
131117
]
132118

133119

120+
spec :: Spec
121+
spec = do
122+
it "GoldenTests" $
123+
defaultMainWithIngredients
124+
[antXMLRunner, rerunningTests [listingTests, consoleTestReporter]]
125+
tests
126+
127+
128+
------------------------------------------------------------------------------
129+
-- | Get a range at the given line and column corresponding to having nothing
130+
-- selected.
131+
--
132+
-- NB: These coordinates are in "file space", ie, 1-indexed.
133+
pointRange :: Int -> Int -> Range
134+
pointRange
135+
(subtract 1 -> line)
136+
(subtract 1 -> col) =
137+
Range (Position line col) (Position line $ col + 1)
138+
139+
140+
------------------------------------------------------------------------------
141+
-- | Get the title of a code action.
142+
codeActionTitle :: (Command |? CodeAction) -> Maybe Text
143+
codeActionTitle InL{} = Nothing
144+
codeActionTitle (InR(CodeAction title _ _ _ _ _ _)) = Just title
145+
146+
134147
------------------------------------------------------------------------------
135148
-- | Make a tactic unit test.
136149
mkTest
@@ -146,7 +159,7 @@ mkTest
146159
-> TestTree
147160
mkTest name fp line col ts =
148161
testCase name $ do
149-
runSession hlsCommand fullCaps tacticPath $ do
162+
runSession testCommand fullCaps tacticPath $ do
150163
doc <- openDoc fp "haskell"
151164
_ <- waitForDiagnostics
152165
actions <- getCodeActions doc $ pointRange line col
@@ -158,6 +171,10 @@ mkTest name fp line col ts =
158171
@? ("Expected a code action with title " <> T.unpack title)
159172

160173

174+
autoTest :: FilePath -> Int -> Int -> TestTree
175+
autoTest fp line col = goldenTest fp line col Auto ""
176+
177+
161178
setFeatureSet :: FeatureSet -> Session ()
162179
setFeatureSet features = do
163180
let unObject (Object obj) = obj
@@ -174,13 +191,15 @@ setFeatureSet features = do
174191
DidChangeConfigurationParams $
175192
toJSON config
176193

194+
177195
goldenTest :: FilePath -> Int -> Int -> TacticCommand -> Text -> TestTree
178196
goldenTest = goldenTest' allFeatures
179197

198+
180199
goldenTest' :: FeatureSet -> FilePath -> Int -> Int -> TacticCommand -> Text -> TestTree
181200
goldenTest' features input line col tc occ =
182201
testCase (input <> " (golden)") $ do
183-
runSession hlsCommand fullCaps tacticPath $ do
202+
runSession testCommand fullCaps tacticPath $ do
184203
setFeatureSet features
185204
doc <- openDoc input "haskell"
186205
_ <- waitForDiagnostics
@@ -201,7 +220,7 @@ goldenTest' features input line col tc occ =
201220
expectFail :: FilePath -> Int -> Int -> TacticCommand -> Text -> TestTree
202221
expectFail input line col tc occ =
203222
testCase (input <> " (golden)") $ do
204-
runSession hlsCommand fullCaps tacticPath $ do
223+
runSession testCommand fullCaps tacticPath $ do
205224
doc <- openDoc input "haskell"
206225
_ <- waitForDiagnostics
207226
actions <- getCodeActions doc $ pointRange line col
@@ -213,11 +232,16 @@ expectFail input line col tc occ =
213232

214233

215234
tacticPath :: FilePath
216-
tacticPath = "test/testdata/tactic"
235+
tacticPath = "test/golden"
236+
217237

238+
testCommand :: String
239+
testCommand = "test-server"
218240

219-
executeCommandWithResp :: Command -> Session (ResponseMessage WorkspaceExecuteCommand)
241+
242+
executeCommandWithResp :: Command -> Session (ResponseMessage 'WorkspaceExecuteCommand)
220243
executeCommandWithResp cmd = do
221244
let args = decode $ encode $ fromJust $ cmd ^. arguments
222245
execParams = ExecuteCommandParams Nothing (cmd ^. command) args
223246
request SWorkspaceExecuteCommand execParams
247+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE ViewPatterns #-}
3+
4+
module Main(main) where
5+
6+
import Data.Default
7+
import Development.IDE.Main
8+
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
9+
import Ide.Plugin.Tactic as T
10+
import Ide.PluginUtils
11+
12+
main :: IO ()
13+
main = defaultMain def
14+
{ argsHlsPlugins = pluginDescToIdePlugins $
15+
[ T.descriptor "tactic"
16+
] <>
17+
Ghcide.descriptors
18+
}
19+

test/functional/Main.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import Reference
2121
import Rename
2222
import Symbol
2323
import Splice
24-
import Tactic
2524
import Test.Tasty
2625
import Test.Tasty.Ingredients.Rerun
2726
import Test.Tasty.Runners (
@@ -58,7 +57,6 @@ main =
5857
, Reference.tests
5958
, Rename.tests
6059
, Symbol.tests
61-
, Tactic.tests
6260
, TypeDefinition.tests
6361
, Splice.tests
6462
, HaddockComments.tests

0 commit comments

Comments
 (0)