From ae37b4b21c56d296c7c77cd7078be322c2e5b241 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com> Date: Thu, 25 Jul 2019 14:50:07 +0200 Subject: [PATCH] stack/cabal for hie-core-tests (#2287) * stack/cabal for hie-core-tests * ./fmt.sh --- hie-core.cabal | 26 +++++++++++++++++++++ stack.yaml | 2 ++ test/BUILD.bazel | 18 ++++++++++++-- test/bazel/Development/IDE/Test/Runfiles.hs | 16 +++++++++++++ test/cabal/Development/IDE/Test/Runfiles.hs | 12 ++++++++++ test/exe/Main.hs | 8 +++---- 6 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 test/bazel/Development/IDE/Test/Runfiles.hs create mode 100644 test/cabal/Development/IDE/Test/Runfiles.hs diff --git a/hie-core.cabal b/hie-core.cabal index 5561c8e6..cdc44369 100644 --- a/hie-core.cabal +++ b/hie-core.cabal @@ -58,10 +58,12 @@ library cpp-options: -DGHC_STABLE default-extensions: BangPatterns + DeriveFunctor DeriveGeneric GeneralizedNewtypeDeriving LambdaCase NamedFieldPuns + OverloadedStrings RecordWildCards ScopedTypeVariables StandaloneDeriving @@ -74,6 +76,7 @@ library exposed-modules: Development.IDE.Core.FileStore Development.IDE.Core.OfInterest + Development.IDE.Core.PositionMapping Development.IDE.Core.Rules Development.IDE.Core.RuleTypes Development.IDE.Core.Service @@ -131,3 +134,26 @@ executable hie-core RecordWildCards TupleSections ViewPatterns + +test-suite hie-core-tests + type: exitcode-stdio-1.0 + default-language: Haskell2010 + build-tool-depends: + hie-core:hie-core + build-depends: + base, + containers, + extra, + filepath, + haskell-lsp-types, + lens, + lsp-test, + parser-combinators, + tasty, + tasty-hunit, + text + hs-source-dirs: test/cabal test/exe test/src + main-is: Main.hs + other-modules: + Development.IDE.Test + Development.IDE.Test.Runfiles diff --git a/stack.yaml b/stack.yaml index 057ee164..dd853f37 100644 --- a/stack.yaml +++ b/stack.yaml @@ -8,6 +8,8 @@ extra-deps: subdirs: - . - haskell-lsp-types +- git: https://github.com/digital-asset/lsp-test.git + commit: 50c43452e19e494d71ccba1f7922d0b3b3fc69c3 - git: https://github.com/mpickering/hie-bios.git commit: 8427e424a83c2f3d60bdd26c02478c00d2189a73 nix: diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 8591ed79..c2f3c445 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -27,6 +27,20 @@ da_haskell_library( ], ) +da_haskell_library( + name = "hie-core-test-runfiles", + srcs = glob(["bazel/**/*.hs"]), + hazel_deps = [ + "base", + "filepath", + ], + src_strip_prefix = "bazel", + visibility = ["//visibility:public"], + deps = [ + "//libs-haskell/bazel-runfiles", + ], +) + da_haskell_test( name = "hie-core-tests", srcs = glob(["exe/**/*.hs"]), @@ -43,8 +57,8 @@ da_haskell_test( ], src_strip_prefix = "exe", deps = [ + ":hie-core-test-runfiles", + ":hie-core-testing", "//compiler/hie-core", - "//compiler/hie-core/test:hie-core-testing", - "//libs-haskell/bazel-runfiles", ], ) diff --git a/test/bazel/Development/IDE/Test/Runfiles.hs b/test/bazel/Development/IDE/Test/Runfiles.hs new file mode 100644 index 00000000..dc765b01 --- /dev/null +++ b/test/bazel/Development/IDE/Test/Runfiles.hs @@ -0,0 +1,16 @@ +-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Development.IDE.Test.Runfiles + ( locateHieCoreExecutable + ) where + +import System.FilePath ((), FilePath) + +import DA.Bazel.Runfiles + + +locateHieCoreExecutable :: IO FilePath +locateHieCoreExecutable = locateRunfiles hieCoreExePath + where + hieCoreExePath = mainWorkspace exe "compiler/hie-core/hie-core-exe" diff --git a/test/cabal/Development/IDE/Test/Runfiles.hs b/test/cabal/Development/IDE/Test/Runfiles.hs new file mode 100644 index 00000000..3f326651 --- /dev/null +++ b/test/cabal/Development/IDE/Test/Runfiles.hs @@ -0,0 +1,12 @@ +-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Development.IDE.Test.Runfiles + ( locateHieCoreExecutable + ) where + +import System.FilePath (FilePath) + + +locateHieCoreExecutable :: IO FilePath +locateHieCoreExecutable = pure "hie-core" diff --git a/test/exe/Main.hs b/test/exe/Main.hs index 7ab29d92..2dbd38a1 100644 --- a/test/exe/Main.hs +++ b/test/exe/Main.hs @@ -1,22 +1,21 @@ -- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -- SPDX-License-Identifier: Apache-2.0 +{-# LANGUAGE DuplicateRecordFields #-} module Main (main) where import Control.Monad (void) import qualified Data.Text as T import Development.IDE.Test +import Development.IDE.Test.Runfiles import Language.Haskell.LSP.Test import Language.Haskell.LSP.Types import System.Environment.Blank (setEnv) -import System.FilePath import System.IO.Extra import Test.Tasty import Test.Tasty.HUnit -import DA.Bazel.Runfiles - main :: IO () main = defaultMain $ testGroup "HIE" @@ -60,8 +59,7 @@ testSession name = testCase name . run run :: Session a -> IO a run s = withTempDir $ \dir -> do - let hieCoreExePath = mainWorkspace exe "compiler/hie-core/hie-core-exe" - hieCoreExe <- locateRunfiles hieCoreExePath + hieCoreExe <- locateHieCoreExecutable let cmd = unwords [hieCoreExe, "--lsp", "--cwd", dir] -- HIE calls getXgdDirectory which assumes that HOME is set. -- Only sets HOME if it wasn't already set.