Skip to content

Commit 85bf86e

Browse files
committed
Test for DimensionError
1 parent 1d96e15 commit 85bf86e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ tryrationalize(::Type{R}, x::R) where {R} = x
8686
tryrationalize(::Type{R}, x::Union{Rational,Integer}) where {R} = convert(R, x)
8787
tryrationalize(::Type{R}, x) where {R} = isinteger(x) ? convert(R, round(Int, x)) : convert(R, rationalize(Int, x))
8888

89-
Base.showerror(io::IO, e::DimensionError) = print(io, "DimensionError: ", e.q1, " and ", e.q2, " have different dimensions")
89+
Base.showerror(io::IO, e::DimensionError) = print(io, "DimensionError: ", e.q1, " and ", e.q2, " have incompatible dimensions")
9090

9191
"""
9292
ustrip(q::Quantity)

test/unittests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ using Test
4141

4242
@test_throws DimensionError x^2 + x
4343

44+
# Check output of error:
45+
try
46+
x^2 + x
47+
@test false
48+
catch e
49+
r"DimensionError: .* and .* have incompatible dimensions."
50+
io = IOBuffer()
51+
showerror(io, e)
52+
msg = String(take!(io))
53+
@test occursin("DimensionError", msg)
54+
@test occursin("incompatible dimensions", msg)
55+
end
4456

4557
y = inv(x)
4658

0 commit comments

Comments
 (0)