Skip to content

Commit ab7a770

Browse files
authored
Merge pull request #54 from timholy/teh/fixmaster
Fix tests on master
2 parents 2a638c6 + c8adf37 commit ab7a770

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ language: julia
33
os:
44
- linux
55
- osx
6+
- windows
67

78
julia:
89
- 1.0
9-
- 1.1
10+
- 1
1011
- nightly
1112

1213
branches:

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CodeTracking"
22
uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
33
authors = ["Tim Holy <[email protected]>"]
4-
version = "0.5.8"
4+
version = "0.5.9"
55

66
[deps]
77
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

src/CodeTracking.jl

Lines changed: 10 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
"""
@@ -193,6 +199,7 @@ function definition(::Type{String}, method::Method)
193199
file, line = whereis(method)
194200
line == 0 && return nothing
195201
src = src_from_file_or_REPL(file)
202+
src = replace(src, "\r"=>"")
196203
eol = isequal('\n')
197204
linestarts = Int[]
198205
istart = 1

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)