Skip to content

Commit 1878cfb

Browse files
committed
Add test for show()
1 parent 58b7793 commit 1878cfb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/RuntimeGeneratedFunctions.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ end
5353
function Base.show(io::IO, f::RuntimeGeneratedFunction{moduletag, id, argnames}) where {moduletag,id,argnames}
5454
body = _lookup_body(moduletag, id)
5555
mod = parentmodule(moduletag)
56-
print(io, "RuntimeGeneratedFunction(#=in $mod=#, :(", :(($(argnames...),)->$body), "))")
56+
func_expr = Expr(:->, Expr(:tuple, argnames...), body)
57+
print(io, "RuntimeGeneratedFunction(#=in $mod=#, ", repr(func_expr), ")")
5758
end
5859

5960
(f::RuntimeGeneratedFunction)(args::Vararg{Any,N}) where N = generated_callfunc(f, args...)
6061

61-
@inline @generated function generated_callfunc(f::RuntimeGeneratedFunction{moduletag, id, argnames},__args...) where {moduletag,id,argnames}
62+
@inline @generated function generated_callfunc(f::RuntimeGeneratedFunction{moduletag, id, argnames}, __args...) where {moduletag,id,argnames}
6263
setup = (:($(argnames[i]) = @inbounds __args[$i]) for i in 1:length(argnames))
6364
quote
6465
$(setup...)

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ function no_worldage()
6767
end
6868
@test no_worldage() === nothing
6969

70+
# Test show()
71+
@test sprint(show, @RuntimeGeneratedFunction(Base.remove_linenums!(:((x,y)->x+y+1)))) ==
72+
"""
73+
RuntimeGeneratedFunction(#=in $(@__MODULE__)=#, :((x, y)->begin
74+
x + y + 1
75+
end))"""
7076

7177
# Test with precompilation
7278
push!(LOAD_PATH, joinpath(@__DIR__, "precomp"))

0 commit comments

Comments
 (0)