64
64
65
65
module Test.Golden
66
66
67
+ import Control.ANSI
68
+
67
69
import Data.Either
68
70
import Data.Maybe
69
71
import Data.List
@@ -92,20 +94,23 @@ record Options where
92
94
onlyNames : List String
93
95
||| Should we run the test suite interactively?
94
96
interactive : Bool
97
+ ||| Should we use colors?
98
+ color : Bool
95
99
||| Should we time and display the tests
96
100
timing : Bool
97
101
||| How many threads should we use?
98
102
threads : Nat
99
103
||| Should we write the list of failing cases from a file?
100
- failureFile : Maybe String
104
+ failureFile : Maybe String
101
105
102
106
export
103
- initOptions : String -> Options
104
- initOptions exe
107
+ initOptions : String -> Bool -> Options
108
+ initOptions exe color
105
109
= MkOptions exe
106
110
Nothing
107
111
[]
108
112
False
113
+ color
109
114
False
110
115
1
111
116
Nothing
@@ -117,6 +122,7 @@ usage exe = unwords
117
122
, " runtests <path>"
118
123
, " [--timing]"
119
124
, " [--interactive]"
125
+ , " [--[no-]color, --[no-]colour]"
120
126
, " [--cg CODEGEN]"
121
127
, " [--threads N]"
122
128
, " [--failure-file PATH]"
@@ -144,6 +150,10 @@ options args = case args of
144
150
[] => pure (only, opts)
145
151
(" --timing" :: xs) => go xs only (record { timing = True } opts)
146
152
(" --interactive" :: xs) => go xs only (record { interactive = True } opts)
153
+ (" --color" :: xs) => go xs only (record { color = True } opts)
154
+ (" --colour" :: xs) => go xs only (record { color = True } opts)
155
+ (" --no-color" :: xs) => go xs only (record { color = False } opts)
156
+ (" --no-colour" :: xs) => go xs only (record { color = False } opts)
147
157
(" --cg" :: cg :: xs) => go xs only (record { codegen = Just cg } opts)
148
158
(" --threads" :: n :: xs) => do let pos : Nat = !(parsePositive n)
149
159
go xs only (record { threads = pos } opts)
@@ -154,7 +164,8 @@ options args = case args of
154
164
155
165
mkOptions : String -> List String -> IO (Maybe Options)
156
166
mkOptions exe rest
157
- = do let Just (mfp, opts) = go rest Nothing (initOptions exe)
167
+ = do color <- (Just " DUMB" /= ) <$> getEnv " TERM"
168
+ let Just (mfp, opts) = go rest Nothing (initOptions exe color)
158
169
| Nothing => pure Nothing
159
170
let Just fp = mfp
160
171
| Nothing => pure (Just opts)
@@ -211,9 +222,11 @@ runTest opts testPath = forkIO $ do
211
222
let time = timeDifference end start
212
223
213
224
if result
214
- then printTiming (timing opts) time $ testPath ++ " : success"
225
+ then printTiming (timing opts) time $ testPath ++ " : " ++
226
+ (if opts. color then show . colored BrightGreen else id ) " success"
215
227
else do
216
- printTiming (timing opts) time $ testPath ++ " : FAILURE"
228
+ printTiming (timing opts) time $ testPath ++ " : " ++
229
+ (if opts. color then show . colored BrightRed else id ) " FAILURE"
217
230
if interactive opts
218
231
then mayOverwrite (Just exp ) out
219
232
else putStrLn . unlines $ expVsOut exp out
@@ -242,7 +255,8 @@ runTest opts testPath = forkIO $ do
242
255
, " Accept new golden value? [yn]"
243
256
]
244
257
Just exp => do
245
- code <- system $ " git diff --no-index --exit-code --word-diff=color " ++
258
+ code <- system $ " git diff --no-index --exit-code " ++
259
+ (if opts. color then " --word-diff=color " else " " ) ++
246
260
testPath ++ " /expected " ++ testPath ++ " /output"
247
261
putStrLn . unlines $
248
262
[" Golden value differs from actual value." ] ++
0 commit comments