-
Notifications
You must be signed in to change notification settings - Fork 1k
RFC: fail test.data.table() if non-test code produces warnings
#7210
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
Conversation
|
Generated via commit 3ddef1a Download link for the artifact containing the test results: ↓ atime-results.zip
|
|
Personally I like requiring warnings to be handled properly everywhere, I'm a fan of setting If it's really a stupid/spurious warning, just That |
| local(if (l10n_info()$`UTF-8` || { | ||
| lc_ctype = Sys.getlocale('LC_CTYPE') | ||
| lc_wantctype = 'en_US.UTF-8' | ||
| # Japanese multibyte characters require utf8. As of 2025, we're likely to be already running in a UTF-8 locale, but if not, try this setlocale() call as a last chance. | ||
| # Unfortunately, there is no guaranteed, portable way of switching to UTF-8 US English. | ||
| if (!l10n_info()$`UTF-8`) Sys.setlocale('LC_CTYPE', "en_US.UTF-8") | ||
| on.exit(Sys.setlocale('LC_CTYPE', lc_ctype)) | ||
| lc_newctype = suppressWarnings(Sys.setlocale('LC_CTYPE', lc_wantctype)) | ||
| if (identical(lc_newctype, lc_wantctype)) { | ||
| on.exit(Sys.setlocale('LC_CTYPE', lc_ctype)) | ||
| TRUE | ||
| } else FALSE | ||
| }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeking suggestions for how to improve this test. The logic is as follows:
- If
l10n_info()$`UTF-8`, that's fine, proceed with the tests. - Otherwise, try to set the UTF-8 charset from the
en_US.UTF-8locale.- If succeeded, use
on.exit()to restore the locale afterwards and proceed with the tests.
- If succeeded, use
- Otherwise, skip the tests.
The current code works, but putting if with side effects inside another if doesn't feel like a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's ugly, but it looks sound.
if anything, maybe we would just move it inside test.data.table() like foreign:
data.table/R/test.data.table.R
Lines 119 to 125 in 39e2875
| foreign = gettext("object '%s' not found", domain="R") != "object '%s' not found" | |
| if (foreign) { | |
| # nocov start | |
| catf("\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") | |
| # nocov end | |
| } | |
| assign("foreign", foreign, envir=env) |
Then we just do, say, if (supports_en_utf) local(...).
It would also facilitate if this sort of check would make other tests easier, we don't need to duplicate this complicated logic more than once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be simpler but no less reliable if we skipped these tests when an enc2native() check fails, but I opened #7217 because there are other tests in a similar position, outside the scope of this PR.
On modern versions of R for Windows, Sys.setlocale() warns for non-UTF-8 locales. Also comment the previous instance of suppressWarnings().
R/test.data.table.R
Outdated
| # nocov start | ||
| if (!silent && showProgress) print(w) | ||
| env$warnings = c(env$warnings, list(list( | ||
| env$prevtest, toString(w), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not conditionMessage()?
should we give this object a bit more structure, e.g. name the elements for clarity? I see it's done below
* conditionMessage() instead of toString() * apply names earlier * don't check for zero-length calls in sys.calls() * be careful not to over-translate an already-translated message Co-Authored-By: Michael Chirico <michaelchirico4@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7210 +/- ##
=======================================
Coverage 98.77% 98.77%
=======================================
Files 81 81
Lines 15215 15237 +22
=======================================
+ Hits 15029 15051 +22
Misses 186 186 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|

Related to #7209. I happened to notice the warning while looking at unrelated failures. Should
test.data.table()explicitly go looking for warnings produced by code outside thetest()calls and failR CMD checkbecause of them?Pros: sometimes there's a good reason to fix the warning (like #7209).
Cons: sometimes warnings happen for stupid reasons outside our direct control. For example, a system that neither currently has a UTF-8 locale set nor has
en_US.UTF-8installed will cause a warning between tests 2252.2 and 2253.01, because thesetlocale()call will fail:https://github.com/Rdatatable/data.table/blob/63339e1bf4a65b1821c0c5a7019270d34e63346e/inst/tests/tests.Rraw#L18619-L18623