-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
runtests.jl
46 lines (38 loc) · 1.82 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
using JSON
using Pkg
using Test
# Setup GHA logger in CI
using Logging: global_logger
using GitHubActions: GitHubActionsLogger
const running_in_gha = get(ENV, "GITHUB_ACTIONS", "false") == "true"
if running_in_gha
global_logger(GitHubActionsLogger())
end
include("eachexercise.jl")
@testset "exemplars" begin
eachexercise(ARGS) do exercise, exercise_type, exercise_path, example_path
@testset "$exercise" begin
# Skip exercise tests if the Julia version doesn't meet the required version as specified in .meta/config.json
cfg = JSON.parsefile(joinpath(exercise_path, ".meta", "config.json"))
required_version_spec = Pkg.Types.semver_spec(get(cfg, "language_versions", "1.0"))
if VERSION ∉ required_version_spec
@info "$exercise requires Julia $required_version_spec, skipping tests."
println()
return
end
# 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.
# So we overwrite @test_skip and @test_broken with @test to enable those tests.
@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.
@eval m include(s) = Base.include($m, $example_path)
running_in_gha || @info "[$(uppercase(exercise_type))] Testing $exercise"
Base.include(m, joinpath(exercise_path, "runtests.jl"))
end
end
end