Skip to content

Fragile tests relying on exact messaging of lintr output #231

@MichaelChirico

Description

@MichaelChirico

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions