Skip to content
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

Fragile tests relying on exact messaging of lintr output #231

Open
MichaelChirico opened this issue Feb 12, 2025 · 0 comments
Open

Fragile tests relying on exact messaging of lintr output #231

MichaelChirico opened this issue Feb 12, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@MichaelChirico
Copy link
Contributor

What happened?

These two tests break under the current development version of R which is in the process of being released to CRAN:

expected <- paste0(
"Line 6 [library_call_linter] Move all library calls to the ",
"top of the script.\n\nLine 8 [undesirable_operator_linter] Operator ",
"`<<-` is undesirable. It\nassigns outside the current environment in a ",
"way that can be hard to reason\nabout. Prefer fully-encapsulated ",
"functions wherever possible, or, if\nnecessary, assign to a specific ",
"environment with assign(). Recall that you\ncan create an environment ",
"at the desired scope with new.env()."
)

"Line 3 [undesirable_operator_linter] Operator `<<-` is undesirable.",
" It\nassigns outside the current environment in a way that can be hard",
" to reason\nabout. Prefer fully-encapsulated functions wherever possible,",
" or, if\nnecessary, assign to a specific environment with assign(). ",
"Recall that you\ncan create an environment at the desired scope with",
" new.env().\n\nLine 4 [undesirable_operator_linter] Operator `<<-` is",
" undesirable. It\nassigns outside the current environment in a way that",
" can be hard to reason\nabout. Prefer fully-encapsulated functions",
" wherever possible, or, if\nnecessary, assign to a specific environment",
" with assign(). Recall that you\ncan create an environment at the",
" desired scope with new.env()."

In general, I try and avoid relying on fragile things like "the exact wording of an error message produced by an upstream package".

For example, in {data.table}, we have this list of messages/message factories for test outputs that come directly from {base} R:

https://github.com/Rdatatable/data.table/blob/c29e313dac1de8b959f5e3438c33c0d00873be05/inst/tests/tests.Rraw#L176-L201

I will submit a quick-fix PR shortly, but it's worth thinking through a more robust way to structure these tests going forward.

Session Information

No response

Reproducible Example

No response

@MichaelChirico MichaelChirico added the bug Something isn't working label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant