forked from exercism/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.jl
63 lines (51 loc) · 2.58 KB
/
runtests.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Test
for exercise in readdir(joinpath("exercises", "concept"))
# Allow only testing specified exercises
if !isempty(ARGS) && !(exercise in ARGS)
continue
end
exercise_path = joinpath(joinpath("exercises", "concept"), exercise)
isdir(exercise_path) || continue
# Create an anonymous module so that exercises are tested in separate scopes
m = Module()
# When testing the example solution, all tests must pass, even those that are marked as skipped or broken.
# The student will not be affected by this.
# Overwrite @test_skip and @test_broken with @test
@eval m using Test
@eval m $(Symbol("@test_skip")) = $(Symbol("@test"))
@eval m $(Symbol("@test_broken")) = $(Symbol("@test"))
# runtests.jl includes the solution by calling `include("slug.jl")`
# Our anonymous module doesn't have `include(s::String)` defined,
# so we define our own. We manually include the example solution in our
# anonymous module, so we can define `m.include(s::String)` to do nothing.
Core.eval(m, :(include(s) = nothing))
Base.include(m, joinpath(exercise_path, joinpath(".meta", "exemplar.jl")))
@info "[CONCEPT] Testing $exercise"
Base.include(m, joinpath(exercise_path, "runtests.jl"))
println() # to make the output more readable
end
for exercise in readdir(joinpath("exercises", "practice"))
# Allow only testing specified exercises
if !isempty(ARGS) && !(exercise in ARGS)
continue
end
exercise_path = joinpath(joinpath("exercises", "practice"), exercise)
isdir(exercise_path) || continue
# Create an anonymous module so that exercises are tested in separate scopes
m = Module()
# When testing the example solution, all tests must pass, even those that are marked as skipped or broken.
# The student will not be affected by this.
# Overwrite @test_skip and @test_broken with @test
@eval m using Test
@eval m $(Symbol("@test_skip")) = $(Symbol("@test"))
@eval m $(Symbol("@test_broken")) = $(Symbol("@test"))
# runtests.jl includes the solution by calling `include("slug.jl")`
# Our anonymous module doesn't have `include(s::String)` defined,
# so we define our own. We manually include the example solution in our
# anonymous module, so we can define `m.include(s::String)` to do nothing.
Core.eval(m, :(include(s) = nothing))
Base.include(m, joinpath(exercise_path, joinpath(".meta", "example.jl")))
@info "[PRACTICE] Testing $exercise"
Base.include(m, joinpath(exercise_path, "runtests.jl"))
println() # to make the output more readable
end