changeset 717:1c5600a711ae feature/selectable_tests

Allow multiple filters
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 12 Mar 2021 19:53:40 +0100
parents 3e64e102e161
children 95b207729b7a
files README.md test/runtests.jl
diffstat 2 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/README.md	Sat Feb 20 21:19:24 2021 +0100
+++ b/README.md	Fri Mar 12 19:53:40 2021 +0100
@@ -21,3 +21,9 @@
 julia> Pkg.test(test_args=["*/readoperators.jl"])
 ```
 to run only the tests in files named `readoperators.jl`.
+Multiple filters are allowed and will cause files matching any of the provided
+filters to be run. For example
+```
+Pkg.test(test_args=["*/lazy_tensor_operations_test.jl", "Grids/*"])
+```
+will run any file named `lazy_tensor_operations_test.jl` and all the files in the `Grids` folder.
--- a/test/runtests.jl	Sat Feb 20 21:19:24 2021 +0100
+++ b/test/runtests.jl	Fri Mar 12 19:53:40 2021 +0100
@@ -4,32 +4,32 @@
 """
     run_testfiles()
     run_testfiles(path)
-    run_testfiles(path, glob)
+    run_testfiles(path, globs)
 
 Find and run all files with filenames ending with "_test.jl". If `path` is omitted the test folder is assumed.
-The argument `glob` can optionally be supplied to filter which test files are run.
+The argument `globs` can optionally be supplied to filter which test files are run.
 """
 function run_testfiles(args)
     if isempty(args)
-        glob = fn"./*"
+        globs = [fn"./*"]
     else
-        glob = Glob.FilenameMatch("./"*args[1]) #TBD: Allow multiple filters?
+        globs = Glob.FilenameMatch.("./".*args)
     end
 
-    run_testfiles(".", glob)
+    run_testfiles(".", globs)
 end
 
-function  run_testfiles(path, glob)
+function  run_testfiles(path, globs)
     for name ∈ readdir(path)
         filepath = joinpath(path, name)
 
         if isdir(filepath)
             @testset "$name" begin
-                run_testfiles(filepath, glob)
+                run_testfiles(filepath, globs)
             end
         end
 
-        if endswith(name, "_test.jl") && occursin(glob, filepath)
+        if endswith(name, "_test.jl") && any(occursin.(globs, filepath))
             printstyled("Running "; bold=true, color=:green)
             println(filepath)
             @testset "$name" begin
@@ -39,7 +39,7 @@
     end
 end
 
-testsetname = isempty(ARGS) ? "Sbplib.jl" : ARGS[1]
+testsetname = isempty(ARGS) ? "Sbplib.jl" : join(ARGS, ", ")
 
 @testset "$testsetname" begin
     run_testfiles(ARGS)