diff --git a/src/util.jl b/src/util.jl index df7d7378..1dc2168d 100644 --- a/src/util.jl +++ b/src/util.jl @@ -96,6 +96,16 @@ julia> redirect_stdout(devnull) do ``` """ function trixi_include(mod::Module, example::AbstractString; kwargs...) + # Check that all kwargs exist as assignments + code = read(example, String) + expr = Meta.parse("begin \n$code \nend") + expr = insert_maxiters(expr) + + for (key, val) in kwargs + # This will throw an error when `key` is not found + find_assignment(expr, key) + end + Base.include(ex -> replace_assignments(insert_maxiters(ex); kwargs...), mod, example) end @@ -282,6 +292,7 @@ end function find_assignment(expr, destination) # declare result to be able to assign to it in the closure local result + found = false # find explicit and keyword assignments walkexpr(expr) do x @@ -289,12 +300,17 @@ function find_assignment(expr, destination) if (x.head === Symbol("=") || x.head === :kw) && x.args[1] === Symbol(destination) result = x.args[2] + found = true # dump(x) end end return x end + if !found + throw(ArgumentError("assignment `$destination` not found in expression")) + end + result end diff --git a/test/test_util.jl b/test/test_util.jl index 8a356847..81027d90 100644 --- a/test/test_util.jl +++ b/test/test_util.jl @@ -41,8 +41,8 @@ macro test_trixi_include(example, args...) if (arg.head == :(=) && !(arg.args[1] in (:l2, :linf, :cons_error, :change_waterheight, :change_velocity, :change_momentum, :change_entropy, - :change_entropy_modified, :atol, :rtol, :atol_ints, - :rtol_ints))) + :change_entropy_modified, :lake_at_rest, + :atol, :rtol, :atol_ints, :rtol_ints))) push!(kwargs, Pair(arg.args...)) end end