logging-3.0.2: test/main.hs
module Main where
import Control.Concurrent
import Control.Exception
import Control.Logging
import Prelude hiding (log)
import Test.Hspec
tryAny :: IO a -> IO (Either SomeException a)
tryAny = try
main :: IO ()
main = hspec $ do
describe "simple logging" $ do
it "logs output" $ withStdoutLogging $ do
log "Hello, world!"
warnS "test-suite" "you've been warned"
timedLog "Did a good thing" $ threadDelay 100000
_ <- tryAny $ timedLog "Did a bad thing" $
threadDelay 100000 >> error "foo"
_ <- tryAny $ errorL "Uh oh"
return ()
it "supports setting log levels" $ do
setLogLevel LevelWarn
withStdoutLogging $ do
debugS "Set LogLevel test" "This is an unshown debug message"
logS "Set LogLevel test" "This is an unshown info message"
warnS "Set LogLevel test" "This is a shown info message"
_ <- tryAny $ errorSL "Set LogLevel test" "This is a shown error message"
return ()
-- setting the log level back to debug so that following tests run
setLogLevel LevelDebug
it "supports using debug classes" $ do
setDebugSourceRegex "foo\\..*"
withStdoutLogging $ do
debugS "foo" "This is a foo message"
debugS "foo.bar" "This is a foo.bar message"