Mercurial > repos > public > sbplib_julia
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 701:38f9894279cd | 709:48a61e085e60 |
|---|---|
| 1 using Test | 1 using Test |
| 2 using TestSetExtensions | 2 using Glob |
| 3 | 3 |
| 4 @testset "All" begin | 4 """ |
| 5 @includetests ARGS | 5 run_testfiles() |
| 6 run_testfiles(path) | |
| 7 run_testfiles(path, glob) | |
| 8 | |
| 9 Find and run all files with filenames starting with "test". If `path` is omitted the test folder is assumed. | |
| 10 The argument `glob` can optionally be supplied to filter which test files are run. | |
| 11 """ | |
| 12 function run_testfiles(args) | |
| 13 if isempty(args) | |
| 14 glob = fn"./*" | |
| 15 else | |
| 16 glob = Glob.FilenameMatch("./"*args[1]) #TBD: Allow multiple filters? | |
| 17 end | |
| 18 | |
| 19 run_testfiles(".", glob) | |
| 6 end | 20 end |
| 21 | |
| 22 # TODO change from prefix `test` to suffix `_test` for testfiles | |
| 23 function run_testfiles(path, glob) | |
| 24 for name ∈ readdir(path) | |
| 25 filepath = joinpath(path, name) | |
| 26 | |
| 27 if isdir(filepath) | |
| 28 @testset "$name" begin | |
| 29 run_testfiles(filepath, glob) | |
| 30 end | |
| 31 end | |
| 32 | |
| 33 if !endswith(name, ".jl") ## TODO combine this into test below when switching to suffix | |
| 34 continue | |
| 35 end | |
| 36 | |
| 37 if startswith(name, "test") && occursin(glob, filepath) | |
| 38 printstyled("Running "; bold=true, color=:green) | |
| 39 println(filepath) | |
| 40 include(filepath) | |
| 41 end | |
| 42 end | |
| 43 end | |
| 44 | |
| 45 testsetname = isempty(ARGS) ? "Sbplib.jl" : ARGS[1] | |
| 46 | |
| 47 @testset "$testsetname" begin | |
| 48 run_testfiles(ARGS) | |
| 49 end |
