Skip to content

Commit 7325002

Browse files
committed
Implement test discovery
`testInDir dir ...` lists all directories in `dir` which contains `run` files, and such directories are considered tests. This is done to make test addition/maintenance cheaper. Convert some test directories to `testInDir`, but not all of them because * some directories are listed in several test groups * other directories are have some tests disabled
1 parent 4eff6ac commit 7325002

File tree

2 files changed

+59
-60
lines changed

2 files changed

+59
-60
lines changed

libs/test/Test/Golden.idr

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,34 @@ record TestPool where
380380
codegen : Codegen
381381
testCases : List String
382382

383+
||| Find all the test in the given directory.
384+
export
385+
testsInDir : (dirName : String) -> (testNameFilter : String -> Bool) -> (poolName : String) -> List Requirement -> Codegen -> IO TestPool
386+
testsInDir dirName testNameFilter poolName reqs cg = do
387+
Right names <- listDir dirName
388+
| Left e => do putStrLn ("failed to list " ++ dirName ++ ": " ++ show e)
389+
exitFailure
390+
let names = [n | n <- names, testNameFilter n]
391+
let testNames = [dirName ++ "/" ++ n | n <- names]
392+
testNames <- filter testNames
393+
when (length testNames == 0) $ do
394+
putStrLn ("no tests found in " ++ dirName)
395+
exitFailure
396+
pure $ MkTestPool poolName reqs cg testNames
397+
where
398+
-- Directory without `run` file is not a test
399+
isTest : (path : String) -> IO Bool
400+
isTest path = exists (path ++ "/run")
401+
402+
filter : (testPaths : List String) -> IO (List String)
403+
filter [] = pure []
404+
filter (p :: ps) =
405+
do rem <- filter ps
406+
case !(isTest p) of
407+
True => pure $ p :: rem
408+
False => pure rem
409+
410+
383411
||| Only keep the tests that have been asked for
384412
export
385413
filterTests : Options -> List String -> List String

tests/Main.idr

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module Main
22

3+
import System
4+
import System.Directory
5+
import System.File
6+
37
import Test.Golden
48

59
%default covering
@@ -199,12 +203,8 @@ idrisTests = MkTestPool "Misc" [] Nothing
199203
-- golden file testing
200204
"golden001"]
201205

202-
typeddTests : TestPool
203-
typeddTests = MkTestPool "Type Driven Development" [] Nothing
204-
[ "chapter01", "chapter02", "chapter03", "chapter04", "chapter05"
205-
, "chapter06", "chapter07", "chapter08", "chapter09", "chapter10"
206-
, "chapter11", "chapter12", "chapter13", "chapter14"
207-
]
206+
typeddTests : IO TestPool
207+
typeddTests = testsInDir "typedd-book" (const True) "Type Driven Development" [] Nothing
208208

209209
chezTests : TestPool
210210
chezTests = MkTestPool "Chez backend" [] (Just Chez)
@@ -226,12 +226,8 @@ chezTests = MkTestPool "Chez backend" [] (Just Chez)
226226
, "channels001", "channels002", "channels003", "channels004", "channels005"
227227
]
228228

229-
refcTests : TestPool
230-
refcTests = MkTestPool "Reference counting C backend" [] (Just C)
231-
[ "refc001" , "refc002"
232-
, "strings", "integers", "doubles"
233-
, "buffer", "clock", "args"
234-
]
229+
refcTests : IO TestPool
230+
refcTests = testsInDir "refc" (const True) "Reference counting C backend" [] (Just C)
235231

236232
racketTests : TestPool
237233
racketTests = MkTestPool "Racket backend" [] (Just Racket)
@@ -264,57 +260,32 @@ nodeTests = MkTestPool "Node backend" [] (Just Node)
264260
, "integers"
265261
]
266262

267-
vmcodeInterpTests : TestPool
268-
vmcodeInterpTests = MkTestPool "VMCode interpreter" [] Nothing
269-
[ "basic001"
270-
]
263+
vmcodeInterpTests : IO TestPool
264+
vmcodeInterpTests = testsInDir "vmcode" (const True) "VMCode interpreter" [] Nothing
271265

