Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test.Utils.Paths: Fix the test data directory for Windows and Nix #1109

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions lib/test-utils/src/Test/Utils/Paths.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@ module Test.Utils.Paths

import Prelude

import Control.Monad.IO.Class
( liftIO )
import Data.FileEmbed
( makeRelativeToProject )
import Language.Haskell.TH.Syntax
( Exp, Q, liftData )
import System.Environment
( lookupEnv )
import System.FilePath
( (</>) )

-- | A TH function to get the test data directory. It combines the current
-- source file location and cabal file to locate the package directory in such a
-- way that works in both the package build and ghci.
-- | A TH function to get the test data directory.
--
-- It combines the current source file location and cabal file to locate the
-- package directory in such a way that works in both the stack/cabal package
-- build and ghci.
--
-- For the Nix build, rather than baking in a path that starts with @/build@, it
-- makes the test data path relative to the current directory.
getTestData :: Q Exp
getTestData = makeRelativeToProject ("test" </> "data") >>= liftData
getTestData = do
let relPath = "test" </> "data"
absPath <- makeRelativeToProject relPath

-- This environment variable indicates we are building under nix.
nixBuildDir <- liftIO $ lookupEnv "NIX_BUILD_TOP"

liftData $ maybe absPath (const relPath) nixBuildDir