Skip to content

Commit 2a72c86

Browse files
committed
Working on moving LSP test code out to lsp-test-helpers noci
1 parent 07292c5 commit 2a72c86

15 files changed

Lines changed: 103 additions & 259 deletions

File tree

tests/app/Spec/Tests/Bash.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tests = describe "Bash" $ introduceNixEnvironment [kernelSpec] [] "Bash" $ intro
3737
-- |] $ \diagnostics -> do
3838
-- assertDiagnosticRanges diagnostics []
3939

40-
testDiagnostics "bash-language-server" "test.sh" Nothing [__i|FOO=42|] $ \diagnostics -> do
40+
testDiagnostics "bash-language-server" "test.sh" [__i|FOO=42|] $ \diagnostics -> do
4141
assertDiagnosticRanges diagnostics [
4242
(Range (Position 0 0) (Position 0 3), Just (InR "SC2034"))
4343
]

tests/app/Spec/Tests/Clojure.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tests = describe "Clojure" $ introduceNixEnvironment [kernelSpec] [] "Clojure" $
3131

3232
testKernelStdout "clojure" [__i|(println "hi")|] "hi\n"
3333

34-
testDiagnostics "clojure-lsp" "test.clj" Nothing [__i|(foo 42)|] $ \diagnostics -> do
34+
testDiagnostics "clojure-lsp" "test.clj" [__i|(foo 42)|] $ \diagnostics -> do
3535
assertDiagnosticRanges diagnostics [(Range (Position 0 1) (Position 0 4), Just (InR "unresolved-symbol"))]
3636

3737

