Skip to content

feat: locale-collation guard in r:cran-prep (scan plus emulation) #162

Backlog

Description

@Data-Wise

Type: feature

Context: found while shipping medfit 0.22.2, a CRAN fix release (medfit 0.21.3 showed a tests ERROR on three macOS flavors on CRAN's check page).

Evidence

A medfit test called Sys.setlocale("LC_COLLATE", "en_US.UTF-8") and assumed the platform honors it. CRAN's macOS builders accept the locale but still sort in C order, so the test failed there only. testthat pins collation to C inside tests, so re-running the suite under several LC_ALL values finds nothing (measured). What did work: (1) a scan for tests that call Sys.setlocale, local_collate, with_locale and similar without a guard, and (2) a run under LC_ALL=C with Sys.setlocale masked so it accepts a locale without changing it, which reproduced the single CRAN failure on the v0.21.3 tag.

Proposed change

Add both as an advisory tier in r:cran-prep: the scan (label each file guarded, exempt or unguarded) and the masked-Sys.setlocale run. A reference implementation is scripts/assess.sh and scripts/emulate-locale.R in medfit (phases locale-use, locale-emul).

Acceptance test (must be able to fail)

A planted unguarded Sys.setlocale test fails the tier; the same test with a skip guard passes.


Update 2026-12-02 (evening)

Status of the reference implementation in medfit, all merged: the collation_is_c() helper (Data-Wise/medfit#596); test-locale-guard.R, which fails a test file that changes the locale without the helper or a listed exemption (#601) and runs in hosted and CRAN runs (#605); assess.sh labels each file guarded, exempt or unguarded (#609).

One defect found after the first version belongs in the acceptance test: the scan matched collation_is_c( inside a comment, so a commented-out guard counted as a guard (#611). A comment line containing the guard name must not count as guarded.

Locale variety on CRAN's flavors (flavor page, read 2026-12-03): en_US.UTF-8 on macOS, en_GB.UTF-8 on Fedora, C.UTF-8 on Debian and German_Germany.utf8 on Windows. The scan should also list tests that depend on the locale without setting it (for example text sorting), because those can differ across these four.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions