comparison test/runtests.jl @ 717:1c5600a711ae feature/selectable_tests

Allow multiple filters
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 12 Mar 2021 19:53:40 +0100
parents be648c6d6686
children 95b207729b7a
comparison
equal deleted inserted replaced
716:3e64e102e161 717:1c5600a711ae
2 using Glob 2 using Glob
3 3
4 """ 4 """
5 run_testfiles() 5 run_testfiles()
6 run_testfiles(path) 6 run_testfiles(path)
7 run_testfiles(path, glob) 7 run_testfiles(path, globs)
8 8
9 Find and run all files with filenames ending with "_test.jl". If `path` is omitted the test folder is assumed. 9 Find and run all files with filenames ending with "_test.jl". If `path` is omitted the test folder is assumed.
10 The argument `glob` can optionally be supplied to filter which test files are run. 10 The argument `globs` can optionally be supplied to filter which test files are run.
11 """ 11 """
12 function run_testfiles(args) 12 function run_testfiles(args)
13 if isempty(args) 13 if isempty(args)
14 glob = fn"./*" 14 globs = [fn"./*"]
15 else 15 else
16 glob = Glob.FilenameMatch("./"*args[1]) #TBD: Allow multiple filters? 16 globs = Glob.FilenameMatch.("./".*args)
17 end 17 end
18 18
19 run_testfiles(".", glob) 19 run_testfiles(".", globs)
20 end 20 end
21 21
22 function run_testfiles(path, glob) 22 function run_testfiles(path, globs)
23 for name ∈ readdir(path) 23 for name ∈ readdir(path)
24 filepath = joinpath(path, name) 24 filepath = joinpath(path, name)
25 25
26 if isdir(filepath) 26 if isdir(filepath)
27 @testset "$name" begin 27 @testset "$name" begin
28 run_testfiles(filepath, glob) 28 run_testfiles(filepath, globs)
29 end 29 end
30 end 30 end
31 31
32 if endswith(name, "_test.jl") && occursin(glob, filepath) 32 if endswith(name, "_test.jl") && any(occursin.(globs, filepath))
33 printstyled("Running "; bold=true, color=:green) 33 printstyled("Running "; bold=true, color=:green)
34 println(filepath) 34 println(filepath)
35 @testset "$name" begin 35 @testset "$name" begin
36 include(filepath) 36 include(filepath)
37 end 37 end
38 end 38 end
39 end 39 end
40 end 40 end
41 41
42 testsetname = isempty(ARGS) ? "Sbplib.jl" : ARGS[1] 42 testsetname = isempty(ARGS) ? "Sbplib.jl" : join(ARGS, ", ")
43 43
44 @testset "$testsetname" begin 44 @testset "$testsetname" begin
45 run_testfiles(ARGS) 45 run_testfiles(ARGS)
46 end 46 end