Reputation: 617
Many people include .ghci
files in their haskell projects to include needed options to load modules into ghci
. Here's an example:
:set -isrc -itest -iexamples -packagehspec2
However when trying to run a file containing main
through runhaskell
one has to repeat all these options, e.g.:
runhaskell -isrc -itest -iexamples -packagehspec2 test/Spec.hs
Is there a good way to let runhaskell
pick up the options from the .ghci
file?
Upvotes: 6
Views: 226
Reputation: 421
I don't know of any way to make runhaskell
work. What I do is just pipe "main"
to ghci:
$ echo main | ghci -v0 test/Spec.hs
If you want to pass command-line arguments, that works too:
$ echo ':main -m "behaves correct"' | ghci -v0 test/Spec.hs
Or you can wrap it up in a script:
#!/usr/bin/env runhaskell
>import System.IO
>import System.Environment
>import System.Exit
>import System.Process
>
>main :: IO ()
>main = do
> source:args <- getArgs
> (Just h, Nothing, Nothing, pid) <- createProcess (proc "ghci" ["-v0", source]) {std_in = CreatePipe}
> hPutStr h ("import System.Environment\nSystem.Environment.withArgs " ++ show args ++ " main\n")
> hClose h
> waitForProcess pid >>= exitWith
Which can be used like so:
$ ./run.lhs test/Spec.hs -m "behaves correct"
Upvotes: 4