Skip to content

Conversation

@aitap
Copy link
Member

@aitap aitap commented Jul 24, 2025

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 the test() calls and fail R CMD check because 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-8 installed will cause a warning between tests 2252.2 and 2253.01, because the setlocale() call will fail:

https://github.com/Rdatatable/data.table/blob/63339e1bf4a65b1821c0c5a7019270d34e63346e/inst/tests/tests.Rraw#L18619-L18623

@aitap aitap requested a review from MichaelChirico as a code owner July 24, 2025 19:59
@github-actions
Copy link

github-actions bot commented Jul 24, 2025

  • HEAD=test-warnings slower P<0.001 for memrecycle regression fixed in #5463
    Comparison Plot

Generated via commit 3ddef1a

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 2 minutes and 55 seconds
Installing different package versions 59 seconds
Running and plotting the test cases 2 minutes and 52 seconds

@MichaelChirico
Copy link
Member

MichaelChirico commented Jul 24, 2025

Personally I like requiring warnings to be handled properly everywhere, I'm a fan of setting options(warn=2) in my own {testthat} suites, for example.

If it's really a stupid/spurious warning, just suppressWarnings() and move on.

That setlocale() example is a case in point -- we should maybe skip some tests where we assume we're allowed to change locales, but can't, that could have unanticipated results.

Comment on lines 18618 to 18628
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
}) {
Copy link
Member Author

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:

  1. If l10n_info()$`UTF-8`, that's fine, proceed with the tests.
  2. Otherwise, try to set the UTF-8 charset from the en_US.UTF-8 locale.
    • If succeeded, use on.exit() to restore the locale afterwards and proceed with the tests.
  3. Otherwise, skip the tests.

The current code works, but putting if with side effects inside another if doesn't feel like a good idea.

Copy link
Member

@MichaelChirico MichaelChirico Jul 27, 2025

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:

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.

Copy link
Member Author

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().
# nocov start
if (!silent && showProgress) print(w)
env$warnings = c(env$warnings, list(list(
env$prevtest, toString(w),
Copy link
Member

@MichaelChirico MichaelChirico Jul 27, 2025

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
Copy link

codecov bot commented Jul 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.77%. Comparing base (ca30752) to head (3ddef1a).
⚠️ Report is 4 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MichaelChirico MichaelChirico merged commit 1e38fc2 into master Jul 28, 2025
12 checks passed
@MichaelChirico MichaelChirico deleted the test-warnings branch July 28, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants