Julia: Lack of type info when `isa` test fails

Created on 9 Mar 2019  Â·  4Comments  Â·  Source: JuliaLang/julia

When @test x isa Thing fails it can show output that _looks_ like it should have passed, because it does not print the type of x.

Here's an example [using Julia 1.1.0]:

julia> using Distributions, LinearAlgebra, Test

julia> covt(x) = cov(x)'   # means we will get an `Adjoint` 
covt (generic function with 1 method)

julia> z = MvNormal(2, 1);

julia> @test covt(z) isa Matrix
Test Failed at REPL[12]:1
  Expression: covt(z) isa Matrix
   Evaluated: [1.0 0.0; 0.0 1.0] isa Array{T,2} where T
ERROR: There was an error during testing
````
This is confusing because if you copy and paste the "Evaluated: ..." code in to a test it will pass
```julia
julia> @test [1.0 0.0; 0.0 1.0] isa Array{T,2} where T
Test Passed

It may be more informative if the output of the failed test was more like

julia> @test covt(z) isa Matrix
Test Failed at REPL[12]:1
  Expression: covt(z) isa Matrix
   Evaluated: Adjoint{Float64,Array{Float64,2}} <: Array{T,2} where T
ERROR: There was an error during testing

(where Evaluiated: could show <: rather than isa, since (Array{Float64,2} isa Array{T,2} where T) == false).

display and printing help wanted testsystem

All 4 comments

Related https://github.com/JuliaLang/julia/pull/30721 -- but I don't think this exact issue was addressed? Not sure. I see this issue got closed https://github.com/JuliaLang/julia/issues/26882

Yes, seems like it would be better to print the type gotten than the value gotten even.

Sorry, for my mistakes, messages and tests were false, if it's OK I can do this:
(1)

julia> @test covt(z) isa Matrix
Test Failed at REPL[12]:1
  Expression: covt(z) isa Matrix
   Evaluated: [1.0 0.0; 0.0 1.0]::Adjoint{Float64,Array{Float64,2}} isa Array{T,2} where T
ERROR: There was an error during testing

Or (2)

julia> @test covt(z) isa Matrix
Test Failed at REPL[12]:1
  Expression: covt(z) isa Matrix
   Evaluated: Adjoint{Float64,Array{Float64,2}}([1.0 0.0; 0.0 1.0]) isa Array{T,2} where T
ERROR: There was an error during testing

if it makes sense.

We may just want to print the type as the values in this case are not providing useful and are most likely obfuscating the reason for the test failure.

Was this page helpful?
0 / 5 - 0 ratings