Skip to content

Commit

Permalink
Add testcases for 'findCradle'
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor committed Oct 10, 2023
1 parent e34ef7f commit e5ae93a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
34 changes: 22 additions & 12 deletions tests/BiosTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Control.Monad ( forM_ )
import Data.List ( sort, isPrefixOf )
import Data.Typeable
import System.Directory
import System.FilePath ((</>) )
import System.FilePath ((</>))
import System.Exit (ExitCode(ExitSuccess, ExitFailure))
import Control.Monad.Extra (unlessM)
import qualified HIE.Bios.Ghc.Gap as Gap
Expand Down Expand Up @@ -48,17 +48,7 @@ main = do

defaultMainWithIngredients (ignoreToolTests:defaultIngredients) $
testGroup "Bios-tests"
[ testGroup "Find cradle"
[ testCaseSteps "simple-cabal" $
runTestEnvLocal "./simple-cabal" $ do
findCradleForModuleM "B.hs" (Just "hie.yaml")

-- Checks if we can find a hie.yaml even when the given filepath
-- is unknown. This functionality is required by Haskell IDE Engine.
, testCaseSteps "simple-cabal-unknown-path" $
runTestEnvLocal "./simple-cabal" $ do
findCradleForModuleM "Foo.hs" (Just "hie.yaml")
]
[ testGroup "Find cradle" findCradleTests
, testGroup "Symlink" symbolicLinkTests
, testGroup "Loading tests"
[ testGroup "bios" biosTestCases
Expand Down Expand Up @@ -301,6 +291,26 @@ directTestCases =
testDirectoryM isMultiCradle "B.hs"
]

findCradleTests :: [TestTree]
findCradleTests =
[ cradleFileTest "Simple Existing File" "./simple-cabal" "B.hs" (Just "hie.yaml")
-- Checks if we can find a hie.yaml even when the given filepath
-- is unknown. This functionality is required by Haskell IDE Engine.
, cradleFileTest "Existing File" "cabal-with-ghc" "src/MyLib.hs" (Just "hie.yaml")
, cradleFileTest "Non-existing file" "cabal-with-ghc" "src/MyLib2.hs" (Just "hie.yaml")
, cradleFileTest "Non-existing file 2" "cabal-with-ghc" "MyLib2.hs" (Just "hie.yaml")
, cradleFileTest "Directory 1" "cabal-with-ghc" "src/" (Just "hie.yaml")
, cradleFileTest "Directory 2" "simple-cabal" "" (Just "hie.yaml")
-- Unknown directory in a project, ought to work as well.
, cradleFileTest "Directory 3" "simple-cabal" "src/" (Just "hie.yaml")
, cradleFileTest "Directory does not exist" "doesnotexist" "A.hs" Nothing
]
where
cradleFileTest :: String -> FilePath -> FilePath -> Maybe FilePath -> TestTree
cradleFileTest testName dir fpTarget result = testCaseSteps testName $ do
runTestEnv dir $ do
findCradleForModuleM fpTarget result

-- ------------------------------------------------------------------
-- Unit-test Helper functions
-- ------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion tests/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,9 @@ findCradleForModuleM fp expected' = do
withTempCopy :: FilePath -> (FilePath -> IO a) -> IO a
withTempCopy srcDir f =
withSystemTempDirectory "hie-bios-test" $ \newDir -> do
copyDir srcDir newDir
exists <- doesDirectoryExist srcDir
when exists $ do
copyDir srcDir newDir
f newDir

copyDir :: FilePath -> FilePath -> IO ()
Expand Down

0 comments on commit e5ae93a

Please sign in to comment.