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

expect_output doesn't let you control console width #805

nealrichardson opened this issue Oct 3, 2018 · 1 comment

expect_output doesn't let you control console width #805

nealrichardson opened this issue Oct 3, 2018 · 1 comment


Copy link

@nealrichardson nealrichardson commented Oct 3, 2018

Unlike expect_known_output(), which lets you pass a width argument, expect_output() has a hard-coded 80-character width. Even though capture_output() does take a width arg, expect_output() calls quasi_capture(), which calls capture_output() with no additional args, so you can't pass it through.

Here's a test that illustrates:

test_that("expect_output respects 'width'", {
    withr::local_options(list(width = 10))
    expect_equal(getOption("width"), 10)
        expect_equal(getOption("width"), 10),

The width check inside of expect_output fails:

debug: .1.

══ Failed ══════════════════════════════════════════════════════════════════════
── 1. Failure: expect_output respects 'width' (@test-debug.R#5)  ───────────────
getOption("width") not equal to 10.
1/1 mismatches
[1] 80 - 10 == 70

I'm happy to submit a patch if you can provide guidance on where you'd like it solved. My instinct would be to move the withr::local_options setting from where it is inside eval_with_output to test_file() or somewhere higher so that you can control print width options within your test files normally using options(width = whatever). You could also extend expect_output to have a width argument to match expect_known_output, but I suspect that's a bigger refactor.

Copy link

@hadley hadley commented Mar 28, 2019

I think the right fix is to add an explicit width option to expect_output(). I don't think you want to inherit the width from your options because that might differ from system to system, leading to spurious failures.

@hadley hadley added this to the testthat 2.1.0 milestone Apr 1, 2019
@hadley hadley closed this in f5ca5c9 Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants