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.
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)
Paths_cardano_wallet_jormungandr.getDataDir, only the first two work.
makeRelativeToProject in a TH splice seems to work in all situations.
Example error with ghci and
: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.