Move test sample code out to external file (#175)

* Move sample code out into into separate source file

* Add test/data/GotoHover.hs to cabal extra-source-files

* hlint: explicit module export list

* hlint: implement and use readFileUtf8

* hlint: remove -Wmissing-signatures
This commit is contained in:
Jacek Generowicz 2019-10-22 16:41:13 +02:00 committed by Andreas Herrmann
parent 38c29030d1
commit 5645a8030c
4 changed files with 42 additions and 32 deletions

View File

@ -15,6 +15,7 @@ homepage: https://github.com/digital-asset/ghcide#readme
bug-reports: https://github.com/digital-asset/ghcide/issues
tested-with: GHC==8.6.5
extra-source-files: include/ghc-api-version.h README.md CHANGELOG.md
test/data/GotoHover.hs
source-repository head
type: git
@ -172,6 +173,7 @@ test-suite ghcide-tests
ghcide:ghcide
build-depends:
base,
bytestring,
containers,
directory,
extra,
@ -184,6 +186,7 @@ test-suite ghcide-tests
-- which works for now.
ghc,
--------------------------------------------------------------
ghcide,
haskell-lsp-types,
lens,
lsp-test >= 0.8,

View File

@ -18,7 +18,8 @@ module Development.IDE.GHC.Util(
runGhcEnv,
textToStringBuffer,
moduleImportPath,
HscEnvEq, hscEnv, newHscEnvEq
HscEnvEq, hscEnv, newHscEnvEq,
readFileUtf8
) where
import Config
@ -35,7 +36,10 @@ import FileCleanup
import Platform
import Data.Unique
import Development.Shake.Classes
import qualified Data.Text as T
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.Encoding.Error as T
import qualified Data.ByteString as BS
import StringBuffer
import System.FilePath
@ -139,3 +143,6 @@ instance Eq HscEnvEq where
instance NFData HscEnvEq where
rnf (HscEnvEq a b) = rnf (hashUnique a) `seq` b `seq` ()
readFileUtf8 :: FilePath -> IO T.Text
readFileUtf8 f = T.decodeUtf8With T.lenientDecode <$> BS.readFile f

21
test/data/GotoHover.hs Normal file
View File

@ -0,0 +1,21 @@
module Testing ( module Testing )where
import Data.Text (Text, pack)
data TypeConstructor = DataConstructor
{ fff :: Text
, ggg :: Int }
aaa :: TypeConstructor
aaa = DataConstructor
{ fff = ""
, ggg = 0
}
bbb :: TypeConstructor
bbb = DataConstructor "" 0
ccc :: (Text, Int)
ccc = (fff bbb, ggg aaa)
ddd :: Num a => a -> a -> a
ddd vv ww = vv +! ww
a +! b = a - b
hhh (Just a) (><) = a >< a
iii a b = a `b` a
jjj s = pack $ s <> s

View File

@ -12,6 +12,7 @@ import Control.Monad
import Control.Monad.IO.Class (liftIO)
import Data.Char (toLower)
import Data.Foldable
import Development.IDE.GHC.Util
import qualified Data.Text as T
import Development.IDE.Test
import Development.IDE.Test.Runfiles
@ -694,7 +695,7 @@ findDefinitionAndHoverTests :: TestTree
findDefinitionAndHoverTests = let
tst (get, check) pos targetRange title = testSession title $ do
doc <- openDoc' sourceFilePath "haskell" source
doc <- openTestDataDoc sourceFilePath
found <- get doc pos
check found targetRange
@ -751,8 +752,8 @@ findDefinitionAndHoverTests = let
(T.unpack $ "failed to find: `" <> part <> "` in hover message:\n" <> whole)
(part `T.isInfixOf` whole)
sourceFilePath = "Testing.hs" -- TODO: convert from sourceFileName
sourceFileName = "Testing.hs"
sourceFilePath = T.unpack sourceFileName
sourceFileName = "GotoHover.hs"
mkFindTests tests = testGroup "get"
[ testGroup "definition" $ mapMaybe fst tests
@ -765,33 +766,6 @@ findDefinitionAndHoverTests = let
hover = (getHover , checkHover)
--type_ = (getTypeDefinitions, checkTDefs) -- getTypeDefinitions always times out
source = T.unlines
-- 0123456789 123456789 123456789 123456789
[ "{-# OPTIONS_GHC -Wmissing-signatures #-}" -- 0
, "module Testing where" -- 1
, "import Data.Text (Text, pack)" -- 2
, "data TypeConstructor = DataConstructor" -- 3
, " { fff :: Text" -- 4
, " , ggg :: Int }" -- 5
, "aaa :: TypeConstructor" -- 6
, "aaa = DataConstructor" -- 7
, " { fff = \"\"" -- 8
, " , ggg = 0" -- 9
-- 0123456789 123456789 123456789 123456789
, " }" -- 10
, "bbb :: TypeConstructor" -- 11
, "bbb = DataConstructor \"\" 0" -- 12
, "ccc :: (Text, Int)" -- 13
, "ccc = (fff bbb, ggg aaa)" -- 14
, "ddd :: Num a => a -> a -> a" -- 15
, "ddd vv ww = vv +! ww" -- 16
, "a +! b = a - b" -- 17
, "hhh (Just a) (><) = a >< a" -- 18
, "iii a b = a `b` a" -- 19
, "jjj s = pack $ s <> s" -- 20
-- 0123456789 123456789 123456789 123456789
]
-- search locations expectations on results
fffL4 = _start fffR ; fffR = mkRange 4 4 4 7 ; fff = [ExpectRange fffR]
fffL8 = Position 8 4 ;
@ -888,3 +862,8 @@ run s = withTempDir $ \dir -> do
-- If you uncomment this you can see all messages
-- which can be quite useful for debugging.
-- { logMessages = True, logColor = False, logStdErr = True }
openTestDataDoc :: FilePath -> Session TextDocumentIdentifier
openTestDataDoc path = do
source <- liftIO $ readFileUtf8 $ "test/data" </> path
openDoc' path "haskell" source