Skip to content

Cleanup func-test suite #3828

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

Merged
merged 6 commits into from
Oct 9, 2023
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
3 changes: 2 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/ghcide/session-loader @pepeiborra @fendor
/hls-graph @pepeiborra
/hls-plugin-api @berberman
/hls-test-utils
/hls-test-utils @fendor
/test @fendor
Comment on lines +6 to +7
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that hls-test-utils has no codeowner, I am volunteering to take over the ownership.
Additionally, added myself as codeowner for func-test. Mostly, to make sure my somewhat arbitrary guidance in test/README.md cannot be further violated without me noticing.

/hie-compat

# Plugins
Expand Down
10 changes: 0 additions & 10 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -529,21 +529,11 @@ test-suite func-test

main-is: Main.hs
other-modules:
Command
Completion
Config
Deferred
Definition
Diagnostic
Format
FunctionalBadProject
FunctionalCodeAction
HieBios
Highlight
Progress
Reference
Symbol
TypeDefinition
Test.Hls.Command
Test.Hls.Flags

Expand Down
9 changes: 8 additions & 1 deletion hls-test-utils/src/Test/Hls/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Test.Hls.Util
, knownBrokenOnWindows
, knownBrokenForGhcVersions
, knownBrokenInEnv
, knownBrokenInSpecificEnv
, onlyWorkForGhcVersions
-- * Extract code actions
, fromAction
Expand Down Expand Up @@ -123,12 +124,18 @@ hostOS
| isMac = MacOS
| otherwise = Linux

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

-- | Mark as broken if /all/ environmental specs match the current environment.
knownBrokenInSpecificEnv :: [EnvSpec] -> String -> TestTree -> TestTree
knownBrokenInSpecificEnv envSpecs reason
| all matchesCurrentEnv envSpecs = expectFailBecause reason
| otherwise = id

knownBrokenOnWindows :: String -> TestTree -> TestTree
knownBrokenOnWindows = knownBrokenInEnv [HostOS Windows]

Expand Down
39 changes: 38 additions & 1 deletion plugins/hls-refactor-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -528,21 +528,43 @@ insertImportTests = testGroup "insert import"
"ModuleDeclAndImports.hs"
"ModuleDeclAndImports.expected.hs"
"import Data.Monoid"
, importQualifiedTests
]

importQualifiedTests :: TestTree
importQualifiedTests = testGroup "import qualified prefix suggestions"
[ checkImport'
"qualified import works with 3.8 code action kinds"
"ImportQualified.hs"
"ImportQualified.expected.hs"
"import qualified Control.Monad as Control"
["import Control.Monad (when)"]
, checkImport'
"qualified import in postfix position works with 3.8 code action kinds"
"ImportPostQualified.hs"
"ImportPostQualified.expected.hs"
"import Control.Monad qualified as Control"
["import qualified Control.Monad as Control", "import Control.Monad (when)"]
]

checkImport :: String -> FilePath -> FilePath -> T.Text -> TestTree
checkImport testComment originalPath expectedPath action =
checkImport' testComment originalPath expectedPath action []

checkImport' :: String -> FilePath -> FilePath -> T.Text -> [T.Text] -> TestTree
checkImport' testComment originalPath expectedPath action excludedActions =
testSessionWithExtraFiles "import-placement" testComment $ \dir ->
check (dir </> originalPath) (dir </> expectedPath) action
where
check :: FilePath -> FilePath -> T.Text -> Session ()
check originalPath expectedPath action = do
oSrc <- liftIO $ readFileUtf8 originalPath
eSrc <- liftIO $ readFileUtf8 expectedPath
eSrc <- liftIO $ readFileUtf8 expectedPath
originalDoc <- createDoc originalPath "haskell" oSrc
_ <- waitForDiagnostics
shouldBeDoc <- createDoc expectedPath "haskell" eSrc
actionsOrCommands <- getAllCodeActions originalDoc
for_ excludedActions (\a -> liftIO $ assertNoActionWithTitle a actionsOrCommands)
chosenAction <- liftIO $ pickActionWithTitle action actionsOrCommands
executeCodeAction chosenAction
originalDocAfterAction <- documentContents originalDoc
Expand Down Expand Up @@ -3734,6 +3756,21 @@ pickActionWithTitle title actions = do
, title == actionTitle
]

assertNoActionWithTitle :: T.Text -> [Command |? CodeAction] -> IO ()
assertNoActionWithTitle title actions = do
assertBool ("Unexpected code action " <> show title <> " in " <> show titles) (null matches)
pure ()
where
titles =
[ actionTitle
| InR CodeAction { _title = actionTitle } <- actions
]
matches =
[ action
| InR action@CodeAction { _title = actionTitle } <- actions
, title == actionTitle
]

findCodeActions :: TextDocumentIdentifier -> Range -> [T.Text] -> Session [CodeAction]
findCodeActions = findCodeActions' (==) "is not a superset of"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE ImportQualifiedPost #-}
{-# OPTIONS_GHC -Wprepositive-qualified-module #-}
import Control.Monad qualified as Control
main :: IO ()
main = Control.when True $ putStrLn "hello"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import qualified Control.Monad as Control
main :: IO ()
main = Control.when True $ putStrLn "hello"
27 changes: 27 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# The `func-test` test suite.

This is the integration test suite for cross-plugin and cross-package features.

Add integration tests to `func-test` only if they satisfy one or more of the following conditions:

* It tests the interaction between more than one plugin.
* For example, plugin A provides a Diagnostic that plugin B requires to provide a CodeAction.
* However, it is also valid, and often preferable, to depend on the required plugin directly in plugin B's test suite.
* It tests HLS specific LSP code.
* For example, we test that config changes are appropriately propagated.
* Note, this is slightly debatable, since the test could also be part of `ghcide`.
* Non HLS specific LSP code may exist in HLS temporarily, but any LSP extensions should be upstreamed to `lsp`.
* It tests features of the `haskell-language-server-wrapper` executable.
* For example, argument parsing.
* It tests features of the `haskell-language-server` executable.
* For example, argument parsing.
* It tests features provided by `hls-plugin-api` that require an integration test (i.e. a unit test doesn't suffice).
* Example: Testing the Logger setup.

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.

Note: `func-test` is a historical test suite. It was originally written for Haskell IDE Engine, which was merged with the `ghcide` project.
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).
When `ghcide` and HIE merged together, the integration test suite was vastly copied.
HLS moved to a plugin-based architecture, which mainly entails that plugin tests are isolated in the respective plugin's test suite.
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.
32 changes: 0 additions & 32 deletions test/functional/Command.hs

This file was deleted.

Loading