272-
ideModeTests : TestPool
273-
ideModeTests = MkTestPool "IDE mode" [] Nothing
274-
[ "ideMode001", "ideMode002", "ideMode003", "ideMode004", "ideMode005"
275-
]
266+
ideModeTests : IO TestPool
267+
ideModeTests = testsInDir "ideMode" (const True) "IDE mode" [] Nothing
276268

277-
preludeTests : TestPool
278-
preludeTests = MkTestPool "Prelude library" [] Nothing
279-
[ "reg001"
280-
]
269+
preludeTests : IO TestPool
270+
preludeTests = testsInDir "prelude" (const True) "Prelude library" [] Nothing
281271

282-
templateTests : TestPool
283-
templateTests = MkTestPool "Test templates" [] Nothing
284-
[ "simple-test", "ttimp", "with-ipkg"
285-
]
272+
templateTests : IO TestPool
273+
templateTests = testsInDir "templates" (const True) "Test templates" [] Nothing
286274

287275
-- base library tests are run against
288276
-- each codegen supported and to keep
289277
-- things simple it's all one test group
290278
-- that only runs if all backends are
291279
-- available.
292-
baseLibraryTests : TestPool
293-
baseLibraryTests = MkTestPool "Base library" [Chez, Node] Nothing
294-
[ "control_app001"
295-
, "system_file001"
296-
, "system_info_os001"
297-
, "system_system"
298-
, "data_bits001"
299-
, "data_string_lines001"
300-
, "data_string_unlines001"
301-
, "system_directory"
302-
, "system_errno"
303-
, "system_info001"
304-
, "system_signal001", "system_signal002", "system_signal003", "system_signal004"
305-
]
280+
baseLibraryTests : IO TestPool
281+
baseLibraryTests = testsInDir "base" (const True) "Base library" [Chez, Node] Nothing
306282

307283
-- same behavior as `baseLibraryTests`
308-
contribLibraryTests : TestPool
309-
contribLibraryTests = MkTestPool "Contrib library" [Chez, Node] Nothing
310-
[ "json_001"
311-
]
284+
contribLibraryTests : IO TestPool
285+
contribLibraryTests = testsInDir "contrib" (const True) "Contrib library" [Chez, Node] Nothing
312286

313-
codegenTests : TestPool
314-
codegenTests = MkTestPool "Code generation" [] Nothing
315-
[ "con001"
316-
, "builtin001"
317-
]
287+
codegenTests : IO TestPool
288+
codegenTests = testsInDir "codegen" (const True) "Code generation" [] Nothing
318289

319290
main : IO ()
320291
main = runner $
@@ -334,18 +305,18 @@ main = runner $
334305
, testPaths "idris2" idrisTestsBuiltin
335306
, testPaths "idris2" idrisTestsEvaluator
336307
, testPaths "idris2" idrisTests
337-
, testPaths "typedd-book" typeddTests
338-
, testPaths "ideMode" ideModeTests
339-
, testPaths "prelude" preludeTests
340-
, testPaths "base" baseLibraryTests
341-
, testPaths "contrib" contribLibraryTests
308+
, !typeddTests
309+
, !ideModeTests
310+
, !preludeTests
311+
, !baseLibraryTests
312+
, !contribLibraryTests
342313
, testPaths "chez" chezTests
343-
, testPaths "refc" refcTests
314+
, !refcTests
344315
, testPaths "racket" racketTests
345316
, testPaths "node" nodeTests
346-
, testPaths "vmcode" vmcodeInterpTests
347-
, testPaths "templates" templateTests
348-
, testPaths "codegen" codegenTests
317+
, !vmcodeInterpTests
318+
, !templateTests
319+
, !codegenTests
349320
]
350321
++ map (testPaths "allbackends" . idrisTestsAllBackends) [Chez, Node, Racket]
351322

0 commit comments

Comments
 (0)