Skip to content

Commit

Permalink
Update CI to regularly test examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lbonaldo committed Mar 8, 2024
1 parent 4c5e6d2 commit 691cef2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Test-example
name: Test-examples

on:
pull_request:
push:
schedule:
- cron: 21 4 * * * # Run at 12:21am US Eastern time
Expand All @@ -10,7 +11,7 @@ jobs:
strategy:
matrix:
branch: ["main", "develop"]
version: ["1.8", "1.9"]
version: ["1.8", "1.9", '1']
runs-on: ubuntu-latest

steps:
Expand All @@ -22,6 +23,6 @@ jobs:
with:
version: ${{ matrix.version }}
- uses: julia-actions/julia-buildpkg@v1
- name: Test an example case
- name: Test examples
run: |
julia --project=. Example_Systems/SmallNewEngland/Simple_Test_Case/Run.jl
julia --project=. test/test_examples.jl
28 changes: 28 additions & 0 deletions test/test_examples.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module TestExamples

using Test
using GenX

include(joinpath(@__DIR__, "utilities.jl"))


# Test that the examples in the example_systems directory run without error
function test_examples()
base_path = Base.dirname(Base.dirname(pathof(GenX)))
examples_path = joinpath(base_path, "example_systems")

examples_dir = readdir(examples_path, join=true)
for example_dir in examples_dir
if isdir(example_dir) && isfile(joinpath(example_dir, "Run.jl"))
@info "Running example in $example_dir"
result = @warn_error_logger run_genx_case!(example_dir)
@test isnothing(result)
end
end
end

@testset "Test examples" begin
test_examples()
end

end # module
15 changes: 15 additions & 0 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,19 @@ function isapprox_col(col1, col2)
return isapprox_col
end
return false
end


macro warn_error_logger(block)
quote
result = nothing
redirect_stdout(devnull) do
# Create a ConsoleLogger that prints any log messages with level >= Warn to stderr
warnerror_logger = ConsoleLogger(stderr, Logging.Warn)
with_logger(warnerror_logger) do
result = $(esc(block))
end
end
result
end
end

0 comments on commit 691cef2

Please sign in to comment.