tests/app/Spec/Tests/Cpp.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ tests' flavor = describe [i|C++ (#{flavor})|] $ introduceNixEnvironment [kernelS
4040
testsWithLsp :: Text -> LanguageSpec
4141
testsWithLsp flavor = describe [i|C++ (#{flavor}) with LSP|] $ introduceNixEnvironment [kernelSpecWithLsp flavor] [] "C++" $ do
4242
describe "LSP" $ do
43-
testDiagnostics'' "simple" lsName "test.cpp" (Just "cpp")
43+
testDiagnostics'' "simple" lsName "test.cpp"
4444
[__i|int main() {
4545
undefined_function();
4646
return 0;

tests/app/Spec/Tests/Go.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tests = describe "Go" $ introduceNixEnvironment [kernelSpec] [] "Go" $ introduce
3333
testKernelStdout "go" [__i|import("fmt")
3434
fmt.Println("hi")|] "hi\n"
3535

36-
testDiagnosticsLabel "gopls: Undeclared name" "gopls" "test.go" Nothing printUnknownCode $ \diagnostics ->
36+
testDiagnosticsLabel "gopls: Undeclared name" "gopls" "test.go" printUnknownCode $ \diagnostics ->
3737
assertDiagnosticRanges diagnostics [(Range (Position 3 12) (Position 3 15), Just (InR "UndeclaredName"))]
3838

3939
printUnknownCode :: Text

tests/app/Spec/Tests/Haskell/Diagnostics.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@ import TestLib.Types
2727
tests :: (LspContext context m, HasNixEnvironment context) => Text -> Text -> SpecFree context m ()
2828
tests ghcPackage lsName = describe "Diagnostics" $ do
2929
describe "Foo.hs" $ do
30-
testDiagnosticsLabelDesired "Out of scope variable" lsName "Foo.hs" Nothing
30+
testDiagnosticsLabelDesired "Out of scope variable" lsName "Foo.hs"
3131
[__i|module Foo where
3232
foo = bar
3333
|]
3434
((== [(Range (Position 1 6) (Position 1 9), Just (InR "GHC-88464"))]) . getDiagnosticRanges)
3535

3636
when (ghcPackage /= "ghc910") $ -- TODO: re-enable hlint test
37-
testDiagnosticsLabelDesired "Eta reduce" lsName "Foo.hs" Nothing etaExpandCode
37+
testDiagnosticsLabelDesired "Eta reduce" lsName "Foo.hs" etaExpandCode
3838
((== [(Range (Position 6 0) (Position 6 14), Just (InR "refact:Eta reduce"))]) . getDiagnosticRanges)
3939

4040
describe "main.ipynb" $ do
41-
testDiagnosticsLabelDesired "Top-level putStrLn" lsName "main.ipynb" Nothing
41+
testDiagnosticsLabelDesired "Top-level putStrLn" lsName "main.ipynb"
4242
[__i|-- A comment
4343
foo = bar
4444

4545
putStrLn "HI"
4646
|]
4747
((== [(Range (Position 1 6) (Position 1 9), Just (InR "GHC-88464"))]) . getDiagnosticRanges)
4848

49-
testDiagnosticsLabel "Top-level putStrLn with diagnostic" lsName "main.ipynb" Nothing
49+
testDiagnosticsLabel "Top-level putStrLn with diagnostic" lsName "main.ipynb"
5050
[__i|-- Some comment
5151
import Data.ByteString.Lazy.Char8 as BL
5252
foo = bar
@@ -56,15 +56,15 @@ tests ghcPackage lsName = describe "Diagnostics" $ do
5656
[(Range (Position 4 0) (Position 4 8), x)] | containsAll x ["Ambiguous occurrence", "putStrLn"] -> return ()
5757
xs -> expectationFailure [i|Unexpected diagnostics: #{xs}|]
5858

59-
testDiagnosticsLabelDesired "Reordering" lsName "main.ipynb" Nothing
59+
testDiagnosticsLabelDesired "Reordering" lsName "main.ipynb"
6060
[__i|import Data.Aeson.TH
6161
{-\# LANGUAGE TemplateHaskell \#-}
6262
foo = bar -- This should be the only diagnostic we get
6363
data Foo = Bar | Baz
6464
$(deriveJSON defaultOptions ''Foo)|]
6565
((== [(Range (Position 2 6) (Position 2 9), Just (InR "GHC-88464"))]) . getDiagnosticRanges)
6666

67-
testDiagnosticsLabelDesired "Complicated reordering" lsName "main.ipynb" Nothing
67+
testDiagnosticsLabelDesired "Complicated reordering" lsName "main.ipynb"
6868
[__i|import Data.Aeson as A
6969
import Data.Aeson.TH
7070
:set -XTemplateHaskell

tests/app/Spec/Tests/Haskell/Statements.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tests ghcPackage = describe "Statements" $ do
2222
timeout 120_000_000 (getHighlights ident (Position 0 1)) >>= (`shouldBe` (Just documentHighlightResults))
2323

2424
when (ghcPackage /= "ghc910") $ -- TODO: re-enable hlint test
25-
testDiagnosticsLabel "Empty diagnostics" lsName "main.ipynb" Nothing statementsCode $ \diagnostics -> do
25+
testDiagnosticsLabel "Empty diagnostics" lsName "main.ipynb" statementsCode $ \diagnostics -> do
2626
-- Note: normally the server wouldn't send empty diagnostics. But the statement inserts "= unsafePerformIO $ ",
2727
-- which causes it to emit a "redundant bracket" diagnostic, which then gets filtered out by untransformPosition
2828
diagnostics `shouldBe` []
@@ -33,7 +33,7 @@ tests ghcPackage = describe "Statements" $ do
3333
timeout 120_000_000 (getHighlights ident (Position 0 1)) >>= (`shouldBe` (Just documentHighlightResults))
3434

3535
when (ghcPackage /= "ghc910") $ -- TODO: re-enable hlint test
36-
testDiagnosticsLabel "Redundant bracket" lsName "main.ipynb" Nothing statementsCodeMultiline $ \diagnostics -> do
36+
testDiagnosticsLabel "Redundant bracket" lsName "main.ipynb" statementsCodeMultiline $ \diagnostics -> do
3737
info [i|Got diagnostics: #{diagnostics}|]
3838
assertDiagnosticRanges diagnostics [(Range (Position 1 9) (Position 1 14), Just (InR "refact:Redundant bracket"))]
3939

tests/app/Spec/Tests/Julia.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ juliaTests juliaPackage = describe [i|Julia (#{juliaPackage})|] $ introduceNixEn
4545
describe "LSP" $ do
4646
Diagnostics.tests lsName
4747

48-
itHasHoverSatisfying lsName "test.jl" (Just "julia") [__i|print("hi")|] (Position 0 2) $ \hover -> do
48+
itHasHoverSatisfying lsName "test.jl" [__i|print("hi")|] (Position 0 2) $ \hover -> do
4949
let InL (MarkupContent MarkupKind_Markdown text) = hover ^. contents
5050
text `textShouldContain` "Write to `io` (or to the default output stream"
5151

tests/app/Spec/Tests/Julia/Diagnostics.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ import TestLib.Types
1313

1414
tests :: (LspContext context m, HasNixEnvironment context) => Text -> SpecFree context m ()
1515
tests lsName = describe "Diagnostics" $ do
16-
testDiagnostics'' "flags a simple missing reference" lsName "test.jl" (Just "julia") [i|printlnzzzz("HI")|] [] $ \diagnostics -> do
16+
testDiagnostics'' "flags a simple missing reference" lsName "test.jl" [i|printlnzzzz("HI")|] [] $ \diagnostics -> do
1717
assertDiagnosticRanges' diagnostics [(Range (Position 0 0) (Position 0 11), Nothing, "Missing reference: printlnzzzz")]
1818

19-
testDiagnosticsLabelDesired "finds symbols from JSON3 package" lsName "test.jl" (Just "julia")
19+
testDiagnosticsLabelDesired "finds symbols from JSON3 package" lsName "test.jl"
2020
[__i|using JSON3: write
2121
tup = (:car,"Mercedes","S500",5,250.1)
2222
write(tup)
2323
printlnzzzz("HI")
2424
|]
2525
((== [(Range (Position 3 0) (Position 3 11), Nothing, "Missing reference: printlnzzzz")]) . getDiagnosticRanges')
2626

27-
testDiagnosticsLabelDesired "finds symbols from Roots package" lsName "test.jl" (Just "julia")
27+
testDiagnosticsLabelDesired "finds symbols from Roots package" lsName "test.jl"
2828
[__i|using Roots: Bisection, find_zero
2929
f(x) = exp(x) - x^4
3030
find_zero(f, (8, 9), Bisection())
@@ -34,7 +34,7 @@ tests lsName = describe "Diagnostics" $ do
3434

3535
-- This test is tricky because symbols like "plot" actually come from RecipesBase (or something), so
3636
-- it checks we're indexing such a transitive dependency.
37-
testDiagnosticsLabelDesired "finds symbols from Plots package" lsName "test.jl" (Just "julia")
37+
testDiagnosticsLabelDesired "finds symbols from Plots package" lsName "test.jl"
3838
[__i|using Plots: plot, plot!
3939
xx = range(0, 10, length=100)
4040
y = sin.(xx)

tests/app/Spec/Tests/Python.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ tests' (kernelName, pythonPackage) = introduceNixEnvironment [kernelSpec kernelN
3535
testKernelStdout "python3" [i|print(42)|] "42\n"
3636
testKernelStdout' "python3" [i|import scipy|] Nothing
3737

38-
testDiagnostics "python-lsp-server" "test.py" Nothing [i|\n\n\nfoo = 42|] $ \diagnostics -> do
38+
testDiagnostics "python-lsp-server" "test.py" [i|\n\n\nfoo = 42|] $ \diagnostics -> do
3939
assertDiagnosticRanges diagnostics []
4040

41-
testDiagnostics "pylint" "test.py" Nothing [i|\n\n\nfoo = 42|] $ \diagnostics -> do
41+
testDiagnostics "pylint" "test.py" [i|\n\n\nfoo = 42|] $ \diagnostics -> do
4242
assertDiagnosticRanges' diagnostics [
4343
(Range (Position 3 0) (Position 3 0), Nothing, "Final newline missing (C0304:missing-final-newline)")
4444
, (Range (Position 0 0) (Position 0 0), Nothing, "Missing module docstring (C0114:missing-module-docstring)")
4545
, (Range (Position 3 0) (Position 3 0), Nothing, "Disallowed name \"foo\" (C0104:disallowed-name)")
4646
]
4747

48-
testDiagnostics "pyright" "test.py" Nothing [__i|\# pyright: strict
48+
testDiagnostics "pyright" "test.py" [__i|\# pyright: strict
4949
def f(x: int, y: str) -> None:
5050
z = 1.0
5151
f("asdf", 42)
@@ -61,10 +61,10 @@ tests' (kernelName, pythonPackage) = introduceNixEnvironment [kernelSpec kernelN
6161
, (Range (Position 2 2) (Position 2 3), Just (InR "reportUnusedVariable"), "Variable \"z\" is not accessed")
6262
]
6363

64-
testDiagnostics "pycodestyle" "test.py" Nothing [__i|def f(x: int, y: str) -> None:
65-
z = 1.0
66-
f("asdf", 42)
67-
|] $ \diagnostics -> do
64+
testDiagnostics "pycodestyle" "test.py" [__i|def f(x: int, y: str) -> None:
65+
z = 1.0
66+
f("asdf", 42)
67+
|] $ \diagnostics -> do
6868
assertDiagnosticRanges diagnostics []
6969

7070

tests/app/Spec/Tests/Ruby.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ kernelTests rubyPackage = do
4949
info [i|RUBY_VERSION result: #{t}|]
5050
t `textShouldContain` versionString
5151

52-
itHasHoverSatisfying "solargraph" "test.rb" Nothing [__i|puts "hi"|] (Position 0 2) $ \hover -> do
52+
itHasHoverSatisfying "solargraph" "test.rb" [__i|puts "hi"|] (Position 0 2) $ \hover -> do
5353
let InL (MarkupContent MarkupKind_Markdown text) = hover ^. contents
5454
text `textShouldContain` "Kernel#puts"
5555
text `textShouldContain` "$stdout.puts(obj"

0 commit comments

Comments
 (0)