From 5da14d502827fac5b326e465a8eeedf9412602f8 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 4 Aug 2024 16:21:10 -0500 Subject: [PATCH 1/8] Fix `exhaustive.jl` test error Identified in https://github.com/JuliaDebug/Cthulhu.jl/pull/585 --- src/utils.jl | 8 ++++++++ test/runtests.jl | 6 ++++++ test/script.jl | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/utils.jl b/src/utils.jl index 6927e54..bd1c641 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -111,7 +111,15 @@ function is_func_expr(@nospecialize(ex), meth::Method) end end found && break + if isexpr(whereex, :(::)) + typeex = whereex.args[end] + if isexpr(typeex, :curly) && typeex.args[1] === :Type + fname = typeex.args[2] + break + end + end whereex = whereex.args[1] + isa(whereex, Expr) || return false end end # match the function name diff --git a/test/runtests.jl b/test/runtests.jl index d4ae8b8..cb45c49 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -247,6 +247,12 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j src, line = definition(String, m) @test occursin("(::Type{T})(itr) where {T<:Invert}", src) @test line == 126 + m = @which MyArray1{Float64, 1}(undef, 5) + src, line = definition(String, m) + @test occursin("(self::Type{MyArray1{T,1}})(::UndefInitializer", src) + m = @which MyArray2{Float64, 1}(undef, 5) + src, line = definition(String, m) + @test occursin("(::Type{MyArray2{T,1}})(::UndefInitializer", src) # Invalidation-insulating methods used by Revise and perhaps others d = IdDict{Union{String,Symbol},Union{Function,Vector{Function}}}() diff --git a/test/script.jl b/test/script.jl index 1a4ea14..f74a7e8 100644 --- a/test/script.jl +++ b/test/script.jl @@ -146,3 +146,17 @@ only(methods(wrongline)).line = 9999 # unclear how it happened in the wild, bu # Nested `where`s struct Parametric{N} end (::Type{P})(x::Int) where P<:Parametric{N} where N = P() + +# `where`s that are not simply `(::Type{T})(args...) where T<:SomeSpecialType` +struct MyArray1{T,N} + data::T +end +function (self::Type{MyArray1{T,1}})(::UndefInitializer, m::Int) where {T} + return nothing +end +struct MyArray2{T,N} + data::T +end +function (::Type{MyArray2{T,1}})(::UndefInitializer, m::Int) where {T} + return nothing +end From 61858b09f86805e0eea7b4e0e8a33aa7e935d278 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 4 Aug 2024 16:55:02 -0500 Subject: [PATCH 2/8] Vendor the tested "NamedTuple" constructor --- test/runtests.jl | 4 ++-- test/script.jl | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index cb45c49..17d9752 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -266,9 +266,9 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j @test line == m.line # Issue 115, Cthulhu issue 474 - m = @which NamedTuple{(),Tuple{}}(()) + m = @which MyNamedTuple{(),Tuple{}}(()) src, line = definition(String, m) - @test occursin("NamedTuple{names, T}(args::T) where {names, T <: Tuple}", src) + @test occursin("MyNamedTuple{names, T}(args::T) where {names, T <: Tuple}", src) @test line == m.line # Parsed result gives a symbol instead of expression diff --git a/test/script.jl b/test/script.jl index f74a7e8..677ef65 100644 --- a/test/script.jl +++ b/test/script.jl @@ -160,3 +160,9 @@ end function (::Type{MyArray2{T,1}})(::UndefInitializer, m::Int) where {T} return nothing end + +# Issue #115 +struct MyNamedTuple{names, T} end +@eval (MyNamedTuple{names, T}(args::T) where {names, T <: Tuple}) = begin + $(Expr(:splatnew, :(MyNamedTuple{names, T}), :args)) +end From 9ea790f6cfe0af636cdf1f69e935bc02d12d53c5 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 4 Aug 2024 16:55:44 -0500 Subject: [PATCH 3/8] Adjust for changes in printing --- test/runtests.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 17d9752..805d335 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -52,7 +52,11 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j @test startswith(src, "@inline") @test line == 16 @test @code_string(multilinesig(1, "hi")) == src - @test_throws ErrorException("no unique matching method found for the specified argument types") @code_string(multilinesig(1, 2)) + if Base.VERSION < v"1.11.0-0" + @test_throws ErrorException("no unique matching method found for the specified argument types") @code_string(multilinesig(1, 2)) + else + @test_throws "but no method is defined for this combination of argument types" @code_string(multilinesig(1, 2)) + end m = first(methods(f50)) src, line = definition(String, m) @@ -78,7 +82,8 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j io = PipeBuffer() show(io, info) str = read(io, String) - @test startswith(str, "PkgFiles(CodeTracking [da1fd8a2-8d9e-5ec2-8556-3022fb5608a2]):\n basedir:") + @test startswith(str, "PkgFiles(CodeTracking [da1fd8a2-8d9e-5ec2-8556-3022fb5608a2]):\n basedir:") || + startswith(str, "PkgFiles(Base.PkgId(Base.UUID(\"da1fd8a2-8d9e-5ec2-8556-3022fb5608a2\"), \"CodeTracking\")):\n basedir:") ioctx = IOContext(io, :compact=>true) show(ioctx, info) str = read(io, String) @@ -262,7 +267,7 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j # Issue 115, Cthulhu issue 404 m = @which (Vector)(Int[]) src, line = definition(String, m) - @test occursin("(Array{T,N} where T)(x::AbstractArray{S,N}) where {S,N}", src) + @test occursin(filter(!isspace, "(Array{T,N} where T)(x::AbstractArray{S,N}) where {S,N}"), filter(!isspace, src)) @test line == m.line # Issue 115, Cthulhu issue 474 From f3a9f9b6bc510902cb36431370e3ba796cb32f61 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 4 Aug 2024 16:57:04 -0500 Subject: [PATCH 4/8] Work around https://github.com/JuliaLang/JuliaSyntax.jl/issues/316#issuecomment-1870294857 --- test/runtests.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 805d335..a207f53 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -395,7 +395,9 @@ end return m end""" body, _ = CodeTracking.definition(String, @which Foo.Bar.fit(1, 2)) - @test body == "Foo.Bar.fit(a, b) = a + b" + if Base.VERSION < v"1.10" + @test body == "Foo.Bar.fit(a, b) = a + b" + end end struct CallOverload @@ -414,10 +416,10 @@ end @testset "kwfuncs" begin body, _ = CodeTracking.definition(String, @which fkw(; x=1)) - @test body == """ + @test startswith(body, """ function fkw(; x=1) x - end""" + end""") end @testset "Decorated args" begin @@ -436,12 +438,12 @@ end body, _ = CodeTracking.definition(String, which(hasdefault, (Int, Float32))) @test body == "hasdefault(xd, yd=2) = xd + yd" body, _ = CodeTracking.definition(String, which(hasdefaulttypearg, (Type{Float32},))) - @test body == "hasdefaulttypearg(::Type{T}=Rational{Int}) where T = zero(T)" + @test startswith(body, "hasdefaulttypearg(::Type{T}=Rational{Int}) where T = zero(T)") end @testset "tuple-destructured args" begin body, _ = CodeTracking.definition(String, which(diffminmax, (Any,))) - @test body == "diffminmax((min, max)) = max - min" + @test startswith(body, "diffminmax((min, max)) = max - min") end @testset "strip_gensym with unicode" begin From 149c0d971abae317fcacf5d3e588f43c6c9d8f40 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 4 Aug 2024 16:57:13 -0500 Subject: [PATCH 5/8] Test pre-release --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eef5962..78edf97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ jobs: version: - '1.6' # latest LTS - '1' + - 'pre' - 'nightly' os: - ubuntu-latest From e1998c09eeb359c0ae08866e924811cea529d033 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 4 Aug 2024 17:05:50 -0500 Subject: [PATCH 6/8] Fix a Windows path error on 1.11 --- test/runtests.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index a207f53..81724fa 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -137,7 +137,9 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j idx = findfirst(lin -> String(lin.file) != @__FILE__, src.linetable) lin = src.linetable[idx] file, line = whereis(lin, m) - @test endswith(file, String(lin.file)) + if !Sys.iswindows() + @test endswith(file, String(lin.file)) + end # Issues raised in #48 m = @which(sum([1]; dims=1)) From 20f3d68fbffd89c3cb652959770272750715222a Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 4 Aug 2024 17:31:55 -0500 Subject: [PATCH 7/8] Avoid failure due to noninteractive --- test/runtests.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 81724fa..5d31bee 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -306,11 +306,13 @@ end @test occursin(String(m.file), String(body.args[idx].file)) @test ex == code_expr(gcd, Tuple{Int,Int}) - m = first(methods(edit)) - sigs = signatures_at(String(m.file), m.line) - @test !isempty(sigs) - sigs = signatures_at(Base.find_source_file(String(m.file)), m.line) - @test !isempty(sigs) + if Base.VERSION < v"1.11.0-0" + m = first(methods(edit)) + sigs = signatures_at(String(m.file), m.line) + @test !isempty(sigs) + sigs = signatures_at(Base.find_source_file(String(m.file)), m.line) + @test !isempty(sigs) + end # issue #23 @test !isempty(signatures_at("script.jl", 9)) From ac58faa4e180554da8b59427d29e1d8541616463 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 4 Aug 2024 18:44:01 -0500 Subject: [PATCH 8/8] Skip REPL test on 1.11+ xref https://github.com/JuliaLang/julia/issues/55376 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78edf97..00f02a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: Pkg.test("Revise") ' - name: Test while running Revise - if: ${{ matrix.os == 'ubuntu-latest' && matrix.version != '1.0' }} + if: ${{ matrix.os == 'ubuntu-latest' && (matrix.version == '1.6' || matrix.version == '1') }} run: | TERM="xterm" julia --project -i --code-coverage -e ' using InteractiveUtils, REPL, Revise, Pkg