Skip to content

Commit 168976d

Browse files
fendormichaelpj
andauthored
Cleanup func-test suite (#3828)
* Cleanup func-test suite This test-suite is vastly legacy from Haskell IDE Engine. It was originally written before we had a plugin-based architecture where each plugin tests its feature in isolation. Over time, this test-suite bitrotted, where a lot of testcases were either redundant or out-of-date and consequentially disabled. We clean up the test-suite, delete old tests and remove unused testdata. * Remove unused config change * Move qualified import tests to hls-refactor-plugin * Add README for `func-test` Provides guidance when to add a test to `func-test` and some historical context. * Add fendor as CODEOWNER for `func-test` and `hls-test-utils` --------- Co-authored-by: Michael Peyton Jones <[email protected]>
1 parent 8e1421a commit 168976d

Some content is hidden

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

77 files changed

+107
-1967
lines changed

CODEOWNERS

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
/ghcide/session-loader @pepeiborra @fendor
44
/hls-graph @pepeiborra
55
/hls-plugin-api @berberman
6-
/hls-test-utils
6+
/hls-test-utils @fendor
7+
/test @fendor
78
/hie-compat
89

910
# Plugins

haskell-language-server.cabal

-10
Original file line numberDiff line numberDiff line change
@@ -529,21 +529,11 @@ test-suite func-test
529529

530530
main-is: Main.hs
531531
other-modules:
532-
Command
533-
Completion
534532
Config
535-
Deferred
536-
Definition
537-
Diagnostic
538533
Format
539534
FunctionalBadProject
540-
FunctionalCodeAction
541535
HieBios
542-
Highlight
543536
Progress
544-
Reference
545-
Symbol
546-
TypeDefinition
547537
Test.Hls.Command
548538
Test.Hls.Flags
549539

hls-test-utils/src/Test/Hls/Util.hs

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Test.Hls.Util
2525
, knownBrokenOnWindows
2626
, knownBrokenForGhcVersions
2727
, knownBrokenInEnv
28+
, knownBrokenInSpecificEnv
2829
, onlyWorkForGhcVersions
2930
-- * Extract code actions
3031
, fromAction
@@ -123,12 +124,18 @@ hostOS
123124
| isMac = MacOS
124125
| otherwise = Linux
125126

126-
-- | Mark as broken if /any/ of environmental spec mathces the current environment.
127+
-- | Mark as broken if /any/ of the environmental specs matches the current environment.
127128
knownBrokenInEnv :: [EnvSpec] -> String -> TestTree -> TestTree
128129
knownBrokenInEnv envSpecs reason
129130
| any matchesCurrentEnv envSpecs = expectFailBecause reason
130131
| otherwise = id
131132

133+
-- | Mark as broken if /all/ environmental specs match the current environment.
134+
knownBrokenInSpecificEnv :: [EnvSpec] -> String -> TestTree -> TestTree
135+
knownBrokenInSpecificEnv envSpecs reason
136+
| all matchesCurrentEnv envSpecs = expectFailBecause reason
137+
| otherwise = id
138+
132139
knownBrokenOnWindows :: String -> TestTree -> TestTree
133140
knownBrokenOnWindows = knownBrokenInEnv [HostOS Windows]
134141

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

+38-1
Original file line numberDiff line numberDiff line change
@@ -528,21 +528,43 @@ insertImportTests = testGroup "insert import"
528528
"ModuleDeclAndImports.hs"
529529
"ModuleDeclAndImports.expected.hs"
530530
"import Data.Monoid"
531+
, importQualifiedTests
532+
]
533+
534+
importQualifiedTests :: TestTree
535+
importQualifiedTests = testGroup "import qualified prefix suggestions"
536+
[ checkImport'
537+
"qualified import works with 3.8 code action kinds"
538+
"ImportQualified.hs"
539+
"ImportQualified.expected.hs"
540+
"import qualified Control.Monad as Control"
541+
["import Control.Monad (when)"]
542+
, checkImport'
543+
"qualified import in postfix position works with 3.8 code action kinds"
544+
"ImportPostQualified.hs"
545+
"ImportPostQualified.expected.hs"
546+
"import Control.Monad qualified as Control"
547+
["import qualified Control.Monad as Control", "import Control.Monad (when)"]
531548
]
532549

