{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
module Test.Syd.Yesod.Def
( yesodSpec,
yesodSpecWithSiteGenerator,
yesodSpecWithSiteGeneratorAndArgument,
yesodSpecWithSiteSupplier,
yesodSpecWithSiteSupplierWith,
yesodSpecWithSiteSetupFunc,
yesodSpecWithSiteSetupFunc',
yesodClientSetupFunc,
YesodSpec,
yit,
ydescribe,
)
where
import GHC.Stack
import Network.HTTP.Client as HTTP
import Test.Syd
import Test.Syd.Wai
import Test.Syd.Yesod.Client
import Yesod.Core as Yesod
yesodSpec :: YesodDispatch site => site -> YesodSpec site -> Spec
yesodSpec :: site -> YesodSpec site -> Spec
yesodSpec site
site = IO site -> YesodSpec site -> Spec
forall site.
YesodDispatch site =>
IO site -> YesodSpec site -> Spec
yesodSpecWithSiteGenerator (IO site -> YesodSpec site -> Spec)
-> IO site -> YesodSpec site -> Spec
forall a b. (a -> b) -> a -> b
$ site -> IO site
forall (f :: * -> *) a. Applicative f => a -> f a
pure site
site
yesodSpecWithSiteGenerator :: YesodDispatch site => IO site -> YesodSpec site -> Spec
yesodSpecWithSiteGenerator :: IO site -> YesodSpec site -> Spec
yesodSpecWithSiteGenerator IO site
siteGen = (() -> IO site) -> YesodSpec site -> Spec
forall site a.
YesodDispatch site =>
(a -> IO site) -> YesodSpec site -> SpecWith a
yesodSpecWithSiteGeneratorAndArgument ((() -> IO site) -> YesodSpec site -> Spec)
-> (() -> IO site) -> YesodSpec site -> Spec
forall a b. (a -> b) -> a -> b
$ \() -> IO site
siteGen
yesodSpecWithSiteGeneratorAndArgument :: YesodDispatch site => (a -> IO site) -> YesodSpec site -> SpecWith a
yesodSpecWithSiteGeneratorAndArgument :: (a -> IO site) -> YesodSpec site -> SpecWith a
yesodSpecWithSiteGeneratorAndArgument a -> IO site
func = (forall r. (site -> IO r) -> a -> IO r)
-> YesodSpec site -> SpecWith a
forall site a.
YesodDispatch site =>
(forall r. (site -> IO r) -> a -> IO r)
-> YesodSpec site -> SpecWith a
yesodSpecWithSiteSupplierWith ((forall r. (site -> IO r) -> a -> IO r)
-> YesodSpec site -> SpecWith a)
-> (forall r. (site -> IO r) -> a -> IO r)
-> YesodSpec site
-> SpecWith a
forall a b. (a -> b) -> a -> b
$ \site -> IO r
f a
a -> a -> IO site
func a
a IO site -> (site -> IO r) -> IO r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= site -> IO r
f
yesodSpecWithSiteSupplier :: YesodDispatch site => (forall r. (site -> IO r) -> IO r) -> YesodSpec site -> Spec
yesodSpecWithSiteSupplier :: (forall r. (site -> IO r) -> IO r) -> YesodSpec site -> Spec
yesodSpecWithSiteSupplier forall r. (site -> IO r) -> IO r
func = (forall r. (site -> IO r) -> () -> IO r) -> YesodSpec site -> Spec
forall site a.
YesodDispatch site =>
(forall r. (site -> IO r) -> a -> IO r)
-> YesodSpec site -> SpecWith a
yesodSpecWithSiteSupplierWith (\site -> IO r
f () -> (site -> IO r) -> IO r
forall r. (site -> IO r) -> IO r
func site -> IO r
f)
yesodSpecWithSiteSupplierWith :: YesodDispatch site => (forall r. (site -> IO r) -> (a -> IO r)) -> YesodSpec site -> SpecWith a
yesodSpecWithSiteSupplierWith :: (forall r. (site -> IO r) -> a -> IO r)
-> YesodSpec site -> SpecWith a
yesodSpecWithSiteSupplierWith forall r. (site -> IO r) -> a -> IO r
func = (Manager -> SetupFunc a site) -> YesodSpec site -> SpecWith a
forall site a (l :: [*]).
YesodDispatch site =>
(Manager -> SetupFunc a site)
-> TestDef (Manager : l) (YesodClient site) -> TestDef l a
yesodSpecWithSiteSetupFunc ((Manager -> SetupFunc a site) -> YesodSpec site -> SpecWith a)
-> (Manager -> SetupFunc a site) -> YesodSpec site -> SpecWith a
forall a b. (a -> b) -> a -> b
$ \Manager
_ -> (forall r. (site -> IO r) -> a -> IO r) -> SetupFunc a site
forall old new.
(forall r. (new -> IO r) -> old -> IO r) -> SetupFunc old new
SetupFunc forall r. (site -> IO r) -> a -> IO r
func
yesodSpecWithSiteSetupFunc :: YesodDispatch site => (HTTP.Manager -> SetupFunc a site) -> TestDef (HTTP.Manager ': l) (YesodClient site) -> TestDef l a
yesodSpecWithSiteSetupFunc :: (Manager -> SetupFunc a site)
-> TestDef (Manager : l) (YesodClient site) -> TestDef l a
yesodSpecWithSiteSetupFunc Manager -> SetupFunc a site
setupFunc = TestDef (Manager : l) a -> TestDef l a
forall (l :: [*]) a. TestDef (Manager : l) a -> TestDef l a
managerSpec (TestDef (Manager : l) a -> TestDef l a)
-> (TestDef (Manager : l) (YesodClient site)
-> TestDef (Manager : l) a)
-> TestDef (Manager : l) (YesodClient site)
-> TestDef l a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Manager -> SetupFunc a site)
-> TestDef (Manager : l) (YesodClient site)
-> TestDef (Manager : l) a
forall site a (l :: [*]).
YesodDispatch site =>
(Manager -> SetupFunc a site)
-> TestDef (Manager : l) (YesodClient site)
-> TestDef (Manager : l) a
yesodSpecWithSiteSetupFunc' Manager -> SetupFunc a site
setupFunc
yesodSpecWithSiteSetupFunc' :: YesodDispatch site => (HTTP.Manager -> SetupFunc a site) -> TestDef (HTTP.Manager ': l) (YesodClient site) -> TestDef (HTTP.Manager ': l) a
yesodSpecWithSiteSetupFunc' :: (Manager -> SetupFunc a site)
-> TestDef (Manager : l) (YesodClient site)
-> TestDef (Manager : l) a
yesodSpecWithSiteSetupFunc' Manager -> SetupFunc a site
setupFunc = (Manager -> SetupFunc a (YesodClient site))
-> TestDef (Manager : l) (YesodClient site)
-> TestDef (Manager : l) a
forall (outers :: [*]) outer oldInner newInner result.
HContains outers outer =>
(outer -> SetupFunc oldInner newInner)
-> TestDefM outers newInner result
-> TestDefM outers oldInner result
setupAroundWith' (\Manager
man -> Manager -> SetupFunc a site
setupFunc Manager
man SetupFunc a site
-> SetupFunc site (YesodClient site)
-> SetupFunc a (YesodClient site)
forall old newer newest.
SetupFunc old newer
-> SetupFunc newer newest -> SetupFunc old newest
`connectSetupFunc` Manager -> SetupFunc site (YesodClient site)
forall site.
YesodDispatch site =>
Manager -> SetupFunc site (YesodClient site)
yesodClientSetupFunc Manager
man)
yesodClientSetupFunc :: YesodDispatch site => HTTP.Manager -> SetupFunc site (YesodClient site)
yesodClientSetupFunc :: Manager -> SetupFunc site (YesodClient site)
yesodClientSetupFunc Manager
man = (site -> SetupFunc () (YesodClient site))
-> SetupFunc site (YesodClient site)
forall old new. (old -> SetupFunc () new) -> SetupFunc old new
wrapSetupFunc ((site -> SetupFunc () (YesodClient site))
-> SetupFunc site (YesodClient site))
-> (site -> SetupFunc () (YesodClient site))
-> SetupFunc site (YesodClient site)
forall a b. (a -> b) -> a -> b
$ \site
site -> do
Application
application <- IO Application -> SetupFunc () Application
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Application -> SetupFunc () Application)
-> IO Application -> SetupFunc () Application
forall a b. (a -> b) -> a -> b
$ site -> IO Application
forall site. YesodDispatch site => site -> IO Application
Yesod.toWaiAppPlain site
site
Port
p <- SetupFunc Application Port -> Application -> SetupFunc () Port
forall old new. SetupFunc old new -> old -> SetupFunc () new
unwrapSetupFunc SetupFunc Application Port
applicationSetupFunc Application
application
let client :: YesodClient site
client =
YesodClient :: forall site. site -> Manager -> Port -> YesodClient site
YesodClient
{ yesodClientManager :: Manager
yesodClientManager = Manager
man,
yesodClientSite :: site
yesodClientSite = site
site,
yesodClientSitePort :: Port
yesodClientSitePort = Port
p
}
YesodClient site -> SetupFunc () (YesodClient site)
forall (f :: * -> *) a. Applicative f => a -> f a
pure YesodClient site
client
type YesodSpec site = TestDef '[HTTP.Manager] (YesodClient site)
yit ::
forall site e.
( HasCallStack,
IsTest (YesodClient site -> IO e),
Arg1 (YesodClient site -> IO e) ~ (),
Arg2 (YesodClient site -> IO e) ~ YesodClient site
) =>
String ->
YesodClientM site e ->
YesodSpec site
yit :: String -> YesodClientM site e -> YesodSpec site
yit String
s YesodClientM site e
f = String -> (YesodClient site -> IO e) -> YesodSpec site
forall (outers :: [*]) inner test.
(HasCallStack, IsTest test, Arg1 test ~ (), Arg2 test ~ inner) =>
String -> test -> TestDefM outers inner ()
it String
s ((\YesodClient site
cenv -> YesodClient site -> YesodClientM site e -> IO e
forall site a. YesodClient site -> YesodClientM site a -> IO a
runYesodClientM YesodClient site
cenv YesodClientM site e
f) :: YesodClient site -> IO e)
ydescribe :: String -> YesodSpec site -> YesodSpec site
ydescribe :: String -> YesodSpec site -> YesodSpec site
ydescribe = String -> YesodSpec site -> YesodSpec site
forall (outers :: [*]) inner.
String -> TestDefM outers inner () -> TestDefM outers inner ()
describe