Skip to content

Commit

Permalink
mark svd test as broken on v1.6 and later & swap between @test an…
Browse files Browse the repository at this point in the history
…d `@test_broken` for `abstractarray.jl` tests
  • Loading branch information
thchr committed Jun 24, 2021
1 parent 8ce8a8c commit b37f31b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
16 changes: 9 additions & 7 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,21 @@ using StaticArrays, Test, LinearAlgebra
@test @inferred(convert(AbstractArray{Float64}, diag)) isa Diagonal{Float64,SVector{2,Float64}}
@test convert(AbstractArray{Float64}, diag) == diag
# The following cases currently convert the SMatrix into an MMatrix, because
# the constructor in Base invokes `similar`, rather than `convert`, on the static array
# the constructor in Base invokes `similar`, rather than `convert`, on the static
# array. This was fixed in https://github.com/JuliaLang/julia/pull/40831; so should
# work from Julia v1.8.0-DEV.55
trans = Transpose(SVector(1,2))
@test_broken @inferred(convert(AbstractArray{Float64}, trans)) isa Transpose{Float64,SVector{2,Float64}}
@test_was_once_broken v"1.8.0-DEV.55" @inferred(convert(AbstractArray{Float64}, trans)) isa Transpose{Float64,SVector{2,Float64}}
adj = Adjoint(SVector(1,2))
@test_broken @inferred(convert(AbstractArray{Float64}, adj)) isa Adjoint{Float64,SVector{2,Float64}}
@test_was_once_broken v"1.8.0-DEV.55" @inferred(convert(AbstractArray{Float64}, adj)) isa Adjoint{Float64,SVector{2,Float64}}
uptri = UpperTriangular(SA[1 2; 0 3])
@test_broken @inferred(convert(AbstractArray{Float64}, uptri)) isa UpperTriangular{Float64,SMatrix{2,2,Float64,4}}
@test_was_once_broken v"1.8.0-DEV.55" @inferred(convert(AbstractArray{Float64}, uptri)) isa UpperTriangular{Float64,SMatrix{2,2,Float64,4}}
lotri = LowerTriangular(SA[1 0; 2 3])
@test_broken @inferred(convert(AbstractArray{Float64}, lotri)) isa LowerTriangular{Float64,SMatrix{2,2,Float64,4}}
@test_was_once_broken v"1.8.0-DEV.55" @inferred(convert(AbstractArray{Float64}, lotri)) isa LowerTriangular{Float64,SMatrix{2,2,Float64,4}}
unituptri = UnitUpperTriangular(SA[1 2; 0 1])
@test_broken @inferred(convert(AbstractArray{Float64}, unituptri)) isa UnitUpperTriangular{Float64,SMatrix{2,2,Float64,4}}
@test_was_once_broken v"1.8.0-DEV.55" @inferred(convert(AbstractArray{Float64}, unituptri)) isa UnitUpperTriangular{Float64,SMatrix{2,2,Float64,4}}
unitlotri = UnitLowerTriangular(SA[1 0; 2 1])
@test_broken @inferred(convert(AbstractArray{Float64}, unitlotri)) isa UnitLowerTriangular{Float64,SMatrix{2,2,Float64,4}}
@test_was_once_broken v"1.8.0-DEV.55" @inferred(convert(AbstractArray{Float64}, unitlotri)) isa UnitLowerTriangular{Float64,SMatrix{2,2,Float64,4}}
end
end

Expand Down
8 changes: 6 additions & 2 deletions test/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ using StaticArrays, Test, LinearAlgebra
@testinf svd(m_sing2'; full=Val(true)) \ v2 svd(Matrix(m_sing2'); full=true) \ Vector(v2)
@testinf svd(m_sing2; full=Val(true)) \ m23' svd(Matrix(m_sing2); full=true) \ Matrix(m23')
@testinf svd(m_sing2'; full=Val(true)) \ m23 svd(Matrix(m_sing2'); full=true) \ Matrix(m23)
if v"1.6" > VERSION >= v"1.5-DEV"
if VERSION >= v"1.5"
# Test that svd of rectangular matrix is inferred.
# Note the placement of @inferred brackets is important.
#
# This only seems to work on v"1.5" due to unknown compiler improvements; seems
# to have stopped working again on v"1.6" and later?
svd_full_false(A) = svd(A, full=false)
@test @inferred(svd_full_false(m_sing2)).S svd(Matrix(m_sing2)).S
if VERSION < v"1.6"
@test @inferred(svd_full_false(m_sing2)).S svd(Matrix(m_sing2)).S
else
@test_broken @inferred(svd_full_false(m_sing2)).S svd(Matrix(m_sing2)).S
end
end

@testinf svd(mc_sing) \ v svd(Matrix(mc_sing)) \ Vector(v)
Expand Down
17 changes: 17 additions & 0 deletions test/testutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ macro inferred_maybe_allow(allow, ex)
end
end

"""
@test_was_once_broken good_version ex
Expands to `@test ex` if `VERSION ≥ good_version` and to `@test_broken ex` if
`VERSION ≥ good_version`. Useful for tests that are broken on earlier versions of Julia
that are fixed on later versions.
"""
macro test_was_once_broken(good_version, ex)
esc(quote
if VERSION < $good_version
@test_broken $ex
else
@test $ex
end
end)
end

@testset "test utils" begin
@testset "@testinf" begin
@testinf [1,2] == [1,2]
Expand Down

0 comments on commit b37f31b

Please sign in to comment.