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.
Unlike
expect_known_output(), which lets you pass awidthargument,expect_output()has a hard-coded 80-character width. Even thoughcapture_output()does take a width arg,expect_output()callsquasi_capture(), which callscapture_output()with no additional args, so you can't pass it through.Here's a test that illustrates:
The width check inside of
expect_outputfails: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_optionssetting from where it is insideeval_with_outputtotest_file()or somewhere higher so that you can control print width options within your test files normally usingoptions(width = whatever). You could also extendexpect_outputto have a width argument to matchexpect_known_output, but I suspect that's a bigger refactor.