Revert "Do more setup/teardown in basic demo (REVERT UPON MERGING)"

This reverts commit 2285bb37508099c3fd5e287aa79c58a000d062ec.
This commit is contained in:
thomasjm 2023-11-19 00:34:12 -08:00
parent 27c63881ef
commit 4186439fa2
3 changed files with 11 additions and 42 deletions

View File

@ -1,48 +1,23 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NumericUnderscores #-}
module Main where
import Control.Concurrent
import Control.Exception.Lifted
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Logger
import Data.String.Interpolate
import Test.Sandwich
data DatabaseContext = MySQLDatabaseContext | SqliteDatabaseContext
deriving Show
database = Label :: Label "database" DatabaseContext
setupDatabase :: MonadIO m => ExampleT context m DatabaseContext
setupDatabase = debug "Spinning up DB..." >> p 3 >> return MySQLDatabaseContext
teardownDatabase :: MonadIO m => DatabaseContext -> ExampleT context m ()
teardownDatabase db = debug "Tearing down DB..." >> p 2 >> return ()
introduceDatabase = introduceWith "introduceWith database" database $ \action ->
bracket setupDatabase teardownDatabase (void . action)
basic :: TopSpec
basic = describe "Simple tests" $ do
before "Pauses" (p 3) $ do
it "adds" $ (2 + 2) `shouldBe` 4
describe "Arithmetic" $ do
it "adds" $ do
(2 + 2) `shouldBe` 4
(2 + 3) `shouldBe` 5
introduceDatabase $ do
it "Uses the database" $ do
db <- getContext database
info [i|Got database: '#{db}'|]
it "subtracts" $ do
warn "This might not be right..."
(3 - 2) `shouldBe` 0
introduce "introduce database" database setupDatabase teardownDatabase $ do
it "Uses the database" $ do
db <- getContext database
info [i|Got database: '#{db}'|]
p :: (MonadIO m) => Double -> m ()
p = liftIO . threadDelay . round . (* 1000000.0)
describe "Strings" $
it "concatenates" $
("abc" <> "def") `shouldBe` "abcdef"
main :: IO ()
main = runSandwichWithCommandLineArgs defaultOptions basic

View File

@ -1,6 +1,6 @@
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.36.0.
-- This file has been generated from package.yaml by hpack version 0.34.4.
--
-- see: https://github.com/sol/hpack
@ -28,8 +28,5 @@ executable demo-basic
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base
, lifted-base
, monad-logger
, sandwich
, string-interpolate
default-language: Haskell2010

View File

@ -4,10 +4,7 @@ license: BSD3
dependencies:
- base
- lifted-base
- monad-logger
- sandwich
- string-interpolate
default-extensions:
- OverloadedStrings