roboservant/test/Spec.hs

52 lines
1.6 KiB
Haskell
Raw Normal View History

2020-09-26 22:26:15 +03:00
2020-09-13 20:42:23 +03:00
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
import qualified Foo
2020-09-26 22:26:15 +03:00
import qualified Seeded
2020-09-14 19:07:17 +03:00
import qualified Headers
2020-09-13 20:42:23 +03:00
import qualified UnsafeIO
2020-09-26 22:26:15 +03:00
import qualified Roboservant as RS
2020-09-24 05:48:59 +03:00
import Test.Hspec.Hedgehog
import Test.Hspec
import Test.Hspec.Core.Spec(shouldFail)
2020-09-13 20:42:23 +03:00
2020-09-26 22:26:15 +03:00
import Data.Dynamic(toDyn)
2020-06-06 17:24:56 +03:00
2020-09-26 22:26:15 +03:00
main :: IO ()
2020-09-24 05:48:59 +03:00
main = hspec spec
2020-09-14 19:07:17 +03:00
2020-09-24 05:48:59 +03:00
spec :: Spec
spec = do
2020-09-26 22:26:15 +03:00
describe "Basic usage" $ do
describe "seeded" $ do
2020-09-26 23:25:25 +03:00
modifyMaxSuccess (const 10000) $
shouldFail $
it "finds an error using information passed in" $
hedgehog $ RS.prop_sequential @Seeded.Api Seeded.server [toDyn $ Seeded.Seed 1]
modifyMaxSuccess (const 10000) $
2020-09-26 22:26:15 +03:00
2020-09-26 23:25:25 +03:00
shouldFail $ it "finds an error in a basic app" $
hedgehog $ RS.prop_sequential @Foo.Api Foo.server []
2020-09-24 05:48:59 +03:00
describe "Headers" $ do
shouldFail $ it "should find a failure that's dependent on using header info" $ do
2020-09-26 22:26:15 +03:00
let _ = hedgehog $ RS.prop_sequential @Headers.Api Headers.server []
pending
2020-09-24 05:48:59 +03:00
-- -- The UnsafeIO checker does not actually really use the contextually aware stuff, though it
-- -- could: it's mostly here to show how to test for concurrency problems.
2020-09-26 22:26:15 +03:00
describe "concurrency bugs" $ do
before UnsafeIO.makeServer $ do
describe "sequential checking" $ do
it "safe use" $ \unsafeServer -> do
hedgehog $ RS.prop_sequential @UnsafeIO.UnsafeApi unsafeServer []
2020-09-24 05:48:59 +03:00
2020-09-26 22:26:15 +03:00
modifyMaxSuccess (const 10000) $
shouldFail $
describe "concurrent" $ do
it "concurrent, dangerous use" $ \unsafeServer -> do
RS.prop_concurrent @UnsafeIO.UnsafeApi unsafeServer []