1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Data.ByteString.Char8
import System.Posix.Syslog
import Test.QuickCheck
import Test.QuickCheck.Property
instance Arbitrary Priority where
arbitrary = arbitraryBoundedEnum
instance Arbitrary Facility where
arbitrary = arbitraryBoundedEnum
instance Arbitrary ByteString where
arbitrary = fmap pack arbitrary
main :: IO ()
main = do
outputTest
dontExplodeTest
{--
This isn't a true test. Instead, we're passing the PERROR option (meaning
syslog will also send messages to STDERR), sending a message that should be
whitelisted by the priority mask, and sending a message that should be
blacklisted by the priority mask. If hsyslog is working correctly, then only
"hsyslog is working" should appear in your test log output.
--}
outputTest :: IO ()
outputTest = withSyslog config $ \syslog -> do
syslog USER Debug "%s%d hsyslog is working :)"
syslog USER Error "hsyslog is not working :("
where
config = defaultConfig
{ options = [PERROR, NDELAY]
, priorityMask = Mask [Debug, Alert]
}
dontExplodeTest :: IO ()
dontExplodeTest = withSyslog defaultConfig $ \syslog -> do
let
prop_dontExplode :: Facility -> Priority -> ByteString -> Property
prop_dontExplode fac pri msg = ioProperty $ do
syslog fac pri msg
return succeeded
quickCheck prop_dontExplode
|