Skip to content

Commit

Permalink
Merge branch 'origin/develop' into mls
Browse files Browse the repository at this point in the history
  • Loading branch information
pcapriotti committed May 16, 2023
2 parents 76ca507 + 4203f0c commit 09ba856
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/5-internal/ptests
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add parametrised tests
8 changes: 3 additions & 5 deletions integration/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
1 change: 1 addition & 0 deletions integration/integration.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ library
Testlib.Prekeys
Testlib.Prelude
Testlib.Printing
Testlib.PTest
Testlib.Run
Testlib.Types

Expand Down
27 changes: 27 additions & 0 deletions integration/test/Testlib/PTest.hs
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions integration/test/Testlib/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 09ba856

Please sign in to comment.