From 5a0bbc2f3cbb282a387fd419465d2d8e59b1262b Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 9 May 2019 18:42:57 +0800 Subject: [PATCH 1/4] seed of attempt at #3039 --- R/test.data.table.R | 3 +++ inst/tests/tests.Rraw | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/R/test.data.table.R b/R/test.data.table.R index c79a211446..96c7ee7b04 100644 --- a/R/test.data.table.R +++ b/R/test.data.table.R @@ -60,6 +60,9 @@ test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE, with.other.p cat("Running", fn, "\n") env = new.env(parent=.GlobalEnv) assign("testDir", function(x) file.path(fulldir, x), envir=env) + # if a translated error is expected from base, compare the error + # produced by data.table to that from base, #3039 + assign("get_base_error", function(expr) tryCatch(expr, error = function(e) e$message), envir = env) assign("nfail", 0L, envir=env) assign("ntest", 0L, envir=env) assign("whichfail", NULL, envir=env) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 043d37d3f3..b8116c6cc5 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -415,7 +415,7 @@ xx = capture.output(ans <- DT[,{print(x);sum(y)},by=x,verbose=FALSE]) test(145, xx, c("[1] \"a\"","[1] \"b\"")) test(146, ans, data.table(x=c("a","b"),V1=c(3L,12L))) -test(147, DT[,MySum=sum(v)], error="unused argument") # user meant DT[,list(MySum=sum(v))]. FR#204 done. +test(147, DT[,MySum=sum(v)], error=get_base_error((function(){})(MySum = sum(v)))) # user meant DT[,list(MySum=sum(v))]. FR#204 done. dt = data.table(a=c(1L,4L,5L), b=1:3, key="a") test(148, dt[CJ(2:3),roll=TRUE], data.table(a=c(2L,3L),b=c(1L,1L),key="a")) From 84dbf12d63abe8de7a9862c65eea3af85b290dbe Mon Sep 17 00:00:00 2001 From: mattdowle Date: Thu, 16 May 2019 16:55:10 -0700 Subject: [PATCH 2/4] message text check off when foreign --- CRAN_Release.cmd | 5 +++++ NEWS.md | 2 ++ R/test.data.table.R | 13 +++++++++---- inst/tests/tests.Rraw | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CRAN_Release.cmd b/CRAN_Release.cmd index 649c86a446..9b5c9b4357 100644 --- a/CRAN_Release.cmd +++ b/CRAN_Release.cmd @@ -121,6 +121,11 @@ q("no") R CMD check data.table_1.12.3.tar.gz rm ~/.Renviron +# Test non-English does not break test.data.table() due to translation of messages; #3039, #630 +LANGUAGE=de R +require(data.table) +test.data.table() + R remove.packages("xml2") # we checked the URLs; don't need to do it again (many minutes) require(data.table) diff --git a/NEWS.md b/NEWS.md index ca415e1689..719c9b52dc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -102,6 +102,8 @@ 10. `externalVar=1:5; DT[, mean(externalVar), by=group]` could return incorrect results rather than a constant (`3` in this example) for each group, [#875](https://github.com/Rdatatable/data.table/issues/875). GForce optimization was being applied incorrectly to the `mean` without realizing `externalVar` was not a column. +11. `test.data.table()` now passes in non-English R sessions, [#630](https://github.com/Rdatatable/data.table/issues/630) [#3039](https://github.com/Rdatatable/data.table/issues/3039). Each test still checks that the number of warnings and/or errors produced is correct. However, a message is displayed suggesting to restart R with `LANGUAGE=en` in order to test that the text of the warning and/or error messages are as expected, too. + #### NOTES 1. `rbindlist`'s `use.names="check"` now emits its message for automatic column names (`"V[0-9]+"`) too, [#3484](https://github.com/Rdatatable/data.table/pull/3484). See news item 5 of v1.12.2 below. diff --git a/R/test.data.table.R b/R/test.data.table.R index 5555ab97e7..56a0fd5fae 100644 --- a/R/test.data.table.R +++ b/R/test.data.table.R @@ -60,9 +60,13 @@ test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE, with.other.p cat("Running", fn, "\n") env = new.env(parent=.GlobalEnv) assign("testDir", function(x) file.path(fulldir, x), envir=env) - # if a translated error is expected from base, compare the error - # produced by data.table to that from base, #3039 - assign("get_base_error", function(expr) tryCatch(expr, error = function(e) e$message), envir = env) + + # are R's messages being translated to a foreign language? #3039, #630 + txt = eval(parse(text="tryCatch(mean(notexist), error = function(e) e$message)"), envir=.GlobalEnv) + foreign = txt != "argument is not numeric or logical: returning NA" + if (foreign) cat("\n**** This R session's language is not English. Each test will still check that the correct number of errors and/or\n", + "**** warnings are produced. However, to test the text of each error/warning too, please restart R with LANGUAGE=en\n\n", sep="") + assign("foreign", foreign, envir=env) assign("nfail", 0L, envir=env) assign("ntest", 0L, envir=env) assign("prevtest", -1, envir=env) @@ -224,6 +228,7 @@ test <- function(num,x,y=TRUE,error=NULL,warning=NULL,output=NULL,message=NULL) memtest = get("memtest", parent.frame()) inittime = get("inittime", parent.frame()) filename = get("filename", parent.frame()) + foreign = get("foreign", parent.frame()) time = nTest = NULL # to avoid 'no visible binding' note on.exit( { now = proc.time()[3] @@ -303,7 +308,7 @@ test <- function(num,x,y=TRUE,error=NULL,warning=NULL,output=NULL,message=NULL) } else { # the expected type occurred and, if more than 1 of that type, in the expected order for (i in seq_along(expected)) { - if (!string_match(expected[i], observed[i])) { + if (!foreign && !string_match(expected[i], observed[i])) { # nocov start cat("Test",numStr,"didn't produce the correct",type,":\n") cat("Expected:", expected[i], "\n") diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 7a6e45d308..749fd54f9c 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -414,7 +414,7 @@ xx = capture.output(ans <- DT[,{print(x);sum(y)},by=x,verbose=FALSE]) test(145, xx, c("[1] \"a\"","[1] \"b\"")) test(146, ans, data.table(x=c("a","b"),V1=c(3L,12L))) -test(147, DT[,MySum=sum(v)], error=get_base_error((function(){})(MySum = sum(v)))) # user meant DT[,list(MySum=sum(v))]. FR#204 done. +test(147, DT[,MySum=sum(v)], error="unused argument") # user meant DT[,list(MySum=sum(v))]. FR#204 done. dt = data.table(a=c(1L,4L,5L), b=1:3, key="a") test(148, dt[CJ(2:3),roll=TRUE], data.table(a=c(2L,3L),b=c(1L,1L),key="a")) From 78353e5f76da7ad671376f2a244b11c7b73ed077 Mon Sep 17 00:00:00 2001 From: mattdowle Date: Thu, 16 May 2019 17:03:31 -0700 Subject: [PATCH 3/4] fixed typo --- R/test.data.table.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/test.data.table.R b/R/test.data.table.R index 56a0fd5fae..4aad45096e 100644 --- a/R/test.data.table.R +++ b/R/test.data.table.R @@ -62,8 +62,8 @@ test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE, with.other.p assign("testDir", function(x) file.path(fulldir, x), envir=env) # are R's messages being translated to a foreign language? #3039, #630 - txt = eval(parse(text="tryCatch(mean(notexist), error = function(e) e$message)"), envir=.GlobalEnv) - foreign = txt != "argument is not numeric or logical: returning NA" + txt = eval(parse(text="tryCatch(mean(not__exist__), error = function(e) e$message)"), envir=.GlobalEnv) + foreign = txt != "object 'not__exist__' not found" if (foreign) cat("\n**** This R session's language is not English. Each test will still check that the correct number of errors and/or\n", "**** warnings are produced. However, to test the text of each error/warning too, please restart R with LANGUAGE=en\n\n", sep="") assign("foreign", foreign, envir=env) From d5d1cf702c9518df07fcf5eab9a1bb37c666fb31 Mon Sep 17 00:00:00 2001 From: mattdowle Date: Thu, 16 May 2019 17:20:59 -0700 Subject: [PATCH 4/4] coverage --- R/test.data.table.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/test.data.table.R b/R/test.data.table.R index 4aad45096e..7f161b3bdc 100644 --- a/R/test.data.table.R +++ b/R/test.data.table.R @@ -64,8 +64,12 @@ test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE, with.other.p # are R's messages being translated to a foreign language? #3039, #630 txt = eval(parse(text="tryCatch(mean(not__exist__), error = function(e) e$message)"), envir=.GlobalEnv) foreign = txt != "object 'not__exist__' not found" - if (foreign) cat("\n**** This R session's language is not English. Each test will still check that the correct number of errors and/or\n", - "**** warnings are produced. However, to test the text of each error/warning too, please restart R with LANGUAGE=en\n\n", sep="") + if (foreign) { + # nocov start + cat("\n**** This R session's language is not English. Each test will still check that the correct number of errors and/or\n", + "**** warnings are produced. However, to test the text of each error/warning too, please restart R with LANGUAGE=en\n\n", sep="") + # nocov end + } assign("foreign", foreign, envir=env) assign("nfail", 0L, envir=env) assign("ntest", 0L, envir=env)