Skip to content

Commit

Permalink
Add @test_nowarn_mod
Browse files Browse the repository at this point in the history
  • Loading branch information
efaulhaber committed Feb 6, 2024
1 parent c310776 commit 7fb7df8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 24 deletions.
44 changes: 22 additions & 22 deletions test/examples/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@testset verbose=true "Examples" begin
@testset verbose=true "Fluid" begin
@trixi_testset "fluid/oscillating_drop_2d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid",
"oscillating_drop_2d.jl"))
@test sol.retcode == ReturnCode.Success
Expand All @@ -12,14 +12,14 @@
end

@trixi_testset "fluid/rectangular_tank_2d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid",
"rectangular_tank_2d.jl"), tspan=(0.0, 0.1))
@test sol.retcode == ReturnCode.Success
end

@trixi_testset "fluid/rectangular_tank_2d.jl with SummationDensity" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid",
"rectangular_tank_2d.jl"), tspan=(0.0, 0.1),
fluid_density_calculator=SummationDensity(),
Expand All @@ -28,14 +28,14 @@
end

@trixi_testset "fluid/rectangular_tank_3d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid",
"rectangular_tank_3d.jl"), tspan=(0.0, 0.1))
@test sol.retcode == ReturnCode.Success
end

@trixi_testset "fluid/rectangular_tank_3d.jl with SummationDensity" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid",
"rectangular_tank_3d.jl"), tspan=(0.0, 0.1),
fluid_density_calculator=SummationDensity(),
Expand All @@ -44,45 +44,45 @@
end

@trixi_testset "fluid/rectangular_tank_edac_2d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid",
"rectangular_tank_edac_2d.jl"),
tspan=(0.0, 0.1))
@test sol.retcode == ReturnCode.Success
end

@trixi_testset "fluid/dam_break_2d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid", "dam_break_2d.jl"),
tspan=(0.0, 0.1))
@test sol.retcode == ReturnCode.Success
end

@trixi_testset "fluid/dam_break_2d_corrections.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid",
"dam_break_2d_corrections.jl"),
tspan=(0.0, 0.1))
@test sol.retcode == ReturnCode.Success
end

@trixi_testset "fluid/dam_break_3d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid", "dam_break_3d.jl"),
tspan=(0.0, 0.1), fluid_particle_spacing=0.1)
@test sol.retcode == ReturnCode.Success
end

@trixi_testset "fluid/falling_water_column_2d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid",
"falling_water_column_2d.jl"),
tspan=(0.0, 0.4))
@test sol.retcode == ReturnCode.Success
end

@trixi_testset "fluid/periodic_channel_2d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fluid",
"periodic_channel_2d.jl"),
tspan=(0.0, 0.4))
Expand All @@ -92,7 +92,7 @@

@testset verbose=true "Solid" begin
@trixi_testset "solid/oscillating_beam_2d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "solid",
"oscillating_beam_2d.jl"), tspan=(0.0, 0.1))
@test sol.retcode == ReturnCode.Success
Expand All @@ -101,7 +101,7 @@

@testset verbose=true "FSI" begin
@trixi_testset "fsi/falling_water_column_2d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fsi",
"falling_water_column_2d.jl"),
tspan=(0.0, 0.4))
Expand All @@ -110,7 +110,7 @@

@trixi_testset "fsi/dam_break_2d.jl" begin
# Use rounded dimensions to avoid warnings
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fsi", "dam_break_2d.jl"),
initial_fluid_size=(0.15, 0.29),
tspan=(0.0, 0.4),
Expand All @@ -119,7 +119,7 @@
end

@trixi_testset "fsi/dam_break_gate_2d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fsi",
"dam_break_gate_2d.jl"),
tspan=(0.0, 0.4),
Expand All @@ -128,7 +128,7 @@
end

@trixi_testset "fsi/falling_spheres_2d.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "fsi",
"falling_spheres_2d.jl"),
tspan=(0.0, 1.0))
Expand All @@ -138,40 +138,40 @@

@testset verbose=true "N-Body" begin
@trixi_testset "n_body/n_body_solar_system.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "n_body",
"n_body_solar_system.jl"))
@test sol.retcode == ReturnCode.Success
end

@trixi_testset "n_body/n_body_benchmark_trixi.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "n_body",
"n_body_benchmark_trixi.jl"))
end

@trixi_testset "n_body/n_body_benchmark_reference.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "n_body",
"n_body_benchmark_reference.jl"))
end

@trixi_testset "n_body/n_body_benchmark_reference_faster.jl" begin
@test_nowarn trixi_include(joinpath(examples_dir(), "n_body",
@test_nowarn_mod trixi_include(joinpath(examples_dir(), "n_body",
"n_body_benchmark_reference_faster.jl"))
end
end

@testset verbose=true "Postprocessing" begin
@trixi_testset "postprocessing/interpolation_plane.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "postprocessing",
"interpolation_plane.jl"),
tspan=(0.0, 0.01))
@test sol.retcode == ReturnCode.Success
end
@trixi_testset "postprocessing/interpolation_point_line.jl" begin
@test_nowarn trixi_include(@__MODULE__,
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "postprocessing",
"interpolation_point_line.jl"))
@test sol.retcode == ReturnCode.Success
Expand Down
51 changes: 49 additions & 2 deletions test/test_util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,66 @@ macro trixi_testset(name, expr)
println(""^100)
println($name)

local time_start = time_ns()

@eval module $mod
using Test
using TrixiParticles

# We also include this file again to provide the definition of
# the other testing macros. This allows to use `@trixi_testset`
# in a nested fashion and also call `@test_nowarn_mod` from
# there.
include(@__FILE__)

@testset verbose=true $name $expr
end

nothing
end
end

# Copied from TrixiBase.jl. See https://github.com/trixi-framework/TrixiBase.jl/issues/9.
"""
@test_nowarn_mod expr
Modified version of `@test_nowarn expr` that prints the content of `stderr` when
it is not empty and ignores some common info statements printed in Trixi.jl
uses.
"""
macro test_nowarn_mod(expr, additional_ignore_content = String[])
quote
let fname = tempname()
try
ret = open(fname, "w") do f
redirect_stderr(f) do
$(esc(expr))
end
end
stderr_content = read(fname, String)
if !isempty(stderr_content)
println("Content of `stderr`:\n", stderr_content)
end

# Patterns matching the following ones will be ignored. Additional patterns
# passed as arguments can also be regular expressions, so we just use the
# type `Any` for `ignore_content`.
ignore_content = Any["[ Info: You just called `trixi_include`. Julia may now compile the code, please be patient.\n"]
append!(ignore_content, $additional_ignore_content)
for pattern in ignore_content
stderr_content = replace(stderr_content, pattern => "")
end

# We also ignore simple module redefinitions for convenience. Thus, we
# check whether every line of `stderr_content` is of the form of a
# module replacement warning.
@test occursin(r"^(WARNING: replacing module .+\.\n)*$", stderr_content)
ret
finally
rm(fname, force = true)
end
end
end
end

function perturb!(data, amplitude)
for i in eachindex(data)
# Perturbation in the interval (-amplitude, amplitude)
Expand Down

0 comments on commit 7fb7df8

Please sign in to comment.