From 0ea7aee12a5036b75f7ed39f7c95f94be8d418af Mon Sep 17 00:00:00 2001 From: lbonaldo Date: Fri, 8 Mar 2024 14:38:53 -0500 Subject: [PATCH] Update CI to regularly test examples --- .github/workflows/test_example.yml | 27 ----------------- .github/workflows/test_examples.yml | 46 +++++++++++++++++++++++++++++ test/test_examples.jl | 28 ++++++++++++++++++ test/utilities.jl | 15 ++++++++++ 4 files changed, 89 insertions(+), 27 deletions(-) delete mode 100644 .github/workflows/test_example.yml create mode 100644 .github/workflows/test_examples.yml create mode 100644 test/test_examples.jl diff --git a/.github/workflows/test_example.yml b/.github/workflows/test_example.yml deleted file mode 100644 index 519cebb9d4..0000000000 --- a/.github/workflows/test_example.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Test-example - -on: - push: - schedule: - - cron: 21 4 * * * # Run at 12:21am US Eastern time - -jobs: - test: - strategy: - matrix: - branch: ["main", "develop"] - version: ["1.8", "1.9"] - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - with: - ref: ${{ matrix.branch }} - - uses: julia-actions/cache@v1.2.2 - - uses: julia-actions/setup-julia@latest - with: - version: ${{ matrix.version }} - - uses: julia-actions/julia-buildpkg@v1 - - name: Test an example case - run: | - julia --project=. Example_Systems/SmallNewEngland/Simple_Test_Case/Run.jl \ No newline at end of file diff --git a/.github/workflows/test_examples.yml b/.github/workflows/test_examples.yml new file mode 100644 index 0000000000..d0f4b37755 --- /dev/null +++ b/.github/workflows/test_examples.yml @@ -0,0 +1,46 @@ +name: Test-examples + +on: + push: + schedule: + - cron: 21 4 * * * # Run at 12:21am US Eastern time + +jobs: + test: + strategy: + matrix: + branch: ["main", "develop"] + version: ["1.8", "1.9", '1'] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ matrix.branch }} + - uses: julia-actions/cache@v1.2.2 + - uses: julia-actions/setup-julia@latest + with: + version: ${{ matrix.version }} + - uses: julia-actions/julia-buildpkg@v1 + - name: Test examples + shell: julia --project=. --color=yes {0} + run: | + using GenX + using Test + + base_path = Base.dirname(Base.dirname(pathof(GenX))) + examples_path = joinpath(base_path, "example_systems") + + if !isdir(examples_path) + @warn "No example systems found in $examples_path" + exit(0) + end + + @testset "Test examples" begin + for example_dir in readdir(examples_path, join=true) + if isdir(example_dir) && isfile(joinpath(example_dir, "Run.jl")) + @info "Running example in $example_dir" + @test isnothing(run_genx_case!(example_dir)) + end + end + end \ No newline at end of file diff --git a/test/test_examples.jl b/test/test_examples.jl new file mode 100644 index 0000000000..ed060f9ca1 --- /dev/null +++ b/test/test_examples.jl @@ -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 \ No newline at end of file diff --git a/test/utilities.jl b/test/utilities.jl index c8e573d533..43417f5462 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -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 \ No newline at end of file