diff --git a/monad-bayes.cabal b/monad-bayes.cabal index c576c005..8dc7b22b 100644 --- a/monad-bayes.cabal +++ b/monad-bayes.cabal @@ -25,6 +25,8 @@ extra-source-files: CHANGELOG.md README.md +data-files: test/fixtures/*.txt + source-repository head type: git location: https://github.com/tweag/monad-bayes.git @@ -78,6 +80,9 @@ common test-deps , transformers ^>=0.5.6 , typed-process ^>=0.2 + autogen-modules: Paths_monad_bayes + other-modules: Paths_monad_bayes + library import: deps exposed-modules: diff --git a/test/TestBenchmarks.hs b/test/TestBenchmarks.hs index 2645d19b..1cd5bcbb 100644 --- a/test/TestBenchmarks.hs +++ b/test/TestBenchmarks.hs @@ -3,12 +3,13 @@ module TestBenchmarks where import Control.Monad (forM_) import Data.Maybe (fromJust) import Helper +import Paths_monad_bayes (getDataDir) import System.IO (readFile') import System.IO.Error (catchIOError, isDoesNotExistError) import Test.Hspec fixtureToFilename :: Model -> Alg -> String -fixtureToFilename model alg = fromJust (serializeModel model) ++ "-" ++ show alg ++ ".txt" +fixtureToFilename model alg = "/test/fixtures/" ++ fromJust (serializeModel model) ++ "-" ++ show alg ++ ".txt" models :: [Model] models = [LR 10, HMM 10, LDA (5, 10)] @@ -21,7 +22,8 @@ test = describe "Benchmarks" $ forM_ models $ \model -> forM_ algs $ testFixture testFixture :: Model -> Alg -> SpecWith () testFixture model alg = do - let filename = "test/fixtures/" ++ fixtureToFilename model alg + dataDir <- runIO getDataDir + let filename = dataDir <> fixtureToFilename model alg it ("should agree with the fixture " ++ filename) $ do fixture <- catchIOError (readFile' filename) $ \e -> if isDoesNotExistError e diff --git a/test/TestSSMFixtures.hs b/test/TestSSMFixtures.hs index ebf2284d..36eb6f6b 100644 --- a/test/TestSSMFixtures.hs +++ b/test/TestSSMFixtures.hs @@ -3,16 +3,18 @@ module TestSSMFixtures where import Control.Monad.Bayes.Sampler.Strict (sampleIOfixed) import NonlinearSSM import NonlinearSSM.Algorithms +import Paths_monad_bayes (getDataDir) import System.IO (readFile') import System.IO.Error (catchIOError, isDoesNotExistError) import Test.Hspec fixtureToFilename :: Alg -> FilePath -fixtureToFilename alg = "test/fixtures/SSM-" ++ show alg ++ ".txt" +fixtureToFilename alg = "/test/fixtures/SSM-" ++ show alg ++ ".txt" testFixture :: Alg -> SpecWith () testFixture alg = do - let filename = fixtureToFilename alg + dataDir <- runIO getDataDir + let filename = dataDir <> fixtureToFilename alg it ("should agree with the fixture " ++ filename) $ do ys <- sampleIOfixed $ generateData t fixture <- catchIOError (readFile' filename) $ \e ->