Permalink
Please
sign in to comment.
Browse files
Merge #1101
1101: tests: Use TH for getting data directory r=rvl a=rvl Relates to a previous PR #976 and is needed for running tests on Windows/Wine. # Overview We need a method of locating the data directories of the test suites that works in multiple situations: - stack build (working directory at .cabal file) - stack ghci (working directory is project root) - ghci (not using cabal) - in the Nix build (working directory is at project root) - when running windows tests (the install prefix baked in to Paths_ will always be wrong) With `Paths_cardano_wallet_jormungandr.getDataDir`, only the first two work. Using `makeRelativeToProject` in a TH splice seems to work in all situations. Example error with ghci and `Paths_` :l lib/jormungandr/test/unit/Cardano/Wallet/Jormungandr/BinarySpec.hs Ok, 24 modules loaded. λ> hspec spec *** Exception: /home/rodney/.cabal/share/x86_64-linux-ghc-8.6.5/cardano-wallet-jormungandr-2019.11.18/block0s: getDirectoryContents:openDirStream: does not exist (No such file or directory) Example error with nix-build: Linking dist/build/unit/unit ... running tests unit: /nix/store/8kgw4dkyx6yl68if3vdk83vx64v7zkw7-cardano-wallet-jormungandr-2019.11.18-test-unit/share/x86_64-osx-ghc-8.6.5/cardano-wallet-jormungandr-2019.11.18/block0s: getDirectoryContents:openDirStream: does not exist (No such file or directory) builder for '/nix/store/z5dphvdqafx9y2nvzch4clhg5j6iyvh6-cardano-wallet-jormungandr-2019.11.18-test-unit.drv' failed with exit code 1 This nix-build error is arguably a bug in Haskell.nix (or maybe it's even a limitation of Cabal). The tests install prefix is different from the library install prefix. Either the tests should be referring to paths in the library install prefix, or the data files should be copied into the tests install prefix. Either way, something needs to be fixed. Example error on Windows: C:\Users\win\cw>cardano-wallet-jormungandr-2019.11.18-test-unit.exe cardano-wallet-jormungandr-2019.11.18-test-unit.exe: /nix/store/rhdan17ab6f4310ibfcjiyhgjx48b7yh-cardano-wallet-jormungandr-2019.11.18-test-unit-x86_64-pc-mingw32/share/x86_64-windows-ghc-8.6.5/cardano-wallet-jormungandr-2019.11.18\block0s: getDirectoryContents:findFirstFile: does not exist (The system cannot find the path specified.) Under Windows, installation prefixes such as /usr/local do not make sense. So it should just be searching for data in the current directory. Co-authored-by: Rodney Lorrimar <rodney.lorrimar@iohk.io> Co-authored-by: KtorZ <matthias.benkort@gmail.com>
- Loading branch information
Showing
with
61 additions
and 35 deletions.
- +3 −5 lib/core/test/unit/Cardano/Pool/MetadataSpec.hs
- +3 −2 lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs
- +0 −9 lib/jormungandr/cardano-wallet-jormungandr.cabal
- +5 −5 lib/jormungandr/test/integration/Cardano/Faucet.hs
- +7 −5 lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/Launch.hs
- +7 −5 lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/CLI/Launcher.hs
- +5 −4 lib/jormungandr/test/unit/Cardano/Wallet/Jormungandr/BinarySpec.hs
- +4 −0 lib/test-utils/cardano-wallet-test-utils.cabal
- +24 −0 lib/test-utils/src/Test/Utils/Paths.hs
- +3 −0 nix/.stack.nix/cardano-wallet-test-utils.nix
@@ -0,0 +1,24 @@ | ||
-- | | ||
-- Copyright: © 2018-2019 IOHK | ||
-- License: Apache-2.0 | ||
-- | ||
-- Utility function for finding the package test data directory. | ||
|
||
module Test.Utils.Paths | ||
( getTestData | ||
) where | ||
|
||
import Prelude | ||
|
||
import Data.FileEmbed | ||
( makeRelativeToProject ) | ||
import Language.Haskell.TH.Syntax | ||
( Exp, Q, liftData ) | ||
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. | ||
getTestData :: Q Exp | ||
getTestData = makeRelativeToProject ("test" </> "data") >>= liftData |
0 comments on commit
74bf02a