2021-11-17 22:50:39 +03:00
|
|
|
-- | Helper functions for easily testing features.
|
|
|
|
module Harness.Feature
|
|
|
|
( feature,
|
|
|
|
Feature (..),
|
|
|
|
Backend (..),
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2021-11-23 21:15:17 +03:00
|
|
|
import Control.Exception
|
2021-11-17 22:50:39 +03:00
|
|
|
import Data.Foldable
|
2021-11-23 21:15:17 +03:00
|
|
|
import Harness.State (State)
|
2021-11-17 22:50:39 +03:00
|
|
|
import Test.Hspec
|
|
|
|
import Prelude
|
|
|
|
|
|
|
|
-- | Use this record to put together a test against a set of backends.
|
|
|
|
data Feature = Feature
|
|
|
|
{ backends :: [Backend],
|
2021-11-23 21:15:17 +03:00
|
|
|
tests :: SpecWith State
|
2021-11-17 22:50:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
-- | A backend specification.
|
|
|
|
data Backend = Backend
|
|
|
|
{ -- | Can be any name you want (e.g. "PostgreSQL" or "MySQL v1.2")
|
|
|
|
-- or whatnot.
|
|
|
|
name :: String,
|
|
|
|
-- | To setup the test suite: Run SQL commands, run metadata track
|
|
|
|
-- tables calls.
|
2021-11-23 21:15:17 +03:00
|
|
|
setup :: State -> IO (),
|
2021-11-17 22:50:39 +03:00
|
|
|
-- | Clean up any resources you created in 'setup'.
|
2021-11-23 21:15:17 +03:00
|
|
|
teardown :: State -> IO ()
|
2021-11-17 22:50:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
-- | Test the feature, running the setup before any tests are run, and
|
|
|
|
-- and ensuring teardown happens after all tests are run.
|
2021-11-23 21:15:17 +03:00
|
|
|
feature :: Feature -> SpecWith State
|
2021-11-17 22:50:39 +03:00
|
|
|
feature Feature {backends, tests} =
|
|
|
|
for_
|
|
|
|
backends
|
|
|
|
( \Backend {name, setup, teardown} ->
|
|
|
|
describe
|
|
|
|
name
|
2021-11-23 21:15:17 +03:00
|
|
|
( aroundAllWith
|
2021-12-30 14:00:52 +03:00
|
|
|
( \actionWith state -> do
|
|
|
|
finally
|
|
|
|
( do
|
|
|
|
setup state
|
|
|
|
actionWith state
|
|
|
|
)
|
|
|
|
(teardown state)
|
2021-11-23 21:15:17 +03:00
|
|
|
)
|
|
|
|
tests
|
|
|
|
)
|
2021-11-17 22:50:39 +03:00
|
|
|
)
|