Skip to content

Capturing multiple messages (or lack thereof) #2324

@MichaelChirico

Description

@MichaelChirico

I'm writing two kinds of test: (1) that multiple messages are produced; (2) that exactly one message is produced.

It doesn't seem to be possible at the moment.

expect_message(message('hi')) # ok
expect_message(message('hi'), 'hi') # ok
expect_no_message(expect_message(message('hi'))) # ostensibly ok
expect_no_message(expect_message(message('hi'), 'hi')) # ostensibly ok

# now some cases where the behavior is less as expected

# might expect the 'bye' message to result here
expect_message({ message('hi'); message('bye') }, 'hi') # no output

expect_message(expect_message({ message('hi'); message('bye') }))
# Error: Expected `expect_message(...)` to produce messages.

# expectation: the 'hi' message is caught while the 'bye' message bubbles up
expect_message(expect_message({ message('hi'); message('bye') }, 'hi'))
# Error: Expected `expect_message(...)` to produce messages.

expect_no_message(expect_message({ message('hi'); message('bye') }, 'hi'))
# passes, but might expect the uncaught 'bye' to fail

I think it mostly comes down to this example: expect_message({ message('hi'); message('bye') }, 'hi') # no output.

The same happens with other signal classes: expect_warning({ warning('hi'); warning('bye') }, 'hi'). But I thought I remembered needing nested expect_warning() in the past?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions