Skip to content

Commit 1d571ce

Browse files
committed
improve test runner
1 parent da3a60d commit 1d571ce

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

test/runtests.jl

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import ParallelStencil: SUPPORTED_PACKAGES, PKG_CUDA, PKG_AMDGPU, PKG_METAL
99

1010
excludedfiles = [ "test_excluded.jl", "test_incremental_compilation.jl", "test_revise.jl"]; # TODO: test_incremental_compilation has to be deactivated until Polyester support released
1111

12-
function runtests()
12+
function runtests(testfiles=String[])
1313
exename = joinpath(Sys.BINDIR, Base.julia_exename())
1414
testdir = pwd()
1515
istest(f) = endswith(f, ".jl") && startswith(basename(f), "test_")
16-
testfiles = sort(filter(istest, vcat([joinpath.(root, files) for (root, dirs, files) in walkdir(testdir)]...)))
16+
testfiles = isempty(testfiles) ? sort(filter(istest, vcat([joinpath.(root, files) for (root, dirs, files) in walkdir(testdir)]...))) : testfiles
1717

18-
nfail = 0
18+
nerror = 0
19+
errorfiles = String[]
1920
printstyled("Testing package ParallelStencil.jl\n"; bold=true, color=:white)
2021

2122
if (PKG_CUDA in SUPPORTED_PACKAGES && !CUDA.functional())
@@ -37,13 +38,49 @@ function runtests()
3738
println("$f")
3839
continue
3940
end
41+
cmd = `$exename -O3 --startup-file=no $(joinpath(testdir, f))`
42+
stdout_path = tempname()
43+
stderr_path = tempname()
44+
stdout_content = ""
45+
stderr_content = ""
4046
try
41-
run(`$exename -O3 --startup-file=no $(joinpath(testdir, f))`)
47+
open(stdout_path, "w") do stdout_io
48+
open(stderr_path, "w") do stderr_io
49+
proc = run(pipeline(Cmd(cmd; ignorestatus=true), stdout=stdout_io, stderr=stderr_io); wait=false)
50+
wait(proc)
51+
end
52+
end
53+
stdout_content = read(stdout_path, String)
54+
stderr_content = read(stderr_path, String)
55+
print(stdout_content)
56+
print(Base.stderr, stderr_content)
4257
catch ex
43-
nfail += 1
58+
println("Test Error: an exception occurred while running the test file $f :")
59+
println(ex)
60+
finally
61+
if ispath(stdout_path)
62+
rm(stdout_path; force=true)
63+
end
64+
if ispath(stderr_path)
65+
rm(stderr_path; force=true)
66+
end
67+
end
68+
if !occursin(r"(?i)test summary", stdout_content)
69+
nerror += 1
70+
push!(errorfiles, f)
71+
end
72+
end
73+
println("")
74+
if nerror == 0
75+
printstyled("Test suite: all selected test files executed (see above for results).\n"; bold=true, color=:green)
76+
else
77+
printstyled("Test suite: $nerror test file(s) aborted execution due to error (see above for details); files aborting execution:\n"; bold=true, color=:red)
78+
for f in errorfiles
79+
println(" - $f")
4480
end
4581
end
46-
return nfail
82+
println("")
83+
return nerror
4784
end
4885

49-
exit(runtests())
86+
exit(runtests(ARGS))

0 commit comments

Comments
 (0)