Skip to content

Commit 24baa93

Browse files
committed
tests: Improve test_throws_unwrap error comparisons
1 parent ed05ae9 commit 24baa93

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

test/thunk.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ end
6969
A = rand(4, 4)
7070
@test fetch(@spawn sum(A; dims=1)) sum(A; dims=1)
7171

72-
@test_throws_unwrap Dagger.ThunkFailedException fetch(@spawn sum(A; fakearg=2))
72+
@test_throws_unwrap (Dagger.ThunkFailedException, MethodError) fetch(@spawn sum(A; fakearg=2))
7373

7474
@test fetch(@spawn reduce(+, A; dims=1, init=2.0))
7575
reduce(+, A; dims=1, init=2.0)
@@ -187,7 +187,7 @@ end
187187
a = @spawn error("Test")
188188
wait(a)
189189
@test isready(a)
190-
@test_throws_unwrap Dagger.ThunkFailedException fetch(a)
190+
@test_throws_unwrap (Dagger.ThunkFailedException, ErrorException) fetch(a)
191191
b = @spawn 1+2
192192
@test fetch(b) == 3
193193
end
@@ -219,36 +219,36 @@ end
219219
@testset "single dependent" begin
220220
a = @spawn error("Test")
221221
b = @spawn a+2
222-
@test_throws_unwrap Dagger.ThunkFailedException fetch(a)
222+
@test_throws_unwrap (Dagger.ThunkFailedException, ErrorException) fetch(a)
223223
end
224224
@testset "multi dependent" begin
225225
a = @spawn error("Test")
226226
b = @spawn a+2
227227
c = @spawn a*2
228-
@test_throws_unwrap Dagger.ThunkFailedException fetch(b)
229-
@test_throws_unwrap Dagger.ThunkFailedException fetch(c)
228+
@test_throws_unwrap (Dagger.ThunkFailedException, ErrorException) fetch(b)
229+
@test_throws_unwrap (Dagger.ThunkFailedException, ErrorException) fetch(c)
230230
end
231231
@testset "dependent chain" begin
232232
a = @spawn error("Test")
233-
@test_throws_unwrap Dagger.ThunkFailedException fetch(a)
233+
@test_throws_unwrap (Dagger.ThunkFailedException, ErrorException) fetch(a)
234234
b = @spawn a+1
235-
@test_throws_unwrap Dagger.ThunkFailedException fetch(b)
235+
@test_throws_unwrap (Dagger.ThunkFailedException, ErrorException) fetch(b)
236236
c = @spawn b+2
237-
@test_throws_unwrap Dagger.ThunkFailedException fetch(c)
237+
@test_throws_unwrap (Dagger.ThunkFailedException, ErrorException) fetch(c)
238238
end
239239
@testset "single input" begin
240240
a = @spawn 1+1
241241
b = @spawn (a->error("Test"))(a)
242242
@test fetch(a) == 2
243-
@test_throws_unwrap Dagger.ThunkFailedException fetch(b)
243+
@test_throws_unwrap (Dagger.ThunkFailedException, ErrorException) fetch(b)
244244
end
245245
@testset "multi input" begin
246246
a = @spawn 1+1
247247
b = @spawn 2*2
248248
c = @spawn ((a,b)->error("Test"))(a,b)
249249
@test fetch(a) == 2
250250
@test fetch(b) == 4
251-
@test_throws_unwrap Dagger.ThunkFailedException fetch(c)
251+
@test_throws_unwrap (Dagger.ThunkFailedException, ErrorException) fetch(c)
252252
end
253253
@testset "diamond" begin
254254
a = @spawn 1+1
@@ -258,7 +258,7 @@ end
258258
@test fetch(a) == 2
259259
@test fetch(b) == 3
260260
@test fetch(c) == 4
261-
@test_throws_unwrap Dagger.ThunkFailedException fetch(d)
261+
@test_throws_unwrap (Dagger.ThunkFailedException, ErrorException) fetch(d)
262262
end
263263
end
264264
@testset "remote spawn" begin
@@ -276,7 +276,7 @@ end
276276
t1 = Dagger.@spawn 1+"fail"
277277
Dagger.@spawn t1+1
278278
end
279-
@test_throws_unwrap Dagger.ThunkFailedException fetch(t2)
279+
@test_throws_unwrap (Dagger.ThunkFailedException, ErrorException) fetch(t2)
280280
end
281281
@testset "undefined function" begin
282282
# Issues #254, #255

test/util.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414
replace_obj!(ex::Symbol, obj) = Expr(:(.), obj, QuoteNode(ex))
1515
replace_obj!(ex, obj) = ex
1616
function _test_throws_unwrap(terr, ex; to_match=[])
17-
@gensym rerr
17+
@gensym oerr rerr
1818
match_expr = Expr(:block)
1919
for m in to_match
2020
if m.head == :(=)
@@ -35,12 +35,17 @@ function _test_throws_unwrap(terr, ex; to_match=[])
3535
end
3636
end
3737
quote
38-
$rerr = try
38+
$oerr, $rerr = try
3939
$(esc(ex))
4040
catch err
41-
Dagger.Sch.unwrap_nested_exception(err)
41+
(err, Dagger.Sch.unwrap_nested_exception(err))
42+
end
43+
if $terr isa Exception
44+
@test $rerr isa $terr
45+
else $terr isa Tuple
46+
@test $oerr isa $terr[1]
47+
@test $rerr isa $terr[2]
4248
end
43-
@test $rerr isa $terr
4449
$match_expr
4550
end
4651
end

0 commit comments

Comments
 (0)