533550
checkImport :: String -> FilePath -> FilePath -> T.Text -> TestTree
534551
checkImport testComment originalPath expectedPath action =
552+
checkImport' testComment originalPath expectedPath action []
553+
554+
checkImport' :: String -> FilePath -> FilePath -> T.Text -> [T.Text] -> TestTree
555+
checkImport' testComment originalPath expectedPath action excludedActions =
535556
testSessionWithExtraFiles "import-placement" testComment $ \dir ->
536557
check (dir </> originalPath) (dir </> expectedPath) action
537558
where
538559
check :: FilePath -> FilePath -> T.Text -> Session ()
539560
check originalPath expectedPath action = do
540561
oSrc <- liftIO $ readFileUtf8 originalPath
541-
eSrc <- liftIO $ readFileUtf8 expectedPath
562+
eSrc <- liftIO $ readFileUtf8 expectedPath
542563
originalDoc <- createDoc originalPath "haskell" oSrc
543564
_ <- waitForDiagnostics
544565
shouldBeDoc <- createDoc expectedPath "haskell" eSrc
545566
actionsOrCommands <- getAllCodeActions originalDoc
567+
for_ excludedActions (\a -> liftIO $ assertNoActionWithTitle a actionsOrCommands)
546568
chosenAction <- liftIO $ pickActionWithTitle action actionsOrCommands
547569
executeCodeAction chosenAction
548570
originalDocAfterAction <- documentContents originalDoc
@@ -3734,6 +3756,21 @@ pickActionWithTitle title actions = do
37343756
, title == actionTitle
37353757
]
37363758

3759+
assertNoActionWithTitle :: T.Text -> [Command |? CodeAction] -> IO ()
3760+
assertNoActionWithTitle title actions = do
3761+
assertBool ("Unexpected code action " <> show title <> " in " <> show titles) (null matches)
3762+
pure ()
3763+
where
3764+
titles =
3765+
[ actionTitle
3766+
| InR CodeAction { _title = actionTitle } <- actions
3767+
]
3768+
matches =
3769+
[ action
3770+
| InR action@CodeAction { _title = actionTitle } <- actions
3771+
, title == actionTitle
3772+
]
3773+
37373774
findCodeActions :: TextDocumentIdentifier -> Range -> [T.Text] -> Session [CodeAction]
37383775
findCodeActions = findCodeActions' (==) "is not a superset of"
37393776

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE ImportQualifiedPost #-}
2+
{-# OPTIONS_GHC -Wprepositive-qualified-module #-}
3+
import Control.Monad qualified as Control
4+
main :: IO ()
5+
main = Control.when True $ putStrLn "hello"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import qualified Control.Monad as Control
2+
main :: IO ()
3+
main = Control.when True $ putStrLn "hello"

test/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# The `func-test` test suite.
2+
3+
This is the integration test suite for cross-plugin and cross-package features.
4+
5+
Add integration tests to `func-test` only if they satisfy one or more of the following conditions:
6+
7+
* It tests the interaction between more than one plugin.
8+
* For example, plugin A provides a Diagnostic that plugin B requires to provide a CodeAction.
9+
* However, it is also valid, and often preferable, to depend on the required plugin directly in plugin B's test suite.
10+
* It tests HLS specific LSP code.
11+
* For example, we test that config changes are appropriately propagated.
12+
* Note, this is slightly debatable, since the test could also be part of `ghcide`.
13+
* Non HLS specific LSP code may exist in HLS temporarily, but any LSP extensions should be upstreamed to `lsp`.
14+
* It tests features of the `haskell-language-server-wrapper` executable.
15+
* For example, argument parsing.
16+
* It tests features of the `haskell-language-server` executable.
17+
* For example, argument parsing.
18+
* It tests features provided by `hls-plugin-api` that require an integration test (i.e. a unit test doesn't suffice).
19+
* Example: Testing the Logger setup.
20+
21+
If you think that a test that currently lives in `func-test` does not meet the conditions above, open a ticket for discussion or try to move the test to a better location.
22+
23+
Note: `func-test` is a historical test suite. It was originally written for Haskell IDE Engine, which was merged with the `ghcide` project.
24+
The integration test-suite `func-test` (back then `unit-test` existed as well) was used to test all kinds of features provided by Haskell IDE Engine (HIE).
25+
When `ghcide` and HIE merged together, the integration test suite was vastly copied.
26+
HLS moved to a plugin-based architecture, which mainly entails that plugin tests are isolated in the respective plugin's test suite.
27+
Over time, `func-test` started to bit rot and wasn't maintained properly any more, since all new tests were added to the plugin or `ghcide` test suites.

test/functional/Command.hs

-32
This file was deleted.

0 commit comments

Comments
 (0)