Evgenii Akentev
·
2023-06-23
Main.hs
1module Main (main) where
2
3import Control.Monad (void)
4import Data.List (isSuffixOf)
5import Test.Tasty (defaultMain, TestTree, testGroup)
6import Test.Tasty.Golden (goldenVsFile)
7import System.Directory (getDirectoryContents, removeFile)
8
9import Debug.Trace.File
10
11main :: IO ()
12main = do
13 -- remove output files
14 outputs <- getDirectoryContents "test/Golden/"
15 mapM_ removeFile (filter (isSuffixOf ".output") $ map ("test/Golden/" <>) outputs)
16
17 defaultMain goldenTests
18
19goldenTests :: TestTree
20goldenTests = testGroup "Debug.Trace.File golden tests"
21 [ let fp = "test/Golden/traceFile.output" in
22 goldenVsFile "traceFile" "test/Golden/traceFile" fp (pure $! traceFile fp "tracing to file" ())
23
24 , let fp = "test/Golden/traceFile.output" in
25 goldenVsFile "traceFileW" "test/Golden/traceFile" fp (pure $! traceFileW fp "tracing to file" ())
26
27 , let fp = "test/Golden/traceFileId.output" in
28 goldenVsFile "traceFileId" "test/Golden/traceFileId" fp ((pure $! traceFileId fp "tracing to file") >> pure ())
29
30 , let fp = "test/Golden/traceFileId.output" in
31 goldenVsFile "traceFileIdW" "test/Golden/traceFileId" fp ((pure $! traceFileIdW fp "tracing to file") >> pure ())
32
33 , let fp = "test/Golden/traceFileShow.output" in
34 goldenVsFile "traceFileShow" "test/Golden/traceFileShow" fp ((pure $! traceFileShow fp (2 :: Int) (3 :: Int)) >> pure ())
35
36 , let fp = "test/Golden/traceFileShow.output" in
37 goldenVsFile "traceFileShowW" "test/Golden/traceFileShow" fp ((pure $! traceFileShowW fp (2 :: Int) (3 :: Int)) >> pure ())
38
39 , let fp = "test/Golden/traceFileShowId.output" in
40 goldenVsFile "traceFileShowId" "test/Golden/traceFileShowId" fp ((pure $! traceFileShowId fp (3 :: Int)) >> pure ())
41
42 , let fp = "test/Golden/traceFileShowId.output" in
43 goldenVsFile "traceFileShowIdW" "test/Golden/traceFileShowId" fp ((pure $! traceFileShowIdW fp (3 :: Int)) >> pure ())
44
45 , let fp = "test/Golden/traceFileWith.output" in
46 goldenVsFile "traceFileWith" "test/Golden/traceFileWith" fp ((pure $! traceFileWith fp fst ("hello","world")) >> pure ())
47
48 , let fp = "test/Golden/traceFileWith.output" in
49 goldenVsFile "traceFileWithW" "test/Golden/traceFileWith" fp ((pure $! traceFileWithW fp fst ("hello","world")) >> pure ())
50
51 , let fp = "test/Golden/traceFileShowWith.output" in
52 goldenVsFile "traceFileShowWith" "test/Golden/traceFileShowWith" fp ((pure $! traceFileShowWith fp length [1 :: Int,2,3]) >> pure ())
53
54 , let fp = "test/Golden/traceFileShowWith.output" in
55 goldenVsFile "traceFileShowWithW" "test/Golden/traceFileShowWith" fp ((pure $! traceFileShowWithW fp length [1 :: Int,2,3]) >> pure ())
56
57 , let fp = "test/Golden/traceFileM.output" in
58 goldenVsFile "traceFileM" "test/Golden/traceFileM" fp $
59 void $ pure $! do
60 x <- Just (3 :: Int)
61 traceFileM fp ("x: " ++ show x)
62 y <- pure 12
63 traceFileM fp ("y: " ++ show y)
64 pure (x*2 + y)
65
66 , let fp = "test/Golden/traceFileMW.output" in
67 goldenVsFile "traceFileMW" "test/Golden/traceFileMW" fp $
68 void $ pure $! do
69 x <- Just (3 :: Int)
70 traceFileMW fp ("x: " ++ show x)
71 y <- pure 12
72 traceFileMW fp ("y: " ++ show y)
73 pure (x*2 + y)
74
75 , let fp = "test/Golden/traceFileShowM.output" in
76 goldenVsFile "traceFileShowM" "test/Golden/traceFileShowM" fp $
77 void $ pure $! do
78 x <- Just (3 :: Int)
79 traceFileShowM fp x
80 y <- pure 12
81 traceFileShowM fp y
82 pure (x*2 + y)
83
84 , let fp = "test/Golden/traceFileShowMW.output" in
85 goldenVsFile "traceFileShowMW" "test/Golden/traceFileShowMW" fp $
86 void $ pure $! do
87 x <- Just (3 :: Int)
88 traceFileShowMW fp x
89 y <- pure 12
90 traceFileShowMW fp y
91 pure (x*2 + y)
92
93 ]