katip 0.3.1.1 → 0.3.1.2
raw patch · 6 files changed
+143/−10 lines, 6 filesdep −temporaryPVP ok
version bump matches the API change (PVP)
Dependencies removed: temporary
API changes (from Hackage documentation)
Files
- changelog.md +4/−0
- katip.cabal +11/−2
- test/Katip/Tests.hs +2/−2
- test/Katip/Tests/Format/Time.hs +81/−0
- test/Katip/Tests/Scribes/Handle-text.golden +40/−0
- test/Katip/Tests/Scribes/Handle.hs +5/−6
changelog.md view
@@ -1,3 +1,7 @@+0.3.1.2+=======+* Add some missing test files+ 0.3.1.1 ======= * Fix some example code that wasn't building
katip.cabal view
@@ -1,5 +1,5 @@ name: katip-version: 0.3.1.1+version: 0.3.1.2 synopsis: A structured logging framework. description: Katip is a structured logging framework. See README.md for more details.@@ -23,6 +23,8 @@ test/Main.hs test/Katip/Tests.hs test/Katip/Tests/Scribes/Handle.hs+ test/Katip/Tests/Scribes/Handle-text.golden+ test/Katip/Tests/Format/Time.hs tested-with: GHC == 7.8.4, GHC== 7.10.3 source-repository head@@ -86,6 +88,10 @@ type: exitcode-stdio-1.0 main-is: Main.hs hs-source-dirs: test+ other-modules:+ Katip.Tests.Format.Time+ Katip.Tests.Scribes.Handle+ Katip.Tests default-language: Haskell2010 build-depends: base , katip@@ -100,11 +106,14 @@ , text , time , time-locale-compat >= 0.1.0.1 && < 0.2- , temporary , directory , regex-tdfa , unordered-containers , microlens+ ghc-options: -Wall+ if flag(lib-Werror)+ ghc-options: -Werror+ benchmark bench type: exitcode-stdio-1.0
test/Katip/Tests.hs view
@@ -11,7 +11,7 @@ --------------------------------------------------------------------------------import Control.Applicative+import Control.Applicative as A import Data.Aeson import qualified Data.HashMap.Strict as HM import Data.Monoid@@ -93,7 +93,7 @@ ------------------------------------------------------------------------------- instance Arbitrary a => Arbitrary (Item a) where arbitrary = Item- <$> arbitrary+ A.<$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
+ test/Katip/Tests/Format/Time.hs view
@@ -0,0 +1,81 @@+module Katip.Tests.Format.Time+ ( tests+ ) where++-------------------------------------------------------------------------------+import Data.Aeson (toJSON)+import qualified Data.Text as Text+import Data.Time+import Data.Time.Clock.POSIX+import qualified Data.Time.Locale.Compat as LC+import Test.Tasty+import Test.Tasty.HUnit+import Test.Tasty.QuickCheck+-------------------------------------------------------------------------------+import Katip.Format.Time+-------------------------------------------------------------------------------+++tests :: TestTree+tests = testGroup "Katip.Format.Time"+ [ testCase "formatAsLogTime" $ do+ assertEqual "time 1" (formatDT t1) (formatAsLogTime t1)+ assertEqual "time 2" (formatDT t2) (formatAsLogTime t2)+ assertEqual "time 3" (formatDT t3) (formatAsLogTime t3)+ assertEqual "time 4" (formatDT t4) (formatAsLogTime t4)+ assertEqual "time 5" (formatDT t5) (formatAsLogTime t5)++ , testCase "formatAsIso8601" $ do+ assertEqual "time 1" (formatDTISO t1) (formatAsIso8601 t1)+ assertEqual "time 2" (formatDTISO t2) (formatAsIso8601 t2)+ assertEqual "time 3" (formatDTISO t3) (formatAsIso8601 t3)+ assertEqual "time 4" (formatDTISO t4) (formatAsIso8601 t4)+ assertEqual "time 5" (formatDTISO t5) (formatAsIso8601 t5)++ , testCase "formatAsIso8601 Aeson" $ do+ assertEqual "time 1" (toJSON t1) (toJSON $ formatAsIso8601 t1)+ assertEqual "time 2" (toJSON t2) (toJSON $ formatAsIso8601 t2)+ assertEqual "time 3" (toJSON t3) (toJSON $ formatAsIso8601 t3)+ assertEqual "time 4" (toJSON t4) (toJSON $ formatAsIso8601 t4)+ assertEqual "time 5" (toJSON t5) (toJSON $ formatAsIso8601 t5)+++ , testProperty "LogTime same as Date.Time" $ \(ArbUTCTime t) ->+ prop_format_log t++ , testProperty "ISO 8601 same as Date.Time" $ \(ArbUTCTime t) ->+ prop_format_iso t++ , testProperty "ISO 8601 same as Aeson" $ \(ArbUTCTime t) ->+ prop_format_aeson t++ ]+ where+ t1 = UTCTime (fromGregorian 2016 12 34) 5025.123456789012+ t2 = UTCTime (fromGregorian 2016 1 23) 5025.123+ t3 = UTCTime (fromGregorian 16 12 1) 025+ t4 = UTCTime (fromGregorian 2000 1 1) 0.000000000001+ t5 = UTCTime (fromGregorian 2000 12 31) 0.100000000001++formatDT :: UTCTime -> Text.Text+formatDT = Text.pack . formatTime LC.defaultTimeLocale "%0Y-%m-%d %H:%M:%S"++formatDTISO :: UTCTime -> Text.Text+formatDTISO = Text.pack . formatTime LC.defaultTimeLocale "%0Y-%m-%dT%H:%M:%S%QZ"++prop_format_log :: UTCTime -> Property+prop_format_log a = formatDT a === formatAsLogTime a++prop_format_iso :: UTCTime -> Property+prop_format_iso a = formatDTISO a === formatAsIso8601 a++prop_format_aeson :: UTCTime -> Property+prop_format_aeson a = toJSON a === toJSON (formatAsIso8601 a)+++newtype ArbUTCTime = ArbUTCTime UTCTime+ deriving (Show)++instance Arbitrary ArbUTCTime where+ arbitrary = fmap (ArbUTCTime . posixSecondsToUTCTime . fromInteger)+ arbitrary
+ test/Katip/Tests/Scribes/Handle-text.golden view
@@ -0,0 +1,40 @@+[2016-06-12 12:34:56][foo][Debug][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Notice][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Warning][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Error][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Critical][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Alert][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Emergency][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][7331][0][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][7331][1][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][7331][2147483647][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][www.example.com][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][127.0.0.1][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][0][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][1][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][1337][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][2147483647][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note] message+with newline+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note] a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message a really long message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note] сообщение+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note] 哈囉世界+[2000-01-01 00:00:00][foo][Info][example][7331][1337][note.deep:some note] message+[2123-12-31 23:59:59][foo][Info][example][7331][1337][note.deep:some note] message+[2016-10-10 01:01:05][foo][Info][example][7331][1337][note.deep:some note] message+[2100-12-31 12:59:10][foo][Info][example][7331][1337][note.deep:some note] message+[1982-01-01 12:30:00][foo][Info][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo.bar][Info][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][фу.бар][Info][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][with+newline][Info][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note] message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note][main:Some.Module path/Some/Module.hs:30:1] message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][note.deep:some note][main:Some.Module путь/Some/Module.hs:3000:9000] message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][sub:null][text:][num:0.0][float:0.0] message+[2016-06-12 12:34:56][foo][Info][example][7331][1337][sub.note.deep:some note][text:note][num:10.0][float:5.5] message
test/Katip/Tests/Scribes/Handle.hs view
@@ -18,7 +18,6 @@ import Lens.Micro ((.~)) import System.Directory import System.IO-import System.IO.Temp import Test.Tasty import Test.Tasty.Golden import Test.Tasty.HUnit@@ -40,10 +39,10 @@ let pat = "\\[[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}\\]\\[katip-test.test\\]\\[Info\\]\\[.+\\]\\[[[:digit:]]+\\]\\[ThreadId [[:digit:]]+\\]\\[note.deep:some note\\] test message" :: String let matches = res =~ pat assertBool (res <> " did not match") matches- , withResource setupTempFile teardownTempFile $ \setup ->+ , withResource setupTempFile teardownTempFile $ \setupFn -> goldenVsString "Text-golden" "test/Katip/Tests/Scribes/Handle-text.golden"- (setup >>= writeTextLog)+ (setupFn >>= writeTextLog) ] @@ -54,8 +53,8 @@ instance ToJSON DummyLogItem where- toJSON (DummyLogItem n) = object- [ "note" .= object [ "deep" .= n+ toJSON dli = object+ [ "note" .= object [ "deep" .= dliNote dli ] ] @@ -143,7 +142,7 @@ | s <- [minBound .. maxBound] ] , [ itemThread .~ (ThreadIdText . T.pack $ show t) $ theItem- | t <- [0, 1, 1337, 2147483647]+ | t <- [0 :: Int, 1, 1337, 2147483647] ] , [ itemHost .~ h $ theItem | h <- ["example", "www.example.com", "127.0.0.1"]