-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTools.hs
More file actions
63 lines (43 loc) · 1.68 KB
/
Tools.hs
File metadata and controls
63 lines (43 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module Tools where
import System.Console.ANSI
import System.Directory
good_loc :: String
good_loc = "./test/test_code/good"
-- | These ones should fail
bad_loc :: String
bad_loc = "./test/test_code/syntax"
type_loc :: String
type_loc = "./test/test_code/type"
test :: String -> (a -> IO ()) -> (b -> IO ()) -> (String -> Either a b) -> String -> IO ()
test loc bad good f s = readFile (loc ++ '/' : s) >>=
either (\a -> putStr ("Filename: " ++ s ++ ":\t") >> bad a)
(\a -> putStr ("Filename: " ++ s ++ ":\t") >> good a) . f
testSTDGood :: Show a => (String -> Either a b) -> String -> IO ()
testSTDGood = testGood good_loc
testSTDBad :: (String -> Either a b) -> String -> IO ()
testSTDBad = testBad bad_loc
testGood :: Show a => String -> (String -> Either a b) -> String -> IO ()
testGood loc = test loc ( badRes . show )
( const bluenice )
testBad loc = test loc (const bluefail )
(const rednice )
testDir :: String -> (String -> IO ()) -> IO ()
testDir dir tester = (listDirectory dir >>= mapM_ tester)
setRed = setSGR [SetColor Foreground Vivid Red]
setBlue = setSGR [SetColor Foreground Vivid Blue]
reset = setSGR []
colorPrint c s = c >> putStrLn s >> reset
redfail :: IO()
redfail = colorPrint setRed "FAIL"
bluefail :: IO()
bluefail = colorPrint setBlue "Nice Fail!"
bluenice :: IO()
bluenice = colorPrint setBlue "NICE!"
rednice :: IO()
rednice = colorPrint setRed "BAD NICE!"
goodRes :: String -> IO ()
goodRes = colorPrint setBlue
badRes :: String -> IO ()
badRes = colorPrint setRed
badResult :: Show a => String -> a -> IO ()
badResult nm err = badRes nm >> print err