Skip to content

Test for infinite recursion error? #1944

Open
@mmuurr

Description

@mmuurr

As part of developing a package there's a specific pattern I want to detect that leads to an infinite recursion error. (If this error ever doesn't happen, then it's likely I broke something in the logic, hence my desire to test for it.)

This test fails:

f <- function() f()
expect_error(f())
# Error: C stack usage 9522952 is too close to the limit

This passes, but is a bit clunky:

f <- function() f()
tryCatch({
  f()
  TRUE
}, error = \(e) {
  FALSE
}) |> expect_false()

Should that first expect_error() test fail, given that the second passes?

({testthat} v3.2.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions