@@ -1351,11 +1351,11 @@ function _check_testset(testsettype, testsetname)
1351
1351
end
1352
1352
1353
1353
"""
1354
- @testset [CustomTestSet] [option=val ...] ["description"] begin ... end
1355
- @testset [CustomTestSet] [option=val ...] ["description \$ v"] for v in (...) ... end
1356
- @testset [CustomTestSet] [option=val ...] ["description \$ v, \$ w"] for v in (...) , w in (...) ... end
1357
- @testset [CustomTestSet] [option=val ...] ["description"] foo ()
1358
- @testset let v = (...) ... end
1354
+ @testset [CustomTestSet] [options ...] ["description"] begin test_ex end
1355
+ @testset [CustomTestSet] [options ...] ["description \$ v"] for v in itr test_ex end
1356
+ @testset [CustomTestSet] [options ...] ["description \$ v, \$ w"] for v in itrv , w in itrw test_ex end
1357
+ @testset [CustomTestSet] [options ...] ["description"] test_func ()
1358
+ @testset let v = v, w = w; test_ex; end
1359
1359
1360
1360
# With begin/end or function call
1361
1361
@@ -1380,7 +1380,7 @@ accepts three boolean options:
1380
1380
This can also be set globally via the env var `JULIA_TEST_FAILFAST`.
1381
1381
1382
1382
!!! compat "Julia 1.8"
1383
- `@testset foo ()` requires at least Julia 1.8.
1383
+ `@testset test_func ()` requires at least Julia 1.8.
1384
1384
1385
1385
!!! compat "Julia 1.9"
1386
1386
`failfast` requires at least Julia 1.9.
@@ -1436,6 +1436,9 @@ parent test set (with the context object appended to any failing tests.)
1436
1436
!!! compat "Julia 1.9"
1437
1437
`@testset let` requires at least Julia 1.9.
1438
1438
1439
+ !!! compat "Julia 1.10"
1440
+ Multiple `let` assignements are supported since Julia 1.10.
1441
+
1439
1442
## Examples
1440
1443
```jldoctest
1441
1444
julia> @testset let logi = log(im)
@@ -1446,6 +1449,17 @@ Test Failed at none:3
1446
1449
Expression: !(iszero(real(logi)))
1447
1450
Context: logi = 0.0 + 1.5707963267948966im
1448
1451
1452
+ ERROR: There was an error during testing
1453
+
1454
+ julia> @testset let logi = log(im), op = !iszero
1455
+ @test imag(logi) == π/2
1456
+ @test op(real(logi))
1457
+ end
1458
+ Test Failed at none:3
1459
+ Expression: op(real(logi))
1460
+ Context: logi = 0.0 + 1.5707963267948966im
1461
+ op = !iszero
1462
+
1449
1463
ERROR: There was an error during testing
1450
1464
```
1451
1465
"""
@@ -1477,30 +1491,46 @@ trigger_test_failure_break(@nospecialize(err)) =
1477
1491
"""
1478
1492
Generate the code for an `@testset` with a `let` argument.
1479
1493
"""
1480
- function testset_context (args, tests , source)
1494
+ function testset_context (args, ex , source)
1481
1495
desc, testsettype, options = parse_testset_args (args[1 : end - 1 ])
1482
1496
if desc != = nothing || testsettype != = nothing
1483
1497
# Reserve this syntax if we ever want to allow this, but for now,
1484
1498
# just do the transparent context test set.
1485
1499
error (" @testset with a `let` argument cannot be customized" )
1486
1500
end
1487
1501
1488
- assgn = tests. args[1 ]
1489
- if ! isa (assgn, Expr) || assgn. head != = :(= )
1490
- error (" `@testset let` must have exactly one assignment" )
1502
+ let_ex = ex. args[1 ]
1503
+
1504
+ if Meta. isexpr (let_ex, :(= ))
1505
+ contexts = Any[let_ex. args[1 ]]
1506
+ elseif Meta. isexpr (let_ex, :block )
1507
+ contexts = Any[]
1508
+ for assign_ex in let_ex. args
1509
+ if Meta. isexpr (assign_ex, :(= ))
1510
+ push! (contexts, assign_ex. args[1 ])
1511
+ else
1512
+ error (" Malformed `let` expression is given" )
1513
+ end
1514
+ end
1515
+ else
1516
+ error (" Malformed `let` expression is given" )
1491
1517
end
1492
- assignee = assgn. args[1 ]
1518
+ reverse! (contexts)
1519
+
1520
+ test_ex = ex. args[2 ]
1493
1521
1494
- tests. args[2 ] = quote
1495
- $ push_testset ($ (ContextTestSet)($ (QuoteNode (assignee)), $ assignee; $ options... ))
1522
+ ex. args[2 ] = quote
1523
+ $ (map (contexts) do context
1524
+ :($ push_testset ($ (ContextTestSet)($ (QuoteNode (context)), $ context; $ options... )))
1525
+ end ... )
1496
1526
try
1497
- $ (tests . args[ 2 ] )
1527
+ $ (test_ex )
1498
1528
finally
1499
- $ pop_testset ()
1529
+ $ ( map (_ -> :( $ pop_testset ()), contexts) ... )
1500
1530
end
1501
1531
end
1502
1532
1503
- return esc (tests )
1533
+ return esc (ex )
1504
1534
end
1505
1535
1506
1536
"""
0 commit comments