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

Closed
nealrichardson opened this issue Oct 3, 2018 · 1 comment
Closed

expect_output doesn't let you control console width #805

nealrichardson opened this issue Oct 3, 2018 · 1 comment
Labels
expectation 🙀 feature a feature request or enhancement

Comments

@nealrichardson
Copy link

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:

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

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.

@hadley hadley added feature a feature request or enhancement expectation 🙀 labels Mar 28, 2019
@hadley
Copy link
Member

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 as completed in f5ca5c9 Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expectation 🙀 feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants