-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathTest.hs
187 lines (170 loc) · 5.77 KB
/
Test.hs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
module Test(main) where
import Control.Exception.Extra
import Control.Monad.Extra
import Data.Maybe
import Data.List.Extra
import System.Directory
import System.Environment
import General.Timing
import Development.Shake.Internal.FileInfo
import Development.Shake.Internal.FileName
import qualified Data.ByteString.Char8 as BS
import Test.Type(sleepFileTimeCalibrate)
import Control.Concurrent.Extra
import qualified Test.Basic
import qualified Test.Batch
import qualified Test.Benchmark
import qualified Test.Builtin
import qualified Test.BuiltinOverride
import qualified Test.C
import qualified Test.Cache
import qualified Test.Cleanup
import qualified Test.CloseFileHandles
import qualified Test.Command
import qualified Test.Config
import qualified Test.Database
import qualified Test.Digest
import qualified Test.Directory
import qualified Test.Docs
import qualified Test.Errors
import qualified Test.Existence
import qualified Test.FileLock
import qualified Test.FilePath
import qualified Test.FilePattern
import qualified Test.Files
import qualified Test.Forward
import qualified Test.History
import qualified Test.Journal
import qualified Test.Lint
import qualified Test.Live
import qualified Test.Manual
import qualified Test.Match
import qualified Test.Monad
import qualified Test.Ninja
import qualified Test.Oracle
import qualified Test.OrderOnly
import qualified Test.Parallel
import qualified Test.Pool
import qualified Test.Progress
import qualified Test.Random
import qualified Test.Rebuild
import qualified Test.Reschedule
import qualified Test.Resources
import qualified Test.Self
import qualified Test.SelfMake
import qualified Test.Tar
import qualified Test.Targets
import qualified Test.Thread
import qualified Test.Tup
import qualified Test.Unicode
import qualified Test.Util
import qualified Test.Verbosity
import qualified Test.Version
import qualified Run
fakes = ["clean" * clean, "test" * test, "make" * makefile, "filetime" * filetime]
where (*) = (,)
mains =
["basic" * Test.Basic.main
,"batch" * Test.Batch.main
,"benchmark" * Test.Benchmark.main
,"builtin" * Test.Builtin.main
,"builtinOverride" * Test.BuiltinOverride.main
,"c" * Test.C.main
,"cache" * Test.Cache.main
,"cleanup" * Test.Cleanup.main
,"closefilehandles" * Test.CloseFileHandles.main
,"command" * Test.Command.main
,"config" * Test.Config.main
,"database" * Test.Database.main
,"digest" * Test.Digest.main
,"directory" * Test.Directory.main
,"docs" * Test.Docs.main
,"errors" * Test.Errors.main
,"existence" * Test.Existence.main
,"filelock" * Test.FileLock.main
,"filepath" * Test.FilePath.main
,"filepattern" * Test.FilePattern.main
,"files" * Test.Files.main
,"forward" * Test.Forward.main
,"history" * Test.History.main
,"journal" * Test.Journal.main
,"lint" * Test.Lint.main
,"live" * Test.Live.main
,"manual" * Test.Manual.main
,"match" * Test.Match.main
,"monad" * Test.Monad.main
,"ninja" * Test.Ninja.main
,"oracle" * Test.Oracle.main
,"orderonly" * Test.OrderOnly.main
,"parallel" * Test.Parallel.main
,"pool" * Test.Pool.main
,"progress" * Test.Progress.main
,"random" * Test.Random.main
,"rebuild" * Test.Rebuild.main
,"reschedule" * Test.Reschedule.main
,"resources" * Test.Resources.main
,"self" * Test.Self.main
,"selfmake" * Test.SelfMake.main
,"tar" * Test.Tar.main
,"targets" * Test.Targets.main
,"thread" * Test.Thread.main
,"tup" * Test.Tup.main
,"unicode" * Test.Unicode.main
,"util" * Test.Util.main
,"verbosity" * Test.Verbosity.main
,"version" * Test.Version.main]
where (*) = (,)
main :: IO ()
main = do
resetTimings
xs <- getArgs
case flip lookup (fakes ++ mains) =<< listToMaybe xs of
_ | null xs -> do
putStrLn "******************************************************************"
putStrLn "** Running shake test suite, run with '--help' to see arguments **"
putStrLn "******************************************************************"
unlessM (doesFileExist "shake.cabal") $ do
putStrLn ""
errorIO "\nERROR: Must run the test suite from a directory containing the Shake repo."
withArgs ["test"] main
withArgs ["random","test","3m"] main
Nothing -> putStrLn $ unlines
["Welcome to the Shake demo"
,""
,unwords $ "Modes:" : map fst fakes
,unwords $ "Demos:" : map fst mains
,""
,"As an example, try:"
,""
," shake-test self --jobs=2 --trace"
,""
,"Which will build Shake, using Shake, on 2 threads."
,"You must run the test suite from a directory containing the Shake repo."
]
Just main -> main =<< sleepFileTimeCalibrate "output/calibrate"
makefile :: IO () -> IO ()
makefile _ = do
args <- getArgs
withArgs (drop1 args) Run.main
filetime :: IO () -> IO ()
filetime _ = do
args <- getArgs
addTiming "Reading files"
files <- concatForM (drop1 args) $ \file ->
BS.lines . BS.filter (/= '\r') <$> BS.readFile file
let n = length files
evaluate n
addTiming "Modtime"
let (a,bcd) = splitAt (n `div` 4) files
let (b,cd) = splitAt (n `div` 4) bcd
let (c,d) = splitAt (n `div` 4) cd
vars <- forM [a,b,c,d] $ \xs ->
onceFork $ mapM_ (getFileInfo False . fileNameFromByteString) xs
sequence_ vars
clean :: IO () -> IO ()
clean extra = sequence_ [withArgs [name,"clean"] $ main extra | (name,main) <- mains]
test :: IO () -> IO ()
test yield = do
args <- getArgs
flip onException (putStrLn "TESTS FAILED") $
sequence_ [withArgs (name:"test":drop1 args) $ test yield | (name,test) <- mains, name /= "random"]