Skip to content
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

Merged
merged 1 commit into from
Jul 26, 2022
Merged

Print more context for complex test conditions #46138

merged 1 commit into from
Jul 26, 2022

Conversation

Keno
Copy link
Member

@Keno Keno commented Jul 22, 2022

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

@Keno Keno requested review from staticfloat and DilumAluthge July 22, 2022 07:28
@Keno Keno force-pushed the kf/testsetlet branch 3 times, most recently from 5ff7ef6 to d90db4b Compare July 22, 2022 11:18
@Keno Keno requested a review from IanButterworth July 22, 2022 16:56
source,
message_only)
end
end

# Fallback constructor without `context` argument (added in Julia 1.9). Remove in Julia 2.0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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)

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)
Copy link
Member

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?

Copy link
Member Author

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.

@DilumAluthge DilumAluthge added testsystem The unit testing framework and Test stdlib stdlib Julia's standard library labels Jul 23, 2022
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
@DilumAluthge
Copy link
Member

Should we add this to NEWS?

ffucci pushed a commit to ffucci/julia that referenced this pull request Aug 11, 2022
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
pcjentsch pushed a commit to pcjentsch/julia that referenced this pull request Aug 18, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Julia's standard library testsystem The unit testing framework and Test stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants