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

incorrect behaviour of expect_output()? #323

Closed
famuvie opened this Issue Nov 22, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@famuvie

famuvie commented Nov 22, 2015

tf <- function() cat('my output')  # test function
expect_output(tf(), 'output')       # passes, as expected
expect_output(tf(), 'xxx')            # error, as expected
# Error: tf() does not match 'xxx'. Actual value: "my output"
expect_output(tf(), NA)              # passes. Expected error. 
expect_output(tf())                     # fails. Expected pass. 
# Error in identical(regexp, NA) : 
#   argument "regexp" missing, without default value
packageVersion('testthat')
# [1] ‘0.11.0.9000’

In the last two expectations:

  • NA means expect no output, however, it passes.
  • omitted regexp means expect some output, however it fails.
@richierocks

This comment has been minimized.

richierocks commented Feb 6, 2016

I can reproduce that the documentation doesn't match the behaviour when regexp is missing.

You can use regexp = "" to match anything as a workaround.

@hadley

This comment has been minimized.

Member

hadley commented Feb 18, 2016

Hmmm, the problem with expect_output(tf(), NA) is that expect_output() always prints the input, so as far as I can tell there's no case in which code won't create output.

@hadley

This comment has been minimized.

Member

hadley commented Feb 18, 2016

Hmmm, the problem with expect_output(tf(), NA) is that expect_output() always prints the input, so as far as I can tell there's no case in which code won't create output.

I'm thinking the next version of testthat will be 1.0.0 so it's probably ok to change this behaviour to force the user to print() the object if they want to inspect the output.

@hadley hadley closed this in 9ae7c4f Feb 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment