From 653f5e02fc62bb85c4218000939e7ac10a5885d8 Mon Sep 17 00:00:00 2001 From: kokobd Date: Fri, 21 Jan 2022 16:28:26 +0800 Subject: [PATCH 1/4] add a failing test case for positionInRange --- hls-plugin-api/hls-plugin-api.cabal | 13 +++++++++++++ hls-plugin-api/src/Ide/PluginUtils.hs | 3 ++- hls-plugin-api/test/Main.hs | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 hls-plugin-api/test/Main.hs diff --git a/hls-plugin-api/hls-plugin-api.cabal b/hls-plugin-api/hls-plugin-api.cabal index 1516d1b591..88133ec3e7 100644 --- a/hls-plugin-api/hls-plugin-api.cabal +++ b/hls-plugin-api/hls-plugin-api.cabal @@ -77,3 +77,16 @@ library DataKinds KindSignatures TypeOperators + +test-suite tests + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: test + main-is: Main.hs + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + base + , hls-plugin-api + , tasty + , tasty-hunit + , lsp-types diff --git a/hls-plugin-api/src/Ide/PluginUtils.hs b/hls-plugin-api/src/Ide/PluginUtils.hs index 4b679f3343..1653a22457 100644 --- a/hls-plugin-api/src/Ide/PluginUtils.hs +++ b/hls-plugin-api/src/Ide/PluginUtils.hs @@ -25,6 +25,7 @@ module Ide.PluginUtils allLspCmdIds', installSigUsr1Handler, subRange, + positionInRange, usePropertyLsp, response, handleMaybe, @@ -178,7 +179,7 @@ getClientConfig = getConfig getPluginConfig :: MonadLsp Config m => PluginId -> m PluginConfig getPluginConfig plugin = do config <- getClientConfig - return $ configForPlugin config plugin + return $ configForPlugin config plugin -- --------------------------------------------------------------------- diff --git a/hls-plugin-api/test/Main.hs b/hls-plugin-api/test/Main.hs new file mode 100644 index 0000000000..0b3f8be78f --- /dev/null +++ b/hls-plugin-api/test/Main.hs @@ -0,0 +1,15 @@ +module Main where + +import Ide.PluginUtils (positionInRange) +import Language.LSP.Types (Position (Position), Range (Range)) +import Test.Tasty +import Test.Tasty.HUnit + +main :: IO () +main = defaultMain tests + +tests :: TestTree +tests = testGroup "PluginUtils" + [ testCase "positionInRange" $ + positionInRange (Position 1 10) (Range (Position 1 1) (Position 1 3)) @?= False + ] From c2176134061b115d43992581677304e965248347 Mon Sep 17 00:00:00 2001 From: kokobd Date: Sat, 22 Jan 2022 16:52:41 +0800 Subject: [PATCH 2/4] fix positionInRange in PluginUtils --- hls-plugin-api/hls-plugin-api.cabal | 1 + hls-plugin-api/src/Ide/PluginUtils.hs | 6 +---- hls-plugin-api/test/Ide/PluginUtilsTest.hs | 27 ++++++++++++++++++++++ hls-plugin-api/test/Main.hs | 9 +++----- 4 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 hls-plugin-api/test/Ide/PluginUtilsTest.hs diff --git a/hls-plugin-api/hls-plugin-api.cabal b/hls-plugin-api/hls-plugin-api.cabal index 88133ec3e7..d7310d71be 100644 --- a/hls-plugin-api/hls-plugin-api.cabal +++ b/hls-plugin-api/hls-plugin-api.cabal @@ -84,6 +84,7 @@ test-suite tests hs-source-dirs: test main-is: Main.hs ghc-options: -threaded -rtsopts -with-rtsopts=-N + other-modules: Ide.PluginUtilsTest build-depends: base , hls-plugin-api diff --git a/hls-plugin-api/src/Ide/PluginUtils.hs b/hls-plugin-api/src/Ide/PluginUtils.hs index 1653a22457..5df855f356 100644 --- a/hls-plugin-api/src/Ide/PluginUtils.hs +++ b/hls-plugin-api/src/Ide/PluginUtils.hs @@ -221,11 +221,7 @@ subRange smallRange range = && positionInRange (_end smallRange) range positionInRange :: Position -> Range -> Bool -positionInRange (Position pl po) (Range (Position sl so) (Position el eo)) = - pl > sl && pl < el - || pl == sl && pl == el && po >= so && po <= eo - || pl == sl && po >= so - || pl == el && po <= eo +positionInRange p (Range sp ep) = sp <= p && p <= ep -- --------------------------------------------------------------------- diff --git a/hls-plugin-api/test/Ide/PluginUtilsTest.hs b/hls-plugin-api/test/Ide/PluginUtilsTest.hs new file mode 100644 index 0000000000..19a832f165 --- /dev/null +++ b/hls-plugin-api/test/Ide/PluginUtilsTest.hs @@ -0,0 +1,27 @@ +module Ide.PluginUtilsTest + ( tests + ) where + +import Ide.PluginUtils (positionInRange) +import Language.LSP.Types (Position (Position), Range (Range)) +import Test.Tasty +import Test.Tasty.HUnit + +tests :: TestTree +tests = testGroup "PluginUtils" + [ positionInRangeTest + ] + +positionInRangeTest :: TestTree +positionInRangeTest = testGroup "positionInRange" + [ testCase "single line, after the end" $ + positionInRange (Position 1 10) (Range (Position 1 1) (Position 1 3)) @?= False + , testCase "single line, before the begining" $ + positionInRange (Position 1 0) (Range (Position 1 1) (Position 1 6)) @?= False + , testCase "single line, in range" $ + positionInRange (Position 1 5) (Range (Position 1 1) (Position 1 6)) @?= True + , testCase "multiline, in range" $ + positionInRange (Position 3 5) (Range (Position 1 1) (Position 5 6)) @?= True + , testCase "multiline, out of range" $ + positionInRange (Position 3 5) (Range (Position 3 6) (Position 4 10)) @?= False + ] diff --git a/hls-plugin-api/test/Main.hs b/hls-plugin-api/test/Main.hs index 0b3f8be78f..5f948eb5e8 100644 --- a/hls-plugin-api/test/Main.hs +++ b/hls-plugin-api/test/Main.hs @@ -1,15 +1,12 @@ module Main where -import Ide.PluginUtils (positionInRange) -import Language.LSP.Types (Position (Position), Range (Range)) +import qualified Ide.PluginUtilsTest as PluginUtilsTest import Test.Tasty -import Test.Tasty.HUnit main :: IO () main = defaultMain tests tests :: TestTree -tests = testGroup "PluginUtils" - [ testCase "positionInRange" $ - positionInRange (Position 1 10) (Range (Position 1 1) (Position 1 3)) @?= False +tests = testGroup "Main" + [ PluginUtilsTest.tests ] From 53d66d629dcc4f3dbb1fb6631fb8977443995c77 Mon Sep 17 00:00:00 2001 From: kokobd Date: Sat, 22 Jan 2022 18:49:05 +0800 Subject: [PATCH 3/4] add hls-plugin-api to CI --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce1e50dc4e..51a5479109 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -133,6 +133,10 @@ jobs: # run the tests without parallelism to avoid running out of memory run: cabal test ghcide --test-options="$TEST_OPTS" || cabal test ghcide --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test ghcide --test-options="$TEST_OPTS" + - if: matrix.test + name: Test hls-plugin-api + run: cabal test hls-plugin-api --test-options="$TEST_OPTS" || cabal test hls-plugin-api --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-plugin-api --test-options="$TEST_OPTS" + - if: matrix.test name: Test func-test suite env: From 608b56d03f85c1d19ee71b8cdd6f7803c44b4ac1 Mon Sep 17 00:00:00 2001 From: kokobd Date: Sat, 22 Jan 2022 20:17:57 +0800 Subject: [PATCH 4/4] fix ci --- hls-plugin-api/hls-plugin-api.cabal | 1 + hls-plugin-api/test/Main.hs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hls-plugin-api/hls-plugin-api.cabal b/hls-plugin-api/hls-plugin-api.cabal index d7310d71be..ec555ee483 100644 --- a/hls-plugin-api/hls-plugin-api.cabal +++ b/hls-plugin-api/hls-plugin-api.cabal @@ -90,4 +90,5 @@ test-suite tests , hls-plugin-api , tasty , tasty-hunit + , tasty-rerun , lsp-types diff --git a/hls-plugin-api/test/Main.hs b/hls-plugin-api/test/Main.hs index 5f948eb5e8..fc58853b4b 100644 --- a/hls-plugin-api/test/Main.hs +++ b/hls-plugin-api/test/Main.hs @@ -1,10 +1,11 @@ module Main where -import qualified Ide.PluginUtilsTest as PluginUtilsTest +import qualified Ide.PluginUtilsTest as PluginUtilsTest import Test.Tasty +import Test.Tasty.Ingredients.Rerun main :: IO () -main = defaultMain tests +main = defaultMainWithRerun tests tests :: TestTree tests = testGroup "Main"