-
Notifications
You must be signed in to change notification settings - Fork 316
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
Preserve empty lines in snapshot output #1524
Conversation
The root cause is that some conditions implicitly add a trailing new line, and some implicitly swallow a trailing new line. This now matches the behaviour I see on the console. |
FWIW this PR does not fix the test cases in cli. After removing the temporary
Is this expected? |
@gaborcsardi do you mind boiling that down to a more minimal reprex? I find it hard to reason about exactly what should occur given all the |
This test was actually not broken in version 3.1.1, but this PR breaks it. It is not about Examplelibrary(testthat)
testthat::test_that("snapshots and whitespace", {
local_edition(3)
msgs <- list("start\n", "\n\n", "until here\n", "\n\n",
"still\n", "\n\n", "again\n")
expect_snapshot(local({
for (m in msgs) message(m, domain = NA, appendLF = FALSE)
}))
}) testthat 3.1.1 output
testthat #1524 output
|
I think this PR is correct, because when I run this at the console I see:
But I think evaluate or knitr gets it wrong because this is the reprex: msgs <- list("start\n", "\n\n", "until here\n", "\n\n",
"still\n", "\n\n", "again\n")
local({
for (m in msgs) message(m, domain = NA, appendLF = FALSE)
})
#> start
#>
#> until here
#>
#> still
#>
#> again Created on 2022-01-05 by the reprex package (v2.0.1) |
i.e. this is wrong: msgs <- c("line 1", "\n", "line 4")
local({
for (m in msgs) message(m)
})
#> line 1
#>
#> line 4 Created on 2022-01-05 by the reprex package (v2.0.1) |
I guess I'm seeing the effects of r-lib/testthat#1509 r-lib/testthat#1524
* Let's get a baseline before introducing real change I predict test failure, due to changes in testthat 3.1.2. * Re-establish the organization, with printing tests in the printing section * Update col_spec tests (at least for edition 2) * Update col spec test snapshots for edition 1 * Update first edition snapsots for whitespace I guess I'm seeing the effects of r-lib/testthat#1509 r-lib/testthat#1524
Fixes #1509