Skip to content
Open
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 @@ -24,6 +24,8 @@

3. Vignettes are now built using `litedown` instead of `knitr`, [#6394](https://github.com/Rdatatable/data.table/issues/6394). Thanks @jangorecki for the suggestion and @ben-schwen and @aitap for the implementation.

4. `test()` gains new argument `requires_utf8` to skip tests when UTF-8 support is not available, [#7336](https://github.com/Rdatatable/data.table/issues/7336). Thanks @MichaelChirico for the suggestion and @ben-schwen for the implementation.

### BUG FIXES

1. `fread()` with `skip=0` and `(header=TRUE|FALSE)` no longer skips the first row when it has fewer fields than subsequent rows, [#7463](https://github.com/Rdatatable/data.table/issues/7463). Thanks @emayerhofer for the report and @ben-schwen for the fix.
Expand Down
18 changes: 17 additions & 1 deletion R/test.data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,12 @@ gc_mem = function() {
# nocov end
}

utf8_check = function(test_str) identical(test_str, enc2native(test_str))

test = function(num, x, y=TRUE,
error=NULL, warning=NULL, message=NULL, output=NULL, notOutput=NULL, ignore.warning=NULL,
options=NULL, env=NULL,
context=NULL) {
context=NULL, requires_utf8=FALSE) {
if (!is.null(env)) {
old = Sys.getenv(names(env), names=TRUE, unset=NA)
to_unset = !lengths(env)
Expand All @@ -387,6 +389,20 @@ test = function(num, x, y=TRUE,
Sys.unsetenv(names(old)[!is_preset])
}, add=TRUE)
}
# Check UTF-8 requirement
if (!isFALSE(requires_utf8)) {
test_str = if (isTRUE(requires_utf8)) "\u00F1\u00FC\u3093" else requires_utf8
if (!utf8_check(test_str)) {
# nocov start
last_utf8_skip = get0("last_utf8_skip", parent.frame(), ifnotfound=0, inherits=TRUE)
if (num - last_utf8_skip >= 1) {
catf("Test %s skipped because required UTF-8 symbols cannot be represented in native encoding.\n", num)
}
assign("last_utf8_skip", num, parent.frame(), inherits=TRUE)
return(invisible(TRUE))
# nocov end
}
}
# Usage:
# i) tests that x equals y when both x and y are supplied, the most common usage
# ii) tests that x is TRUE when y isn't supplied
Expand Down
Loading
Loading