Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

TrixiTest.jl follows the interpretation of
[semantic versioning (semver)](https://julialang.github.io/Pkg.jl/dev/compatibility/#Version-specifier-format-1)
used in the Julia ecosystem. Notable changes will be documented in this file
for human readability.

## Breaking changes from v0.1.x to v0.2

- The keyword argument `RealT` in the macro `@test_trixi_include_base`
has been renamed to `RealT_for_test_tolerances` to avoid name clashes
when passing a keyword argument `RealT`.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TrixiTest"
uuid = "0a316866-cbd0-4425-8bcb-08103b2c1f26"
authors = ["Joshua Lampert <joshua.lampert@uni-hamburg.de>"]
version = "0.1.8-DEV"
version = "0.2.0"

[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
15 changes: 12 additions & 3 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,25 @@ end

"""
@test_trixi_include_base(elixir; additional_ignore_content = Any[],
l2=nothing, linf=nothing, RealT=Float64,
atol=500*eps(RealT), rtol=sqrt(eps(RealT)),
l2 = nothing, linf = nothing,
RealT_for_test_tolerances = Float64,
atol = 500 * eps(RealT_for_test_tolerances),
rtol = sqrt(eps(RealT_for_test_tolerances)),
parameters...)

Test an `elixir` file by calling `trixi_include(elixir; parameters...)`.

The `additional_ignore_content` argument is passed to [`@trixi_test_nowarn`](@ref)
and can be used to ignore additional patterns in the `stderr` output.
By default, only the absence of error output is checked.

If `l2` or `linf` are specified, in addition the resulting L2/Linf errors
are compared approximately against these reference values, using `atol, rtol`
as absolute/relative tolerance.

The keyword arguments `additional_ignore_content`, `l2`, `linf`,
`RealT_for_test_tolerances`, `atol`, and `rtol` are not passed to
`trixi_include(elixir; parameters...)`.
"""
macro test_trixi_include_base(elixir, args...)
# Note: The variables below are just Symbols, not actual errors/types
Expand All @@ -69,7 +77,8 @@ macro test_trixi_include_base(elixir, args...)
local kwargs = Pair{Symbol, Any}[]
for arg in args
if (arg.head == :(=) &&
!(arg.args[1] in (:additional_ignore_content, :l2, :linf, :RealT, :atol, :rtol)))
!(arg.args[1] in (:additional_ignore_content, :l2, :linf,
:RealT_for_test_tolerances, :atol, :rtol)))
push!(kwargs, Pair(arg.args...))
end
end
Expand Down
35 changes: 34 additions & 1 deletion test/test_test_trixi_include.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ end
@test x == 5
end

# overwrite included variable by another included variables
# overwrite included variable by another included variable
@test_trixi_include_base(path, x=seed)
if VERSION >= v"1.12"
mod = @__MODULE__
Expand Down Expand Up @@ -207,4 +207,37 @@ end
@test_trixi_include(path, maxiters=iters)
end
end

# RealT is used internally to compute error tolerances when l2 or linf are used
# However, it should also be forwarded as a keyword argument to trixi_include
@trixi_testset "RealT" begin
example = """
RealT = Float64
"""

mktemp() do path, io
write(io, example)
close(io)

@test_trixi_include_base(path, RealT=Float32)
if VERSION >= v"1.12"
mod = @__MODULE__
@test @invokelatest isdefined(mod, :RealT)
@test (@invokelatest mod.RealT) == Float32
else
@test @isdefined RealT
@test RealT == Float32
end

@test_trixi_include(path, RealT=Float32)
if VERSION >= v"1.12"
mod = @__MODULE__
@test @invokelatest isdefined(mod, :RealT)
@test (@invokelatest mod.RealT) == Float32
else
@test @isdefined RealT
@test RealT == Float32
end
end
end
end