Skip to content

Commit 9134f5d

Browse files
committed
Fix tests on Julia master
1 parent 2a638c6 commit 9134f5d

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/CodeTracking.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ using InteractiveUtils
88

99
export whereis, definition, pkgfiles, signatures_at
1010

11+
# More recent Julia versions assign the line number to the line with the function declaration,
12+
# not the first non-comment line of the body.
13+
const line_is_decl = VERSION >= v"1.5.0-DEV.567"
14+
1115
include("pkgfiles.jl")
1216
include("utils.jl")
1317

@@ -44,8 +48,9 @@ const juliastdlib = joinpath("julia", "stdlib", "v$(VERSION.major).$(VERSION.min
4448
"""
4549
filepath, line = whereis(method::Method)
4650
47-
Return the file and line of the definition of `method`. `line`
48-
is the first line of the method's body.
51+
Return the file and line of the definition of `method`. The meaning of `line`
52+
depends on the Julia version: on Julia 1.5 and higher it is the line number of
53+
the method declaration, otherwise it is the first line of the method's body.
4954
"""
5055
function whereis(method::Method)
5156
file, line = String(method.file), method.line
@@ -111,7 +116,8 @@ end
111116
sigs = signatures_at(filename, line)
112117
113118
Return the signatures of all methods whose definition spans the specified location.
114-
`line` must correspond to a line in the method body (not the signature or final `end`).
119+
Prior to Julia 1.5, `line` must correspond to a line in the method body
120+
(not the signature or final `end`).
115121
116122
Returns `nothing` if there are no methods at that location.
117123
"""

test/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[deps]
2+
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
3+
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
4+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ using CodeTracking
44
using Test, InteractiveUtils
55
# Note: ColorTypes needs to be installed, but note the intentional absence of `using ColorTypes`
66

7+
using CodeTracking: line_is_decl
8+
79
isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl")
810

911
@testset "CodeTracking.jl" begin
1012
m = first(methods(f1))
1113
file, line = whereis(m)
1214
scriptpath = normpath(joinpath(@__DIR__, "script.jl"))
1315
@test file == scriptpath
14-
@test line == 4
16+
@test line == (line_is_decl ? 2 : 4)
1517
trace = try
1618
call_throws()
1719
catch

0 commit comments

Comments
 (0)