What is the best way to test (using cabal test
) my Haskell code that depends on ccall
DLL code?
Let’s say I have this code:
{-# LANGUAGE ForeignFunctionInterface #-}
module MyDllFunctions where
foreign import ccall "mydll.h myFunctions"
myDLLFunction :: Int -> IO (Int)
myFunction :: Int -> IO (Int)
myFunction a = do
b <- myDLLFunction a
return b
How can I test the myFunction
without calling myDLLFunction
directly?
What I’ve considered so far:
- Passing the function as a parameter - This would work, but it would make calling
myFunction
difficult later (myFunction f x
) - Creating a fake DLL to enable testing, and using “#ifndef” to change the DLL based on the compilation target in cabal. This what I would do in C - I’m hoping for a more “Haskelly” solution