|
1 | 1 | {-# LANGUAGE OverloadedStrings #-} |
| 2 | +{-# LANGUAGE TemplateHaskell #-} |
2 | 3 |
|
3 | 4 | module Control.Carrier.Logger.WriterSpec ( |
4 | 5 | spec, |
5 | 6 | ) where |
6 | 7 |
|
7 | 8 | import Control.Carrier.Interpret (run) |
8 | 9 | import Control.Carrier.Logger.Writer (runLoggerW) |
9 | | -import Control.Monad.Logger (LogLevel (..), defaultLoc, logDebugN, logInfoN, logWarnN) |
10 | | -import Test.Hspec (Spec, describe, it, shouldBe) |
| 10 | +import Control.Monad (forM_) |
| 11 | +import Control.Monad.Logger ( |
| 12 | + Loc (..), |
| 13 | + LogLevel (..), |
| 14 | + LogLine, |
| 15 | + defaultLoc, |
| 16 | + logDebugN, |
| 17 | + logDebugS, |
| 18 | + logInfoN, |
| 19 | + logInfoS, |
| 20 | + logWarnN, |
| 21 | + logWarnS, |
| 22 | + ) |
| 23 | +import Test.Hspec (Spec, context, describe, it, shouldBe, shouldContain, shouldNotBe) |
11 | 24 |
|
12 | 25 | spec :: Spec |
13 | 26 | spec = do |
14 | 27 | describe "LoggerWriterC" $ do |
15 | | - it "no log" $ |
16 | | - run (runLoggerW (pure ())) `shouldBe` ([], ()) |
| 28 | + context "non-TH" $ do |
| 29 | + it "no log" $ |
| 30 | + run (runLoggerW (pure ())) `shouldBe` ([], ()) |
17 | 31 |
|
18 | | - it "3 logs" $ do |
19 | | - let action = do |
20 | | - logDebugN "1" |
21 | | - logInfoN "2" |
22 | | - logWarnN "3" |
23 | | - logLines = |
24 | | - [ (defaultLoc, "", LevelDebug, "1") |
25 | | - , (defaultLoc, "", LevelInfo, "2") |
26 | | - , (defaultLoc, "", LevelWarn, "3") |
| 32 | + it "3 logs" $ do |
| 33 | + let action = do |
| 34 | + logDebugN "1" |
| 35 | + logInfoN "2" |
| 36 | + logWarnN "3" |
| 37 | + logLines = |
| 38 | + [ (defaultLoc, "", LevelDebug, "1") |
| 39 | + , (defaultLoc, "", LevelInfo, "2") |
| 40 | + , (defaultLoc, "", LevelWarn, "3") |
| 41 | + ] |
| 42 | + |
| 43 | + run (runLoggerW action) `shouldBe` (logLines, ()) |
| 44 | + |
| 45 | + it "TH" $ do |
| 46 | + let action = |
| 47 | + do |
| 48 | + $logDebugS "test" "1" |
| 49 | + $logInfoS "test" "2" |
| 50 | + $logWarnS "test" "3" |
| 51 | + expected = |
| 52 | + [ (LevelDebug, "1") |
| 53 | + , (LevelInfo, "2") |
| 54 | + , (LevelWarn, "3") |
27 | 55 | ] |
| 56 | + results = run (runLoggerW action) |
28 | 57 |
|
29 | | - run (runLoggerW action) `shouldBe` (logLines, ()) |
| 58 | + length (fst results) `shouldBe` 3 |
| 59 | + forM_ (zip (fst results :: [LogLine]) expected) $ |
| 60 | + \((loc, src, lvl, msg), (expLvl, expMsg)) -> do |
| 61 | + loc_filename loc `shouldBe` "test/Control/Carrier/Logger/WriterSpec.hs" |
| 62 | + loc_package loc `shouldContain` "fused-effects-logger" |
| 63 | + loc_module loc `shouldBe` "Control.Carrier.Logger.WriterSpec" |
| 64 | + loc_start loc `shouldNotBe` (0, 0) |
| 65 | + loc_end loc `shouldNotBe` (0, 0) |
| 66 | + src `shouldBe` "test" |
| 67 | + lvl `shouldBe` expLvl |
| 68 | + msg `shouldBe` expMsg |
0 commit comments