Skip to content

Commit 40a152f

Browse files
committed
Make "broken" tests explicit
1 parent 506fae7 commit 40a152f

File tree

3 files changed

+75
-17
lines changed

3 files changed

+75
-17
lines changed

plugins/hls-explicit-fixity-plugin/test/Main.hs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DataKinds #-}
12
{-# LANGUAGE OverloadedStrings #-}
23

34
module Main where
@@ -41,15 +42,29 @@ tests = testGroup "Explicit fixity"
4142
, hoverTest "operator" (Position 36 2) "infixr 9 `>>>:`"
4243
, hoverTest "escape" (Position 39 2) "infixl 3 `~\\:`"
4344
-- TODO: Ensure that there is no one extra new line in import statement
44-
, hoverTest "import" (Position 2 18) "Control.Monad\n\n"
45+
, hoverTestExpectFail
46+
"import"
47+
(Position 2 18)
48+
(BrokenIdeal "Control.Monad***")
49+
(BrokenCurrent "Control.Monad\n\n")
4550
, hoverTestImport "import" (Position 4 7) "infixr 9 `>>>:`"
4651
]
4752

4853
hoverTest :: TestName -> Position -> T.Text -> TestTree
4954
hoverTest = hoverTest' "Hover.hs"
55+
5056
hoverTestImport :: TestName -> Position -> T.Text -> TestTree
5157
hoverTestImport = hoverTest' "HoverImport.hs"
5258

59+
hoverTestExpectFail
60+
:: TestName
61+
-> Position
62+
-> ExpectBroken 'Ideal T.Text
63+
-> ExpectBroken 'Current T.Text
64+
-> TestTree
65+
hoverTestExpectFail title pos _ =
66+
hoverTest title pos . unCurrent
67+
5368
hoverTest' :: String -> TestName -> Position -> T.Text -> TestTree
5469
hoverTest' docName title pos expected = testCase title $ runSessionWithServer def plugin testDataDir $ do
5570
doc <- openDoc docName "haskell"

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

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,20 +1507,46 @@ extendImportTests = testGroup "extend import actions"
15071507
, "x = Refl"
15081508
])
15091509
-- TODO: importing pattern synonyms is unsupported
1510-
-- Ideally the result is "Add pattern Some of the import list of A"
1511-
, testSession "extend import list with pattern synonym" $ noCodeActionsTemplate
1512-
[("ModuleA.hs", T.unlines
1513-
[ "{-# LANGUAGE PatternSynonyms #-}"
1514-
, "module ModuleA where"
1515-
, "pattern Some x = Just x"
1516-
])
1517-
]
1518-
("ModuleB.hs", T.unlines
1519-
[ "module ModuleB where"
1520-
, "import A ()"
1521-
, "k (Some x) = x"
1522-
])
1523-
(Range (Position 2 3) (Position 2 7))
1510+
, testSessionExpectFail "extend import list with pattern synonym"
1511+
(BrokenIdeal $
1512+
template
1513+
[("ModuleA.hs", T.unlines
1514+
[ "{-# LANGUAGE PatternSynonyms #-}"
1515+
, "module ModuleA where"
1516+
, "pattern Some x = Just x"
1517+
])
1518+
]
1519+
("ModuleB.hs", T.unlines
1520+
[ "module ModuleB where"
1521+
, "import A ()"
1522+
, "k (Some x) = x"
1523+
]
1524+
)
1525+
(Range (Position 2 3) (Position 2 7))
1526+
["Add pattern Some to the import list of A"]
1527+
(T.unlines
1528+
[ "module ModuleB where"
1529+
, "import A (pattern Some)"
1530+
, "k (Some x) = x"
1531+
]
1532+
)
1533+
)
1534+
(BrokenCurrent $
1535+
noCodeActionsTemplate
1536+
[("ModuleA.hs", T.unlines
1537+
[ "{-# LANGUAGE PatternSynonyms #-}"
1538+
, "module ModuleA where"
1539+
, "pattern Some x = Just x"
1540+
])
1541+
]
1542+
("ModuleB.hs", T.unlines
1543+
[ "module ModuleB where"
1544+
, "import A ()"
1545+
, "k (Some x) = x"
1546+
]
1547+
)
1548+
(Range (Position 2 3) (Position 2 7))
1549+
)
15241550
, ignoreForGhcVersions [GHC94] "Diagnostic message has no suggestions" $
15251551
testSession "type constructor name same as data constructor name" $ template
15261552
[("ModuleA.hs", T.unlines
@@ -3808,6 +3834,13 @@ assertActionWithTitle actions title =
38083834
testSession :: TestName -> Session () -> TestTree
38093835
testSession name = testCase name . run
38103836

3837+
testSessionExpectFail
3838+
:: TestName
3839+
-> ExpectBroken 'Ideal (Session ())
3840+
-> ExpectBroken 'Current (Session ())
3841+
-> TestTree
3842+
testSessionExpectFail name _ = testSession name . unCurrent
3843+
38113844
testSessionWithExtraFiles :: HasCallStack => FilePath -> TestName -> (FilePath -> Session ()) -> TestTree
38123845
testSessionWithExtraFiles prefix name = testCase name . runWithExtraFiles prefix
38133846

test/functional/Config.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import Control.Monad
88
import Data.Hashable
99
import qualified Data.HashMap.Strict as HM
1010
import qualified Data.Map as Map
11+
import qualified Data.Text as T
1112
import Data.Typeable (Typeable)
1213
import Development.IDE (RuleResult, action, define,
1314
getFilesOfInterestUntracked,
1415
getPluginConfigAction, ideErrorText,
1516
uses_)
16-
import Development.IDE.Test (expectDiagnostics)
17+
import Development.IDE.Test (Cursor, expectDiagnostics)
1718
import GHC.Generics
1819
import Ide.Plugin.Config
1920
import Ide.Types
@@ -49,7 +50,9 @@ genericConfigTests = testGroup "generic plugin config"
4950
-- test that the user config doesn't accidentally override the initial config
5051
setHlsConfig $ changeConfig testPluginId def{plcHoverOn = False}
5152
-- getting only the expected diagnostics means the plugin wasn't enabled
52-
expectDiagnostics testPluginDiagnostics
53+
expectDiagnosticsFail
54+
(BrokenIdeal standardDiagnostics)
55+
(BrokenCurrent testPluginDiagnostics)
5356
, testCase "custom defaults and overlapping user plugin config" $ runConfigSession "diagnostics" $ do
5457
_doc <- createDoc "Foo.hs" "haskell" "module Foo where\nfoo = False"
5558
-- test that the user config overrides the default initial config
@@ -104,3 +107,10 @@ data GetTestDiagnostics = GetTestDiagnostics
104107
instance Hashable GetTestDiagnostics
105108
instance NFData GetTestDiagnostics
106109
type instance RuleResult GetTestDiagnostics = ()
110+
111+
expectDiagnosticsFail
112+
:: HasCallStack
113+
=> ExpectBroken 'Ideal [(FilePath, [(DiagnosticSeverity, Cursor, T.Text)])]
114+
-> ExpectBroken 'Current [(FilePath, [(DiagnosticSeverity, Cursor, T.Text)])]
115+
-> Session ()
116+
expectDiagnosticsFail _ = expectDiagnostics . unCurrent

0 commit comments

Comments
 (0)