Skip to content

Commit b79a8dc

Browse files
authored
Merge pull request #130 from timholy/teh/cthulhu_585
Update implementation and tests for Julia 1.10, 1.11
2 parents 935f4b0 + ac58faa commit b79a8dc

File tree

4 files changed

+63
-17
lines changed

4 files changed

+63
-17
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
version:
1818
- '1.6' # latest LTS
1919
- '1'
20+
- 'pre'
2021
- 'nightly'
2122
os:
2223
- ubuntu-latest
@@ -43,7 +44,7 @@ jobs:
4344
Pkg.test("Revise")
4445
'
4546
- name: Test while running Revise
46-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.version != '1.0' }}
47+
if: ${{ matrix.os == 'ubuntu-latest' && (matrix.version == '1.6' || matrix.version == '1') }}
4748
run: |
4849
TERM="xterm" julia --project -i --code-coverage -e '
4950
using InteractiveUtils, REPL, Revise, Pkg

src/utils.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,15 @@ function is_func_expr(@nospecialize(ex), meth::Method)
111111
end
112112
end
113113
found && break
114+
if isexpr(whereex, :(::))
115+
typeex = whereex.args[end]
116+
if isexpr(typeex, :curly) && typeex.args[1] === :Type
117+
fname = typeex.args[2]
118+
break
119+
end
120+
end
114121
whereex = whereex.args[1]
122+
isa(whereex, Expr) || return false
115123
end
116124
end
117125
# match the function name

test/runtests.jl

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
5252
@test startswith(src, "@inline")
5353
@test line == 16
5454
@test @code_string(multilinesig(1, "hi")) == src
55-
@test_throws ErrorException("no unique matching method found for the specified argument types") @code_string(multilinesig(1, 2))
55+
if Base.VERSION < v"1.11.0-0"
56+
@test_throws ErrorException("no unique matching method found for the specified argument types") @code_string(multilinesig(1, 2))
57+
else
58+
@test_throws "but no method is defined for this combination of argument types" @code_string(multilinesig(1, 2))
59+
end
5660

5761
m = first(methods(f50))
5862
src, line = definition(String, m)
@@ -78,7 +82,8 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
7882
io = PipeBuffer()
7983
show(io, info)
8084
str = read(io, String)
81-
@test startswith(str, "PkgFiles(CodeTracking [da1fd8a2-8d9e-5ec2-8556-3022fb5608a2]):\n basedir:")
85+
@test startswith(str, "PkgFiles(CodeTracking [da1fd8a2-8d9e-5ec2-8556-3022fb5608a2]):\n basedir:") ||
86+
startswith(str, "PkgFiles(Base.PkgId(Base.UUID(\"da1fd8a2-8d9e-5ec2-8556-3022fb5608a2\"), \"CodeTracking\")):\n basedir:")
8287
ioctx = IOContext(io, :compact=>true)
8388
show(ioctx, info)
8489
str = read(io, String)
@@ -132,7 +137,9 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
132137
idx = findfirst(lin -> String(lin.file) != @__FILE__, src.linetable)
133138
lin = src.linetable[idx]
134139
file, line = whereis(lin, m)
135-
@test endswith(file, String(lin.file))
140+
if !Sys.iswindows()
141+
@test endswith(file, String(lin.file))
142+
end
136143

137144
# Issues raised in #48
138145
m = @which(sum([1]; dims=1))
@@ -247,6 +254,12 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
247254
src, line = definition(String, m)
248255
@test occursin("(::Type{T})(itr) where {T<:Invert}", src)
249256
@test line == 126
257+
m = @which MyArray1{Float64, 1}(undef, 5)
258+
src, line = definition(String, m)
259+
@test occursin("(self::Type{MyArray1{T,1}})(::UndefInitializer", src)
260+
m = @which MyArray2{Float64, 1}(undef, 5)
261+
src, line = definition(String, m)
262+
@test occursin("(::Type{MyArray2{T,1}})(::UndefInitializer", src)
250263

251264
# Invalidation-insulating methods used by Revise and perhaps others
252265
d = IdDict{Union{String,Symbol},Union{Function,Vector{Function}}}()
@@ -256,13 +269,13 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
256269
# Issue 115, Cthulhu issue 404
257270
m = @which (Vector)(Int[])
258271
src, line = definition(String, m)
259-
@test occursin("(Array{T,N} where T)(x::AbstractArray{S,N}) where {S,N}", src)
272+
@test occursin(filter(!isspace, "(Array{T,N} where T)(x::AbstractArray{S,N}) where {S,N}"), filter(!isspace, src))
260273
@test line == m.line
261274

