Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

7. `fread()` would not give a warning when every second line of input was empty, [#3339](https://github.com/Rdatatable/data.table/issues/3339). Now, a warning message 'The rows in this file appear to be separated by blank lines.' is given and suggests to set `blank.lines.skip` to `TRUE`. Thanks to @Henrik-P for the report and @Asa-Henry for the fix.

8. `test()` now reports multiple expected warnings more clearly when `warning=` has length greater than 1L, instead of printing a collapsed or repeated mismatch summary after messages like `Test 1 produced 1 warnings but expected 2`, [#7092](https://github.com/Rdatatable/data.table/issues/7092). Expected and observed warnings are now printed on separate aligned lines, making small differences easier to spot. Thanks @MichaelChirico for the report, @ben-schwen for assistance, and @lucaslarson25, @tjdavis51, @D3VTHSTVR, and @car723 for the fix.

### Notes

1. {data.table} now depends on R 3.5.0 (2018).
Expand Down
11 changes: 10 additions & 1 deletion R/test.data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,16 @@ test = function(num, x, y=TRUE,
}
if (length(expected) != length(observed) && (!foreign || is.null(ignore.warning))) {
# nocov start
catf("Test %s produced %d %ss but expected %d\n%s\n%s\n", numStr, length(observed), type, length(expected), paste("Expected:", expected), paste("Observed:", observed, collapse = "\n"))
align_messages = function(label, x) paste(
c(
paste0(label, x[1L]),
if (length(x) > 1L) paste0(strrep(" ", nchar(label)), x[-1L])
),
collapse = "\n"
)
expected_text = align_messages("Expected: ", expected)
observed_text = align_messages("Observed: ", observed)
catf("Test %s produced %d %ss but expected %d\n%s\n%s\n", numStr, length(observed), type, length(expected), expected_text, observed_text)
fail = TRUE
# nocov end
} else if (!foreign) {
Expand Down
6 changes: 6 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -21607,3 +21607,9 @@ test(2370.2, yearmon(x, format="numeric"), yearmon(x)) # numeric is the default
test(2370.3, yearmon(x, format="character"), c("1111M11", "2019M01", "2019M02", "2019M03", "2019M12", "2020M02", "2020M03", "2020M12", "2040M01", "2040M12", "2100M03", NA_character_))
test(2370.4, yearmon("2016-08-03 01:02:03.45", format="character"), "2016M08")
test(2370.5, yearmon(NA, format="character"), NA_character_)

# multiple expected/observed warnings in test() are printed on aligned lines, #7092
test(2371.1, test(0, {warning("a"); 2L}, 2L, warning=c("a", "b")), FALSE,
output="Test 0 produced 1 warnings but expected 2\nExpected: a\n b\nObserved: a")
test(2372.2, test(0, {warning("a"); warning("b"); 2L}, 2L, warning="a"), FALSE,
output="Test 0 produced 2 warnings but expected 1\nExpected: a\nObserved: a\n b")
Loading