-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print more context for complex test conditions #46138
Conversation
5ff7ef6
to
d90db4b
Compare
stdlib/Test/src/Test.jl
Outdated
source, | ||
message_only) | ||
end | ||
end | ||
|
||
# Fallback constructor without `context` argument (added in Julia 1.9). Remove in Julia 2.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Fallback constructor without `context` argument (added in Julia 1.9). Remove in Julia 2.0. | |
# Deprecated fallback constructor without `context` argument (added in Julia 1.9). Remove in Julia 2.0. |
(will make it easier to grep for later)
stdlib/Test/src/Test.jl
Outdated
source::LineNumberNode | ||
message_only::Bool | ||
function Fail(test_type::Symbol, orig_expr, data, value, source::LineNumberNode, message_only::Bool=false) | ||
function Fail(test_type::Symbol, orig_expr, data, value, context, source::LineNumberNode, message_only::Bool=false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If context
is set to a LineNumberNode (let source=@__SOURCE__
), it will call the wrong (the deprecated) function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I'll remove the =false
for now to make it explicit.
On some failures, e.g. in the cmdlineargs failure in [1], printing the failing expression doesn't give us very much information, because what we're doing is just testing a small part of a larger structure, but to really diagnose the failure, we'd really want to see the whole structure (in this case the stderr output, not just the failure bool). This introduces an additional `@testset` feature that lets failures optionally include a context variable that gets printed on failure. Example: ``` julia> @testset let v=(1,2,3) @test v[1] == 1 @test v[2] == 3 end Test Failed at REPL[8]:3 Expression: v[2] == 3 Evaluated: 2 == 3 Context: v = (1, 2, 3) ERROR: There was an error during testing ``` The syntax here is `@testset let`, which was previously unused. The testset is transparent and failures/successes are passed through directly to the parent testset. In particular, using this kind of testset does not cause additional nesting in the default testset print. [1] https://buildkite.com/julialang/julia-master/builds/14160#01822311-84f0-467a-a8af-a5d751f2c6ab/448-728
Should we add this to NEWS? |
On some failures, e.g. in the cmdlineargs failure in [1], printing the failing expression doesn't give us very much information, because what we're doing is just testing a small part of a larger structure, but to really diagnose the failure, we'd really want to see the whole structure (in this case the stderr output, not just the failure bool). This introduces an additional `@testset` feature that lets failures optionally include a context variable that gets printed on failure. Example: ``` julia> @testset let v=(1,2,3) @test v[1] == 1 @test v[2] == 3 end Test Failed at REPL[8]:3 Expression: v[2] == 3 Evaluated: 2 == 3 Context: v = (1, 2, 3) ERROR: There was an error during testing ``` The syntax here is `@testset let`, which was previously unused. The testset is transparent and failures/successes are passed through directly to the parent testset. In particular, using this kind of testset does not cause additional nesting in the default testset print. [1] https://buildkite.com/julialang/julia-master/builds/14160#01822311-84f0-467a-a8af-a5d751f2c6ab/448-728
On some failures, e.g. in the cmdlineargs failure in [1], printing the failing expression doesn't give us very much information, because what we're doing is just testing a small part of a larger structure, but to really diagnose the failure, we'd really want to see the whole structure (in this case the stderr output, not just the failure bool). This introduces an additional `@testset` feature that lets failures optionally include a context variable that gets printed on failure. Example: ``` julia> @testset let v=(1,2,3) @test v[1] == 1 @test v[2] == 3 end Test Failed at REPL[8]:3 Expression: v[2] == 3 Evaluated: 2 == 3 Context: v = (1, 2, 3) ERROR: There was an error during testing ``` The syntax here is `@testset let`, which was previously unused. The testset is transparent and failures/successes are passed through directly to the parent testset. In particular, using this kind of testset does not cause additional nesting in the default testset print. [1] https://buildkite.com/julialang/julia-master/builds/14160#01822311-84f0-467a-a8af-a5d751f2c6ab/448-728
On some failures, e.g. in the cmdlineargs failure in [1],
printing the failing expression doesn't give us very much
information, because what we're doing is just testing a
small part of a larger structure, but to really diagnose
the failure, we'd really want to see the whole structure
(in this case the stderr output, not just the failure bool).
This introduces an additional
@testset
feature that letsfailures optionally include a context variable that gets printed
on failure. Example:
The syntax here is
@testset let
, which was previously unused.The testset is transparent and failures/successes are passed
through directly to the parent testset. In particular, using
this kind of testset does not cause additional nesting in
the default testset print.
[1] https://buildkite.com/julialang/julia-master/builds/14160#01822311-84f0-467a-a8af-a5d751f2c6ab/448-728