diff test/runtests.jl @ 709:48a61e085e60 feature/selectable_tests

Add function for selecting tests
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 20 Feb 2021 20:31:08 +0100
parents a79d7b3209c9
children df88aee35bb9
line wrap: on
line diff
--- a/test/runtests.jl	Mon Feb 15 11:13:12 2021 +0100
+++ b/test/runtests.jl	Sat Feb 20 20:31:08 2021 +0100
@@ -1,6 +1,49 @@
 using Test
-using TestSetExtensions
+using Glob
+
+"""
+    run_testfiles()
+    run_testfiles(path)
+    run_testfiles(path, glob)
+
+Find and run all files with filenames starting with "test". If `path` is omitted the test folder is assumed.
+The argument `glob` can optionally be supplied to filter which test files are run.
+"""
+function run_testfiles(args)
+    if isempty(args)
+        glob = fn"./*"
+    else
+        glob = Glob.FilenameMatch("./"*args[1]) #TBD: Allow multiple filters?
+    end
+
+    run_testfiles(".", glob)
+end
 
-@testset "All" begin
-    @includetests ARGS
+# TODO change from prefix `test` to suffix `_test` for testfiles
+function  run_testfiles(path, glob)
+    for name ∈ readdir(path)
+        filepath = joinpath(path, name)
+
+        if isdir(filepath)
+            @testset "$name" begin
+                run_testfiles(filepath, glob)
+            end
+        end
+
+        if !endswith(name, ".jl") ## TODO combine this into test below when switching to suffix
+            continue
+        end
+
+        if startswith(name, "test") && occursin(glob, filepath)
+            printstyled("Running "; bold=true, color=:green)
+            println(filepath)
+            include(filepath)
+        end
+    end
 end
+
+testsetname = isempty(ARGS) ? "Sbplib.jl" : ARGS[1]
+
+@testset "$testsetname" begin
+    run_testfiles(ARGS)
+end