diff --git a/changelog.d/5-internal/ptests b/changelog.d/5-internal/ptests new file mode 100644 index 0000000000..55443d72a3 --- /dev/null +++ b/changelog.d/5-internal/ptests @@ -0,0 +1 @@ +Add parametrised tests diff --git a/integration/Setup.hs b/integration/Setup.hs index 33276dca90..f2214094f5 100644 --- a/integration/Setup.hs +++ b/integration/Setup.hs @@ -111,14 +111,12 @@ testHooks hooks = dest ( unlines [ "module RunAllTests where", - "import Testlib.Types", + "import Testlib.PTest", "import Prelude", unlines (map ("import qualified " <>) modules), - "allTests :: [(String, String, String, String, App ())]", + "allTests :: [Test]", "allTests =", - " [", - " " <> intercalate ",\n " (map (\(m, n, s, f) -> "(" <> intercalate ", " [show m, show n, show s, show f, m <> "." <> n] <> ")") tests), - " ]" + " " <> intercalate " <>\n " (map (\(m, n, s, f) -> "mkTests " <> unwords [show m, show n, show s, show f, m <> "." <> n]) tests) ] ) pure () diff --git a/integration/integration.cabal b/integration/integration.cabal index 4d3bc68961..1c33462eb6 100644 --- a/integration/integration.cabal +++ b/integration/integration.cabal @@ -102,6 +102,7 @@ library Testlib.Prekeys Testlib.Prelude Testlib.Printing + Testlib.PTest Testlib.Run Testlib.Types diff --git a/integration/test/Testlib/PTest.hs b/integration/test/Testlib/PTest.hs new file mode 100644 index 0000000000..02b8084b33 --- /dev/null +++ b/integration/test/Testlib/PTest.hs @@ -0,0 +1,27 @@ +module Testlib.PTest where + +import Data.Aeson (Value (..)) +import qualified Data.Text as T +import Testlib.App +import Testlib.JSON +import Testlib.Types +import Prelude + +type Test = (String, String, String, String, App ()) + +class HasTests x where + mkTests :: String -> String -> String -> String -> x -> [Test] + +instance HasTests (App ()) where + mkTests m n s f x = [(m, n, s, f, x)] + +data Domain = OwnDomain | OtherDomain + +instance MakesValue Domain where + make OwnDomain = String . T.pack <$> ownDomain + make OtherDomain = String . T.pack <$> otherDomain + +instance HasTests x => HasTests (Domain -> x) where + mkTests m n s f x = + mkTests m (n <> "[domain=own]") s f (x OwnDomain) + <> mkTests m (n <> "[domain=other]") s f (x OtherDomain) diff --git a/integration/test/Testlib/Prelude.hs b/integration/test/Testlib/Prelude.hs index 35c25f1626..1187480186 100644 --- a/integration/test/Testlib/Prelude.hs +++ b/integration/test/Testlib/Prelude.hs @@ -7,6 +7,7 @@ module Testlib.Prelude module Testlib.ModService, module Testlib.HTTP, module Testlib.JSON, + module Testlib.PTest, module Data.Aeson, module Prelude, module Control.Applicative, @@ -117,6 +118,7 @@ import Testlib.Env import Testlib.HTTP import Testlib.JSON import Testlib.ModService +import Testlib.PTest import Testlib.Types import UnliftIO.Exception import Prelude