Reputation: 1152
This is probably a basic question but I've been Googling for a while on it... I have a Cabal-ized Haskell project and I'm in the process of writing integration tests for it. I want to be able to include test resources for my project in the same repo and access them in tests. For example, here are a couple things I want to accomplish:
1) Check a dummy database instance into my repo, including a shell script that spins up a database process. I want to write an Hspec integration test that spins up the database process, makes some calls to it, and then shuts it down. So I need to be able to find the shell script so I can use System.Process.createProcess
on it.
2) Check in paired "input" and "output" files. My test should process each of the input files and compare them to a corresponding output file to make sure they match. (I've read about "golden" but it doesn't seem to solve the problem of finding/reading the input files in the first place?)
In short, how can I go about creating a "resources" folder in the root folder of my Haskell project and find the path to it inside tests?
Upvotes: 4
Views: 883
Reputation: 24593
I don't believe the the question asked has been answered satisfactorily. Specifically, we want to answer the following questions:
src/test/resources
, but AFAICT, there's no such convention in Haskell. So, putting the files inside the test directory, presumably under the same module path, makes sense to me.
For example, If the code under test is in the module A.B
, then putting the test data in the directory test/A/B
is fine. If using HSpec, the test module is A.BSpec
.readFile test/A/B/file.txt
from the test works. Otherwise, these files can be listed in the data-files
field of cabal. See Accessing data files from package code. This, however, means that the data files will be shipped with the code.Upvotes: -1
Reputation: 7403
Have a look at an existing project that uses input and output file.
For example, take haddock, the source code is at https://github.com/haskell/haddock. They have the test files under a folder (https://github.com/haskell/haddock/tree/master/html-test/ref) and they are referenced as extra-source-files in the cabal file (https://github.com/haskell/haddock/blob/master/haddock.cabal). Then the test code (https://github.com/haskell/haddock/blob/master/html-test/run.lhs) uses some CPP macro (__FILE__
) to get the current directory, and can then resolve the files relative to that folder.
Upvotes: 3