From 323094f418c7d3b056847debd5d7ebd240889111 Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Mon, 20 Nov 2023 13:50:39 +0100 Subject: [PATCH 1/2] throw error in trixi_include when assignment is not found --- src/util.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 From 0cf23a497e6951f0632b9adb97b1bea789b8034f Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Mon, 20 Nov 2023 14:05:19 +0100 Subject: [PATCH 2/2] remove lake_at_rest from kwarg list in test_trixi_include --- test/test_util.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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