I have some data files that only belong with my test program and would be confusing to distribute with the main library.
Unfortunately, the .cabal data-files
field only applies to an entire cabal file, not a single section like the test-suite
. If I try to use it in a test-suite stanza I just get:
Warning: ssh.cabal: Unknown fields: data-files (line 71)
Is there a natural way to associate these files with my test program so that they get copied around only if --enable-tests
is specified?
If there's no better way I'll probably use Template Haskell to embed them into the executable and then write them out again at runtime or something like that, but it feels pretty ugly.
There is no Cabal attribute that allows you to associate data files with a test suite (or any non-global stanza of your build).
The common solution to this problem is to declare those files in the extra-source-files
attribute. That attribute is global, too, and it ensures that the files listed are included in the release tarball so that the test suite can find them when run. Unlike data-files
, however, extra-source-files
are not installed — which is probably what you want since your test suite is not installed either. So the files are available during the build (and test suite run), but they won't take up space in the installation.
Build drivers like cabal-install
and stack
will execute the test suite with the current working directory pointing into the top-level directory of your project, i.e. in the directory that contains your project's Cabal file. Thus, if you have a data file at test/my-data-file.txt
, then your test suite can access the file using exactly that path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With