julia
0a1393f6 - Add ability to test_logs against kwargs.

Commit
3 years ago
Add ability to test_logs against kwargs. Currently, you cannot use `@test_logs` to test a log message's keyword arguments. This extends `@test_logs` to let you do this. Additionally, while I was here, I also changed `@test_logs` itself to let you specify _patterns_ using keyword args / NamedTuples, so that you can more easily specify parts of the LogRecord that come at the end (like the `kwargs`). Here is an example of a log message with kwargs: ```julia julia> @info "hi" x=2 ┌ Info: hi └ x = 2 ``` Which produces this LogRecord: ```julia LogRecord(Info, "hi", Main, Symbol("REPL[5]"), :Main_c95d07ae, "REPL[5]", 2, Base.Pairs(:x => 2)) ``` After this PR, you can test for this kind of log message by matching the `:kwargs` field to `@test_logs`: ```julia @test_logs (:info, "hi", Test.Ignored(), Test.Ignored(), Test.Ignored(), Test.Ignored(), Test.Ignored(), (;y=3)) @info("hi", x=2) ``` But obviously the above is way verbose, so as I described in the second paragraph, this PR also adds the following shorter syntax: ```julia @test_logs (level=:info, message="hi", kwargs=(;x=2)) @info("hi", x=2) ``` Also updated the docstring.
Author
Committer
Parents
Loading