Skip to content

Commit 72f655a

Browse files
committed
test: add TH compatibility tests
1 parent ea63b62 commit 72f655a

File tree

1 file changed

+53
-14
lines changed

1 file changed

+53
-14
lines changed
Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,68 @@
11
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE TemplateHaskell #-}
23

34
module Control.Carrier.Logger.WriterSpec (
45
spec,
56
) where
67

78
import Control.Carrier.Interpret (run)
89
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)
1124

1225
spec :: Spec
1326
spec = do
1427
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` ([], ())
1731

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")
2755
]
56+
results = run (runLoggerW action)
2857

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

Comments
 (0)