0 | module Test.Golden.RunnerHelper
5 | import public Language.Reflection
7 | import public Test.Golden
10 | import System.Directory
15 | record BuildDir where
16 | constructor MkBuildDir
22 | interface RunScriptArg where
23 | constructor MkRunScriptArg
24 | runScriptArg : BuildDir => String
31 | DefaultRunScriptArg : RunScriptArg
32 | DefaultRunScriptArg = R where
33 | [R] RunScriptArg where
34 | runScriptArg = buildDir %search ++ "/.pack_lock"
38 | nproc : IO $
Maybe Nat
40 | rawThreads <- getEnv "NUM_THREADS"
41 | let Nothing = rawThreads >>= parsePositive
42 | | Just n => pure $
Just n
43 | (str, 0) <- run "nproc"
45 | pure $
parsePositive str
48 | nproc' = fromMaybe 1 . filter (> 0) <$> nproc
50 | fitsPattern : (pattern, test : String) -> Bool
51 | fitsPattern = isInfixOf
53 | testOptions : RunScriptArg => BuildDir => IO Options
55 | onlies <- filter (not . null) . tail' <$> getArgs
57 | { color := isNothing !(getEnv "NO_COLOR")
59 | , interactive := !((Just "true" /=) <$> getEnv "CI")
60 | , failureFile := Just "failures"
61 | , onlyNames := onlies <&> \patterns, test => any (`fitsPattern` test) patterns
62 | , threads := !nproc'
63 | } (initOptions runScriptArg True)
68 | interface TestPoolLike a where
69 | toTestPool : a -> IO $
List TestPool
72 | TestPoolLike (IO TestPool) where
73 | toTestPool = map pure
76 | TestPoolLike TestPool where
77 | toTestPool = pure @{Compose}
80 | TestPoolLike (List TestPool) where
84 | TestPoolLike (IO $
List TestPool) where
88 | TestPoolLike (List $
IO TestPool) where
89 | toTestPool = sequence
92 | data TestPools = MkTestPools (IO $
List TestPool)
98 | Nil = MkTestPools $
pure []
101 | (::) : TestPoolLike a => a -> TestPools -> TestPools
102 | x :: MkTestPools xs = MkTestPools [| toTestPool x ++ xs |]
105 | (++) : TestPools -> TestPools -> TestPools
106 | MkTestPools xs ++ MkTestPools ys = MkTestPools [| xs ++ ys |]
108 | toList : TestPools -> IO $
List TestPool
109 | toList $
MkTestPools xs = xs
114 | atDir : (poolName : String) -> (dir : String) -> IO TestPool
115 | atDir poolName dir = do
117 | | False => emptyPool
118 | Right (_::_) <- listDir dir
120 | testsInDir dir poolName {pred=not . isPrefixOf "_"}
123 | emptyPool : IO TestPool
124 | emptyPool = pure $
MkTestPool poolName [] Nothing []
129 | goldenRunner' : RunScriptArg => (projectDir, buildDir : String) -> TestPools -> IO ()
130 | goldenRunner' projectDir buildDir tps = do
131 | let _ = MkBuildDir buildDir
132 | ignore $
changeDir projectDir
133 | runnerWith !testOptions !(toList tps)
136 | goldenRunner : RunScriptArg => TestPools -> Elab $
IO ()
137 | goldenRunner tps = pure $
goldenRunner' !(idrisDir ProjectDir) !(idrisDir BuildDir) tps