Skip to content

Commit 7e02c91

Browse files
authored
Add fixtures to datadir (#326)
1 parent 93bad5b commit 7e02c91

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

monad-bayes.cabal

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extra-source-files:
2525
CHANGELOG.md
2626
README.md
2727

28+
data-files: test/fixtures/*.txt
29+
2830
source-repository head
2931
type: git
3032
location: https://github.com/tweag/monad-bayes.git
@@ -78,6 +80,9 @@ common test-deps
7880
, transformers ^>=0.5.6
7981
, typed-process ^>=0.2
8082

83+
autogen-modules: Paths_monad_bayes
84+
other-modules: Paths_monad_bayes
85+
8186
library
8287
import: deps
8388
exposed-modules:

test/TestBenchmarks.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ module TestBenchmarks where
33
import Control.Monad (forM_)
44
import Data.Maybe (fromJust)
55
import Helper
6+
import Paths_monad_bayes (getDataDir)
67
import System.IO (readFile')
78
import System.IO.Error (catchIOError, isDoesNotExistError)
89
import Test.Hspec
910

1011
fixtureToFilename :: Model -> Alg -> String
11-
fixtureToFilename model alg = fromJust (serializeModel model) ++ "-" ++ show alg ++ ".txt"
12+
fixtureToFilename model alg = "/test/fixtures/" ++ fromJust (serializeModel model) ++ "-" ++ show alg ++ ".txt"
1213

1314
models :: [Model]
1415
models = [LR 10, HMM 10, LDA (5, 10)]
@@ -21,7 +22,8 @@ test = describe "Benchmarks" $ forM_ models $ \model -> forM_ algs $ testFixture
2122

2223
testFixture :: Model -> Alg -> SpecWith ()
2324
testFixture model alg = do
24-
let filename = "test/fixtures/" ++ fixtureToFilename model alg
25+
dataDir <- runIO getDataDir
26+
let filename = dataDir <> fixtureToFilename model alg
2527
it ("should agree with the fixture " ++ filename) $ do
2628
fixture <- catchIOError (readFile' filename) $ \e ->
2729
if isDoesNotExistError e

test/TestSSMFixtures.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ module TestSSMFixtures where
33
import Control.Monad.Bayes.Sampler.Strict (sampleIOfixed)
44
import NonlinearSSM
55
import NonlinearSSM.Algorithms
6+
import Paths_monad_bayes (getDataDir)
67
import System.IO (readFile')
78
import System.IO.Error (catchIOError, isDoesNotExistError)
89
import Test.Hspec
910

1011
fixtureToFilename :: Alg -> FilePath
11-
fixtureToFilename alg = "test/fixtures/SSM-" ++ show alg ++ ".txt"
12+
fixtureToFilename alg = "/test/fixtures/SSM-" ++ show alg ++ ".txt"
1213

1314
testFixture :: Alg -> SpecWith ()
1415
testFixture alg = do
15-
let filename = fixtureToFilename alg
16+
dataDir <- runIO getDataDir
17+
let filename = dataDir <> fixtureToFilename alg
1618
it ("should agree with the fixture " ++ filename) $ do
1719
ys <- sampleIOfixed $ generateData t
1820
fixture <- catchIOError (readFile' filename) $ \e ->

0 commit comments

Comments
 (0)