JuliaLang/julia

Lack of type info when `isa` test fails

Open

#31,304 创建于 2019年3月9日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)Julia (5,773 fork)batch import
display and printinghelp wantedtestsystem

仓库指标

Star
 (48,709 star)
PR 合并指标
 (平均合并 20天 6小时) (30 天内合并 157 个 PR)

描述

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

贡献者指南