-
Notifications
You must be signed in to change notification settings - Fork 0
Fix @test_trixi_include_base to support locally-defined kwarg values
#32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5ee263a
17884fb
bdd9c2e
ed25f76
ec15b71
7b9af4f
03c8833
37714cf
42709c6
696388b
281695a
4d0c5c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,18 +74,47 @@ macro test_trixi_include_base(elixir, args...) | |
| local atol = get_kwarg(args, :atol, atol_default) | ||
| local rtol = get_kwarg(args, :rtol, rtol_default) | ||
|
|
||
| local kwargs = Pair{Symbol, Any}[] | ||
| # Build escaped kwarg expressions. For bare-symbol values there are three cases: | ||
| # 1. Symbol is also a key in this kwarg list (e.g. `seed=6, x=seed`): always pass | ||
| # as Symbol so trixi_include resolves it inside the elixir after the other | ||
| # override (seed=6) has been applied. | ||
| # 2. Locally-defined values defined in the testset body: | ||
| # @isdefined returns true (same world age), so the actual value is passed. | ||
| # 3. Elixir-internal variable references (e.g. bare `x=seed` with no seed= key): | ||
| # on Julia >= 1.12, @isdefined returns false because bindings set inside | ||
| # Base.include have a newer world age; on older Julia the value is visible and | ||
| # also correct (same as the elixir default). | ||
| # For non-Symbol expressions (closures, calls, literals), always evaluate at call site. | ||
| local kwarg_keys = Set(arg.args[1] | ||
| for arg in args | ||
| if arg.head == :(=) && | ||
| !(arg.args[1] in (:additional_ignore_content, :l2, :linf, | ||
| :RealT_for_test_tolerances, :atol, :rtol))) | ||
| local kwarg_exprs = Expr[] | ||
| for arg in args | ||
| if (arg.head == :(=) && | ||
| !(arg.args[1] in (:additional_ignore_content, :l2, :linf, | ||
| :RealT_for_test_tolerances, :atol, :rtol))) | ||
| push!(kwargs, Pair(arg.args...)) | ||
| key = arg.args[1] | ||
| val = arg.args[2] | ||
| if val isa Symbol && val in kwarg_keys | ||
| # Case 1: chained override — pass as Symbol for elixir-internal resolution | ||
| push!(kwarg_exprs, Expr(:kw, key, QuoteNode(val))) | ||
| elseif val isa Symbol | ||
| # Cases 2 & 3: use @isdefined to capture locally-defined values while | ||
| # falling back to Symbol for elixir-internal references | ||
| push!(kwarg_exprs, | ||
| Expr(:kw, key, | ||
| esc(:((@isdefined $val) ? $val : $(QuoteNode(val)))))) | ||
|
ranocha marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't your comment above saying that this won't work for 1.12
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what exactly you mean, but
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also please
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am still not sure why the comment should contradict what is implemented. I find Claude's comment (I already shortened it slightly) helpful, but if you have a concrete suggestion, please make it.
Does this answer your question? If yes, should we adjust the comment for clarification, should I reduce the comment further (as you suggested), or is it fine? If not, could you please explain more your concerns, ideally by making suggestions to improve the comment or asking for concrete examples I can test? |
||
| else | ||
| push!(kwarg_exprs, Expr(:kw, key, esc(val))) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # if `maxiters` is set in tests, it is usually set to a small number to | ||
| # run only a few steps - ignore possible warnings coming from that | ||
| if any(==(:maxiters) ∘ first, kwargs) | ||
| if any(e -> e.args[1] == :maxiters, kwarg_exprs) | ||
| args = append_to_kwargs(args, :additional_ignore_content, | ||
| [ | ||
| r"┌ Warning: Verbosity toggle: max_iters \n│ Interrupted\. Larger maxiters is needed\..*\n└ @ SciMLBase .+\n", | ||
|
|
@@ -99,7 +128,7 @@ macro test_trixi_include_base(elixir, args...) | |
| mpi_isroot() && println($(esc(elixir))) | ||
|
|
||
| # evaluate examples in the scope of the module they're called from | ||
| @trixi_test_nowarn trixi_include(@__MODULE__, $(esc(elixir)); $kwargs...) $additional_ignore_content | ||
| @trixi_test_nowarn trixi_include(@__MODULE__, $(esc(elixir)); $(kwarg_exprs...)) $additional_ignore_content | ||
|
|
||
| # if present, compare l2 and linf errors against reference values | ||
| if !isnothing($l2) || !isnothing($linf) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.