Skip to content

Commit 79633d0

Browse files
authored
Get tests working on recent Julia versions (#82)
1 parent beb25bc commit 79633d0

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/CodeTracking.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function signatures_at(filename::AbstractString, line::Integer)
143143
spath = splitpath(rpath)
144144
libname = spath[1]
145145
project = Base.active_project()
146-
id = PkgId(Base.project_deps_get(project, libname), libname)
146+
id = getpkgid(project, libname)
147147
return signatures_at(id, joinpath(spath[2:end]...), line)
148148
end
149149
if startswith(filename, "REPL[")

src/utils.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
function checkname(fdef::Expr, name)
22
fproto = fdef.args[1]
33
fdef.head === :where && return checkname(fproto, name)
4+
fdef.head === :call || return false
45
if fproto isa Expr
6+
# A metaprogramming-generated function
7+
fproto.head === :$ && return true # uncheckable, let's assume all is well
58
# Is the check below redundant?
69
fproto.head === :. || return false
710
# E.g. `function Mod.bar.foo(a, b)`
@@ -137,3 +140,35 @@ function postpath(filename, pre)
137140
post[1:1] == Base.Filesystem.path_separator && return post[2:end]
138141
return post
139142
end
143+
144+
if Base.VERSION < v"1.1"
145+
function splitpath(p::String)
146+
# splitpath became available with Julia 1.1
147+
# Implementation copied from Base except doesn't handle the drive
148+
out = String[]
149+
isempty(p) && (pushfirst!(out,p)) # "" means the current directory.
150+
while !isempty(p)
151+
dir, base = _splitdir_nodrive(p)
152+
dir == p && (pushfirst!(out, dir); break) # Reached root node.
153+
if !isempty(base) # Skip trailing '/' in basename
154+
pushfirst!(out, base)
155+
end
156+
p = dir
157+
end
158+
return out
159+
end
160+
splitpath(p::AbstractString) = splitpath(String(p))
161+
162+
_splitdir_nodrive(path::String) = _splitdir_nodrive("", path)
163+
function _splitdir_nodrive(a::String, b::String)
164+
m = match(Base.Filesystem.path_dir_splitter,b)
165+
m === nothing && return (a,b)
166+
a = string(a, isempty(m.captures[1]) ? m.captures[2][1] : m.captures[1])
167+
a, String(m.captures[3])
168+
end
169+
end
170+
171+
# Robust across Julia versions
172+
getpkgid(project::AbstractString, libname) = getpkgid(Base.project_deps_get(project, libname), libname)
173+
getpkgid(id::PkgId, libname) = id
174+
getpkgid(uuid::UUID, libname) = PkgId(uuid, libname)

test/runtests.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
131131
# Ensure that we don't error on difficult cases
132132
m = which(+, (AbstractSparseVector, AbstractSparseVector)) # defined inside an `@eval`
133133
d = definition(String, m)
134-
@test d === nothing || isa(d[1], String)
134+
@test d === nothing || isa(d[1], AbstractString)
135135

136136
# Check for existence of file
137137
id = Base.PkgId("__PackagePrecompilationStatementModule") # not all Julia versions have this
@@ -149,7 +149,9 @@ end
149149
@test !isempty(sigs)
150150
ex = @code_expr(gcd(10, 20))
151151
@test ex isa Expr
152-
@test occursin(String(m.file), String(ex.args[2].args[2].args[1].file))
152+
body = ex.args[2]
153+
idx = findfirst(x -> isa(x, LineNumberNode), body.args)
154+
@test occursin(String(m.file), String(body.args[idx].file))
153155
@test ex == code_expr(gcd, Tuple{Int,Int})
154156

155157
m = first(methods(edit))

0 commit comments

Comments
 (0)