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 DependentFileTest] part of #4173 Migrate ghcide tests to hls test utils #4195

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 12 additions & 5 deletions ghcide/test/exe/DependentFileTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

module DependentFileTest (tests) where

import Config
import Control.Monad.IO.Class (liftIO)
import Data.Row
import qualified Data.Text as T
import Debug.Trace (traceShowM)
import Development.IDE.Test (expectDiagnostics)
import Development.IDE.Types.Location
import Language.LSP.Protocol.Message
Expand All @@ -16,19 +18,20 @@
SemanticTokensEdit (..),
mkRange)
import Language.LSP.Test
import System.FilePath
import Test.Hls.FileSystem (FileSystem, toAbsFp)
import Test.Tasty
import TestUtils

tests :: TestTree
tests = testGroup "addDependentFile"
[testGroup "file-changed" [testSession' "test" test]
[testGroup "file-changed" [testWithDummyPlugin' "test" (mkIdeTestFs []) test]
]
where
test :: FileSystem -> Session ()
test dir = do
-- If the file contains B then no type error
-- otherwise type error
let depFilePath = dir </> "dep-file.txt"
traceShowM "beginning test"

Check failure on line 33 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Error in tests in module DependentFileTest: Avoid restricted function ▫︎ Found: "traceShowM" ▫︎ Note: may break the code

Check warning on line 33 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / flags (9.6, ubuntu-latest)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 33 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / flags (9.4, ubuntu-latest)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 33 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, ubuntu-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 33 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, macOS-latest, false)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 33 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, macOS-latest, false)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 33 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, ubuntu-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 33 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, windows-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 33 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, windows-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints
let depFilePath = toAbsFp dir "dep-file.txt"
liftIO $ writeFile depFilePath "A"
let fooContent = T.unlines
[ "{-# LANGUAGE TemplateHaskell #-}"
Expand All @@ -40,11 +43,14 @@
, " f <- qRunIO (readFile \"dep-file.txt\")"
, " if f == \"B\" then [| 1 |] else lift f)"
]
traceShowM "before create Foo.hs"

Check failure on line 46 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Error in tests in module DependentFileTest: Avoid restricted function ▫︎ Found: "traceShowM" ▫︎ Note: may break the code

Check warning on line 46 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / flags (9.6, ubuntu-latest)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 46 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / flags (9.4, ubuntu-latest)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 46 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, ubuntu-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 46 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, macOS-latest, false)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 46 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, macOS-latest, false)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 46 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, ubuntu-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 46 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, windows-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 46 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, windows-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints
let bazContent = T.unlines ["module Baz where", "import Foo ()"]
_ <- createDoc "Foo.hs" "haskell" fooContent
_fooDoc <- createDoc "Foo.hs" "haskell" fooContent
traceShowM "created foo"

Check failure on line 49 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Error in tests in module DependentFileTest: Avoid restricted function ▫︎ Found: "traceShowM" ▫︎ Note: may break the code

Check warning on line 49 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / flags (9.6, ubuntu-latest)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 49 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / flags (9.4, ubuntu-latest)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 49 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, ubuntu-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 49 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, macOS-latest, false)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 49 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, macOS-latest, false)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 49 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, ubuntu-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 49 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, windows-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 49 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, windows-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints
doc <- createDoc "Baz.hs" "haskell" bazContent
expectDiagnostics
[("Foo.hs", [(DiagnosticSeverity_Error, (4,11), "Couldn't match type")])]
traceShowM "after expectDiagnostics"

Check failure on line 53 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Error in tests in module DependentFileTest: Avoid restricted function ▫︎ Found: "traceShowM" ▫︎ Note: may break the code

Check warning on line 53 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / flags (9.6, ubuntu-latest)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 53 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / flags (9.4, ubuntu-latest)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 53 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, ubuntu-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 53 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, macOS-latest, false)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 53 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, macOS-latest, false)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 53 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, ubuntu-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 53 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, windows-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 53 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, windows-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints
-- Now modify the dependent file
liftIO $ writeFile depFilePath "B"
sendNotification SMethod_WorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams
Expand All @@ -55,4 +61,5 @@
.+ #rangeLength .== Nothing
.+ #text .== "f = ()"
changeDoc doc [change]
traceShowM "before last expectDiagnostics"

Check failure on line 64 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Error in tests in module DependentFileTest: Avoid restricted function ▫︎ Found: "traceShowM" ▫︎ Note: may break the code

Check warning on line 64 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / flags (9.6, ubuntu-latest)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 64 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / flags (9.4, ubuntu-latest)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 64 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, ubuntu-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 64 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, macOS-latest, false)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 64 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, macOS-latest, false)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 64 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, ubuntu-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 64 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.6, windows-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints

Check warning on line 64 in ghcide/test/exe/DependentFileTest.hs

View workflow job for this annotation

GitHub Actions / test (9.4, windows-latest, true)

• Defaulting the type variable ‘a0’ to type ‘String’ in the following constraints
expectDiagnostics [("Foo.hs", [])]
7 changes: 6 additions & 1 deletion ghcide/test/src/Development/IDE/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import Data.Proxy
import Data.Text (Text)
import qualified Data.Text as T
import Debug.Trace (traceShowM)
import Development.IDE.Plugin.Test (TestRequest (..),
WaitForIdeRuleResult,
ideResultSuccess)
Expand Down Expand Up @@ -124,7 +125,9 @@
expectDiagnosticsWithTags expected = do
let f = getDocUri >=> liftIO . canonicalizeUri >=> pure . toNormalizedUri
next = unwrapDiagnostic <$> skipManyTill anyMessage diagnostic
traceShowM $ "Trace: " <> show expected

Check failure on line 128 in ghcide/test/src/Development/IDE/Test.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Error in expectDiagnosticsWithTags in module Development.IDE.Test: Avoid restricted function ▫︎ Found: "traceShowM" ▫︎ Note: may break the code
expected' <- Map.fromListWith (<>) <$> traverseOf (traverse . _1) f expected
traceShowM $ "Trace: " <> show expected'

Check failure on line 130 in ghcide/test/src/Development/IDE/Test.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Error in expectDiagnosticsWithTags in module Development.IDE.Test: Avoid restricted function ▫︎ Found: "traceShowM" ▫︎ Note: may break the code
expectDiagnosticsWithTags' next expected'

expectDiagnosticsWithTags' ::
Expand All @@ -134,18 +137,20 @@
m ()
expectDiagnosticsWithTags' next m | null m = do
(_,actual) <- next
traceShowM $ "Trace: " <> show actual

Check failure on line 140 in ghcide/test/src/Development/IDE/Test.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Error in expectDiagnosticsWithTags' in module Development.IDE.Test: Avoid restricted function ▫︎ Found: "traceShowM" ▫︎ Note: may break the code
case actual of
[] ->
return ()
_ ->
liftIO $ assertFailure $ "Got unexpected diagnostics:" <> show actual

-- get the next diagnostic message and check and remove the expected diagnostics from the map
expectDiagnosticsWithTags' next expected = go expected
where
go m
| Map.null m = pure ()
| otherwise = do
(fileUri, actual) <- next
traceShowM $ "Trace: " <> show actual

Check failure on line 153 in ghcide/test/src/Development/IDE/Test.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Error in expectDiagnosticsWithTags' in module Development.IDE.Test: Avoid restricted function ▫︎ Found: "traceShowM" ▫︎ Note: may break the code
canonUri <- liftIO $ toNormalizedUri <$> canonicalizeUri fileUri
case Map.lookup canonUri m of
Nothing -> do
Expand Down
Loading