Skip to content

Commit

Permalink
Fix explicit description behavior, add documentation to docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
Seelengrab committed Oct 12, 2021
1 parent dc558ac commit fa7293d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@ end
@testset [CustomTestSet] [option=val ...] ["description"] begin ... end
@testset [CustomTestSet] [option=val ...] ["description \$v"] for v in (...) ... end
@testset [CustomTestSet] [option=val ...] ["description \$v, \$w"] for v in (...), w in (...) ... end
@testset [CustomTestSet] [option=val ...] ["description \$v, \$w"] foo()
Starts a new test set, or multiple test sets if a `for` loop is provided.
Expand All @@ -1241,6 +1242,7 @@ nested testsets is shown even when they all pass (the default is `false`).
The description string accepts interpolation from the loop indices.
If no description is provided, one is constructed based on the variables.
If a function call is provided, its name will be used. Explicit description strings override this behavior.
By default the `@testset` macro will return the testset object itself, though
this behavior can be customized in other testset types. If a `for` loop is used
Expand Down Expand Up @@ -1293,10 +1295,11 @@ Generate the code for a `@testset` with a function call or `begin`/`end` argumen
function testset_beginend_call(args, tests, source)
desc, testsettype, options = parse_testset_args(args[1:end-1])
if desc === nothing
desc = "test set"
end
if tests.head === :call
desc = string(tests.args[1]) # use the function name as test name
if tests.head === :call
desc = string(tests.args[1]) # use the function name as test name
else
desc = "test set"
end
end
# If we're at the top level we'll default to DefaultTestSet. Otherwise
# default to the type of the parent testset
Expand Down
2 changes: 2 additions & 0 deletions stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1250,8 +1250,10 @@ let
end
end
tret = @testset h(1)
tdesc = @testset "description" h(1)
@testset "Function calls" begin
@test tret.description == "h"
@test tdesc.description == "description"
@test length(tret.results) == 5
@test tret.results[1].description == "f"
@test tret.results[2].description == "success"
Expand Down

0 comments on commit fa7293d

Please sign in to comment.