Skip to content

Commit

Permalink
Reduce track-level runtests.jl output (#696)
Browse files Browse the repository at this point in the history
* Reduce track-level runtests.jl output

Inspired by #680 and #686

* Less logging on GHA

The info lines are useful when run interactively so that it's clear to the user that something is happening. The GHA bot won't get impatient or confused, though, so we can skip these lines.
  • Loading branch information
cmcaine authored Jan 30, 2024
1 parent 87962e5 commit 4fc647d
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,42 @@ using Test
# Setup GHA logger in CI
using Logging: global_logger
using GitHubActions: GitHubActionsLogger
get(ENV, "GITHUB_ACTIONS", "false") == "true" && global_logger(GitHubActionsLogger())

include("eachexercise.jl")
const running_in_gha = get(ENV, "GITHUB_ACTIONS", "false") == "true"

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
if running_in_gha
global_logger(GitHubActionsLogger())
end

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

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

0 comments on commit 4fc647d

Please sign in to comment.