Skip to content

Commit 525ffa4

Browse files
oxinaboxmzgubic
andauthored
Apply suggestions from code review
Co-authored-by: Miha Zgubic <mzgubic@users.noreply.github.com>
1 parent 439d036 commit 525ffa4

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/check_result.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ All keyword arguments are passed to `isapprox`.
1818
function check_equal(
1919
actual::Union{AbstractArray{<:Number},Number},
2020
expected::Union{AbstractArray{<:Number},Number},
21-
msg="",
22-
;
21+
msg="";
2322
kwargs...,
2423
)
2524
@test_msg msg isapprox(actual, expected; kwargs...)
@@ -74,7 +73,7 @@ function check_equal(actual::AbstractArray, expected::AbstractArray, msg=""; kwa
7473
if _can_pass_early(actual, expected)
7574
@test true
7675
else
77-
@test_msg "$msg: indexes must match" eachindex(actual) == eachindex(expected)
76+
@test_msg "$msg: indices must match" eachindex(actual) == eachindex(expected)
7877
for ii in eachindex(actual)
7978
new_msg = "$msg $(typeof(actual))[$ii]"
8079
check_equal(actual[ii], expected[ii], new_msg; kwargs...)
@@ -124,7 +123,7 @@ end
124123
check_equal(x, y::Tangent, msg=""; kwargs...) = check_equal(y, x, msg; kwargs...)
125124

126125
# This catches comparisons of Tangents and Tuples/NamedTuple
127-
# and gives an error message complaining about that. the `@test` will definately fail
126+
# and gives an error message complaining about that. the `@test` will definitely fail
128127
const LegacyZygoteCompTypes = Union{Tuple,NamedTuple}
129128
function check_equal(x::Tangent, y::LegacyZygoteCompTypes, msg=""; kwargs...)
130129
@test_msg "$msg: for structural differentials use `Tangent`" typeof(x) === typeof(y)

src/output_control.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ julia> @test_msg a sum(1:1000) < 10;
4141
```
4242
"""
4343
macro test_msg(msg, ex, kws...)
44+
# This code is basically a evil hack that accesses the internals of the Test stdlib.
45+
# Code below is based on the `@test` macro definition as it was in Julia 1.6.
46+
# https://github.com/JuliaLang/julia/blob/v1.6.1/stdlib/Test/src/Test.jl#L371-L376
4447
Test.test_expr!("@test_msg msg", ex, kws...)
4548

4649
result = Test.get_test_result(ex, __source__)

0 commit comments

Comments
 (0)