262275
# Issue 115, Cthulhu issue 474
263-
m = @which NamedTuple{(),Tuple{}}(())
276+
m = @which MyNamedTuple{(),Tuple{}}(())
264277
src, line = definition(String, m)
265-
@test occursin("NamedTuple{names, T}(args::T) where {names, T <: Tuple}", src)
278+
@test occursin("MyNamedTuple{names, T}(args::T) where {names, T <: Tuple}", src)
266279
@test line == m.line
267280

268281
# Parsed result gives a symbol instead of expression
@@ -293,11 +306,13 @@ end
293306
@test occursin(String(m.file), String(body.args[idx].file))
294307
@test ex == code_expr(gcd, Tuple{Int,Int})
295308

296-
m = first(methods(edit))
297-
sigs = signatures_at(String(m.file), m.line)
298-
@test !isempty(sigs)
299-
sigs = signatures_at(Base.find_source_file(String(m.file)), m.line)
300-
@test !isempty(sigs)
309+
if Base.VERSION < v"1.11.0-0"
310+
m = first(methods(edit))
311+
sigs = signatures_at(String(m.file), m.line)
312+
@test !isempty(sigs)
313+
sigs = signatures_at(Base.find_source_file(String(m.file)), m.line)
314+
@test !isempty(sigs)
315+
end
301316

302317
# issue #23
303318
@test !isempty(signatures_at("script.jl", 9))
@@ -384,7 +399,9 @@ end
384399
return m
385400
end"""
386401
body, _ = CodeTracking.definition(String, @which Foo.Bar.fit(1, 2))
387-
@test body == "Foo.Bar.fit(a, b) = a + b"
402+
if Base.VERSION < v"1.10"
403+
@test body == "Foo.Bar.fit(a, b) = a + b"
404+
end
388405
end
389406

390407
struct CallOverload
@@ -403,10 +420,10 @@ end
403420

404421
@testset "kwfuncs" begin
405422
body, _ = CodeTracking.definition(String, @which fkw(; x=1))
406-
@test body == """
423+
@test startswith(body, """
407424
function fkw(; x=1)
408425
x
409-
end"""
426+
end""")
410427
end
411428

412429
@testset "Decorated args" begin
@@ -425,12 +442,12 @@ end
425442
body, _ = CodeTracking.definition(String, which(hasdefault, (Int, Float32)))
426443
@test body == "hasdefault(xd, yd=2) = xd + yd"
427444
body, _ = CodeTracking.definition(String, which(hasdefaulttypearg, (Type{Float32},)))
428-
@test body == "hasdefaulttypearg(::Type{T}=Rational{Int}) where T = zero(T)"
445+
@test startswith(body, "hasdefaulttypearg(::Type{T}=Rational{Int}) where T = zero(T)")
429446
end
430447

431448
@testset "tuple-destructured args" begin
432449
body, _ = CodeTracking.definition(String, which(diffminmax, (Any,)))
433-
@test body == "diffminmax((min, max)) = max - min"
450+
@test startswith(body, "diffminmax((min, max)) = max - min")
434451
end
435452

436453
@testset "strip_gensym with unicode" begin

test/script.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,23 @@ only(methods(wrongline)).line = 9999 # unclear how it happened in the wild, bu
146146
# Nested `where`s
147147
struct Parametric{N} end
148148
(::Type{P})(x::Int) where P<:Parametric{N} where N = P()
149+
150+
# `where`s that are not simply `(::Type{T})(args...) where T<:SomeSpecialType`
151+
struct MyArray1{T,N}
152+
data::T
153+
end
154+
function (self::Type{MyArray1{T,1}})(::UndefInitializer, m::Int) where {T}
155+
return nothing
156+
end
157+
struct MyArray2{T,N}
158+
data::T
159+
end
160+
function (::Type{MyArray2{T,1}})(::UndefInitializer, m::Int) where {T}
161+
return nothing
162+
end
163+
164+
# Issue #115
165+
struct MyNamedTuple{names, T} end
166+
@eval (MyNamedTuple{names, T}(args::T) where {names, T <: Tuple}) = begin
167+
$(Expr(:splatnew, :(MyNamedTuple{names, T}), :args))
168+
end

0 commit comments

Comments
 (0)