11# Note: some of CodeTracking's functionality can only be tested by Revise
22
33using CodeTracking
4- using Test, InteractiveUtils, LinearAlgebra, SparseArrays
4+ using Test, InteractiveUtils, REPL, LinearAlgebra, SparseArrays
55# Note: ColorTypes needs to be installed, but note the intentional absence of `using ColorTypes`
66
77using CodeTracking: line_is_decl
@@ -67,6 +67,10 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
6767 show (io, info)
6868 str = String (take! (io))
6969 @test startswith (str, " PkgFiles(CodeTracking [da1fd8a2-8d9e-5ec2-8556-3022fb5608a2]):\n basedir:" )
70+ ioctx = IOContext (io, :compact => true )
71+ show (ioctx, info)
72+ str = String (take! (io))
73+ @test match (r" PkgFiles\( CodeTracking, .*CodeTracking(\. jl)?, String\[\]\) " , str) != = nothing
7074
7175 @test pkgfiles (" ColorTypes" ) === nothing
7276 @test_throws ErrorException pkgfiles (" NotAPkg" )
@@ -86,17 +90,6 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
8690 oldlookup = CodeTracking. method_lookup_callback[]
8791 CodeTracking. method_lookup_callback[] = m -> error (" oops" )
8892 @test whereis (m) == (" REPL[1]" , 1 )
89- # Test with definition(String, m)
90- if isdefined (Base, :active_repl )
91- hp = Base. active_repl. interface. modes[1 ]. hist
92- fstr = " __fREPL__(x::Int16) = 0"
93- histidx = length (hp. history) + 1 - hp. start_idx
94- ex = Base. parse_input_line (fstr; filename= " REPL[$histidx ]" )
95- f = Core. eval (Main, ex)
96- push! (hp. history, fstr)
97- @test definition (String, first (methods (f))) == (fstr, 1 )
98- pop! (hp. history)
99- end
10093 CodeTracking. method_lookup_callback[] = oldlookup
10194
10295 m = first (methods (Test. eval))
@@ -109,6 +102,10 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
109102 end
110103 m = first (methods (f150))
111104 src = Base. uncompressed_ast (m)
105+ idx = findfirst (lin -> String (lin. file) == @__FILE__ , src. linetable)
106+ lin = src. linetable[idx]
107+ file, line = whereis (lin, m)
108+ @test endswith (file, String (lin. file))
112109 idx = findfirst (lin -> String (lin. file) != @__FILE__ , src. linetable)
113110 lin = src. linetable[idx]
114111 file, line = whereis (lin, m)
167164
168165 # issue #23
169166 @test ! isempty (signatures_at (" script.jl" , 9 ))
167+
168+ @test_throws ArgumentError signatures_at (" nofile.jl" , 1 )
169+
170+ if isdefined (Revise, :add_revise_deps )
171+ Revise. add_revise_deps ()
172+ sigs = signatures_at (CodeTracking, " src/utils.jl" , 5 )
173+ @test length (sigs) == 1 # only isn't available on julia 1.0
174+ @test first (sigs) == Tuple{typeof (CodeTracking. checkname), Expr, Any}
175+ @test pkgfiles (CodeTracking). id == Base. PkgId (CodeTracking)
176+ end
177+
178+ # REPL (test copied from Revise)
179+ if isdefined (Base, :active_repl )
180+ hp = Base. active_repl. interface. modes[1 ]. hist
181+ fstr = " __fREPL__(x::Int16) = 0"
182+ histidx = length (hp. history) + 1 - hp. start_idx
183+ ex = Base. parse_input_line (fstr; filename= " REPL[$histidx ]" )
184+ f = Core. eval (Main, ex)
185+ if ex. head === :toplevel
186+ ex = ex. args[end ]
187+ end
188+ push! (hp. history, fstr)
189+ m = first (methods (f))
190+ @test definition (String, first (methods (f))) == (fstr, 1 )
191+ @test ! isempty (signatures_at (String (m. file), m. line))
192+ pop! (hp. history)
193+ elseif haskey (ENV , " CI" )
194+ error (" CI Revise tests must be run with -i" )
195+ end
170196 end
171197end
172198
0 commit comments