From 980dd131d4e550a06a23fb52ecf10376b0426917 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 28 Apr 2020 06:55:47 -0500 Subject: [PATCH 1/2] Handle inner functions (fixes #50) --- src/CodeTracking.jl | 4 ++-- src/utils.jl | 10 +++++++--- test/runtests.jl | 5 +++++ test/script.jl | 5 +++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/CodeTracking.jl b/src/CodeTracking.jl index 8ee3299..33175b3 100644 --- a/src/CodeTracking.jl +++ b/src/CodeTracking.jl @@ -209,13 +209,13 @@ function definition(::Type{String}, method::Method) end ex, iend = Meta.parse(src, istart) iend = prevind(src, iend) - if isfuncexpr(ex) + if isfuncexpr(ex, method.name) iend = min(iend, lastindex(src)) return strip(src[istart:iend], '\n'), line end # The function declaration was presumably on a previous line lineindex = lastindex(linestarts) - while !isfuncexpr(ex) && lineindex > 0 + while !isfuncexpr(ex, method.name) && lineindex > 0 istart = linestarts[lineindex] try ex, iend = Meta.parse(src, istart) diff --git a/src/utils.jl b/src/utils.jl index a4a702e..9818046 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1,10 +1,14 @@ -function isfuncexpr(ex) +function isfuncexpr(ex, name=nothing) + checkname(fdef::Expr, name) = checkname(fdef.args[1], name) + checkname(fname::Symbol, name::Symbol) = fname == name + checkname(fname::Symbol, ::Nothing) = true + # Strip any macros that wrap the method definition while isexpr(ex, :macrocall) && length(ex.args) == 3 ex = ex.args[3] end isa(ex, Expr) || return false - ex.head == :function && return true + ex.head == :function && return checkname(ex, name) if ex.head == :(=) a = ex.args[1] if isa(a, Expr) @@ -12,7 +16,7 @@ function isfuncexpr(ex) a = a.args[1] isa(a, Expr) || return false end - a.head == :call && return true + a.head == :call && return checkname(a, name) end end return false diff --git a/test/runtests.jl b/test/runtests.jl index c8f9bc6..0cb5aec 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -46,6 +46,11 @@ isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl") @test startswith(src, "@inline") @test line == 16 + m = first(methods(f50)) + src, line = definition(String, m) + @test occursin("100x", src) + @test line == 22 + info = CodeTracking.PkgFiles(Base.PkgId(CodeTracking)) @test Base.PkgId(info) === info.id @test CodeTracking.basedir(info) == dirname(@__DIR__) diff --git a/test/script.jl b/test/script.jl index c460fea..7eec125 100644 --- a/test/script.jl +++ b/test/script.jl @@ -18,3 +18,8 @@ f2(x, y) = x + y z = x + 1 return z end + +function f50() # issue #50 + todB(x) = 10*log10(x) + println("100x is $(todB(100)) dB.") +end From c4065b5284f3a108029989284ad9317c87bd6fea Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 28 Apr 2020 07:33:00 -0500 Subject: [PATCH 2/2] Stop testing on Appveyeor --- appveyor.yml | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index d6d8cd1..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,43 +0,0 @@ -environment: - matrix: - - julia_version: 1.0 - - julia_version: 1 - - julia_version: nightly - -platform: - - x86 # 32-bit - - x64 # 64-bit - -# # Uncomment the following lines to allow failures on nightly julia -# # (tests will run but not make your overall status red) -# matrix: -# allow_failures: -# - julia_version: nightly - -branches: - only: - - master - - /release-.*/ - -notifications: - - provider: Email - on_build_success: false - on_build_failure: false - on_build_status_changed: false - -install: - - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1")) - -build_script: - - echo "%JL_BUILD_SCRIPT%" - - C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%" - -test_script: - - echo "%JL_TEST_SCRIPT%" - - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" - -# # Uncomment to support code coverage upload. Should only be enabled for packages -# # which would have coverage gaps without running on Windows -# on_success: -# - echo "%JL_CODECOV_SCRIPT%" -# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"