Skip to content

Commit

Permalink
Reduce track-level runtests.jl output
Browse files Browse the repository at this point in the history
Inspired by #680 and #686
  • Loading branch information
cmcaine committed Jan 30, 2024
1 parent 87962e5 commit 37edc96
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,33 @@ get(ENV, "GITHUB_ACTIONS", "false") == "true" && global_logger(GitHubActionsLogg

include("eachexercise.jl")

eachexercise(ARGS) do exercise, exercise_type, exercise_path, example_path
# 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()
@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

# 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"))
# Create an anonymous module so that exercises are tested in separate scopes
m = Module()

# 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)
@info "[$(uppercase(exercise_type))] Testing $exercise"
Base.include(m, joinpath(exercise_path, "runtests.jl"))
# 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"))

println() # to make the output more readable
# 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)
@info "[$(uppercase(exercise_type))] Testing $exercise"
Base.include(m, joinpath(exercise_path, "runtests.jl"))
end
end
end

0 comments on commit 37edc96

Please sign in to comment.