Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TrixiBase"
uuid = "9a0f1c46-06d5-4909-a5a3-ce25d3fa3284"
authors = ["Michael Schlottke-Lakemper <michael@sloede.com>"]
version = "0.1.11-DEV"
version = "0.1.11"

[deps]
ChangePrecision = "3cb15238-376d-56a3-8042-d33272777c9a"
Expand Down
7 changes: 5 additions & 2 deletions src/trixi_include.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ function replace_assignments(expr, recursive = false; kwargs...)
for (key, val) in kwargs
if (x.head === Symbol("=") || x.head === :kw) &&
x.args[1] === Symbol(key)
x.args[2] = :($val)
# Symbols need to be quoted so that they are evaluated as values instead
# of variable names in the included file.
x.args[2] = val isa Symbol ? QuoteNode(val) : val
# dump(x)
end
end
Expand Down Expand Up @@ -242,7 +244,8 @@ function replace_assignments(expr, recursive = false; kwargs...)
# `x = ...` in the file, which will also be replaced in the loop above.
for (key, val) in kwargs
if !(Symbol(key) in existing_kwargs)
push!(x.args, Expr(:kw, Symbol(key), val))
value = val isa Symbol ? QuoteNode(val) : val
push!(x.args, Expr(:kw, Symbol(key), value))
end
end
end
Expand Down
23 changes: 23 additions & 0 deletions test/trixi_include.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
@test x == 7
end

@trixi_test_nowarn trixi_include(@__MODULE__, path, x = :symbol)
Comment thread
efaulhaber marked this conversation as resolved.

if VERSION >= v"1.12"
mod = @__MODULE__
@test (@invokelatest mod.x) === :symbol
else
@test x === :symbol
end

# Verify default version (that includes in `Main`)
@trixi_test_nowarn trixi_include(path, x = 11)
if VERSION >= v"1.12"
Expand Down Expand Up @@ -196,6 +205,20 @@
@test y == 20 # Overridden from nested file
@test z == 30 # Overridden from top file
end

# Test a Symbol override that is only assigned in the nested file.
# This covers the branch where missing kwargs are injected
# into the nested `trixi_include` call.
@test_warn "assignments" trixi_include(@__MODULE__, path2;
x = :symbol,
replace_assignments_recursive = true)
if VERSION >= v"1.12"
mod = @__MODULE__
@test (@invokelatest mod.x) === :symbol
else
@test x === :symbol
end

# Test that kwargs are NOT passed recursively
@trixi_test_nowarn trixi_include(@__MODULE__, path2;
x = 10, y = 20, z = 30,
Expand Down
Loading