1- {- ORMOLU_DISABLE -} -- Remove this when the file is ready to be auto-formatted
21{-# LANGUAGE OverloadedStrings #-}
32
43{- This module kicks off the Transcript Tests.
54 It doesn't do the transcript parsing itself.
65-}
76module Main (main ) where
87
9- import Unison.Prelude
10- import EasyTest
11- import Shellmet (($|) )
12- import System.Directory
13- import System.FilePath ( (</>)
14- , splitFileName
15- , takeExtensions
16- , takeBaseName
17- )
18- import System.Process ( readProcessWithExitCode )
19-
20- import Data.Text ( pack
21- , unpack
22- )
23- import Data.List
24-
8+ import Data.Bifunctor (second )
9+ import Data.List
10+ import Data.Text
11+ ( pack ,
12+ unpack ,
13+ )
14+ import EasyTest
15+ import Shellmet (($|) )
16+ import System.Directory
2517import System.Environment (getArgs )
18+ import System.FilePath
19+ ( splitFileName ,
20+ takeBaseName ,
21+ takeExtensions ,
22+ (</>) ,
23+ )
24+ import System.Process (readProcessWithExitCode )
25+ import Unison.Prelude
2626
2727data TestConfig = TestConfig
28- { matchPrefix :: Maybe String
29- } deriving Show
28+ { matchPrefix :: Maybe String
29+ }
30+ deriving (Show )
3031
3132type TestBuilder = FilePath -> FilePath -> [String ] -> String -> Test ()
3233
33- testBuilder
34- :: FilePath -> FilePath -> [String ] -> String -> Test ()
34+ testBuilder ::
35+ FilePath -> FilePath -> [String ] -> String -> Test ()
3536testBuilder ucm dir prelude transcript = scope transcript $ do
3637 io $ fromString ucm args
3738 ok
3839 where
3940 files = fmap (pack . (dir </> )) (prelude ++ [transcript])
4041 args = [" transcript" ] ++ files
4142
42- testBuilder'
43- :: FilePath -> FilePath -> [String ] -> String -> Test ()
43+ testBuilder' ::
44+ FilePath -> FilePath -> [String ] -> String -> Test ()
4445testBuilder' ucm dir prelude transcript = scope transcript $ do
4546 let output = dir </> takeBaseName transcript <> " .output.md"
4647 io $ runAndCaptureError ucm args output
@@ -60,31 +61,31 @@ testBuilder' ucm dir prelude transcript = scope transcript $ do
6061 dropRunMessage :: String -> String
6162 dropRunMessage = unlines . reverse . drop 3 . reverse . lines
6263
63-
6464buildTests :: TestConfig -> TestBuilder -> FilePath -> Test ()
6565buildTests config testBuilder dir = do
6666 io
67- . putStrLn
68- . unlines
69- $ [ " "
70- , " Searching for transcripts to run in: " ++ dir
71- ]
67+ . putStrLn
68+ . unlines
69+ $ [ " " ,
70+ " Searching for transcripts to run in: " ++ dir
71+ ]
7272 files <- io $ listDirectory dir
73- let
74- -- Any files that start with _ are treated as prelude
75- (prelude, transcripts) =
76- partition ((isPrefixOf " _ " ) . snd . splitFileName)
77- . sort
78- -- if there is a matchPrefix set, check for a prefix match - or return True
79- . filter ( \ f -> maybe True ( `isPrefixOf` f) ( matchPrefix config))
80- . filter (\ f -> takeExtensions f == " .md " ) $ files
73+ -- Any files that start with _ are treated as prelude
74+ let (prelude, transcripts) =
75+ files
76+ & sort
77+ & filter ( \ f -> takeExtensions f == " .md " )
78+ & partition ((isPrefixOf " _ " ) . snd . splitFileName)
79+ -- if there is a matchPrefix set, filter non-prelude files by that prefix - or return True
80+ & second ( filter (\ f -> maybe True ( `isPrefixOf` f) (matchPrefix config)))
8181
8282 ucm <- io $ unpack <$> " stack" $| [" exec" , " --" , " which" , " unison" ] -- todo: what is it in windows?
8383 case length transcripts of
84- 0 -> pure () -- EasyTest exits early with "no test results recorded"
85- -- if you don't give it any tests, this keeps it going
86- -- till the end so we can search all transcripts for
87- -- prefix matches.
84+ 0 -> pure ()
85+ -- EasyTest exits early with "no test results recorded"
86+ -- if you don't give it any tests, this keeps it going
87+ -- till the end so we can search all transcripts for
88+ -- prefix matches.
8889 _ -> tests (testBuilder ucm dir prelude <$> transcripts)
8990
9091-- Transcripts that exit successfully get cleaned-up by the transcript parser.
@@ -102,29 +103,27 @@ cleanup = do
102103 io
103104 . putStrLn
104105 . unlines
105- $ [ " "
106- , " NOTE: All transcript codebases have been moved into"
107- , " the `test-output` directory. Feel free to delete it."
106+ $ [ " " ,
107+ " NOTE: All transcript codebases have been moved into" ,
108+ " the `test-output` directory. Feel free to delete it."
108109 ]
109110
110111test :: TestConfig -> Test ()
111112test config = do
112- buildTests config testBuilder
113- $ " unison-src" </> " transcripts"
114- buildTests config testBuilder
115- $ " unison-src" </> " transcripts-using-base"
116- buildTests config testBuilder'
117- $ " unison-src" </> " transcripts" </> " errors"
113+ buildTests config testBuilder $
114+ " unison-src" </> " transcripts"
115+ buildTests config testBuilder $
116+ " unison-src" </> " transcripts-using-base"
117+ buildTests config testBuilder' $
118+ " unison-src" </> " transcripts" </> " errors"
118119 cleanup
119120
120121handleArgs :: [String ] -> TestConfig
121122handleArgs args =
122- let
123- matchPrefix = case args of
124- [prefix] -> Just prefix
125- _ -> Nothing
126- in
127- TestConfig matchPrefix
123+ let matchPrefix = case args of
124+ [prefix] -> Just prefix
125+ _ -> Nothing
126+ in TestConfig matchPrefix
128127
129128main :: IO ()
130129main = do
0 commit comments