JuliaLang/julia

Lack of type info when `isa` test fails

Open

#31 304 ouverte le 9 mars 2019

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)Julia (5 773 forks)batch import
display and printinghelp wantedtestsystem

Métriques du dépôt

Stars
 (48 709 stars)
Métriques de merge PR
 (Merge moyen 20j 6h) (157 PRs mergées en 30 j)

Description

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> @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).

Guide contributeur