forked from ucsd-progsys/liquidhaskell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCommits.hs
More file actions
executable file
·115 lines (85 loc) · 3.17 KB
/
TestCommits.hs
File metadata and controls
executable file
·115 lines (85 loc) · 3.17 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
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
#!/usr/bin/env runhaskell
{- GeneralizedNewtypeDeriving -}
import System.Environment (getArgs)
import System.Process (system)
import Text.Printf (printf)
import Data.List (isSuffixOf, stripPrefix)
import Data.Maybe (fromMaybe)
{- | Run this script as:
$ ./TestCommit.hs commits.txt
where commits.txt is a file with a single git commit on each line, OR
$ ./TestCommit.hs NUMBER
which will get the last N(UMBER) of commits from the `branch`
-}
--------------------------------------------------------------------------------
-- | Configuration parameters
--------------------------------------------------------------------------------
project :: String
project = "liquidhaskell"
-- project = "liquidhaskell --fast --test-arguments=\"-p Peano\""
branch :: String
branch = "develop"
tmpFile :: FilePath
tmpFile = "/tmp/commits"
summaryPath :: FilePath
summaryPath = "/Users/rjhala/research/stack/lh-test/tests/logs/cur/summary.csv"
--------------------------------------------------------------------------------
main :: IO ()
--------------------------------------------------------------------------------
main = do
p <- strParam . head <$> getArgs
case p of
File f -> testCommits f
Size n -> makeCommits n
makeCommits :: Int -> IO ()
makeCommits n = do
system (genCommand n)
putStrLn $ "Wrote commits into: " ++ tmpFile
testCommits :: FilePath -> IO ()
testCommits f = do
is <- readCommits f
putStrLn "Generating test summaries for:"
mapM_ (putStrLn . (" " ++)) is
runCmd setupCmd
mapM_ runCommit is
runCmd setupCmd
strParam :: String -> Param
strParam s
| ".txt" `isSuffixOf` s = File s
| otherwise = Size (read s)
--------------------------------------------------------------------------------
-- | Types
--------------------------------------------------------------------------------
data Param = File FilePath
| Size Int
type CommitId = String
type Command = [String]
--------------------------------------------------------------------------------
_commits :: Param -> IO [CommitId]
--------------------------------------------------------------------------------
_commits (File f) = readCommits f
_commits (Size n) = system (genCommand n) >> readCommits tmpFile
genCommand :: Int -> String
genCommand n = printf "git log -n %d --walk-reflogs %s | grep \"commit \" > %s"
n branch tmpFile
readCommits :: FilePath -> IO [CommitId]
readCommits f = map strCommit . lines <$> readFile f
strCommit :: String -> CommitId
strCommit s = fromMaybe s (stripPrefix "commit " s)
--------------------------------------------------------------------------------
runCommit :: CommitId -> IO ()
--------------------------------------------------------------------------------
runCommit i = do
putStrLn ("Running commit: " ++ i)
runCmd (commitCmd i)
runCmd :: Command -> IO ()
runCmd = mapM_ system
setupCmd :: Command
setupCmd = [ printf "git checkout %s" branch ]
commitCmd :: CommitId -> Command
commitCmd i =
[ printf "git checkout %s" i
, "git submodule update"
, printf "stack test %s" project
, printf "cp %s ~/tmp/summary-%s.csv" summaryPath i
]